From 3c0e33136358c6f32ecf507c09021a7d72014dee Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 15 Nov 2022 12:17:18 +0100 Subject: [PATCH 001/109] Gizmo measure modified to accept single full instance selection, to combine the volumes meshes into a single mesh and pass it to the back end after transform it in world coordinates Changes embedded into tech ENABLE_GIZMO_MEASURE_WORLD_COORDINATES --- src/libslic3r/Measure.cpp | 37 ++++ src/libslic3r/Measure.hpp | 19 +- src/libslic3r/Technologies.hpp | 2 + src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 215 ++++++++++++++++++++++- src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp | 35 ++++ src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp | 13 ++ src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp | 7 + src/slic3r/GUI/Selection.cpp | 13 ++ src/slic3r/GUI/Selection.hpp | 4 + 9 files changed, 338 insertions(+), 7 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 43b9782a83..1ffd72c14d 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -45,6 +45,9 @@ public: std::optional get_feature(size_t face_idx, const Vec3d& point) const; std::vector> get_planes_triangle_indices() const; const std::vector& get_plane_features(unsigned int plane_id) const; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const TriangleMesh& get_mesh() const; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES private: void update_planes(); @@ -52,7 +55,11 @@ private: std::vector m_planes; std::vector m_face_to_plane; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + TriangleMesh m_mesh; +#else const indexed_triangle_set& m_its; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES }; @@ -61,7 +68,11 @@ private: MeasuringImpl::MeasuringImpl(const indexed_triangle_set& its) +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +: m_mesh(its) +#else : m_its{its} +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES { update_planes(); extract_features(); @@ -74,10 +85,17 @@ void MeasuringImpl::update_planes() // Now we'll go through all the facets and append Points of facets sharing the same normal. // This part is still performed in mesh coordinate system. +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const size_t num_of_facets = m_mesh.its.indices.size(); + m_face_to_plane.resize(num_of_facets, size_t(-1)); + const std::vector face_normals = its_face_normals(m_mesh.its); + const std::vector face_neighbors = its_face_neighbors(m_mesh.its); +#else const size_t num_of_facets = m_its.indices.size(); m_face_to_plane.resize(num_of_facets, size_t(-1)); const std::vector face_normals = its_face_normals(m_its); const std::vector face_neighbors = its_face_neighbors(m_its); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES std::vector facet_queue(num_of_facets, 0); int facet_queue_cnt = 0; const stl_normal* normal_ptr = nullptr; @@ -126,7 +144,11 @@ void MeasuringImpl::update_planes() assert(std::none_of(m_face_to_plane.begin(), m_face_to_plane.end(), [](size_t val) { return val == size_t(-1); })); // Now we will walk around each of the planes and save vertices which form the border. +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + SurfaceMesh sm(m_mesh.its); +#else SurfaceMesh sm(m_its); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES for (int plane_id=0; plane_id < int(m_planes.size()); ++plane_id) { const auto& facets = m_planes[plane_id].facets; m_planes[plane_id].borders.clear(); @@ -508,6 +530,12 @@ const std::vector& MeasuringImpl::get_plane_features(unsigned in return m_planes[plane_id].surface_features; } +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +const TriangleMesh& MeasuringImpl::get_mesh() const +{ + return this->m_mesh; +} +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES @@ -549,6 +577,13 @@ const std::vector& Measuring::get_plane_features(unsigned int pl return priv->get_plane_features(plane_id); } +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +const TriangleMesh& Measuring::get_mesh() const +{ + return priv->get_mesh(); +} +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const AngleAndEdges AngleAndEdges::Dummy = { 0.0, Vec3d::Zero(), { Vec3d::Zero(), Vec3d::Zero() }, { Vec3d::Zero(), Vec3d::Zero() }, 0.0, true }; static AngleAndEdges angle_edge_edge(const std::pair& e1, const std::pair& e2) @@ -1147,6 +1182,7 @@ MeasurementResult get_measurement(const SurfaceFeature& a, const SurfaceFeature& return result; } +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES void DistAndPoints::transform(const Transform3d& trafo) { from = trafo * from; to = trafo * to; @@ -1167,6 +1203,7 @@ void AngleAndEdges::transform(const Transform3d& trafo) { const double average_scale = 0.5 * (new_e1.norm() / old_e1.norm() + new_e2.norm() / old_e2.norm()); radius = average_scale * radius; } +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES diff --git a/src/libslic3r/Measure.hpp b/src/libslic3r/Measure.hpp index ede8c634ee..b2e2008d15 100644 --- a/src/libslic3r/Measure.hpp +++ b/src/libslic3r/Measure.hpp @@ -87,9 +87,11 @@ class MeasuringImpl; class Measuring { public: - // Construct the measurement object on a given its. The its must remain - // valid and unchanged during the whole lifetime of the object. - explicit Measuring(const indexed_triangle_set& its); + // Construct the measurement object on a given its. +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + // The its must remain valid and unchanged during the whole lifetime of the object. +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + explicit Measuring(const indexed_triangle_set& its); ~Measuring(); // Return a reference to a list of all features identified on the its. @@ -108,6 +110,11 @@ public: // Returns the surface features of the plane with the given index const std::vector& get_plane_features(unsigned int plane_id) const; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + // Returns the mesh used for measuring + const TriangleMesh& get_mesh() const; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + private: std::unique_ptr priv; }; @@ -119,7 +126,9 @@ struct DistAndPoints { Vec3d from; Vec3d to; +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES void transform(const Transform3d& trafo); +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES }; struct AngleAndEdges { @@ -132,7 +141,9 @@ struct AngleAndEdges { double radius; bool coplanar; +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES void transform(const Transform3d& trafo); +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES static const AngleAndEdges Dummy; }; @@ -151,6 +162,7 @@ struct MeasurementResult { return angle.has_value() || distance_infinite.has_value() || distance_strict.has_value() || distance_xyz.has_value(); } +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES void transform(const Transform3d& trafo) { if (angle.has_value()) angle->transform(trafo); @@ -161,6 +173,7 @@ struct MeasurementResult { distance_xyz = (distance_strict->to - distance_strict->from).cwiseAbs(); } } +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES }; // Returns distance/angle between two SurfaceFeatures. diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index a3e72cf0c5..9e7c660ae0 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -64,6 +64,8 @@ // Enable picking using raytracing #define ENABLE_RAYCAST_PICKING (1 && ENABLE_LEGACY_OPENGL_REMOVAL) #define ENABLE_RAYCAST_PICKING_DEBUG (0 && ENABLE_RAYCAST_PICKING) +// Enable gizmo measure combining volumes meshes and passing them to the backend in world coordinates +#define ENABLE_GIZMO_MEASURE_WORLD_COORDINATES (1 && ENABLE_2_5_0_ALPHA1) #endif // _prusaslicer_technologies_h_ diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 8b26422c8f..5ae906eac9 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -5,9 +5,11 @@ #include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/GUI_ObjectManipulation.hpp" -#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" #include "libslic3r/Model.hpp" +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES #include "libslic3r/PresetBundle.hpp" #include "libslic3r/MeasureUtils.hpp" @@ -242,7 +244,10 @@ private: TransformHelper::Cache TransformHelper::s_cache = { { 0, 0, 0, 0 }, Matrix4d::Identity(), Transform3d::Identity() }; GLGizmoMeasure::GLGizmoMeasure(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) - : GLGizmoBase(parent, icon_filename, sprite_id) +: GLGizmoBase(parent, icon_filename, sprite_id) +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +, m_raycaster(nullptr) +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES { GLModel::Geometry sphere_geometry = smooth_sphere(16, 7.5f); m_sphere.mesh_raycaster = std::make_unique(std::make_shared(sphere_geometry.get_as_indexed_triangle_set())); @@ -370,8 +375,10 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) if (m_selected_features != selected_features_old && m_selected_features.second.feature.has_value()) { m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // transform to world coordinates m_measurement_result.transform(m_volume_matrix); +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } m_imgui->set_requires_extra_frame(); @@ -419,6 +426,9 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) void GLGizmoMeasure::data_changed() { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + update_if_needed(); +#else const Selection& selection = m_parent.get_selection(); const ModelObject* model_object = nullptr; const ModelVolume* model_volume = nullptr; @@ -429,13 +439,16 @@ void GLGizmoMeasure::data_changed() } if (model_object != m_old_model_object || model_volume != m_old_model_volume) update_if_needed(); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES m_last_inv_zoom = 0.0f; m_last_plane_idx = -1; if (m_pending_scale) { m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // transform to world coordinates m_measurement_result.transform(m_volume_matrix); +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES m_pending_scale = false; } else @@ -512,6 +525,9 @@ void GLGizmoMeasure::on_set_state() m_editing_distance = false; m_is_editing_distance_first_frame = true; m_measuring.reset(); +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + m_raycaster.release(); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } else { m_mode = EMode::FeatureSelection; @@ -528,10 +544,12 @@ void GLGizmoMeasure::on_set_state() } } +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES CommonGizmosDataID GLGizmoMeasure::on_get_requirements() const { return CommonGizmosDataID(int(CommonGizmosDataID::SelectionInfo) | int(CommonGizmosDataID::Raycaster)); } +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES std::string GLGizmoMeasure::on_get_name() const { @@ -543,9 +561,15 @@ bool GLGizmoMeasure::on_is_activable() const const Selection& selection = m_parent.get_selection(); bool res = (wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA) ? selection.is_single_full_instance() : +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + selection.is_single_full_instance() || selection.is_single_volume() || selection.is_single_modifier(); + if (res) + res &= !selection.contains_sinking_volumes(); +#else selection.is_single_volume() || selection.is_single_volume_instance(); if (res) res &= !selection.get_first_volume()->is_sinking(); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES return res; } @@ -562,8 +586,10 @@ void GLGizmoMeasure::on_render() const Selection& selection = m_parent.get_selection(); +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES if ((wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA && selection.is_single_full_instance()) || (selection.is_single_volume() || selection.is_single_volume_instance())) { +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES update_if_needed(); const Camera& camera = wxGetApp().plater()->get_camera(); @@ -572,7 +598,11 @@ void GLGizmoMeasure::on_render() Vec3f position_on_model; Vec3f normal_on_model; size_t model_facet_idx; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const bool mouse_on_object = m_raycaster.raycaster()->unproject_on_mesh(m_mouse_pos, Transform3d::Identity(), camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); +#else const bool mouse_on_object = m_c->raycaster()->raycasters().front()->unproject_on_mesh(m_mouse_pos, m_volume_matrix, camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const bool is_hovering_on_feature = (m_mode == EMode::PointSelection || m_mode == EMode::CenterSelection) && m_hover_id != -1; auto update_circle = [this, inv_zoom]() { @@ -581,7 +611,11 @@ void GLGizmoMeasure::on_render() m_last_circle = m_curr_feature; m_circle.reset(); const auto [center, radius, normal] = m_curr_feature->get_circle(); +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); +#else GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), m_volume_matrix.cast()); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES m_circle.mesh_raycaster = std::make_unique(std::make_shared(circle_geometry.get_as_indexed_triangle_set())); m_circle.model.init_from(std::move(circle_geometry)); return true; @@ -639,7 +673,11 @@ void GLGizmoMeasure::on_render() const auto [idx, normal, point] = m_curr_feature->get_plane(); if (m_last_plane_idx != idx) { m_last_plane_idx = idx; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const indexed_triangle_set& its = m_measuring->get_mesh().its; +#else const indexed_triangle_set its = (m_old_model_volume != nullptr) ? m_old_model_volume->mesh().its : m_old_model_object->volumes.front()->mesh().its; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const std::vector> planes_triangles = m_measuring->get_planes_triangle_indices(); GLModel::Geometry init_data = init_plane_data(its, planes_triangles, idx); m_plane.reset(); @@ -689,12 +727,20 @@ void GLGizmoMeasure::on_render() if (extra.has_value() && m_hover_id == POINT_ID) m_curr_point_on_feature_position = *extra; else +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + m_curr_point_on_feature_position = position_on_feature(EDGE_ID, camera, [](const Vec3f& v) { return Vec3f(0.0f, 0.0f, v.z()); }); +#else m_curr_point_on_feature_position = m_volume_matrix.inverse() * position_on_feature(EDGE_ID, camera, [](const Vec3f& v) { return Vec3f(0.0f, 0.0f, v.z()); }); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES break; } case Measure::SurfaceFeatureType::Plane: { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + m_curr_point_on_feature_position = position_on_feature(PLANE_ID, camera); +#else m_curr_point_on_feature_position = m_volume_matrix.inverse() * position_on_feature(PLANE_ID, camera); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES break; } case Measure::SurfaceFeatureType::Circle: @@ -704,9 +750,17 @@ void GLGizmoMeasure::on_render() m_curr_point_on_feature_position = center; else { const Vec3d world_pof = position_on_feature(CIRCLE_ID, camera, [](const Vec3f& v) { return v; }); +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Eigen::Hyperplane plane(normal, center); +#else const Eigen::Hyperplane plane(m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal, m_volume_matrix * center); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const Transform3d local_to_model_matrix = Geometry::translation_transform(center) * Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), normal); +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Vec3d local_proj = local_to_model_matrix.inverse() * plane.projection(world_pof); +#else const Vec3d local_proj = local_to_model_matrix.inverse() * m_volume_matrix.inverse() * plane.projection(world_pof); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES double angle = std::atan2(local_proj.y(), local_proj.x()); if (angle < 0.0) angle += 2.0 * double(M_PI); @@ -767,8 +821,12 @@ void GLGizmoMeasure::on_render() default: { assert(false); break; } case Measure::SurfaceFeatureType::Point: { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Transform3d feature_matrix = Geometry::translation_transform(feature.get_point()) * Geometry::scale_transform(inv_zoom); +#else const Vec3d position = TransformHelper::model_to_world(feature.get_point(), m_volume_matrix); const Transform3d feature_matrix = Geometry::translation_transform(position) * Geometry::scale_transform(inv_zoom); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES set_matrix_uniforms(feature_matrix); set_emission_uniform(colors.front(), hover); m_sphere.model.set_color(colors.front()); @@ -785,8 +843,12 @@ void GLGizmoMeasure::on_render() const auto& [center, radius, normal] = feature.get_circle(); // render center if (update_raycasters_transform) { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Transform3d center_matrix = Geometry::translation_transform(center) * Geometry::scale_transform(inv_zoom); +#else const Vec3d center_world = TransformHelper::model_to_world(center, m_volume_matrix); const Transform3d center_matrix = Geometry::translation_transform(center_world) * Geometry::scale_transform(inv_zoom); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES set_matrix_uniforms(center_matrix); set_emission_uniform(colors.front(), hover); m_sphere.model.set_color(colors.front()); @@ -809,7 +871,11 @@ void GLGizmoMeasure::on_render() } else { GLModel circle; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); +#else GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), m_volume_matrix.cast()); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES circle.init_from(std::move(circle_geometry)); set_emission_uniform(colors.back(), hover); circle.set_color(colors.back()); @@ -825,8 +891,12 @@ void GLGizmoMeasure::on_render() if (update_raycasters_transform) { const std::optional extra = feature.get_extra_point(); if (extra.has_value()) { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Transform3d point_matrix = Geometry::translation_transform(*extra) * Geometry::scale_transform(inv_zoom); +#else const Vec3d extra_world = TransformHelper::model_to_world(*extra, m_volume_matrix); const Transform3d point_matrix = Geometry::translation_transform(extra_world) * Geometry::scale_transform(inv_zoom); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES set_matrix_uniforms(point_matrix); set_emission_uniform(colors.front(), hover); m_sphere.model.set_color(colors.front()); @@ -838,11 +908,17 @@ void GLGizmoMeasure::on_render() } // render edge if (m_mode != EMode::CenterSelection) { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Transform3d edge_matrix = Geometry::translation_transform(from) * + Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), to - from) * + Geometry::scale_transform({ (double)inv_zoom, (double)inv_zoom, (to - from).norm() }); +#else const Vec3d from_world = TransformHelper::model_to_world(from, m_volume_matrix); const Vec3d to_world = TransformHelper::model_to_world(to, m_volume_matrix); const Transform3d edge_matrix = Geometry::translation_transform(from_world) * Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), to_world - from_world) * Geometry::scale_transform({ (double)inv_zoom, (double)inv_zoom, (to_world - from_world).norm() }); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES set_matrix_uniforms(edge_matrix); set_emission_uniform(colors.back(), hover); m_cylinder.model.set_color(colors.back()); @@ -861,7 +937,11 @@ void GLGizmoMeasure::on_render() if (colors.front() != m_parent.get_selection().get_first_volume()->render_color) { const auto& [idx, normal, pt] = feature.get_plane(); assert(idx < m_plane_models_cache.size()); +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + set_matrix_uniforms(Transform3d::Identity()); +#else set_matrix_uniforms(m_volume_matrix); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES set_emission_uniform(colors.front(), hover); m_plane_models_cache[idx].set_color(colors.front()); m_plane_models_cache[idx].render(); @@ -869,7 +949,11 @@ void GLGizmoMeasure::on_render() if (update_raycasters_transform) { auto it = m_raycasters.find(PLANE_ID); if (it != m_raycasters.end() && it->second != nullptr) +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + it->second->set_transform(Transform3d::Identity()); +#else it->second->set_transform(m_volume_matrix); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } break; } @@ -924,7 +1008,11 @@ void GLGizmoMeasure::on_render() auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_1_ID; }); if (it != m_selection_raycasters.end()) +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + (*it)->set_transform(Geometry::translation_transform(m_selected_features.first.feature->get_point()) * Geometry::scale_transform(inv_zoom)); +#else (*it)->set_transform(m_volume_matrix * Geometry::translation_transform(m_selected_features.first.feature->get_point()) * Geometry::scale_transform(inv_zoom)); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } } if (m_selected_features.second.feature.has_value() && (!m_curr_feature.has_value() || *m_curr_feature != *m_selected_features.second.feature)) { @@ -934,14 +1022,22 @@ void GLGizmoMeasure::on_render() auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_2_ID; }); if (it != m_selection_raycasters.end()) +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + (*it)->set_transform(Geometry::translation_transform(m_selected_features.second.feature->get_point()) * Geometry::scale_transform(inv_zoom)); +#else (*it)->set_transform(m_volume_matrix * Geometry::translation_transform(m_selected_features.second.feature->get_point()) * Geometry::scale_transform(inv_zoom)); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } } if (is_hovering_on_feature && m_curr_point_on_feature_position.has_value()) { if (m_hover_id != POINT_ID) { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Transform3d matrix = Geometry::translation_transform(*m_curr_point_on_feature_position) * Geometry::scale_transform(inv_zoom); +#else const Vec3d position = TransformHelper::model_to_world(*m_curr_point_on_feature_position, m_volume_matrix); const Transform3d matrix = Geometry::translation_transform(position) * Geometry::scale_transform(inv_zoom); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES set_matrix_uniforms(matrix); const ColorRGBA color = hover_selection_color(); set_emission_uniform(color, true); @@ -954,7 +1050,9 @@ void GLGizmoMeasure::on_render() if (old_cullface) glsafe(::glEnable(GL_CULL_FACE)); +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES render_dimensioning(); } @@ -971,6 +1069,24 @@ void GLGizmoMeasure::update_if_needed() } }; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + auto do_update = [this, update_plane_models_cache](const std::vector& volumes_cache, const Selection& selection) { + TriangleMesh composite_mesh; + for (const auto& vol : volumes_cache) { +// if (selection.is_single_full_instance() && vol.volume->is_modifier()) +// continue; + + TriangleMesh volume_mesh = vol.volume->mesh(); + volume_mesh.transform(vol.instance->get_transformation().get_matrix() * vol.volume->get_transformation().get_matrix()); + composite_mesh.merge(volume_mesh); + } + + m_measuring.reset(new Measure::Measuring(composite_mesh.its)); + update_plane_models_cache(m_measuring->get_mesh().its); + m_raycaster.update_from(m_measuring->get_mesh()); + m_volumes_cache = volumes_cache; + }; +#else auto do_update = [this, update_plane_models_cache](const ModelObject* object, const ModelVolume* volume) { const indexed_triangle_set& its = (volume != nullptr) ? volume->mesh().its : object->volumes.front()->mesh().its; m_measuring.reset(new Measure::Measuring(its)); @@ -980,24 +1096,44 @@ void GLGizmoMeasure::update_if_needed() // Let's save what we calculated it from: m_volumes_matrices.clear(); m_volumes_types.clear(); - m_first_instance_scale = Vec3d::Ones(); + m_first_instance_scale = Vec3d::Ones(); m_first_instance_mirror = Vec3d::Ones(); if (object != nullptr) { for (const ModelVolume* vol : object->volumes) { m_volumes_matrices.push_back(vol->get_matrix()); m_volumes_types.push_back(vol->type()); } - m_first_instance_scale = object->instances.front()->get_scaling_factor(); + m_first_instance_scale = object->instances.front()->get_scaling_factor(); m_first_instance_mirror = object->instances.front()->get_mirror(); } m_old_model_object = object; m_old_model_volume = volume; }; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const Selection& selection = m_parent.get_selection(); if (selection.is_empty()) return; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Selection::IndicesList& idxs = selection.get_volume_idxs(); + std::vector volumes_cache; + volumes_cache.reserve(idxs.size()); + for (unsigned int idx : idxs) { + const GLVolume* v = selection.get_volume(idx); + const ModelObject* obj = selection.get_model()->objects[v->object_idx()]; + const ModelInstance* inst = obj->instances[v->instance_idx()]; + const ModelVolume* vol = obj->volumes[v->volume_idx()]; + const VolumeCacheItem item = { obj, inst, vol, inst->get_matrix() * vol->get_matrix() }; + volumes_cache.emplace_back(item); + } + + if (m_state != On || volumes_cache.empty()) + return; + + if (m_measuring == nullptr || m_volumes_cache != volumes_cache) + do_update(volumes_cache, selection); +#else m_volume_matrix = selection.get_first_volume()->world_matrix(); const ModelObject* mo = m_c->selection_info()->model_object(); @@ -1026,6 +1162,7 @@ void GLGizmoMeasure::update_if_needed() break; } } +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } void GLGizmoMeasure::disable_scene_raycasters() @@ -1145,6 +1282,62 @@ void GLGizmoMeasure::render_dimensioning() const double ratio = new_value / old_value; wxGetApp().plater()->take_snapshot(_L("Scale")); +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + struct TrafoData + { + double ratio; + Vec3d old_pivot; + Vec3d new_pivot; + Transform3d scale_matrix; + + TrafoData(double ratio, const Vec3d& pivot) { + this->ratio = ratio; + this->scale_matrix = Geometry::scale_transform(ratio); + this->old_pivot = pivot; + this->new_pivot = { pivot.x(), pivot.y(), (this->scale_matrix * pivot).z() }; + } + + Vec3d transform(const Vec3d& point) const { + return this->scale_matrix * (point - this->old_pivot) + this->new_pivot; + } + }; + + auto scale_feature = [this](Measure::SurfaceFeature& feature, const TrafoData& trafo_data) { + switch (feature.get_type()) + { + case Measure::SurfaceFeatureType::Point: + { + feature = Measure::SurfaceFeature(trafo_data.transform(feature.get_point())); + break; + } + case Measure::SurfaceFeatureType::Edge: + { + const auto [from, to] = feature.get_edge(); + const std::optional extra = feature.get_extra_point(); + const std::optional new_extra = extra.has_value() ? trafo_data.transform(*extra) : extra; + feature = Measure::SurfaceFeature(Measure::SurfaceFeatureType::Edge, trafo_data.transform(from), trafo_data.transform(to), new_extra); + break; + } + case Measure::SurfaceFeatureType::Circle: + { + const auto [center, radius, normal] = feature.get_circle(); + feature = Measure::SurfaceFeature(Measure::SurfaceFeatureType::Circle, trafo_data.transform(center), normal, std::nullopt, trafo_data.ratio * radius); + break; + } + case Measure::SurfaceFeatureType::Plane: + { + const auto [idx, normal, origin] = feature.get_plane(); + feature = Measure::SurfaceFeature(Measure::SurfaceFeatureType::Plane, normal, trafo_data.transform(origin), std::nullopt, idx); + break; + } + } + }; + + const TrafoData trafo_data(ratio, m_parent.get_selection().get_bounding_box().center()); + scale_feature(*m_selected_features.first.feature, trafo_data); + scale_feature(*m_selected_features.second.feature, trafo_data); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + TransformationType type; type.set_world(); type.set_relative(); @@ -1203,8 +1396,10 @@ void GLGizmoMeasure::render_dimensioning() assert(f1.get_type() == Measure::SurfaceFeatureType::Point && f2.get_type() == Measure::SurfaceFeatureType::Edge); std::pair e = f2.get_edge(); // Transform to world coordinates +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES e.first = TransformHelper::model_to_world(e.first, m_volume_matrix); e.second = TransformHelper::model_to_world(e.second, m_volume_matrix); +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const Vec3d v_proj = m_measurement_result.distance_infinite->to; @@ -1485,15 +1680,21 @@ void GLGizmoMeasure::render_debug_dialog() { case Measure::SurfaceFeatureType::Point: { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(item.feature->get_point()), ImGui::GetStyleColorVec4(ImGuiCol_Text)); +#else const Vec3d position = m_volume_matrix * item.feature->get_point(); add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(position), ImGui::GetStyleColorVec4(ImGuiCol_Text)); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES break; } case Measure::SurfaceFeatureType::Edge: { auto [from, to] = item.feature->get_edge(); +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES from = m_volume_matrix * from; to = m_volume_matrix * to; +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(from), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_pt2", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(to), ImGui::GetStyleColorVec4(ImGuiCol_Text)); break; @@ -1501,8 +1702,10 @@ void GLGizmoMeasure::render_debug_dialog() case Measure::SurfaceFeatureType::Plane: { auto [idx, normal, origin] = item.feature->get_plane(); +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES origin = m_volume_matrix * origin; normal = m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal; +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(normal), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_pt2", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(origin), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_value", ImGuiWrapper::COL_ORANGE_LIGHT, format_double(idx), ImGui::GetStyleColorVec4(ImGuiCol_Text)); @@ -1511,9 +1714,13 @@ void GLGizmoMeasure::render_debug_dialog() case Measure::SurfaceFeatureType::Circle: { auto [center, radius, normal] = item.feature->get_circle(); +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Vec3d on_circle = center + radius * Measure::get_orthogonal(normal, true); +#else const Vec3d on_circle = m_volume_matrix * (center + radius * Measure::get_orthogonal(normal, true)); center = m_volume_matrix * center; normal = (m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal).normalized(); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES radius = (on_circle - center).norm(); add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(center), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_pt2", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(normal), ImGui::GetStyleColorVec4(ImGuiCol_Text)); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp index 7bfc2e8c93..606012f7c4 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp @@ -5,10 +5,16 @@ #include "slic3r/GUI/GLModel.hpp" #include "slic3r/GUI/GUI_Utils.hpp" #include "libslic3r/Measure.hpp" +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" +#include "libslic3r/Model.hpp" +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES namespace Slic3r { +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES class ModelVolume; +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES enum class ModelVolumeType : int; @@ -68,6 +74,23 @@ class GLGizmoMeasure : public GLGizmoBase } }; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + struct VolumeCacheItem + { + const ModelObject* object{ nullptr }; + const ModelInstance* instance{ nullptr }; + const ModelVolume* volume{ nullptr }; + Transform3d world_trafo; + + bool operator == (const VolumeCacheItem& other) const { + return this->object == other.object && this->instance == other.instance && this->volume == other.volume && + this->world_trafo.isApprox(other.world_trafo); + } + }; + + std::vector m_volumes_cache; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + EMode m_mode{ EMode::FeatureSelection }; Measure::MeasurementResult m_measurement_result; @@ -85,7 +108,13 @@ class GLGizmoMeasure : public GLGizmoBase }; Dimensioning m_dimensioning; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + // Uses a standalone raycaster and not the shared one because of the + // difference in how the mesh is updated + CommonGizmosDataObjects::Raycaster m_raycaster; +#else Transform3d m_volume_matrix{ Transform3d::Identity() }; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES std::vector m_plane_models_cache; std::map> m_raycasters; std::vector> m_selection_raycasters; @@ -100,17 +129,21 @@ class GLGizmoMeasure : public GLGizmoBase std::vector m_scene_raycasters; // These hold information to decide whether recalculation is necessary: +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES std::vector m_volumes_matrices; std::vector m_volumes_types; Vec3d m_first_instance_scale{ Vec3d::Ones() }; Vec3d m_first_instance_mirror{ Vec3d::Ones() }; +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES float m_last_inv_zoom{ 0.0f }; std::optional m_last_circle; int m_last_plane_idx{ -1 }; bool m_mouse_left_down{ false }; // for detection left_up of this gizmo +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const ModelObject* m_old_model_object{ nullptr }; const ModelVolume* m_old_model_volume{ nullptr }; +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES Vec2d m_mouse_pos{ Vec2d::Zero() }; @@ -153,7 +186,9 @@ protected: bool on_is_activable() const override; void on_render() override; void on_set_state() override; +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES CommonGizmosDataID on_get_requirements() const override; +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES virtual void on_render_input_window(float x, float y, float bottom_limit) override; virtual void on_register_raycasters_for_picking() override; diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp index 394e879b7c..dca64a5266 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp @@ -327,6 +327,19 @@ const TriangleMesh* HollowedMesh::get_hollowed_interior() const } +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +void Raycaster::update_from(const TriangleMesh& mesh) +{ + std::vector meshes = { &mesh }; + if (meshes != m_old_meshes) { + wxBusyCursor wait; + m_raycasters.clear(); + m_raycasters.emplace_back(new MeshRaycaster(std::make_shared(mesh))); + m_old_meshes = meshes; + } + validate(); +} +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES void Raycaster::on_update() diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp index 42faa25f84..b02e3a920c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp @@ -137,6 +137,9 @@ protected: virtual void on_update() = 0; CommonGizmosDataPool* get_pool() const { return m_common; } +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + void validate() { m_is_valid = true; } +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES private: bool m_is_valid = false; @@ -242,6 +245,10 @@ public: const MeshRaycaster* raycaster() const { assert(m_raycasters.size() == 1); return m_raycasters.front().get(); } std::vector raycasters() const; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + void update_from(const TriangleMesh& mesh); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + protected: void on_update() override; void on_release() override; diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index 9a4169b318..2e50fc37c9 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -602,6 +602,19 @@ bool Selection::contains_any_volume(const std::vector& volume_idxs return false; } +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +bool Selection::contains_sinking_volumes(bool ignore_modifiers) const +{ + for (const GLVolume* v : *m_volumes) { + if (!ignore_modifiers || !v->is_modifier) { + if (v->is_sinking()) + return true; + } + } + return false; +} +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + bool Selection::matches(const std::vector& volume_idxs) const { unsigned int count = 0; diff --git a/src/slic3r/GUI/Selection.hpp b/src/slic3r/GUI/Selection.hpp index c4720a3081..0064f27999 100644 --- a/src/slic3r/GUI/Selection.hpp +++ b/src/slic3r/GUI/Selection.hpp @@ -337,6 +337,10 @@ public: bool contains_all_volumes(const std::vector& volume_idxs) const; // returns true if the selection contains at least one of the given indices bool contains_any_volume(const std::vector& volume_idxs) const; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + // returns true if the selection contains any sinking volume + bool contains_sinking_volumes(bool ignore_modifiers = true) const; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // returns true if the selection contains all and only the given indices bool matches(const std::vector& volume_idxs) const; From 182e5ece2e47547a243962d518a667b40b3556d8 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 15 Nov 2022 12:42:22 +0100 Subject: [PATCH 002/109] Added missing declaration --- src/libslic3r/Measure.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libslic3r/Measure.hpp b/src/libslic3r/Measure.hpp index b2e2008d15..9cc380dd2b 100644 --- a/src/libslic3r/Measure.hpp +++ b/src/libslic3r/Measure.hpp @@ -12,6 +12,11 @@ struct indexed_triangle_set; namespace Slic3r { + +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +class TriangleMesh; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + namespace Measure { From c98ba0e651d63fc277e879232276adce0bdd49c9 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 15 Nov 2022 16:07:38 +0100 Subject: [PATCH 003/109] Measurement: refactoring - do not touch common raycaster interface when there is no need --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 9 +++------ src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp | 4 ++-- src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp | 15 --------------- src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp | 8 -------- 4 files changed, 5 insertions(+), 31 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 5ae906eac9..8cfbf634eb 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -245,9 +245,6 @@ TransformHelper::Cache TransformHelper::s_cache = { { 0, 0, 0, 0 }, Matrix4d::Id GLGizmoMeasure::GLGizmoMeasure(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) : GLGizmoBase(parent, icon_filename, sprite_id) -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES -, m_raycaster(nullptr) -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES { GLModel::Geometry sphere_geometry = smooth_sphere(16, 7.5f); m_sphere.mesh_raycaster = std::make_unique(std::make_shared(sphere_geometry.get_as_indexed_triangle_set())); @@ -526,7 +523,7 @@ void GLGizmoMeasure::on_set_state() m_is_editing_distance_first_frame = true; m_measuring.reset(); #if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - m_raycaster.release(); + m_raycaster.reset(); #endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } else { @@ -599,7 +596,7 @@ void GLGizmoMeasure::on_render() Vec3f normal_on_model; size_t model_facet_idx; #if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const bool mouse_on_object = m_raycaster.raycaster()->unproject_on_mesh(m_mouse_pos, Transform3d::Identity(), camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); + const bool mouse_on_object = m_raycaster->unproject_on_mesh(m_mouse_pos, Transform3d::Identity(), camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); #else const bool mouse_on_object = m_c->raycaster()->raycasters().front()->unproject_on_mesh(m_mouse_pos, m_volume_matrix, camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); #endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES @@ -1083,7 +1080,7 @@ void GLGizmoMeasure::update_if_needed() m_measuring.reset(new Measure::Measuring(composite_mesh.its)); update_plane_models_cache(m_measuring->get_mesh().its); - m_raycaster.update_from(m_measuring->get_mesh()); + m_raycaster.reset(new MeshRaycaster(std::make_shared(m_measuring->get_mesh()))); m_volumes_cache = volumes_cache; }; #else diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp index 606012f7c4..fbbf30da78 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp @@ -4,9 +4,9 @@ #include "GLGizmoBase.hpp" #include "slic3r/GUI/GLModel.hpp" #include "slic3r/GUI/GUI_Utils.hpp" +#include "slic3r/GUI/MeshUtils.hpp" #include "libslic3r/Measure.hpp" #if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES -#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" #include "libslic3r/Model.hpp" #endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES @@ -111,7 +111,7 @@ class GLGizmoMeasure : public GLGizmoBase #if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // Uses a standalone raycaster and not the shared one because of the // difference in how the mesh is updated - CommonGizmosDataObjects::Raycaster m_raycaster; + std::unique_ptr m_raycaster; #else Transform3d m_volume_matrix{ Transform3d::Identity() }; #endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp index dca64a5266..11c44113bc 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp @@ -327,21 +327,6 @@ const TriangleMesh* HollowedMesh::get_hollowed_interior() const } -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES -void Raycaster::update_from(const TriangleMesh& mesh) -{ - std::vector meshes = { &mesh }; - if (meshes != m_old_meshes) { - wxBusyCursor wait; - m_raycasters.clear(); - m_raycasters.emplace_back(new MeshRaycaster(std::make_shared(mesh))); - m_old_meshes = meshes; - } - validate(); -} -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - - void Raycaster::on_update() { wxBusyCursor wait; diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp index b02e3a920c..3878c6b25a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp @@ -137,10 +137,6 @@ protected: virtual void on_update() = 0; CommonGizmosDataPool* get_pool() const { return m_common; } -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - void validate() { m_is_valid = true; } -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - private: bool m_is_valid = false; CommonGizmosDataPool* m_common = nullptr; @@ -245,10 +241,6 @@ public: const MeshRaycaster* raycaster() const { assert(m_raycasters.size() == 1); return m_raycasters.front().get(); } std::vector raycasters() const; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - void update_from(const TriangleMesh& mesh); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - protected: void on_update() override; void on_release() override; From 6dac9f2aca0439fef6af8e6c0f6b0d6a77788b03 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 15 Nov 2022 16:08:27 +0100 Subject: [PATCH 004/109] Measurement: Partially fixed the common gizmo raycaster for self-intersecting meshes --- src/slic3r/GUI/MeshUtils.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/MeshUtils.cpp b/src/slic3r/GUI/MeshUtils.cpp index e33d29ba16..3805151af1 100644 --- a/src/slic3r/GUI/MeshUtils.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -409,6 +409,12 @@ bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& Vec3d direction; line_from_mouse_pos(mouse_pos, trafo, camera, point, direction); + if (rand()%100 == 0) { + int a=5; + int b=6; + int c=7; + } + std::vector hits = m_emesh.query_ray_hits(point, direction); if (hits.empty()) @@ -429,10 +435,10 @@ bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& // All hits are clipped. return false; } - if ((hits.size()-i) % 2 != 0) { + if (clipping_plane && (hits.size()-i) % 2 != 0) { // There is an odd number of unclipped hits - meaning the nearest must be from inside the mesh. // In that case, calculate intersection with the clipping place. - if (clipping_plane && was_clipping_plane_hit) { + if (was_clipping_plane_hit) { direction = direction + point; point = trafo * point; // transform to world coords direction = trafo * direction - point; From c24ce158054bf23daaca10499799cbd946dca15b Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 16 Nov 2022 08:53:02 +0100 Subject: [PATCH 005/109] Tech ENABLE_GIZMO_MEASURE_WORLD_COORDINATES set as default --- src/libslic3r/Measure.cpp | 48 -- src/libslic3r/Measure.hpp | 30 +- src/libslic3r/Technologies.hpp | 2 - src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 850 +++++++++-------------- src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp | 26 +- src/slic3r/GUI/Selection.cpp | 2 - src/slic3r/GUI/Selection.hpp | 2 - 7 files changed, 323 insertions(+), 637 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 1ffd72c14d..cea9f0b77e 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -45,9 +45,7 @@ public: std::optional get_feature(size_t face_idx, const Vec3d& point) const; std::vector> get_planes_triangle_indices() const; const std::vector& get_plane_features(unsigned int plane_id) const; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const TriangleMesh& get_mesh() const; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES private: void update_planes(); @@ -55,11 +53,7 @@ private: std::vector m_planes; std::vector m_face_to_plane; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES TriangleMesh m_mesh; -#else - const indexed_triangle_set& m_its; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES }; @@ -68,11 +62,7 @@ private: MeasuringImpl::MeasuringImpl(const indexed_triangle_set& its) -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES : m_mesh(its) -#else -: m_its{its} -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES { update_planes(); extract_features(); @@ -85,17 +75,10 @@ void MeasuringImpl::update_planes() // Now we'll go through all the facets and append Points of facets sharing the same normal. // This part is still performed in mesh coordinate system. -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const size_t num_of_facets = m_mesh.its.indices.size(); m_face_to_plane.resize(num_of_facets, size_t(-1)); const std::vector face_normals = its_face_normals(m_mesh.its); const std::vector face_neighbors = its_face_neighbors(m_mesh.its); -#else - const size_t num_of_facets = m_its.indices.size(); - m_face_to_plane.resize(num_of_facets, size_t(-1)); - const std::vector face_normals = its_face_normals(m_its); - const std::vector face_neighbors = its_face_neighbors(m_its); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES std::vector facet_queue(num_of_facets, 0); int facet_queue_cnt = 0; const stl_normal* normal_ptr = nullptr; @@ -144,11 +127,7 @@ void MeasuringImpl::update_planes() assert(std::none_of(m_face_to_plane.begin(), m_face_to_plane.end(), [](size_t val) { return val == size_t(-1); })); // Now we will walk around each of the planes and save vertices which form the border. -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES SurfaceMesh sm(m_mesh.its); -#else - SurfaceMesh sm(m_its); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES for (int plane_id=0; plane_id < int(m_planes.size()); ++plane_id) { const auto& facets = m_planes[plane_id].facets; m_planes[plane_id].borders.clear(); @@ -530,12 +509,10 @@ const std::vector& MeasuringImpl::get_plane_features(unsigned in return m_planes[plane_id].surface_features; } -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const TriangleMesh& MeasuringImpl::get_mesh() const { return this->m_mesh; } -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES @@ -577,12 +554,10 @@ const std::vector& Measuring::get_plane_features(unsigned int pl return priv->get_plane_features(plane_id); } -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const TriangleMesh& Measuring::get_mesh() const { return priv->get_mesh(); } -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const AngleAndEdges AngleAndEdges::Dummy = { 0.0, Vec3d::Zero(), { Vec3d::Zero(), Vec3d::Zero() }, { Vec3d::Zero(), Vec3d::Zero() }, 0.0, true }; @@ -1182,29 +1157,6 @@ MeasurementResult get_measurement(const SurfaceFeature& a, const SurfaceFeature& return result; } -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES -void DistAndPoints::transform(const Transform3d& trafo) { - from = trafo * from; - to = trafo * to; - dist = (to - from).norm(); -} - -void AngleAndEdges::transform(const Transform3d& trafo) { - const Vec3d old_e1 = e1.second - e1.first; - const Vec3d old_e2 = e2.second - e2.first; - center = trafo * center; - e1.first = trafo * e1.first; - e1.second = trafo * e1.second; - e2.first = trafo * e2.first; - e2.second = trafo * e2.second; - angle = std::acos(std::clamp(Measure::edge_direction(e1).dot(Measure::edge_direction(e2)), -1.0, 1.0)); - const Vec3d new_e1 = e1.second - e1.first; - const Vec3d new_e2 = e2.second - e2.first; - const double average_scale = 0.5 * (new_e1.norm() / old_e1.norm() + new_e2.norm() / old_e2.norm()); - radius = average_scale * radius; -} -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - diff --git a/src/libslic3r/Measure.hpp b/src/libslic3r/Measure.hpp index 9cc380dd2b..3a1a4b89d9 100644 --- a/src/libslic3r/Measure.hpp +++ b/src/libslic3r/Measure.hpp @@ -13,9 +13,7 @@ struct indexed_triangle_set; namespace Slic3r { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES class TriangleMesh; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES namespace Measure { @@ -93,10 +91,7 @@ class MeasuringImpl; class Measuring { public: // Construct the measurement object on a given its. -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - // The its must remain valid and unchanged during the whole lifetime of the object. -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - explicit Measuring(const indexed_triangle_set& its); + explicit Measuring(const indexed_triangle_set& its); ~Measuring(); // Return a reference to a list of all features identified on the its. @@ -115,10 +110,8 @@ public: // Returns the surface features of the plane with the given index const std::vector& get_plane_features(unsigned int plane_id) const; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // Returns the mesh used for measuring const TriangleMesh& get_mesh() const; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES private: std::unique_ptr priv; @@ -130,10 +123,6 @@ struct DistAndPoints { double dist; Vec3d from; Vec3d to; - -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - void transform(const Transform3d& trafo); -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES }; struct AngleAndEdges { @@ -146,10 +135,6 @@ struct AngleAndEdges { double radius; bool coplanar; -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - void transform(const Transform3d& trafo); -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - static const AngleAndEdges Dummy; }; @@ -166,19 +151,6 @@ struct MeasurementResult { bool has_any_data() const { return angle.has_value() || distance_infinite.has_value() || distance_strict.has_value() || distance_xyz.has_value(); } - -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - void transform(const Transform3d& trafo) { - if (angle.has_value()) - angle->transform(trafo); - if (distance_infinite.has_value()) - distance_infinite->transform(trafo); - if (distance_strict.has_value()) { - distance_strict->transform(trafo); - distance_xyz = (distance_strict->to - distance_strict->from).cwiseAbs(); - } - } -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES }; // Returns distance/angle between two SurfaceFeatures. diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 9e7c660ae0..a3e72cf0c5 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -64,8 +64,6 @@ // Enable picking using raytracing #define ENABLE_RAYCAST_PICKING (1 && ENABLE_LEGACY_OPENGL_REMOVAL) #define ENABLE_RAYCAST_PICKING_DEBUG (0 && ENABLE_RAYCAST_PICKING) -// Enable gizmo measure combining volumes meshes and passing them to the backend in world coordinates -#define ENABLE_GIZMO_MEASURE_WORLD_COORDINATES (1 && ENABLE_2_5_0_ALPHA1) #endif // _prusaslicer_technologies_h_ diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 8cfbf634eb..35767121d7 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -6,10 +6,6 @@ #include "slic3r/GUI/GUI_ObjectManipulation.hpp" -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES -#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" -#include "libslic3r/Model.hpp" -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES #include "libslic3r/PresetBundle.hpp" #include "libslic3r/MeasureUtils.hpp" @@ -370,13 +366,8 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) } } - if (m_selected_features != selected_features_old && m_selected_features.second.feature.has_value()) { + if (m_selected_features != selected_features_old && m_selected_features.second.feature.has_value()) m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - // transform to world coordinates - m_measurement_result.transform(m_volume_matrix); -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - } m_imgui->set_requires_extra_frame(); @@ -423,29 +414,12 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) void GLGizmoMeasure::data_changed() { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES update_if_needed(); -#else - const Selection& selection = m_parent.get_selection(); - const ModelObject* model_object = nullptr; - const ModelVolume* model_volume = nullptr; - if (selection.is_single_full_instance() || - selection.is_from_single_object() ) { - model_object = selection.get_model()->objects[selection.get_object_idx()]; - model_volume = model_object->volumes[selection.get_first_volume()->volume_idx()]; - } - if (model_object != m_old_model_object || model_volume != m_old_model_volume) - update_if_needed(); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES m_last_inv_zoom = 0.0f; m_last_plane_idx = -1; if (m_pending_scale) { m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - // transform to world coordinates - m_measurement_result.transform(m_volume_matrix); -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES m_pending_scale = false; } else @@ -522,9 +496,7 @@ void GLGizmoMeasure::on_set_state() m_editing_distance = false; m_is_editing_distance_first_frame = true; m_measuring.reset(); -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES m_raycaster.reset(); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } else { m_mode = EMode::FeatureSelection; @@ -541,13 +513,6 @@ void GLGizmoMeasure::on_set_state() } } -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES -CommonGizmosDataID GLGizmoMeasure::on_get_requirements() const -{ - return CommonGizmosDataID(int(CommonGizmosDataID::SelectionInfo) | int(CommonGizmosDataID::Raycaster)); -} -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - std::string GLGizmoMeasure::on_get_name() const { return _u8L("Measure"); @@ -558,15 +523,9 @@ bool GLGizmoMeasure::on_is_activable() const const Selection& selection = m_parent.get_selection(); bool res = (wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA) ? selection.is_single_full_instance() : -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES selection.is_single_full_instance() || selection.is_single_volume() || selection.is_single_modifier(); if (res) res &= !selection.contains_sinking_volumes(); -#else - selection.is_single_volume() || selection.is_single_volume_instance(); - if (res) - res &= !selection.get_first_volume()->is_sinking(); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES return res; } @@ -583,473 +542,390 @@ void GLGizmoMeasure::on_render() const Selection& selection = m_parent.get_selection(); -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - if ((wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA && selection.is_single_full_instance()) || - (selection.is_single_volume() || selection.is_single_volume_instance())) { -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - update_if_needed(); + update_if_needed(); - const Camera& camera = wxGetApp().plater()->get_camera(); - const float inv_zoom = (float)camera.get_inv_zoom(); + const Camera& camera = wxGetApp().plater()->get_camera(); + const float inv_zoom = (float)camera.get_inv_zoom(); - Vec3f position_on_model; - Vec3f normal_on_model; - size_t model_facet_idx; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const bool mouse_on_object = m_raycaster->unproject_on_mesh(m_mouse_pos, Transform3d::Identity(), camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); -#else - const bool mouse_on_object = m_c->raycaster()->raycasters().front()->unproject_on_mesh(m_mouse_pos, m_volume_matrix, camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const bool is_hovering_on_feature = (m_mode == EMode::PointSelection || m_mode == EMode::CenterSelection) && m_hover_id != -1; + Vec3f position_on_model; + Vec3f normal_on_model; + size_t model_facet_idx; + const bool mouse_on_object = m_raycaster->unproject_on_mesh(m_mouse_pos, Transform3d::Identity(), camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); + const bool is_hovering_on_feature = (m_mode == EMode::PointSelection || m_mode == EMode::CenterSelection) && m_hover_id != -1; - auto update_circle = [this, inv_zoom]() { - if (m_last_inv_zoom != inv_zoom || m_last_circle != m_curr_feature) { - m_last_inv_zoom = inv_zoom; - m_last_circle = m_curr_feature; - m_circle.reset(); - const auto [center, radius, normal] = m_curr_feature->get_circle(); -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); -#else - GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), m_volume_matrix.cast()); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - m_circle.mesh_raycaster = std::make_unique(std::make_shared(circle_geometry.get_as_indexed_triangle_set())); - m_circle.model.init_from(std::move(circle_geometry)); - return true; - } - return false; - }; + auto update_circle = [this, inv_zoom]() { + if (m_last_inv_zoom != inv_zoom || m_last_circle != m_curr_feature) { + m_last_inv_zoom = inv_zoom; + m_last_circle = m_curr_feature; + m_circle.reset(); + const auto [center, radius, normal] = m_curr_feature->get_circle(); + GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); + m_circle.mesh_raycaster = std::make_unique(std::make_shared(circle_geometry.get_as_indexed_triangle_set())); + m_circle.model.init_from(std::move(circle_geometry)); + return true; + } + return false; + }; - if (m_mode == EMode::FeatureSelection || m_mode == EMode::PointSelection) { - if ((m_hover_id == SELECTION_1_ID && boost::algorithm::istarts_with(m_selected_features.first.source, _u8L("Center"))) || - (m_hover_id == SELECTION_2_ID && boost::algorithm::istarts_with(m_selected_features.second.source, _u8L("Center")))) { - // Skip feature detection if hovering on a selected center - m_curr_feature.reset(); + if (m_mode == EMode::FeatureSelection || m_mode == EMode::PointSelection) { + if ((m_hover_id == SELECTION_1_ID && boost::algorithm::istarts_with(m_selected_features.first.source, _u8L("Center"))) || + (m_hover_id == SELECTION_2_ID && boost::algorithm::istarts_with(m_selected_features.second.source, _u8L("Center")))) { + // Skip feature detection if hovering on a selected center + m_curr_feature.reset(); + m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID); + m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID); + m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, PLANE_ID); + m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID); + m_curr_point_on_feature_position.reset(); + } + else { + std::optional curr_feature = mouse_on_object ? m_measuring->get_feature(model_facet_idx, position_on_model.cast()) : std::nullopt; + if (m_curr_feature != curr_feature || + (curr_feature.has_value() && curr_feature->get_type() == Measure::SurfaceFeatureType::Circle && (m_curr_feature != curr_feature || m_last_inv_zoom != inv_zoom))) { m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID); m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID); m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, PLANE_ID); m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID); - m_curr_point_on_feature_position.reset(); - } - else { - std::optional curr_feature = mouse_on_object ? m_measuring->get_feature(model_facet_idx, position_on_model.cast()) : std::nullopt; - if (m_curr_feature != curr_feature || - (curr_feature.has_value() && curr_feature->get_type() == Measure::SurfaceFeatureType::Circle && (m_curr_feature != curr_feature || m_last_inv_zoom != inv_zoom))) { - m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID); - m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID); - m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, PLANE_ID); - m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID); - m_raycasters.clear(); - m_curr_feature = curr_feature; - if (!m_curr_feature.has_value()) - return; + m_raycasters.clear(); + m_curr_feature = curr_feature; + if (!m_curr_feature.has_value()) + return; - switch (m_curr_feature->get_type()) { - default: { assert(false); break; } - case Measure::SurfaceFeatureType::Point: - { - m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); - break; - } - case Measure::SurfaceFeatureType::Edge: - { - m_raycasters.insert({ EDGE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID, *m_cylinder.mesh_raycaster) }); - if (m_curr_feature->get_extra_point().has_value()) - m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); - break; - } - case Measure::SurfaceFeatureType::Circle: - { - update_circle(); - m_raycasters.insert({ CIRCLE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID, *m_circle.mesh_raycaster) }); - m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); - break; - } - case Measure::SurfaceFeatureType::Plane: - { - const auto [idx, normal, point] = m_curr_feature->get_plane(); - if (m_last_plane_idx != idx) { - m_last_plane_idx = idx; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const indexed_triangle_set& its = m_measuring->get_mesh().its; -#else - const indexed_triangle_set its = (m_old_model_volume != nullptr) ? m_old_model_volume->mesh().its : m_old_model_object->volumes.front()->mesh().its; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const std::vector> planes_triangles = m_measuring->get_planes_triangle_indices(); - GLModel::Geometry init_data = init_plane_data(its, planes_triangles, idx); - m_plane.reset(); - m_plane.mesh_raycaster = std::make_unique(std::make_shared(init_data.get_as_indexed_triangle_set())); - m_plane.model.init_from(std::move(init_data)); - } - - m_raycasters.insert({ PLANE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, PLANE_ID, *m_plane.mesh_raycaster) }); - break; - } - } - } - } - } - - if (m_mode != EMode::PointSelection) - m_curr_point_on_feature_position.reset(); - else if (is_hovering_on_feature) { - auto position_on_feature = [this](int feature_type_id, const Camera& camera, std::function callback = nullptr) -> Vec3d { - auto it = m_raycasters.find(feature_type_id); - if (it != m_raycasters.end() && it->second != nullptr) { - Vec3f p; - Vec3f n; - const Transform3d& trafo = it->second->get_transform(); - bool res = it->second->get_raycaster()->closest_hit(m_mouse_pos, trafo, camera, p, n); - if (res) { - if (callback) - p = callback(p); - return trafo * p.cast(); - } - } - return Vec3d::Zero(); - }; - - if (m_curr_feature.has_value()) { - switch (m_curr_feature->get_type()) - { + switch (m_curr_feature->get_type()) { default: { assert(false); break; } case Measure::SurfaceFeatureType::Point: { - m_curr_point_on_feature_position = m_curr_feature->get_point(); + m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); break; } case Measure::SurfaceFeatureType::Edge: { - const std::optional extra = m_curr_feature->get_extra_point(); - if (extra.has_value() && m_hover_id == POINT_ID) - m_curr_point_on_feature_position = *extra; - else -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - m_curr_point_on_feature_position = position_on_feature(EDGE_ID, camera, [](const Vec3f& v) { return Vec3f(0.0f, 0.0f, v.z()); }); -#else - m_curr_point_on_feature_position = m_volume_matrix.inverse() * position_on_feature(EDGE_ID, camera, [](const Vec3f& v) { return Vec3f(0.0f, 0.0f, v.z()); }); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + m_raycasters.insert({ EDGE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID, *m_cylinder.mesh_raycaster) }); + if (m_curr_feature->get_extra_point().has_value()) + m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); + break; + } + case Measure::SurfaceFeatureType::Circle: + { + update_circle(); + m_raycasters.insert({ CIRCLE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID, *m_circle.mesh_raycaster) }); + m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); break; } case Measure::SurfaceFeatureType::Plane: { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - m_curr_point_on_feature_position = position_on_feature(PLANE_ID, camera); -#else - m_curr_point_on_feature_position = m_volume_matrix.inverse() * position_on_feature(PLANE_ID, camera); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - break; - } - case Measure::SurfaceFeatureType::Circle: - { - const auto [center, radius, normal] = m_curr_feature->get_circle(); - if (m_hover_id == POINT_ID) - m_curr_point_on_feature_position = center; - else { - const Vec3d world_pof = position_on_feature(CIRCLE_ID, camera, [](const Vec3f& v) { return v; }); -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Eigen::Hyperplane plane(normal, center); -#else - const Eigen::Hyperplane plane(m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal, m_volume_matrix * center); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Transform3d local_to_model_matrix = Geometry::translation_transform(center) * Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), normal); -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Vec3d local_proj = local_to_model_matrix.inverse() * plane.projection(world_pof); -#else - const Vec3d local_proj = local_to_model_matrix.inverse() * m_volume_matrix.inverse() * plane.projection(world_pof); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - double angle = std::atan2(local_proj.y(), local_proj.x()); - if (angle < 0.0) - angle += 2.0 * double(M_PI); - - const Vec3d local_pos = radius * Vec3d(std::cos(angle), std::sin(angle), 0.0); - m_curr_point_on_feature_position = local_to_model_matrix * local_pos; + const auto [idx, normal, point] = m_curr_feature->get_plane(); + if (m_last_plane_idx != idx) { + m_last_plane_idx = idx; + const indexed_triangle_set& its = m_measuring->get_mesh().its; + const std::vector> planes_triangles = m_measuring->get_planes_triangle_indices(); + GLModel::Geometry init_data = init_plane_data(its, planes_triangles, idx); + m_plane.reset(); + m_plane.mesh_raycaster = std::make_unique(std::make_shared(init_data.get_as_indexed_triangle_set())); + m_plane.model.init_from(std::move(init_data)); } + + m_raycasters.insert({ PLANE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, PLANE_ID, *m_plane.mesh_raycaster) }); break; } } } } - else { - if (m_curr_feature.has_value() && m_curr_feature->get_type() == Measure::SurfaceFeatureType::Circle) { - if (update_circle()) { - m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID); - auto it = m_raycasters.find(CIRCLE_ID); - if (it != m_raycasters.end()) - m_raycasters.erase(it); - m_raycasters.insert({ CIRCLE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID, *m_circle.mesh_raycaster) }); + } + + if (m_mode != EMode::PointSelection) + m_curr_point_on_feature_position.reset(); + else if (is_hovering_on_feature) { + auto position_on_feature = [this](int feature_type_id, const Camera& camera, std::function callback = nullptr) -> Vec3d { + auto it = m_raycasters.find(feature_type_id); + if (it != m_raycasters.end() && it->second != nullptr) { + Vec3f p; + Vec3f n; + const Transform3d& trafo = it->second->get_transform(); + bool res = it->second->get_raycaster()->closest_hit(m_mouse_pos, trafo, camera, p, n); + if (res) { + if (callback) + p = callback(p); + return trafo * p.cast(); } } + return Vec3d::Zero(); + }; + + if (m_curr_feature.has_value()) { + switch (m_curr_feature->get_type()) + { + default: { assert(false); break; } + case Measure::SurfaceFeatureType::Point: + { + m_curr_point_on_feature_position = m_curr_feature->get_point(); + break; + } + case Measure::SurfaceFeatureType::Edge: + { + const std::optional extra = m_curr_feature->get_extra_point(); + if (extra.has_value() && m_hover_id == POINT_ID) + m_curr_point_on_feature_position = *extra; + else + m_curr_point_on_feature_position = position_on_feature(EDGE_ID, camera, [](const Vec3f& v) { return Vec3f(0.0f, 0.0f, v.z()); }); + break; + } + case Measure::SurfaceFeatureType::Plane: + { + m_curr_point_on_feature_position = position_on_feature(PLANE_ID, camera); + break; + } + case Measure::SurfaceFeatureType::Circle: + { + const auto [center, radius, normal] = m_curr_feature->get_circle(); + if (m_hover_id == POINT_ID) + m_curr_point_on_feature_position = center; + else { + const Vec3d world_pof = position_on_feature(CIRCLE_ID, camera, [](const Vec3f& v) { return v; }); + const Eigen::Hyperplane plane(normal, center); + const Transform3d local_to_model_matrix = Geometry::translation_transform(center) * Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), normal); + const Vec3d local_proj = local_to_model_matrix.inverse() * plane.projection(world_pof); + double angle = std::atan2(local_proj.y(), local_proj.x()); + if (angle < 0.0) + angle += 2.0 * double(M_PI); + + const Vec3d local_pos = radius * Vec3d(std::cos(angle), std::sin(angle), 0.0); + m_curr_point_on_feature_position = local_to_model_matrix * local_pos; + } + break; + } + } } + } + else { + if (m_curr_feature.has_value() && m_curr_feature->get_type() == Measure::SurfaceFeatureType::Circle) { + if (update_circle()) { + m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID); + auto it = m_raycasters.find(CIRCLE_ID); + if (it != m_raycasters.end()) + m_raycasters.erase(it); + m_raycasters.insert({ CIRCLE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID, *m_circle.mesh_raycaster) }); + } + } + } - if (!m_curr_feature.has_value() && !m_selected_features.first.feature.has_value()) - return; + if (!m_curr_feature.has_value() && !m_selected_features.first.feature.has_value()) + return; - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); - if (shader == nullptr) - return; + GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); + if (shader == nullptr) + return; - shader->start_using(); - shader->set_uniform("projection_matrix", camera.get_projection_matrix()); + shader->start_using(); + shader->set_uniform("projection_matrix", camera.get_projection_matrix()); - glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); - glsafe(::glEnable(GL_DEPTH_TEST)); - const bool old_cullface = ::glIsEnabled(GL_CULL_FACE); - glsafe(::glDisable(GL_CULL_FACE)); + glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); + glsafe(::glEnable(GL_DEPTH_TEST)); + const bool old_cullface = ::glIsEnabled(GL_CULL_FACE); + glsafe(::glDisable(GL_CULL_FACE)); - const Transform3d& view_matrix = camera.get_view_matrix(); + const Transform3d& view_matrix = camera.get_view_matrix(); - auto set_matrix_uniforms = [shader, &view_matrix](const Transform3d& model_matrix) { - const Transform3d view_model_matrix = view_matrix * model_matrix; - shader->set_uniform("view_model_matrix", view_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(); - shader->set_uniform("view_normal_matrix", view_normal_matrix); - }; + auto set_matrix_uniforms = [shader, &view_matrix](const Transform3d& model_matrix) { + const Transform3d view_model_matrix = view_matrix * model_matrix; + shader->set_uniform("view_model_matrix", view_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(); + shader->set_uniform("view_normal_matrix", view_normal_matrix); + }; - auto set_emission_uniform = [this, shader](const ColorRGBA& color, bool hover) { - shader->set_uniform("emission_factor", (color == m_parent.get_selection().get_first_volume()->render_color) ? 0.0f : - hover ? 0.5f : 0.25f); - }; + auto set_emission_uniform = [this, shader](const ColorRGBA& color, bool hover) { + shader->set_uniform("emission_factor", (color == m_parent.get_selection().get_first_volume()->render_color) ? 0.0f : + hover ? 0.5f : 0.25f); + }; - auto render_feature = [this, set_matrix_uniforms, set_emission_uniform](const Measure::SurfaceFeature& feature, const std::vector& colors, - float inv_zoom, bool hover, bool update_raycasters_transform) { - switch (feature.get_type()) - { - default: { assert(false); break; } - case Measure::SurfaceFeatureType::Point: - { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Transform3d feature_matrix = Geometry::translation_transform(feature.get_point()) * Geometry::scale_transform(inv_zoom); -#else - const Vec3d position = TransformHelper::model_to_world(feature.get_point(), m_volume_matrix); - const Transform3d feature_matrix = Geometry::translation_transform(position) * Geometry::scale_transform(inv_zoom); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - set_matrix_uniforms(feature_matrix); + auto render_feature = [this, set_matrix_uniforms, set_emission_uniform](const Measure::SurfaceFeature& feature, const std::vector& colors, + float inv_zoom, bool hover, bool update_raycasters_transform) { + switch (feature.get_type()) + { + default: { assert(false); break; } + case Measure::SurfaceFeatureType::Point: + { + const Transform3d feature_matrix = Geometry::translation_transform(feature.get_point()) * Geometry::scale_transform(inv_zoom); + set_matrix_uniforms(feature_matrix); + set_emission_uniform(colors.front(), hover); + m_sphere.model.set_color(colors.front()); + m_sphere.model.render(); + if (update_raycasters_transform) { + auto it = m_raycasters.find(POINT_ID); + if (it != m_raycasters.end() && it->second != nullptr) + it->second->set_transform(feature_matrix); + } + break; + } + case Measure::SurfaceFeatureType::Circle: + { + const auto& [center, radius, normal] = feature.get_circle(); + // render center + if (update_raycasters_transform) { + const Transform3d center_matrix = Geometry::translation_transform(center) * Geometry::scale_transform(inv_zoom); + set_matrix_uniforms(center_matrix); set_emission_uniform(colors.front(), hover); m_sphere.model.set_color(colors.front()); m_sphere.model.render(); - if (update_raycasters_transform) { - auto it = m_raycasters.find(POINT_ID); - if (it != m_raycasters.end() && it->second != nullptr) - it->second->set_transform(feature_matrix); - } - break; + auto it = m_raycasters.find(POINT_ID); + if (it != m_raycasters.end() && it->second != nullptr) + it->second->set_transform(center_matrix); } - case Measure::SurfaceFeatureType::Circle: - { - const auto& [center, radius, normal] = feature.get_circle(); - // render center + // render circle + if (m_mode != EMode::CenterSelection) { + const Transform3d circle_matrix = Transform3d::Identity(); + set_matrix_uniforms(circle_matrix); if (update_raycasters_transform) { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Transform3d center_matrix = Geometry::translation_transform(center) * Geometry::scale_transform(inv_zoom); -#else - const Vec3d center_world = TransformHelper::model_to_world(center, m_volume_matrix); - const Transform3d center_matrix = Geometry::translation_transform(center_world) * Geometry::scale_transform(inv_zoom); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - set_matrix_uniforms(center_matrix); + set_emission_uniform(colors.back(), hover); + m_circle.model.set_color(colors.back()); + m_circle.model.render(); + auto it = m_raycasters.find(CIRCLE_ID); + if (it != m_raycasters.end() && it->second != nullptr) + it->second->set_transform(circle_matrix); + } + else { + GLModel circle; + GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); + circle.init_from(std::move(circle_geometry)); + set_emission_uniform(colors.back(), hover); + circle.set_color(colors.back()); + circle.render(); + } + } + break; + } + case Measure::SurfaceFeatureType::Edge: + { + const auto& [from, to] = feature.get_edge(); + // render extra point + if (update_raycasters_transform) { + const std::optional extra = feature.get_extra_point(); + if (extra.has_value()) { + const Transform3d point_matrix = Geometry::translation_transform(*extra) * Geometry::scale_transform(inv_zoom); + set_matrix_uniforms(point_matrix); set_emission_uniform(colors.front(), hover); m_sphere.model.set_color(colors.front()); m_sphere.model.render(); auto it = m_raycasters.find(POINT_ID); if (it != m_raycasters.end() && it->second != nullptr) - it->second->set_transform(center_matrix); + it->second->set_transform(point_matrix); } - // render circle - if (m_mode != EMode::CenterSelection) { - const Transform3d circle_matrix = Transform3d::Identity(); - set_matrix_uniforms(circle_matrix); - if (update_raycasters_transform) { - set_emission_uniform(colors.back(), hover); - m_circle.model.set_color(colors.back()); - m_circle.model.render(); - auto it = m_raycasters.find(CIRCLE_ID); - if (it != m_raycasters.end() && it->second != nullptr) - it->second->set_transform(circle_matrix); - } - else { - GLModel circle; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); -#else - GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), m_volume_matrix.cast()); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - circle.init_from(std::move(circle_geometry)); - set_emission_uniform(colors.back(), hover); - circle.set_color(colors.back()); - circle.render(); - } - } - break; } - case Measure::SurfaceFeatureType::Edge: - { - const auto& [from, to] = feature.get_edge(); - // render extra point + // render edge + if (m_mode != EMode::CenterSelection) { + const Transform3d edge_matrix = Geometry::translation_transform(from) * + Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), to - from) * + Geometry::scale_transform({ (double)inv_zoom, (double)inv_zoom, (to - from).norm() }); + set_matrix_uniforms(edge_matrix); + set_emission_uniform(colors.back(), hover); + m_cylinder.model.set_color(colors.back()); + m_cylinder.model.render(); if (update_raycasters_transform) { - const std::optional extra = feature.get_extra_point(); - if (extra.has_value()) { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Transform3d point_matrix = Geometry::translation_transform(*extra) * Geometry::scale_transform(inv_zoom); -#else - const Vec3d extra_world = TransformHelper::model_to_world(*extra, m_volume_matrix); - const Transform3d point_matrix = Geometry::translation_transform(extra_world) * Geometry::scale_transform(inv_zoom); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - set_matrix_uniforms(point_matrix); - set_emission_uniform(colors.front(), hover); - m_sphere.model.set_color(colors.front()); - m_sphere.model.render(); - auto it = m_raycasters.find(POINT_ID); - if (it != m_raycasters.end() && it->second != nullptr) - it->second->set_transform(point_matrix); - } - } - // render edge - if (m_mode != EMode::CenterSelection) { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Transform3d edge_matrix = Geometry::translation_transform(from) * - Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), to - from) * - Geometry::scale_transform({ (double)inv_zoom, (double)inv_zoom, (to - from).norm() }); -#else - const Vec3d from_world = TransformHelper::model_to_world(from, m_volume_matrix); - const Vec3d to_world = TransformHelper::model_to_world(to, m_volume_matrix); - const Transform3d edge_matrix = Geometry::translation_transform(from_world) * - Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), to_world - from_world) * - Geometry::scale_transform({ (double)inv_zoom, (double)inv_zoom, (to_world - from_world).norm() }); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - set_matrix_uniforms(edge_matrix); - set_emission_uniform(colors.back(), hover); - m_cylinder.model.set_color(colors.back()); - m_cylinder.model.render(); - if (update_raycasters_transform) { - auto it = m_raycasters.find(EDGE_ID); - if (it != m_raycasters.end() && it->second != nullptr) - it->second->set_transform(edge_matrix); - } - } - break; - } - case Measure::SurfaceFeatureType::Plane: - { - // no need to render the plane in case it is rendered with the same color as the volume in the 3D scene - if (colors.front() != m_parent.get_selection().get_first_volume()->render_color) { - const auto& [idx, normal, pt] = feature.get_plane(); - assert(idx < m_plane_models_cache.size()); -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - set_matrix_uniforms(Transform3d::Identity()); -#else - set_matrix_uniforms(m_volume_matrix); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - set_emission_uniform(colors.front(), hover); - m_plane_models_cache[idx].set_color(colors.front()); - m_plane_models_cache[idx].render(); - } - if (update_raycasters_transform) { - auto it = m_raycasters.find(PLANE_ID); + auto it = m_raycasters.find(EDGE_ID); if (it != m_raycasters.end() && it->second != nullptr) -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - it->second->set_transform(Transform3d::Identity()); -#else - it->second->set_transform(m_volume_matrix); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + it->second->set_transform(edge_matrix); } - break; } + break; + } + case Measure::SurfaceFeatureType::Plane: + { + // no need to render the plane in case it is rendered with the same color as the volume in the 3D scene + if (colors.front() != m_parent.get_selection().get_first_volume()->render_color) { + const auto& [idx, normal, pt] = feature.get_plane(); + assert(idx < m_plane_models_cache.size()); + set_matrix_uniforms(Transform3d::Identity()); + set_emission_uniform(colors.front(), hover); + m_plane_models_cache[idx].set_color(colors.front()); + m_plane_models_cache[idx].render(); } - }; + if (update_raycasters_transform) { + auto it = m_raycasters.find(PLANE_ID); + if (it != m_raycasters.end() && it->second != nullptr) + it->second->set_transform(Transform3d::Identity()); + } + break; + } + } + }; - auto hover_selection_color = [this]() { - return !m_selected_features.first.feature.has_value() ? SELECTED_1ST_COLOR : SELECTED_2ND_COLOR; - }; + auto hover_selection_color = [this]() { + return !m_selected_features.first.feature.has_value() ? SELECTED_1ST_COLOR : SELECTED_2ND_COLOR; + }; - auto hovering_color = [this, hover_selection_color, &selection]() { - return (m_mode == EMode::PointSelection) ? selection.get_first_volume()->render_color : hover_selection_color(); - }; + auto hovering_color = [this, hover_selection_color, &selection]() { + return (m_mode == EMode::PointSelection) ? selection.get_first_volume()->render_color : hover_selection_color(); + }; - if (m_curr_feature.has_value()) { - std::vector colors; - if (m_selected_features.first.feature.has_value() && *m_curr_feature == *m_selected_features.first.feature) + if (m_curr_feature.has_value()) { + std::vector colors; + if (m_selected_features.first.feature.has_value() && *m_curr_feature == *m_selected_features.first.feature) + colors.emplace_back(hovering_color()); + else if (m_selected_features.second.feature.has_value() && *m_curr_feature == *m_selected_features.second.feature) + colors.emplace_back(hovering_color()); + else { + switch (m_curr_feature->get_type()) + { + default: { assert(false); break; } + case Measure::SurfaceFeatureType::Point: + { + colors.emplace_back(hover_selection_color()); + break; + } + case Measure::SurfaceFeatureType::Edge: + case Measure::SurfaceFeatureType::Circle: + { + colors.emplace_back((m_hover_id == POINT_ID) ? hover_selection_color() : hovering_color()); colors.emplace_back(hovering_color()); - else if (m_selected_features.second.feature.has_value() && *m_curr_feature == *m_selected_features.second.feature) + break; + } + case Measure::SurfaceFeatureType::Plane: + { colors.emplace_back(hovering_color()); - else { - switch (m_curr_feature->get_type()) - { - default: { assert(false); break; } - case Measure::SurfaceFeatureType::Point: - { - colors.emplace_back(hover_selection_color()); - break; - } - case Measure::SurfaceFeatureType::Edge: - case Measure::SurfaceFeatureType::Circle: - { - colors.emplace_back((m_hover_id == POINT_ID) ? hover_selection_color() : hovering_color()); - colors.emplace_back(hovering_color()); - break; - } - case Measure::SurfaceFeatureType::Plane: - { - colors.emplace_back(hovering_color()); - break; - } - } + break; } - - render_feature(*m_curr_feature, colors, inv_zoom, true, true); - } - - if (m_selected_features.first.feature.has_value() && (!m_curr_feature.has_value() || *m_curr_feature != *m_selected_features.first.feature)) { - const std::vector colors = { SELECTED_1ST_COLOR }; - render_feature(*m_selected_features.first.feature, colors, inv_zoom, m_hover_id == SELECTION_1_ID, false); - if (m_selected_features.first.feature->get_type() == Measure::SurfaceFeatureType::Point) { - auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), - [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_1_ID; }); - if (it != m_selection_raycasters.end()) -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - (*it)->set_transform(Geometry::translation_transform(m_selected_features.first.feature->get_point()) * Geometry::scale_transform(inv_zoom)); -#else - (*it)->set_transform(m_volume_matrix * Geometry::translation_transform(m_selected_features.first.feature->get_point()) * Geometry::scale_transform(inv_zoom)); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - } - } - if (m_selected_features.second.feature.has_value() && (!m_curr_feature.has_value() || *m_curr_feature != *m_selected_features.second.feature)) { - const std::vector colors = { SELECTED_2ND_COLOR }; - render_feature(*m_selected_features.second.feature, colors, inv_zoom, m_hover_id == SELECTION_2_ID, false); - if (m_selected_features.second.feature->get_type() == Measure::SurfaceFeatureType::Point) { - auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), - [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_2_ID; }); - if (it != m_selection_raycasters.end()) -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - (*it)->set_transform(Geometry::translation_transform(m_selected_features.second.feature->get_point()) * Geometry::scale_transform(inv_zoom)); -#else - (*it)->set_transform(m_volume_matrix * Geometry::translation_transform(m_selected_features.second.feature->get_point()) * Geometry::scale_transform(inv_zoom)); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } } - if (is_hovering_on_feature && m_curr_point_on_feature_position.has_value()) { - if (m_hover_id != POINT_ID) { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Transform3d matrix = Geometry::translation_transform(*m_curr_point_on_feature_position) * Geometry::scale_transform(inv_zoom); -#else - const Vec3d position = TransformHelper::model_to_world(*m_curr_point_on_feature_position, m_volume_matrix); - const Transform3d matrix = Geometry::translation_transform(position) * Geometry::scale_transform(inv_zoom); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - set_matrix_uniforms(matrix); - const ColorRGBA color = hover_selection_color(); - set_emission_uniform(color, true); - m_sphere.model.set_color(color); - m_sphere.model.render(); - } - } - - shader->stop_using(); - - if (old_cullface) - glsafe(::glEnable(GL_CULL_FACE)); -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + render_feature(*m_curr_feature, colors, inv_zoom, true, true); } -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + + if (m_selected_features.first.feature.has_value() && (!m_curr_feature.has_value() || *m_curr_feature != *m_selected_features.first.feature)) { + const std::vector colors = { SELECTED_1ST_COLOR }; + render_feature(*m_selected_features.first.feature, colors, inv_zoom, m_hover_id == SELECTION_1_ID, false); + if (m_selected_features.first.feature->get_type() == Measure::SurfaceFeatureType::Point) { + auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), + [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_1_ID; }); + if (it != m_selection_raycasters.end()) + (*it)->set_transform(Geometry::translation_transform(m_selected_features.first.feature->get_point()) * Geometry::scale_transform(inv_zoom)); + } + } + if (m_selected_features.second.feature.has_value() && (!m_curr_feature.has_value() || *m_curr_feature != *m_selected_features.second.feature)) { + const std::vector colors = { SELECTED_2ND_COLOR }; + render_feature(*m_selected_features.second.feature, colors, inv_zoom, m_hover_id == SELECTION_2_ID, false); + if (m_selected_features.second.feature->get_type() == Measure::SurfaceFeatureType::Point) { + auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), + [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_2_ID; }); + if (it != m_selection_raycasters.end()) + (*it)->set_transform(Geometry::translation_transform(m_selected_features.second.feature->get_point()) * Geometry::scale_transform(inv_zoom)); + } + } + + if (is_hovering_on_feature && m_curr_point_on_feature_position.has_value()) { + if (m_hover_id != POINT_ID) { + const Transform3d matrix = Geometry::translation_transform(*m_curr_point_on_feature_position) * Geometry::scale_transform(inv_zoom); + set_matrix_uniforms(matrix); + const ColorRGBA color = hover_selection_color(); + set_emission_uniform(color, true); + m_sphere.model.set_color(color); + m_sphere.model.render(); + } + } + + shader->stop_using(); + + if (old_cullface) + glsafe(::glEnable(GL_CULL_FACE)); render_dimensioning(); } @@ -1066,7 +942,6 @@ void GLGizmoMeasure::update_if_needed() } }; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES auto do_update = [this, update_plane_models_cache](const std::vector& volumes_cache, const Selection& selection) { TriangleMesh composite_mesh; for (const auto& vol : volumes_cache) { @@ -1083,36 +958,11 @@ void GLGizmoMeasure::update_if_needed() m_raycaster.reset(new MeshRaycaster(std::make_shared(m_measuring->get_mesh()))); m_volumes_cache = volumes_cache; }; -#else - auto do_update = [this, update_plane_models_cache](const ModelObject* object, const ModelVolume* volume) { - const indexed_triangle_set& its = (volume != nullptr) ? volume->mesh().its : object->volumes.front()->mesh().its; - m_measuring.reset(new Measure::Measuring(its)); - - update_plane_models_cache(its); - - // Let's save what we calculated it from: - m_volumes_matrices.clear(); - m_volumes_types.clear(); - m_first_instance_scale = Vec3d::Ones(); - m_first_instance_mirror = Vec3d::Ones(); - if (object != nullptr) { - for (const ModelVolume* vol : object->volumes) { - m_volumes_matrices.push_back(vol->get_matrix()); - m_volumes_types.push_back(vol->type()); - } - m_first_instance_scale = object->instances.front()->get_scaling_factor(); - m_first_instance_mirror = object->instances.front()->get_mirror(); - } - m_old_model_object = object; - m_old_model_volume = volume; - }; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const Selection& selection = m_parent.get_selection(); if (selection.is_empty()) return; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const Selection::IndicesList& idxs = selection.get_volume_idxs(); std::vector volumes_cache; volumes_cache.reserve(idxs.size()); @@ -1130,36 +980,6 @@ void GLGizmoMeasure::update_if_needed() if (m_measuring == nullptr || m_volumes_cache != volumes_cache) do_update(volumes_cache, selection); -#else - m_volume_matrix = selection.get_first_volume()->world_matrix(); - - const ModelObject* mo = m_c->selection_info()->model_object(); - const ModelVolume* mv = m_c->selection_info()->model_volume(); - if (m_state != On || (mo == nullptr && mv == nullptr)) - return; - - if (mo == nullptr) - mo = mv->get_object(); - - if (mo->instances.empty()) - return; - - if (!m_measuring || mo != m_old_model_object || mv != m_old_model_volume || mo->volumes.size() != m_volumes_matrices.size()) - do_update(mo, mv); - - // We want to recalculate when the scale changes - some planes could (dis)appear. - if (!mo->instances.front()->get_scaling_factor().isApprox(m_first_instance_scale) || - !mo->instances.front()->get_mirror().isApprox(m_first_instance_mirror)) - do_update(mo, mv); - - for (unsigned int i = 0; i < mo->volumes.size(); ++i) { - if (!mo->volumes[i]->get_matrix().isApprox(m_volumes_matrices[i]) || - mo->volumes[i]->type() != m_volumes_types[i]) { - do_update(mo, mv); - break; - } - } -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } void GLGizmoMeasure::disable_scene_raycasters() @@ -1279,7 +1099,6 @@ void GLGizmoMeasure::render_dimensioning() const double ratio = new_value / old_value; wxGetApp().plater()->take_snapshot(_L("Scale")); -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES struct TrafoData { double ratio; @@ -1333,7 +1152,6 @@ void GLGizmoMeasure::render_dimensioning() const TrafoData trafo_data(ratio, m_parent.get_selection().get_bounding_box().center()); scale_feature(*m_selected_features.first.feature, trafo_data); scale_feature(*m_selected_features.second.feature, trafo_data); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES TransformationType type; type.set_world(); @@ -1392,14 +1210,7 @@ void GLGizmoMeasure::render_dimensioning() auto point_edge = [this, shader](const Measure::SurfaceFeature& f1, const Measure::SurfaceFeature& f2) { assert(f1.get_type() == Measure::SurfaceFeatureType::Point && f2.get_type() == Measure::SurfaceFeatureType::Edge); std::pair e = f2.get_edge(); - // Transform to world coordinates -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - e.first = TransformHelper::model_to_world(e.first, m_volume_matrix); - e.second = TransformHelper::model_to_world(e.second, m_volume_matrix); -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Vec3d v_proj = m_measurement_result.distance_infinite->to; - const Vec3d e1e2 = e.second - e.first; const Vec3d v_proje1 = v_proj - e.first; const bool on_e1_side = v_proje1.dot(e1e2) < -EPSILON; @@ -1677,21 +1488,12 @@ void GLGizmoMeasure::render_debug_dialog() { case Measure::SurfaceFeatureType::Point: { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(item.feature->get_point()), ImGui::GetStyleColorVec4(ImGuiCol_Text)); -#else - const Vec3d position = m_volume_matrix * item.feature->get_point(); - add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(position), ImGui::GetStyleColorVec4(ImGuiCol_Text)); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES break; } case Measure::SurfaceFeatureType::Edge: { auto [from, to] = item.feature->get_edge(); -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - from = m_volume_matrix * from; - to = m_volume_matrix * to; -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(from), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_pt2", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(to), ImGui::GetStyleColorVec4(ImGuiCol_Text)); break; @@ -1699,10 +1501,6 @@ void GLGizmoMeasure::render_debug_dialog() case Measure::SurfaceFeatureType::Plane: { auto [idx, normal, origin] = item.feature->get_plane(); -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - origin = m_volume_matrix * origin; - normal = m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal; -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(normal), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_pt2", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(origin), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_value", ImGuiWrapper::COL_ORANGE_LIGHT, format_double(idx), ImGui::GetStyleColorVec4(ImGuiCol_Text)); @@ -1711,13 +1509,7 @@ void GLGizmoMeasure::render_debug_dialog() case Measure::SurfaceFeatureType::Circle: { auto [center, radius, normal] = item.feature->get_circle(); -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const Vec3d on_circle = center + radius * Measure::get_orthogonal(normal, true); -#else - const Vec3d on_circle = m_volume_matrix * (center + radius * Measure::get_orthogonal(normal, true)); - center = m_volume_matrix * center; - normal = (m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal).normalized(); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES radius = (on_circle - center).norm(); add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(center), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_pt2", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(normal), ImGui::GetStyleColorVec4(ImGuiCol_Text)); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp index fbbf30da78..9699d73cc8 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp @@ -6,16 +6,10 @@ #include "slic3r/GUI/GUI_Utils.hpp" #include "slic3r/GUI/MeshUtils.hpp" #include "libslic3r/Measure.hpp" -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES #include "libslic3r/Model.hpp" -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES namespace Slic3r { -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES -class ModelVolume; -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - enum class ModelVolumeType : int; namespace Measure { class Measuring; } @@ -74,7 +68,6 @@ class GLGizmoMeasure : public GLGizmoBase } }; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES struct VolumeCacheItem { const ModelObject* object{ nullptr }; @@ -89,7 +82,6 @@ class GLGizmoMeasure : public GLGizmoBase }; std::vector m_volumes_cache; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES EMode m_mode{ EMode::FeatureSelection }; Measure::MeasurementResult m_measurement_result; @@ -108,13 +100,10 @@ class GLGizmoMeasure : public GLGizmoBase }; Dimensioning m_dimensioning; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // Uses a standalone raycaster and not the shared one because of the // difference in how the mesh is updated std::unique_ptr m_raycaster; -#else - Transform3d m_volume_matrix{ Transform3d::Identity() }; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + std::vector m_plane_models_cache; std::map> m_raycasters; std::vector> m_selection_raycasters; @@ -129,21 +118,11 @@ class GLGizmoMeasure : public GLGizmoBase std::vector m_scene_raycasters; // These hold information to decide whether recalculation is necessary: -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - std::vector m_volumes_matrices; - std::vector m_volumes_types; - Vec3d m_first_instance_scale{ Vec3d::Ones() }; - Vec3d m_first_instance_mirror{ Vec3d::Ones() }; -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES float m_last_inv_zoom{ 0.0f }; std::optional m_last_circle; int m_last_plane_idx{ -1 }; bool m_mouse_left_down{ false }; // for detection left_up of this gizmo -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const ModelObject* m_old_model_object{ nullptr }; - const ModelVolume* m_old_model_volume{ nullptr }; -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES Vec2d m_mouse_pos{ Vec2d::Zero() }; @@ -186,9 +165,6 @@ protected: bool on_is_activable() const override; void on_render() override; void on_set_state() override; -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - CommonGizmosDataID on_get_requirements() const override; -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES virtual void on_render_input_window(float x, float y, float bottom_limit) override; virtual void on_register_raycasters_for_picking() override; diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index 2e50fc37c9..ee06e008b9 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -602,7 +602,6 @@ bool Selection::contains_any_volume(const std::vector& volume_idxs return false; } -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES bool Selection::contains_sinking_volumes(bool ignore_modifiers) const { for (const GLVolume* v : *m_volumes) { @@ -613,7 +612,6 @@ bool Selection::contains_sinking_volumes(bool ignore_modifiers) const } return false; } -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES bool Selection::matches(const std::vector& volume_idxs) const { diff --git a/src/slic3r/GUI/Selection.hpp b/src/slic3r/GUI/Selection.hpp index 0064f27999..080acda0d1 100644 --- a/src/slic3r/GUI/Selection.hpp +++ b/src/slic3r/GUI/Selection.hpp @@ -337,10 +337,8 @@ public: bool contains_all_volumes(const std::vector& volume_idxs) const; // returns true if the selection contains at least one of the given indices bool contains_any_volume(const std::vector& volume_idxs) const; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // returns true if the selection contains any sinking volume bool contains_sinking_volumes(bool ignore_modifiers = true) const; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // returns true if the selection contains all and only the given indices bool matches(const std::vector& volume_idxs) const; From 45e6dbab8fc3b023a800918734832c032ac977e1 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 16 Nov 2022 09:38:19 +0100 Subject: [PATCH 006/109] Gizmo measure - Fixed orientation of arrows in arc dimensioning --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index e35dc79fd2..e4973287e6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1292,7 +1292,7 @@ void GLGizmoMeasure::render_dimensioning() const double angle = (endpoint_id == 1) ? 0.0 : step * double(resolution); const Vec3d position_model = Geometry::translation_transform(center) * (draw_radius * (Eigen::Quaternion(Eigen::AngleAxisd(angle, normal)) * e1_unit)); const Vec3d direction_model = (endpoint_id == 1) ? -normal.cross(position_model - center).normalized() : normal.cross(position_model - center).normalized(); - const auto qz = Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), normal); + const auto qz = Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), (endpoint_id == 1) ? normal : -normal); const auto qx = Eigen::Quaternion::FromTwoVectors(qz * Vec3d::UnitX(), direction_model); const Transform3d view_model_matrix = camera.get_view_matrix() * Geometry::translation_transform(position_model) * qx * qz * Geometry::scale_transform(camera.get_inv_zoom()); From 5e6041823873055e55d9286d2a6df9c421046053 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 16 Nov 2022 09:42:55 +0100 Subject: [PATCH 007/109] Fixed warnings --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index e4973287e6..23b130d282 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1115,7 +1115,7 @@ void GLGizmoMeasure::render_dimensioning() } }; - auto scale_feature = [this](Measure::SurfaceFeature& feature, const TrafoData& trafo_data) { + auto scale_feature = [](Measure::SurfaceFeature& feature, const TrafoData& trafo_data) { switch (feature.get_type()) { case Measure::SurfaceFeatureType::Point: @@ -1143,6 +1143,7 @@ void GLGizmoMeasure::render_dimensioning() feature = Measure::SurfaceFeature(Measure::SurfaceFeatureType::Plane, normal, trafo_data.transform(origin), std::nullopt, idx); break; } + default: { break; } } }; From 2c2f10beb7855654ff1289e8adbd39b917108806 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 16 Nov 2022 09:46:50 +0100 Subject: [PATCH 008/109] Fixed warnings --- src/libslic3r/Measure.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index cea9f0b77e..e3cd61cd1d 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -289,14 +289,14 @@ void MeasuringImpl::extract_features() // point happened to be inside the segment. The discrimination of too small segments // will follow, so we need a complete picture before that. if (circles_idxs.size() > 1 - && circles_idxs.back().second == angles.size()-1 + && circles_idxs.back().second == (int)angles.size()-1 && circles_idxs.front().first == 0) { // Possibly the same circle. Check that the angle and length criterion holds along the combined segment. bool same = true; double last_len = -1.; double last_angle = 0.; for (int i=circles_idxs.back().first + 1; i != circles_idxs.front().second; ++i) { - if (i == angles.size()) + if (i == (int)angles.size()) i = 1; if (last_len == -1.) { last_len = lengths[i]; @@ -345,12 +345,12 @@ void MeasuringImpl::extract_features() for (int i=int(circles_idxs.size())-1; i>=0; --i) { const auto& [start, end] = circles_idxs[i]; int N = start >= 0 - ? end - start + (start == 0 && end == border.size()-1 ? 0 : 1) // last point is the same as first + ? end - start + (start == 0 && end == (int)border.size()-1 ? 0 : 1) // last point is the same as first : end + (border.size() + start); if (N < 5) { circles.erase(circles.begin() + i); circles_idxs.erase(circles_idxs.begin() + i); - } else if (N <= 8 && start == 0 && end == border.size()-1) { + } else if (N <= 8 && start == 0 && end == (int)border.size()-1) { // This is a regular 5-8 polygon. Add the edges as edges with a special // point and remove the circle. Leave the indices in circles_idxs, so // the edges are not picked up again later. From 692573abf112e6b797cfa291cadec3c03544e9b9 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 16 Nov 2022 10:04:25 +0100 Subject: [PATCH 009/109] Removed debug code --- src/slic3r/GUI/MeshUtils.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/slic3r/GUI/MeshUtils.cpp b/src/slic3r/GUI/MeshUtils.cpp index 3805151af1..ba16aad251 100644 --- a/src/slic3r/GUI/MeshUtils.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -409,12 +409,6 @@ bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& Vec3d direction; line_from_mouse_pos(mouse_pos, trafo, camera, point, direction); - if (rand()%100 == 0) { - int a=5; - int b=6; - int c=7; - } - std::vector hits = m_emesh.query_ray_hits(point, direction); if (hits.empty()) From 1f0fbd500afd7f41e5e84426fdbcb9b0c3f281f9 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 16 Nov 2022 12:04:38 +0100 Subject: [PATCH 010/109] Gizmo measure - Fixed angle for perpendicular edge-plane use case --- src/libslic3r/Measure.cpp | 53 +++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index e3cd61cd1d..535b898cf4 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -27,6 +27,21 @@ static std::pair get_center_and_radius(const std::vector& return std::make_pair(trafo.inverse() * Vec3d(circle.center.x(), circle.center.y(), z), circle.radius); } +static std::array orthonormal_basis(const Vec3d& v) +{ + std::array ret; + ret[2] = v.normalized(); + int index; + ret[2].maxCoeff(&index); + switch (index) + { + case 0: { ret[0] = Vec3d(ret[2].y(), -ret[2].x(), 0.0).normalized(); break; } + case 1: { ret[0] = Vec3d(0.0, ret[2].z(), -ret[2].y()).normalized(); break; } + case 2: { ret[0] = Vec3d(-ret[2].z(), 0.0, ret[2].x()).normalized(); break; } + } + ret[1] = ret[2].cross(ret[0]).normalized(); + return ret; +} @@ -628,8 +643,8 @@ static AngleAndEdges angle_edge_edge(const std::pair& e1, const st static AngleAndEdges angle_edge_plane(const std::pair& e, const std::tuple& p) { const auto& [idx, normal, origin] = p; - const Vec3d e1e2_unit = edge_direction(e); - if (are_parallel(e1e2_unit, normal) || are_perpendicular(e1e2_unit, normal)) + Vec3d e1e2_unit = edge_direction(e); + if (are_perpendicular(e1e2_unit, normal)) return AngleAndEdges::Dummy; // ensure the edge is pointing away from the intersection @@ -641,8 +656,22 @@ static AngleAndEdges angle_edge_plane(const std::pair& e, const st // then verify edge direction and revert it, if needed Vec3d e1 = e.first; Vec3d e2 = e.second; - if ((e1 - inters).squaredNorm() > (e2 - inters).squaredNorm()) + if ((e1 - inters).squaredNorm() > (e2 - inters).squaredNorm()) { std::swap(e1, e2); + e1e2_unit = -e1e2_unit; + } + + if (are_parallel(e1e2_unit, normal)) { + const std::array basis = orthonormal_basis(e1e2_unit); + const double radius = (0.5 * (e1 + e2) - inters).norm(); + const Vec3d edge_on_plane_dir = (basis[1].dot(origin - inters) >= 0.0) ? basis[1] : -basis[1]; + std::pair edge_on_plane = std::make_pair(inters, inters + radius * edge_on_plane_dir); + if (!inters.isApprox(e1)) { + edge_on_plane.first += radius * edge_on_plane_dir; + edge_on_plane.second += radius * edge_on_plane_dir; + } + return AngleAndEdges(0.5 * double(PI), inters, std::make_pair(e1, e2), edge_on_plane, radius, inters.isApprox(e1)); + } const Vec3d e1e2 = e2 - e1; const double e1e2_len = e1e2.norm(); @@ -771,7 +800,8 @@ MeasurementResult get_measurement(const SurfaceFeature& a, const SurfaceFeature& /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// - } else if (f1.get_type() == SurfaceFeatureType::Edge) { + } + else if (f1.get_type() == SurfaceFeatureType::Edge) { if (f2.get_type() == SurfaceFeatureType::Edge) { std::vector distances; @@ -898,21 +928,6 @@ MeasurementResult get_measurement(const SurfaceFeature& a, const SurfaceFeature& const Vec3d D = c1 - c0; if (!are_parallel(n0, n1)) { - auto orthonormal_basis = [](const Vec3d& v) { - std::array ret; - ret[2] = v.normalized(); - int index; - ret[2].maxCoeff(&index); - switch (index) - { - case 0: { ret[0] = Vec3d(ret[2].y(), -ret[2].x(), 0.0).normalized(); break; } - case 1: { ret[0] = Vec3d(0.0, ret[2].z(), -ret[2].y()).normalized(); break; } - case 2: { ret[0] = Vec3d(-ret[2].z(), 0.0, ret[2].x()).normalized(); break; } - } - ret[1] = ret[2].cross(ret[0]).normalized(); - return ret; - }; - // Get parameters for constructing the degree-8 polynomial phi. const double one = 1.0; const double two = 2.0; From c57247b044928ed74318686d24a654bb26f61c84 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 16 Nov 2022 15:44:01 +0100 Subject: [PATCH 011/109] Removed debug code --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 23b130d282..33d65ddc53 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -396,7 +396,6 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) else if (mouse_event.RightDown()) { // let the event pass through to allow panning/rotating the 3D scene if ((m_mode != EMode::CenterSelection && mouse_event.CmdDown()) || (m_mode == EMode::CenterSelection && m_hover_id != SELECTION_1_ID && m_hover_id != SELECTION_2_ID)) { - std::cout << "RightDown -> false\n"; return false; } From 3eaa4b014996b8c37efba17eebaa048ad0eb9df8 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 18 Nov 2022 08:42:47 +0100 Subject: [PATCH 012/109] Gizmo measure - Draw background for dimensioning labels --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 33d65ddc53..6dfd5dbcec 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1068,8 +1068,17 @@ void GLGizmoMeasure::render_dimensioning() ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 1.0f, 1.0f }); m_imgui->begin(std::string("distance"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration); + ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow()); ImGui::AlignTextToFramePadding(); - m_imgui->text(curr_value_str + " " + units); + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + const ImVec2 pos = ImGui::GetCursorScreenPos(); + const std::string txt = curr_value_str + " " + units; + ImVec2 txt_size = ImGui::CalcTextSize(txt.c_str()); + const ImGuiStyle& style = ImGui::GetStyle(); + draw_list->AddRectFilled({ pos.x - style.FramePadding.x, pos.y + style.FramePadding.y }, { pos.x + txt_size.x + 2.0f * style.FramePadding.x , pos.y + txt_size.y + 2.0f * style.FramePadding.y }, + ImGuiWrapper::to_ImU32(ColorRGBA(0.5f, 0.5f, 0.5f, 0.5f))); + ImGui::SetCursorScreenPos({ pos.x + style.FramePadding.x, pos.y }); + m_imgui->text(txt); ImGui::SameLine(); if (m_imgui->image_button(ImGui::SliderFloatEditBtnIcon, _L("Edit to scale"))) { m_editing_distance = true; @@ -1342,7 +1351,16 @@ void GLGizmoMeasure::render_dimensioning() ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); m_imgui->begin(_L("##angle"), ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove); ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow()); - m_imgui->text(format_double(Geometry::rad2deg(angle)) + "°"); + ImGui::AlignTextToFramePadding(); + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + const ImVec2 pos = ImGui::GetCursorScreenPos(); + const std::string txt = format_double(Geometry::rad2deg(angle)) + "°"; + ImVec2 txt_size = ImGui::CalcTextSize(txt.c_str()); + const ImGuiStyle& style = ImGui::GetStyle(); + draw_list->AddRectFilled({ pos.x - style.FramePadding.x, pos.y + style.FramePadding.y }, { pos.x + txt_size.x + 2.0f * style.FramePadding.x , pos.y + txt_size.y + 2.0f * style.FramePadding.y }, + ImGuiWrapper::to_ImU32(ColorRGBA(0.5f, 0.5f, 0.5f, 0.5f))); + ImGui::SetCursorScreenPos({ pos.x + style.FramePadding.x, pos.y }); + m_imgui->text(txt); m_imgui->end(); ImGui::PopStyleVar(); }; From 4435484a0a9aa254add6a7b2285910778efbd967 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 18 Nov 2022 10:53:42 +0100 Subject: [PATCH 013/109] Gizmo measure - Show diameter of selected circles into imgui dialog --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 6dfd5dbcec..36a8ab0474 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1786,10 +1786,23 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit ImGui::Separator(); const ImGuiTableFlags flags = ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersH; if (ImGui::BeginTable("Selection", 2, flags)) { - add_strings_row_to_table(*m_imgui, _u8L("Selection") + " 1:", ImGuiWrapper::to_ImVec4(SELECTED_1ST_COLOR), m_selected_features.first.feature.has_value() ? - m_selected_features.first.source : _u8L("None"), ImGuiWrapper::to_ImVec4(SELECTED_1ST_COLOR)); - add_strings_row_to_table(*m_imgui, _u8L("Selection") + " 2:", ImGuiWrapper::to_ImVec4(SELECTED_2ND_COLOR), m_selected_features.second.feature.has_value() ? - m_selected_features.second.source : _u8L("None"), ImGuiWrapper::to_ImVec4(SELECTED_2ND_COLOR)); + auto format_item_text = [use_inches, &units](const SelectedFeatures::Item& item) { + std::string txt = item.feature.has_value() ? item.source : _u8L("None"); + if (item.feature.has_value() && item.feature->get_type() == Measure::SurfaceFeatureType::Circle) { + auto [center, radius, normal] = item.feature->get_circle(); + const Vec3d on_circle = center + radius * Measure::get_orthogonal(normal, true); + radius = (on_circle - center).norm(); + if (use_inches) + radius = ObjectManipulation::mm_to_in * radius; + txt += " (" + _u8L("Diameter:") + " " + format_double(2.0 * radius) + units + ")"; + } + return txt; + }; + + add_strings_row_to_table(*m_imgui, _u8L("Selection") + " 1:", ImGuiWrapper::to_ImVec4(SELECTED_1ST_COLOR), format_item_text(m_selected_features.first), + ImGuiWrapper::to_ImVec4(SELECTED_1ST_COLOR)); + add_strings_row_to_table(*m_imgui, _u8L("Selection") + " 2:", ImGuiWrapper::to_ImVec4(SELECTED_2ND_COLOR), format_item_text(m_selected_features.second), + ImGuiWrapper::to_ImVec4(SELECTED_2ND_COLOR)); ImGui::EndTable(); } From 83c0be60610aec8d763a4a7abeb1c501928203b0 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 18 Nov 2022 11:17:20 +0100 Subject: [PATCH 014/109] Removed commented out code --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 104 ----------------------- 1 file changed, 104 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 36a8ab0474..0b7a43c746 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1679,110 +1679,6 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit const bool use_inches = wxGetApp().app_config->get("use_inches") == "1"; const std::string units = use_inches ? " " + _u8L("in") : " " + _u8L("mm"); - //const Measure::SurfaceFeatureType feature_type = m_curr_feature.has_value() ? m_curr_feature->get_type() : Measure::SurfaceFeatureType::Undef; - //bool data_text_set = false; - //ImGui::Separator(); - //if (feature_type != Measure::SurfaceFeatureType::Undef) { - // if (m_mode == EMode::FeatureSelection) { - // m_imgui->text(surface_feature_type_as_string(feature_type)); - // data_text_set = true; - // } - // else if (m_mode == EMode::PointSelection) { - // if (m_hover_id != -1 && m_curr_point_on_feature_position.has_value()) { - // m_imgui->text(point_on_feature_type_as_string(feature_type, m_hover_id)); - // data_text_set = true; - // } - // } - // else if (m_mode == EMode::CenterSelection) { - // if (m_hover_id != -1 && m_curr_point_on_feature_position.has_value()) { - // m_imgui->text(center_on_feature_type_as_string(feature_type)); - // data_text_set = true; - // } - // } - //} - //if (!data_text_set) - // m_imgui->text(_u8L("No feature")); - - //const unsigned int max_data_row_count = 3; - //unsigned int data_row_count = 0; - //if (ImGui::BeginTable("Data", 2)) { - // if (m_mode == EMode::FeatureSelection) { - // switch (feature_type) - // { - // default: { break; } - // case Measure::SurfaceFeatureType::Point: - // { - // Vec3d position = m_volume_matrix * m_curr_feature->get_point(); - // if (use_inches) - // position = ObjectManipulation::mm_to_in * position; - // add_strings_row_to_table(*m_imgui, _u8L("Position"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(position), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // data_row_count = 1; - // break; - // } - // case Measure::SurfaceFeatureType::Edge: - // { - // auto [from, to] = m_curr_feature->get_edge(); - // from = m_volume_matrix * from; - // to = m_volume_matrix * to; - // if (use_inches) { - // from = ObjectManipulation::mm_to_in * from; - // to = ObjectManipulation::mm_to_in * to; - // } - // add_strings_row_to_table(*m_imgui, _u8L("From"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(from), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // add_strings_row_to_table(*m_imgui, _u8L("To"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(to), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // add_strings_row_to_table(*m_imgui, _u8L("Length"), ImGuiWrapper::COL_ORANGE_LIGHT, format_double((to - from).norm()) + units, ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // data_row_count = 3; - // break; - // } - // case Measure::SurfaceFeatureType::Circle: - // { - // auto [center, radius, normal] = m_curr_feature->get_circle(); - // // generic point on circle, used to recalculate radius after transformation - // const Vec3d on_circle = m_volume_matrix * (center + radius * Measure::get_orthogonal(normal, true)); - // center = m_volume_matrix * center; - // normal = (m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal).normalized(); - // radius = (on_circle - center).norm(); - // if (use_inches) { - // center = ObjectManipulation::mm_to_in * center; - // radius = ObjectManipulation::mm_to_in * radius; - // } - // add_strings_row_to_table(*m_imgui, _u8L("Center"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(center), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // add_strings_row_to_table(*m_imgui, _u8L("Radius"), ImGuiWrapper::COL_ORANGE_LIGHT, format_double(radius) + units, ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // add_strings_row_to_table(*m_imgui, _u8L("Normal"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(normal), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // data_row_count = 3; - // break; - // } - // case Measure::SurfaceFeatureType::Plane: - // { - // auto [idx, normal, origin] = m_curr_feature->get_plane(); - // origin = m_volume_matrix * origin; - // normal = m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal; - // if (use_inches) - // origin = ObjectManipulation::mm_to_in * origin; - // add_strings_row_to_table(*m_imgui, _u8L("Origin"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(origin), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // add_strings_row_to_table(*m_imgui, _u8L("Normal"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(normal), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // data_row_count = 2; - // break; - // } - // } - // } - // else { - // if (m_hover_id != -1 && m_curr_point_on_feature_position.has_value()) { - // Vec3d position = m_volume_matrix * *m_curr_point_on_feature_position; - // if (use_inches) - // position = ObjectManipulation::mm_to_in * position; - // add_strings_row_to_table(*m_imgui, _u8L("Position"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(position), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // data_row_count = 1; - // } - // } - - // // add dummy rows to keep dialog size fixed - // for (unsigned int i = data_row_count; i < max_data_row_count; ++i) { - // add_strings_row_to_table(*m_imgui, " ", ImGuiWrapper::COL_ORANGE_LIGHT, " ", ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // } - // ImGui::EndTable(); - //} - ImGui::Separator(); const ImGuiTableFlags flags = ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersH; if (ImGui::BeginTable("Selection", 2, flags)) { From 3485db4f1b82495e34f33be1d3769466a1b6805b Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 18 Nov 2022 14:53:19 +0100 Subject: [PATCH 015/109] Gizmo measure - Render dimensioning thicker main lines --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 72 +++++++++++++++++++++++- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 0b7a43c746..ed83ae7ca9 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1003,7 +1003,7 @@ void GLGizmoMeasure::render_dimensioning() if (shader == nullptr) return; - auto point_point = [this, shader](const Vec3d& v1, const Vec3d& v2, float distance) { + auto point_point = [this, &shader](const Vec3d& v1, const Vec3d& v2, float distance) { if ((v2 - v1).squaredNorm() < 0.000001 || distance < 0.001f) return; @@ -1033,6 +1033,25 @@ void GLGizmoMeasure::render_dimensioning() const Transform3d ss_to_ndc_matrix = TransformHelper::ndc_to_ss_matrix_inverse(viewport); +#if ENABLE_GL_CORE_PROFILE + if (OpenGLManager::get_gl_info().is_core_profile()) { + shader->stop_using(); + + shader = wxGetApp().get_shader("dashed_thick_lines"); + if (shader == nullptr) + return; + + shader->start_using(); + shader->set_uniform("projection_matrix", Transform3d::Identity()); + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 1.0f); + shader->set_uniform("gap_size", 0.0f); + } + else +#endif // ENABLE_GL_CORE_PROFILE + glsafe(::glLineWidth(2.0f)); + // stem shader->set_uniform("view_model_matrix", overlap ? ss_to_ndc_matrix * Geometry::translation_transform(v1ss_3) * q12ss * Geometry::translation_transform(-2.0 * TRIANGLE_HEIGHT * Vec3d::UnitX()) * Geometry::scale_transform({ v12ss_len + 4.0 * TRIANGLE_HEIGHT, 1.0f, 1.0f }) : @@ -1040,6 +1059,20 @@ void GLGizmoMeasure::render_dimensioning() m_dimensioning.line.set_color(ColorRGBA::WHITE()); m_dimensioning.line.render(); +#if ENABLE_GL_CORE_PROFILE + if (OpenGLManager::get_gl_info().is_core_profile()) { + shader->stop_using(); + + shader = wxGetApp().get_shader("flat"); + if (shader == nullptr) + return; + + shader->start_using(); + } + else +#endif // ENABLE_GL_CORE_PROFILE + glsafe(::glLineWidth(1.0f)); + // arrow 1 shader->set_uniform("view_model_matrix", overlap ? ss_to_ndc_matrix * Geometry::translation_transform(v1ss_3) * q12ss : @@ -1248,7 +1281,7 @@ void GLGizmoMeasure::render_dimensioning() } }; - auto arc_edge_edge = [this, shader](const Measure::SurfaceFeature& f1, const Measure::SurfaceFeature& f2, double radius = 0.0) { + auto arc_edge_edge = [this, &shader](const Measure::SurfaceFeature& f1, const Measure::SurfaceFeature& f2, double radius = 0.0) { assert(f1.get_type() == Measure::SurfaceFeatureType::Edge && f2.get_type() == Measure::SurfaceFeatureType::Edge); if (!m_measurement_result.angle.has_value()) return; @@ -1290,12 +1323,45 @@ void GLGizmoMeasure::render_dimensioning() m_dimensioning.arc.init_from(std::move(init_data)); } - // arc const Camera& camera = wxGetApp().plater()->get_camera(); +#if ENABLE_GL_CORE_PROFILE + if (OpenGLManager::get_gl_info().is_core_profile()) { + shader->stop_using(); + + shader = wxGetApp().get_shader("dashed_thick_lines"); + if (shader == nullptr) + return; + + shader->start_using(); + shader->set_uniform("projection_matrix", Transform3d::Identity()); + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 1.0f); + shader->set_uniform("gap_size", 0.0f); + } + else +#endif // ENABLE_GL_CORE_PROFILE + glsafe(::glLineWidth(2.0f)); + + // arc shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * Geometry::translation_transform(center)); m_dimensioning.arc.render(); +#if ENABLE_GL_CORE_PROFILE + if (OpenGLManager::get_gl_info().is_core_profile()) { + shader->stop_using(); + + shader = wxGetApp().get_shader("flat"); + if (shader == nullptr) + return; + + shader->start_using(); + } + else +#endif // ENABLE_GL_CORE_PROFILE + glsafe(::glLineWidth(1.0f)); + // arrows auto render_arrow = [this, shader, &camera, &normal, ¢er, &e1_unit, draw_radius, step, resolution](unsigned int endpoint_id) { const double angle = (endpoint_id == 1) ? 0.0 : step * double(resolution); From fdc9c73340060cea7d8335e1211836681e18cae0 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 21 Nov 2022 08:37:58 +0100 Subject: [PATCH 016/109] Gizmo Measure - When CTRL+dragging to pan/rotate the scene, do not select the hovered feature, if any --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index ed83ae7ca9..179e8c5d2d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -254,6 +254,7 @@ GLGizmoMeasure::GLGizmoMeasure(GLCanvas3D& parent, const std::string& icon_filen bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) { m_mouse_pos = { double(mouse_event.GetX()), double(mouse_event.GetY()) }; + m_dragging = false; if (mouse_event.Moving()) { // only for sure @@ -261,6 +262,8 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) return false; } else if (mouse_event.Dragging()) { + m_dragging = true; + // Enable/Disable panning/rotating the 3D scene // Ctrl is pressed or the mouse is not hovering a selected volume bool unlock_dragging = mouse_event.CmdDown() || (m_hover_id == -1 && !m_parent.get_selection().contains_volume(m_parent.get_first_hover_volume_idx())); @@ -578,7 +581,9 @@ void GLGizmoMeasure::on_render() m_curr_point_on_feature_position.reset(); } else { - std::optional curr_feature = mouse_on_object ? m_measuring->get_feature(model_facet_idx, position_on_model.cast()) : std::nullopt; + std::optional curr_feature = m_dragging ? m_curr_feature : + mouse_on_object ? m_measuring->get_feature(model_facet_idx, position_on_model.cast()) : std::nullopt; + if (m_curr_feature != curr_feature || (curr_feature.has_value() && curr_feature->get_type() == Measure::SurfaceFeatureType::Circle && (m_curr_feature != curr_feature || m_last_inv_zoom != inv_zoom))) { m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID); From 4660527dda6881c1dfb51b115a75f8cfddf17cbd Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 21 Nov 2022 09:13:28 +0100 Subject: [PATCH 017/109] Gizmo Measure - Use [Delete] key in place of Shift+Right mouse to restart selection --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 13 ++++++------- src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 179e8c5d2d..153ffaf8df 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -401,12 +401,6 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) if ((m_mode != EMode::CenterSelection && mouse_event.CmdDown()) || (m_mode == EMode::CenterSelection && m_hover_id != SELECTION_1_ID && m_hover_id != SELECTION_2_ID)) { return false; } - - if (mouse_event.ShiftDown()) { - m_selected_features.reset(); - m_selection_raycasters.clear(); - m_parent.request_extra_frame(); - } } else if (mouse_event.Leaving()) m_mouse_left_down = false; @@ -477,6 +471,11 @@ bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_po m_mode = control_down ? EMode::PointSelection : EMode::FeatureSelection; restore_scene_raycasters_state(); } + else if (action == SLAGizmoEventType::Delete) { + m_selected_features.reset(); + m_selection_raycasters.clear(); + m_parent.request_extra_frame(); + } return true; } @@ -1735,7 +1734,7 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit } if (m_selected_features.first.feature.has_value()) { - add_strings_row_to_table(*m_imgui, _u8L("Shift") + "+" + _u8L("Right mouse button"), ImGuiWrapper::COL_ORANGE_LIGHT, _u8L("Restart selection"), ImGui::GetStyleColorVec4(ImGuiCol_Text)); + add_strings_row_to_table(*m_imgui, _u8L("Delete"), ImGuiWrapper::COL_ORANGE_LIGHT, _u8L("Restart selection"), ImGui::GetStyleColorVec4(ImGuiCol_Text)); ++row_count; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 07b4baa350..a97dce346d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -552,7 +552,7 @@ bool GLGizmosManager::on_char(wxKeyEvent& evt) case WXK_BACK: case WXK_DELETE: { - if ((m_current == SlaSupports || m_current == Hollow || m_current == Cut) && gizmo_event(SLAGizmoEventType::Delete)) + if ((m_current == SlaSupports || m_current == Hollow || m_current == Cut || m_current == Measure) && gizmo_event(SLAGizmoEventType::Delete)) processed = true; break; From 5cbe5c9d73e83f39469d62c8e1614898fb58e734 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 21 Nov 2022 09:46:30 +0100 Subject: [PATCH 018/109] Gizmo Measure - Added [Restart selection] button to imgui dialog --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 153ffaf8df..ae1f90a258 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1772,13 +1772,13 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit ImGui::EndTable(); } - //if (m_selected_features.first.feature.has_value()) { - // if (m_imgui->button(_u8L("Restart"))) { - // m_selected_features.reset(); - // m_selection_raycasters.clear(); - // m_imgui->set_requires_extra_frame(); - // } - //} + m_imgui->disabled_begin(!m_selected_features.first.feature.has_value()); + if (m_imgui->button(_u8L("Restart selection"))) { + m_selected_features.reset(); + m_selection_raycasters.clear(); + m_imgui->set_requires_extra_frame(); + } + m_imgui->disabled_end(); auto add_measure_row_to_table = [this](const std::string& col_1, const ImVec4& col_1_color, const std::string& col_2, const ImVec4& col_2_color) { ImGui::TableNextRow(); From f0e8a22504da74e8ddc3867a0cf14b821a32d736 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 21 Nov 2022 10:26:53 +0100 Subject: [PATCH 019/109] Gizmo Measure - Clicking on 1st selected let second selected to be promoted as first selected --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 27 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index ae1f90a258..1ec7cc5c1c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -354,6 +354,10 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) else { if (!m_selected_features.second.feature.has_value()) m_selected_features.first.reset(); + else { + m_selected_features.first = m_selected_features.second; + m_selected_features.second.reset(); + } } } else { @@ -850,7 +854,7 @@ void GLGizmoMeasure::on_render() }; auto hover_selection_color = [this]() { - return !m_selected_features.first.feature.has_value() ? SELECTED_1ST_COLOR : SELECTED_2ND_COLOR; + return (!m_selected_features.first.feature.has_value() || *m_curr_feature == *m_selected_features.first.feature) ? SELECTED_1ST_COLOR : SELECTED_2ND_COLOR; }; auto hovering_color = [this, hover_selection_color, &selection]() { @@ -1690,14 +1694,27 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit std::string text; ColorRGBA color; if (m_selected_features.second.feature.has_value()) { - if (m_selected_features.second.feature == m_curr_feature && m_mode == EMode::FeatureSelection) + if (m_selected_features.first.feature == m_curr_feature && m_mode == EMode::FeatureSelection) { text = _u8L("Unselect feature"); - else if (m_hover_id == SELECTION_2_ID) + color = SELECTED_1ST_COLOR; + } + else if (m_selected_features.second.feature == m_curr_feature && m_mode == EMode::FeatureSelection) { + text = _u8L("Unselect feature"); + color = SELECTED_2ND_COLOR; + } + else if (m_hover_id == SELECTION_1_ID) { text = (m_mode == EMode::CenterSelection) ? _u8L("Unselect center") : _u8L("Unselect point"); - else + color = SELECTED_1ST_COLOR; + } + else if (m_hover_id == SELECTION_2_ID) { + text = (m_mode == EMode::CenterSelection) ? _u8L("Unselect center") : _u8L("Unselect point"); + color = SELECTED_2ND_COLOR; + } + else { text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : (m_mode == EMode::CenterSelection) ? _u8L("Select center") : _u8L("Select feature"); - color = SELECTED_2ND_COLOR; + color = SELECTED_2ND_COLOR; + } } else { if (m_selected_features.first.feature.has_value()) { From 621a43c3a2b5eca5373206eee9798ee2bb33a7f7 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 21 Nov 2022 11:20:14 +0100 Subject: [PATCH 020/109] Gizmo Measure - Handling of [ESC] key When two features are selected -> unselected second feature When one feature is selected -> unselect first feature When no feature is selected -> close gizmo --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 31 ++++++++++++++++++++++- src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp | 1 + src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 5 +++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 1ec7cc5c1c..d50ef9e269 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -480,6 +480,16 @@ bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_po m_selection_raycasters.clear(); m_parent.request_extra_frame(); } + else if (action == SLAGizmoEventType::Escape) { + if (!m_selected_features.first.feature.has_value()) + return false; + else { + if (m_selected_features.second.feature.has_value()) + m_selected_features.second.feature.reset(); + else + m_selected_features.first.feature.reset(); + } + } return true; } @@ -1755,8 +1765,27 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit ++row_count; } + if (m_selected_features.first.feature.has_value() || m_selected_features.second.feature.has_value()) { + add_row_to_table( + [this]() { + m_imgui->text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, _u8L("Esc")); + }, + [this]() { + m_imgui->text_colored(ImGui::GetStyleColorVec4(ImGuiCol_Text), _u8L("Unselect")); + ImGui::SameLine(); + const ImVec2 pos = ImGui::GetCursorScreenPos(); + const float rect_size = ImGui::GetTextLineHeight(); + const ColorRGBA color = m_selected_features.second.feature.has_value() ? SELECTED_2ND_COLOR : SELECTED_1ST_COLOR; + ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(pos.x + 1.0f, pos.y + 1.0f), ImVec2(pos.x + rect_size, pos.y + rect_size), ImGuiWrapper::to_ImU32(color)); + ImGui::Dummy(ImVec2(rect_size, rect_size)); + } + ); + + ++row_count; + } + // add dummy rows to keep dialog size fixed - for (unsigned int i = row_count; i < 4; ++i) { + for (unsigned int i = row_count; i < 5; ++i) { add_strings_row_to_table(*m_imgui, " ", ImGuiWrapper::COL_ORANGE_LIGHT, " ", ImGui::GetStyleColorVec4(ImGuiCol_Text)); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp index 3878c6b25a..c1b605726c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp @@ -29,6 +29,7 @@ enum class SLAGizmoEventType : unsigned char { ShiftDown, ShiftUp, AltUp, + Escape, ApplyChanges, DiscardChanges, AutomaticGeneration, diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index a97dce346d..62ccce73e4 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -524,7 +524,10 @@ bool GLGizmosManager::on_char(wxKeyEvent& evt) case WXK_ESCAPE: { if (m_current != Undefined) { - if ((m_current != SlaSupports) || !gizmo_event(SLAGizmoEventType::DiscardChanges)) + if (m_current == Measure && gizmo_event(SLAGizmoEventType::Escape)) { + // do nothing + } + else if (m_current != SlaSupports || !gizmo_event(SLAGizmoEventType::DiscardChanges)) reset_all_states(); processed = true; From e6ea462ae63d6ae38e1cf174b32c2cfb6d1baaf5 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 21 Nov 2022 12:01:22 +0100 Subject: [PATCH 021/109] Gizmo Measure - Fixed point color and hint in dialog when adding a point on a selected feature --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index d50ef9e269..428ce5617e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -864,7 +864,9 @@ void GLGizmoMeasure::on_render() }; auto hover_selection_color = [this]() { - return (!m_selected_features.first.feature.has_value() || *m_curr_feature == *m_selected_features.first.feature) ? SELECTED_1ST_COLOR : SELECTED_2ND_COLOR; + return ((m_mode == EMode::PointSelection && !m_selected_features.first.feature.has_value()) || + (m_mode != EMode::PointSelection && (!m_selected_features.first.feature.has_value() || *m_curr_feature == *m_selected_features.first.feature))) ? + SELECTED_1ST_COLOR : SELECTED_2ND_COLOR; }; auto hovering_color = [this, hover_selection_color, &selection]() { @@ -1728,11 +1730,14 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit } else { if (m_selected_features.first.feature.has_value()) { - if (m_selected_features.first.feature == m_curr_feature) + if (m_selected_features.first.feature == m_curr_feature && m_mode == EMode::FeatureSelection) { text = _u8L("Unselect feature"); - else if (m_hover_id == SELECTION_1_ID) + color = SELECTED_1ST_COLOR; + } + else if (m_hover_id == SELECTION_1_ID) { text = (m_mode == EMode::CenterSelection) ? _u8L("Unselect center") : _u8L("Unselect point"); - color = SELECTED_1ST_COLOR; + color = SELECTED_1ST_COLOR; + } } if (text.empty()) { text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : From 42e78720f98fc36bc9e5cb74bbc5582290bcf839 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 21 Nov 2022 14:44:31 +0100 Subject: [PATCH 022/109] Fixed crash when opening Measure Gizmo after slicing in SLA mode --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 428ce5617e..2b6e1dcd3e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -965,7 +965,7 @@ void GLGizmoMeasure::update_if_needed() // continue; TriangleMesh volume_mesh = vol.volume->mesh(); - volume_mesh.transform(vol.instance->get_transformation().get_matrix() * vol.volume->get_transformation().get_matrix()); + volume_mesh.transform(vol.world_trafo); composite_mesh.merge(volume_mesh); } @@ -984,10 +984,17 @@ void GLGizmoMeasure::update_if_needed() volumes_cache.reserve(idxs.size()); for (unsigned int idx : idxs) { const GLVolume* v = selection.get_volume(idx); + const int volume_idx = v->volume_idx(); + if (volume_idx < 0) + continue; + const ModelObject* obj = selection.get_model()->objects[v->object_idx()]; const ModelInstance* inst = obj->instances[v->instance_idx()]; - const ModelVolume* vol = obj->volumes[v->volume_idx()]; - const VolumeCacheItem item = { obj, inst, vol, inst->get_matrix() * vol->get_matrix() }; + const ModelVolume* vol = obj->volumes[volume_idx]; + const VolumeCacheItem item = { + obj, inst, vol, + Geometry::translation_transform(selection.get_first_volume()->get_sla_shift_z() * Vec3d::UnitZ()) * inst->get_matrix() * vol->get_matrix() + }; volumes_cache.emplace_back(item); } From b75e403d147eef901d13b15a1cb64a9e5cd6482b Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 22 Nov 2022 08:34:12 +0100 Subject: [PATCH 023/109] Gizmo measure - Fixed dimensioning after scaling a part of a multipart object --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 2b6e1dcd3e..1395847994 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1171,16 +1171,14 @@ void GLGizmoMeasure::render_dimensioning() Vec3d new_pivot; Transform3d scale_matrix; - TrafoData(double ratio, const Vec3d& pivot) { + TrafoData(double ratio, const Vec3d& old_pivot, const Vec3d& new_pivot) { this->ratio = ratio; this->scale_matrix = Geometry::scale_transform(ratio); - this->old_pivot = pivot; - this->new_pivot = { pivot.x(), pivot.y(), (this->scale_matrix * pivot).z() }; + this->old_pivot = old_pivot; + this->new_pivot = new_pivot; } - Vec3d transform(const Vec3d& point) const { - return this->scale_matrix * (point - this->old_pivot) + this->new_pivot; - } + Vec3d transform(const Vec3d& point) const { return this->scale_matrix * (point - this->old_pivot) + this->new_pivot; } }; auto scale_feature = [](Measure::SurfaceFeature& feature, const TrafoData& trafo_data) { @@ -1215,22 +1213,26 @@ void GLGizmoMeasure::render_dimensioning() } }; - const TrafoData trafo_data(ratio, m_parent.get_selection().get_bounding_box().center()); - scale_feature(*m_selected_features.first.feature, trafo_data); - scale_feature(*m_selected_features.second.feature, trafo_data); - + // apply scale TransformationType type; type.set_world(); type.set_relative(); type.set_joint(); - // apply scale + // scale selection Selection& selection = m_parent.get_selection(); + const Vec3d old_center = selection.get_bounding_box().center(); selection.setup_cache(); selection.scale(ratio * Vec3d::Ones(), type); wxGetApp().plater()->canvas3D()->do_scale(""); // avoid storing another snapshot wxGetApp().obj_manipul()->set_dirty(); + // scale dimensioning + const Vec3d new_center = selection.get_bounding_box().center(); + const TrafoData trafo_data(ratio, old_center, new_center); + scale_feature(*m_selected_features.first.feature, trafo_data); + scale_feature(*m_selected_features.second.feature, trafo_data); + // update measure on next call to data_changed() m_pending_scale = true; }; From 9bdaf0bae2ba857204e3ed95c7683ab9baa4df8b Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 22 Nov 2022 12:36:51 +0100 Subject: [PATCH 024/109] Gizmo measure - Fixed incorrect point on feature detection --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 1395847994..1e4ba61c70 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -666,7 +666,7 @@ void GLGizmoMeasure::on_render() return trafo * p.cast(); } } - return Vec3d::Zero(); + return Vec3d(DBL_MAX, DBL_MAX, DBL_MAX); }; if (m_curr_feature.has_value()) { @@ -683,8 +683,11 @@ void GLGizmoMeasure::on_render() const std::optional extra = m_curr_feature->get_extra_point(); if (extra.has_value() && m_hover_id == POINT_ID) m_curr_point_on_feature_position = *extra; - else - m_curr_point_on_feature_position = position_on_feature(EDGE_ID, camera, [](const Vec3f& v) { return Vec3f(0.0f, 0.0f, v.z()); }); + else { + const Vec3d pos = position_on_feature(EDGE_ID, camera, [](const Vec3f& v) { return Vec3f(0.0f, 0.0f, v.z()); }); + if (!pos.isApprox(Vec3d(DBL_MAX, DBL_MAX, DBL_MAX))) + m_curr_point_on_feature_position = pos; + } break; } case Measure::SurfaceFeatureType::Plane: @@ -715,6 +718,7 @@ void GLGizmoMeasure::on_render() } } else { + m_curr_point_on_feature_position.reset(); if (m_curr_feature.has_value() && m_curr_feature->get_type() == Measure::SurfaceFeatureType::Circle) { if (update_circle()) { m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID); From d1146ae67a74ef441efbeac0bc55c951f70d028c Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 22 Nov 2022 13:13:25 +0100 Subject: [PATCH 025/109] Gizmo measure - Fixed calculation of angle edge-plane --- src/libslic3r/Measure.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 535b898cf4..17689063c3 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -32,7 +32,7 @@ static std::array orthonormal_basis(const Vec3d& v) std::array ret; ret[2] = v.normalized(); int index; - ret[2].maxCoeff(&index); + ret[2].cwiseAbs().maxCoeff(&index); switch (index) { case 0: { ret[0] = Vec3d(ret[2].y(), -ret[2].x(), 0.0).normalized(); break; } From 456837d54159765592a749176fb27c5ab943af19 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 22 Nov 2022 14:40:35 +0100 Subject: [PATCH 026/109] Follow-up of fdc9c73340060cea7d8335e1211836681e18cae0 - Alternate implementation of 'When panning/rotating the scene, do not select the hovered feature, if any' --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 1e4ba61c70..0255bd1e3b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -254,7 +254,6 @@ GLGizmoMeasure::GLGizmoMeasure(GLCanvas3D& parent, const std::string& icon_filen bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) { m_mouse_pos = { double(mouse_event.GetX()), double(mouse_event.GetY()) }; - m_dragging = false; if (mouse_event.Moving()) { // only for sure @@ -262,8 +261,6 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) return false; } else if (mouse_event.Dragging()) { - m_dragging = true; - // Enable/Disable panning/rotating the 3D scene // Ctrl is pressed or the mouse is not hovering a selected volume bool unlock_dragging = mouse_event.CmdDown() || (m_hover_id == -1 && !m_parent.get_selection().contains_volume(m_parent.get_first_hover_volume_idx())); @@ -594,7 +591,7 @@ void GLGizmoMeasure::on_render() m_curr_point_on_feature_position.reset(); } else { - std::optional curr_feature = m_dragging ? m_curr_feature : + std::optional curr_feature = wxGetMouseState().LeftIsDown() ? m_curr_feature : mouse_on_object ? m_measuring->get_feature(model_facet_idx, position_on_model.cast()) : std::nullopt; if (m_curr_feature != curr_feature || From d437d1bebf83df16c88340b8ffeb5d8d3f59dd64 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 23 Nov 2022 08:24:08 +0100 Subject: [PATCH 027/109] Gizmo measure - Fixed color of hovered features when part of the object is outside the printbed --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 0255bd1e3b..55f1027529 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -752,7 +752,7 @@ void GLGizmoMeasure::on_render() }; auto set_emission_uniform = [this, shader](const ColorRGBA& color, bool hover) { - shader->set_uniform("emission_factor", (color == m_parent.get_selection().get_first_volume()->render_color) ? 0.0f : + shader->set_uniform("emission_factor", (color == GLVolume::SELECTED_COLOR) ? 0.0f : hover ? 0.5f : 0.25f); }; @@ -871,7 +871,7 @@ void GLGizmoMeasure::on_render() }; auto hovering_color = [this, hover_selection_color, &selection]() { - return (m_mode == EMode::PointSelection) ? selection.get_first_volume()->render_color : hover_selection_color(); + return (m_mode == EMode::PointSelection) ? GLVolume::SELECTED_COLOR : hover_selection_color(); }; if (m_curr_feature.has_value()) { From 2a944d4cdeb616dfa5def543bf2fd19a88709a90 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 23 Nov 2022 09:10:56 +0100 Subject: [PATCH 028/109] Fixed warnings --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 55f1027529..6489340b89 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -751,7 +751,7 @@ void GLGizmoMeasure::on_render() shader->set_uniform("view_normal_matrix", view_normal_matrix); }; - auto set_emission_uniform = [this, shader](const ColorRGBA& color, bool hover) { + auto set_emission_uniform = [shader](const ColorRGBA& color, bool hover) { shader->set_uniform("emission_factor", (color == GLVolume::SELECTED_COLOR) ? 0.0f : hover ? 0.5f : 0.25f); }; @@ -870,7 +870,7 @@ void GLGizmoMeasure::on_render() SELECTED_1ST_COLOR : SELECTED_2ND_COLOR; }; - auto hovering_color = [this, hover_selection_color, &selection]() { + auto hovering_color = [this, hover_selection_color]() { return (m_mode == EMode::PointSelection) ? GLVolume::SELECTED_COLOR : hover_selection_color(); }; From cc13e8a44f3cc4711e9e0a03af45dd5cdb6df981 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 23 Nov 2022 12:03:36 +0100 Subject: [PATCH 029/109] Gizmo measure - Hide SLA supports and pad when opening the gizmo --- src/slic3r/GUI/GLCanvas3D.cpp | 19 +++++++++++++++++-- src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp | 5 +++++ src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 3 +++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index e631643aec..b64a982b8f 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1346,11 +1346,26 @@ void GLCanvas3D::toggle_sla_auxiliaries_visibility(bool visible, const ModelObje m_render_sla_auxiliaries = visible; +#if ENABLE_RAYCAST_PICKING + std::vector>* raycasters = get_raycasters_for_picking(SceneRaycaster::EType::Volume); +#endif // ENABLE_RAYCAST_PICKING + for (GLVolume* vol : m_volumes.volumes) { +#if ENABLE_RAYCAST_PICKING 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) + && (instance_idx == -1 || vol->composite_id.instance_id == instance_idx) + && vol->composite_id.volume_id < 0) { vol->is_active = visible; + auto it = std::find_if(raycasters->begin(), raycasters->end(), [vol](std::shared_ptr item) { return item->get_raycaster() == vol->mesh_raycaster.get(); }); + if (it != raycasters->end()) + (*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 } } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp index 1ce118d71d..51ea56c821 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp @@ -900,6 +900,11 @@ RENDER_AGAIN: bool show_sups = m_c->instances_hider()->are_supports_shown(); if (m_imgui->checkbox(m_desc["show_supports"], show_sups)) { m_c->instances_hider()->show_supports(show_sups); +#if ENABLE_RAYCAST_PICKING + if (show_sups) + // ensure supports and pad are disabled from picking even when they are visible + set_sla_auxiliary_volumes_picking_state(false); +#endif // ENABLE_RAYCAST_PICKING force_refresh = true; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 6489340b89..38dd4686e4 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -411,6 +411,8 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) void GLGizmoMeasure::data_changed() { + m_parent.toggle_sla_auxiliaries_visibility(false, nullptr, -1); + update_if_needed(); m_last_inv_zoom = 0.0f; @@ -500,6 +502,7 @@ bool GLGizmoMeasure::on_init() void GLGizmoMeasure::on_set_state() { if (m_state == Off) { + m_parent.toggle_sla_auxiliaries_visibility(true, nullptr, -1); m_ctrl_kar_filter.reset_count(); m_shift_kar_filter.reset_count(); m_curr_feature.reset(); From 3c1ec473a741939baee83d475040acfdaa71d41d Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 23 Nov 2022 12:37:54 +0100 Subject: [PATCH 030/109] Gizmo measure - Undo/Redo related fix --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp index 9699d73cc8..1672e8b74e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp @@ -159,6 +159,11 @@ public: bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down); + bool wants_enter_leave_snapshots() const override { return true; } + std::string get_gizmo_entering_text() const override { return _u8L("Entering Measure gizmo"); } + std::string get_gizmo_leaving_text() const override { return _u8L("Leaving Measure gizmo"); } + std::string get_action_snapshot_name() override { return _u8L("Measure gizmo editing"); } + protected: bool on_init() override; std::string on_get_name() const override; From 9952003f61c9a9b12613b40846f8cd2af014a523 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 22 Nov 2022 09:49:10 +0100 Subject: [PATCH 031/109] Measurement: Fixed and refactored circle detection: - first/last segment of a circular segment was sometimes separated - circles were sometimes shown where they shouldn't be --- src/libslic3r/Measure.cpp | 236 +++++++++++++++++++------------------- 1 file changed, 120 insertions(+), 116 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 17689063c3..e80ff50195 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -12,17 +12,17 @@ namespace Measure { constexpr double feature_hover_limit = 0.5; // how close to a feature the mouse must be to highlight it -static std::pair get_center_and_radius(const std::vector& border, int start_idx, int end_idx, const Transform3d& trafo) +static std::pair get_center_and_radius(const std::vector& points, const Transform3d& trafo) { - Vec2ds pts; + Vec2ds out; double z = 0.; - for (int i=start_idx; i<=end_idx; ++i) { - Vec3d pt_transformed = trafo * border[i]; + for (const Vec3d pt : points) { + Vec3d pt_transformed = trafo * pt; z = pt_transformed.z(); - pts.emplace_back(pt_transformed.x(), pt_transformed.y()); + out.emplace_back(pt_transformed.x(), pt_transformed.y()); } - auto circle = Geometry::circle_ransac(pts, 20); // FIXME: iterations? + auto circle = Geometry::circle_ransac(out, 20); // FIXME: iterations? return std::make_pair(trafo.inverse() * Vec3d(circle.center.x(), circle.center.y(), z), circle.radius); } @@ -214,6 +214,7 @@ void MeasuringImpl::update_planes() m_planes[plane_id].borders.pop_back(); else { assert(last_border.front() == last_border.back()); + last_border.pop_back(); } } } @@ -231,6 +232,9 @@ void MeasuringImpl::update_planes() void MeasuringImpl::extract_features() { + auto are_angles_same = [](double a, double b) { return Slic3r::is_approx(a,b); }; + auto are_lengths_same = [](double a, double b) { return Slic3r::is_approx(a,b); }; + std::vector angles; std::vector lengths; @@ -244,152 +248,152 @@ void MeasuringImpl::extract_features() q.setFromTwoVectors(plane.normal, Vec3d::UnitZ()); Transform3d trafo = Transform3d::Identity(); trafo.rotate(q); - + for (const std::vector& border : plane.borders) { if (border.size() <= 1) continue; - assert(border.front() == border.back()); - int start_idx = -1; - std::vector edges; + // Given an idx into border, return the index that is idx+offset position, + // while taking into account the need for warp-around and the fact that + // the first and last point are the same. + auto offset_to_index = [border_size = int(border.size())](int idx, int offset) -> int { + assert(std::abs(offset) < border_size); + int out = idx+offset; + if (out >= border_size) + out = out - border_size; + else if (out < 0) + out = border_size + out; + + return out; + }; // First calculate angles at all the vertices. angles.clear(); lengths.clear(); - for (int i=0; i M_PI) angle = 2*M_PI - angle; angles.push_back(angle); lengths.push_back(v2.norm()); + if (first_different_angle_idx == 0 && angles.size() > 1) { + if (! are_angles_same(angles.back(), angles[angles.size()-2])) + first_different_angle_idx = angles.size()-1; + } } assert(border.size() == angles.size()); assert(border.size() == lengths.size()); - // First go around the border and pick what might be circular segments. // Save pair of indices to where such potential segments start and end. // Also remember the length of these segments. + int start_idx = -1; bool circle = false; + bool first_iter = true; std::vector circles; + std::vector edges; std::vector> circles_idxs; - std::vector circles_lengths; - for (int i=1; i<(int)angles.size(); ++i) { - if (Slic3r::is_approx(lengths[i], lengths[i-1]) - && Slic3r::is_approx(angles[i], angles[i-1]) - && i != (int)angles.size()-1 ) { + //std::vector circles_lengths; + std::vector single_circle; // could be in loop-scope, but reallocations + double single_circle_length = 0.; + int first_pt_idx = offset_to_index(first_different_angle_idx, 1); + int i = first_pt_idx; + while (i != first_pt_idx || first_iter) { + if (are_angles_same(angles[i], angles[offset_to_index(i,-1)]) + && i != offset_to_index(first_pt_idx, -1) // not the last point + && i != start_idx ) { // circle if (! circle) { circle = true; - start_idx = std::max(0, i-2); + single_circle.clear(); + single_circle_length = 0.; + start_idx = offset_to_index(i, -2); + single_circle = { border[start_idx], border[offset_to_index(start_idx,1)] }; + single_circle_length += lengths[offset_to_index(i, -1)]; } + single_circle.emplace_back(border[i]); + single_circle_length += lengths[i]; } else { - if (circle) { - const auto& [center, radius] = get_center_and_radius(border, start_idx, i, trafo); - // Add the circle and remember indices into borders. - circles_idxs.emplace_back(start_idx, i); - circles.emplace_back(SurfaceFeature(SurfaceFeatureType::Circle, center, plane.normal, std::nullopt, radius)); - circles_lengths.emplace_back(std::accumulate(lengths.begin() + start_idx + 1, lengths.begin() + i + 1, 0.)); - circle = false; - } - } - } + if (circle && single_circle.size() >= 5) { // Less than 5 vertices? Not a circle. + single_circle.emplace_back(border[i]); + single_circle_length += lengths[i]; - // At this point we might need to merge the first and last segment, if the starting - // point happened to be inside the segment. The discrimination of too small segments - // will follow, so we need a complete picture before that. - if (circles_idxs.size() > 1 - && circles_idxs.back().second == (int)angles.size()-1 - && circles_idxs.front().first == 0) { - // Possibly the same circle. Check that the angle and length criterion holds along the combined segment. - bool same = true; - double last_len = -1.; - double last_angle = 0.; - for (int i=circles_idxs.back().first + 1; i != circles_idxs.front().second; ++i) { - if (i == (int)angles.size()) - i = 1; - if (last_len == -1.) { - last_len = lengths[i]; - last_angle = angles[i]; - } else { - if (! Slic3r::is_approx(lengths[i], last_len) || ! Slic3r::is_approx(angles[i], last_angle)) { - same = false; - break; + bool accept_circle = true; + { + // Check that lengths of internal (!!!) edges match. + int j = offset_to_index(start_idx, 3); + while (j != i) { + if (! are_lengths_same(lengths[offset_to_index(j,-1)], lengths[j])) { + accept_circle = false; + break; + } + j = offset_to_index(j, 1); + } + } + + if (accept_circle) { + const auto& [center, radius] = get_center_and_radius(single_circle, trafo); + + // Check that the fit went well. The tolerance is high, only to + // reject complete failures. + for (const Vec3d& pt : single_circle) { + if (std::abs((pt - center).norm() - radius) > 0.5) { + accept_circle = false; + break; + } + } + + // If the segment subtends less than 90 degrees, throw it away. + accept_circle &= single_circle_length / radius > 0.9*M_PI/2.; + + // If this is all-around and 5 to 8 vertices, consider it a polygon. + bool is_polygon = start_idx == i && single_circle.size() <= 9 && single_circle.size() >= 6; + + if (accept_circle) { + // Add the circle and remember indices into borders. + circles_idxs.emplace_back(start_idx, i); + if (is_polygon) { + for (int j=0; j<=i; ++j) // No wrap-around handling needed here. + edges.emplace_back(SurfaceFeature(SurfaceFeatureType::Edge, + border[j==0 ? border.size()-1 : j-1], border[j], + std::make_optional(center))); + } + else + circles.emplace_back(SurfaceFeature(SurfaceFeatureType::Circle, center, plane.normal, std::nullopt, radius)); + } } } + circle = false; } - if (same) { - // This seems to really be the same circle. Better apply ransac again. The parts can be small and inexact. - std::vector points(border.begin() + circles_idxs.back().first, border.end()); - points.insert(points.end(), border.begin(), border.begin() + circles_idxs.front().second+1); - auto [c, radius] = get_center_and_radius(points, 0, points.size()-1, trafo); - - // Now replace the first circle with the combined one, remove the last circle. - // First index of the first circle is saved negative - we are going to pick edges - // from the border later, we will need to know where the merged in segment was. - // The sign simplifies the algorithm that picks the remaining edges - see below. - circles.front() = SurfaceFeature(SurfaceFeatureType::Circle, c, plane.normal, std::nullopt, radius); - circles_idxs.front().first = - circles_idxs.back().first; - circles_lengths.front() += circles_lengths.back(); - circles.pop_back(); - circles_idxs.pop_back(); - circles_lengths.pop_back(); - } - } - - // Now throw away all circles that subtend less than 90 deg. - assert(circles.size() == circles_lengths.size()); - for (int i=0; i(circles[i].get_circle()); - if (circles_lengths[i] / r < 0.9*M_PI/2.) { - circles_lengths.erase(circles_lengths.begin() + i); - circles.erase(circles.begin() + i); - circles_idxs.erase(circles_idxs.begin() + i); - --i; - } + // Take care of the wrap around. + first_iter = false; + i = offset_to_index(i, 1); } - circles_lengths.clear(); // no longer needed, make it obvious - - // Anything under 5 vertices shall not be considered a circle. - assert(circles_idxs.size() == circles.size()); - for (int i=int(circles_idxs.size())-1; i>=0; --i) { - const auto& [start, end] = circles_idxs[i]; - int N = start >= 0 - ? end - start + (start == 0 && end == (int)border.size()-1 ? 0 : 1) // last point is the same as first - : end + (border.size() + start); - if (N < 5) { - circles.erase(circles.begin() + i); - circles_idxs.erase(circles_idxs.begin() + i); - } else if (N <= 8 && start == 0 && end == (int)border.size()-1) { - // This is a regular 5-8 polygon. Add the edges as edges with a special - // point and remove the circle. Leave the indices in circles_idxs, so - // the edges are not picked up again later. - const Vec3d center = std::get<0>(circles[i].get_circle()); - for (int j=1; j<=end; ++j) - edges.emplace_back(SurfaceFeature(SurfaceFeatureType::Edge, - border[j - 1], border[j], std::make_optional(center))); - circles.erase(circles.begin() + i); - } - } - // We have the circles. Now go around again and pick edges, while jumping over circles. - // If the first index of the first circle is negative, it means that it was merged - // with a segment that was originally at the back and is no longer there. Ressurect - // its pair of indices so that edges are not picked again. - if (! circles_idxs.empty() && circles_idxs.front().first < 0) - circles_idxs.emplace_back(-circles_idxs.front().first, int(border.size())); - int cidx = 0; // index of next circle to jump over - for (int i=1; i (int)circles_idxs[cidx].first) - i = circles_idxs[cidx++].second; - else - edges.emplace_back(SurfaceFeature(SurfaceFeatureType::Edge, border[i - 1], border[i])); + if (circles_idxs.empty()) { + // Just add all edges. + for (int i=1; i Date: Fri, 25 Nov 2022 13:45:23 +0100 Subject: [PATCH 032/109] Measurement: prevent ending up in an infinite loop with broken models --- src/libslic3r/Measure.cpp | 16 ++++++++++++++-- src/libslic3r/SurfaceMesh.hpp | 9 +++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index e80ff50195..5b9a75c045 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -187,10 +187,16 @@ void MeasuringImpl::update_planes() he = sm.next_around_target(he); if (he.is_invalid()) goto PLANE_FAILURE; + + // For broken meshes, the iteration might never get back to he_orig. + // Remember all halfedges we saw to break out of such infinite loops. + boost::container::small_vector he_seen; + while ( (int)m_face_to_plane[sm.face(he)] == plane_id && he != he_orig) { + he_seen.emplace_back(he); he = sm.next_around_target(he); - if (he.is_invalid()) - goto PLANE_FAILURE; + if (he.is_invalid() || std::find(he_seen.begin(), he_seen.end(), he) != he_seen.end()) + goto PLANE_FAILURE; } he = sm.opposite(he); if (he.is_invalid()) @@ -208,6 +214,12 @@ void MeasuringImpl::update_planes() visited[face_it - facets.begin()][he.side()] = true; last_border.emplace_back(sm.point(sm.source(he)).cast()); + + // In case of broken meshes, this loop might be infinite. Break + // out in case it is clearly going bad. + if (last_border.size() > 3*facets.size()) + goto PLANE_FAILURE; + } while (he != he_start); if (last_border.size() == 1) diff --git a/src/libslic3r/SurfaceMesh.hpp b/src/libslic3r/SurfaceMesh.hpp index 9e547eec49..93eb9fdaa6 100644 --- a/src/libslic3r/SurfaceMesh.hpp +++ b/src/libslic3r/SurfaceMesh.hpp @@ -4,6 +4,8 @@ #include #include +#include "boost/container/small_vector.hpp" + namespace Slic3r { class TriangleMesh; @@ -115,11 +117,18 @@ public: size_t degree(Vertex_index v) const { + // In case the mesh is broken badly, the loop might end up to be infinite, + // never getting back to the first halfedge. Remember list of all half-edges + // and trip if any is encountered for the second time. Halfedge_index h_first = halfedge(v); + boost::container::small_vector he_visited; Halfedge_index h = next_around_target(h_first); size_t degree = 2; while (! h.is_invalid() && h != h_first) { + he_visited.emplace_back(h); h = next_around_target(h); + if (std::find(he_visited.begin(), he_visited.end(), h) == he_visited.end()) + return 0; ++degree; } return h.is_invalid() ? 0 : degree - 1; From 5a3f36da0106a03ded52a066dc45507bae763b4b Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 29 Nov 2022 11:13:09 +0100 Subject: [PATCH 033/109] Tech ENABLE_RAYCAST_PICKING_DEBUG - Extended data shown into debug imgui dialog --- src/slic3r/GUI/GLCanvas3D.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index b64a982b8f..0261501d50 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5508,12 +5508,17 @@ void GLCanvas3D::_picking_pass() default: { break; } } - auto add_strings_row_to_table = [&imgui](const std::string& col_1, const ImVec4& col_1_color, const std::string& col_2, const ImVec4& col_2_color) { + auto add_strings_row_to_table = [&imgui](const std::string& col_1, const ImVec4& col_1_color, const std::string& col_2, const ImVec4& col_2_color, + const std::string& col_3 = "", const ImVec4& col_3_color = ImGui::GetStyleColorVec4(ImGuiCol_Text)) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); imgui.text_colored(col_1_color, col_1.c_str()); ImGui::TableSetColumnIndex(1); imgui.text_colored(col_2_color, col_2.c_str()); + if (!col_3.empty()) { + ImGui::TableSetColumnIndex(2); + imgui.text_colored(col_3_color, col_3.c_str()); + } }; char buf[1024]; @@ -5542,6 +5547,21 @@ void GLCanvas3D::_picking_pass() add_strings_row_to_table("Gizmo elements", ImGuiWrapper::COL_ORANGE_LIGHT, std::string(buf), ImGui::GetStyleColorVec4(ImGuiCol_Text)); ImGui::EndTable(); } + + std::vector>* gizmo_raycasters = m_scene_raycaster.get_raycasters(SceneRaycaster::EType::Gizmo); + if (gizmo_raycasters != nullptr && !gizmo_raycasters->empty()) { + ImGui::Separator(); + imgui.text("Gizmo raycasters IDs:"); + if (ImGui::BeginTable("GizmoRaycasters", 3)) { + for (size_t i = 0; i < gizmo_raycasters->size(); ++i) { + add_strings_row_to_table(std::to_string(i), ImGuiWrapper::COL_ORANGE_LIGHT, + std::to_string(SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, (*gizmo_raycasters)[i]->get_id())), ImGui::GetStyleColorVec4(ImGuiCol_Text), + to_string(Geometry::Transformation((*gizmo_raycasters)[i]->get_transform()).get_offset()), ImGui::GetStyleColorVec4(ImGuiCol_Text)); + } + ImGui::EndTable(); + } + } + imgui.end(); #endif // ENABLE_RAYCAST_PICKING_DEBUG } From 2a82f1d39689e5fffbe1d1dc3fee085489d4733e Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 30 Nov 2022 11:58:02 +0100 Subject: [PATCH 034/109] Gizmo measure - Modified circle and edge with extra point selection --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 510 ++++++++++++++--------- src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp | 18 +- 2 files changed, 320 insertions(+), 208 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 38dd4686e4..eb1a7162eb 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -20,15 +20,16 @@ namespace Slic3r { namespace GUI { -static const Slic3r::ColorRGBA SELECTED_1ST_COLOR = { 0.25f, 0.75f, 0.75f, 1.0f }; -static const Slic3r::ColorRGBA SELECTED_2ND_COLOR = { 0.75f, 0.25f, 0.75f, 1.0f }; +static const Slic3r::ColorRGBA SELECTED_1ST_COLOR = { 0.25f, 0.75f, 0.75f, 1.0f }; +static const Slic3r::ColorRGBA SELECTED_2ND_COLOR = { 0.75f, 0.25f, 0.75f, 1.0f }; +static const Slic3r::ColorRGBA NEUTRAL_COLOR = { 0.5f, 0.5f, 0.5f, 1.0f }; static const int POINT_ID = 100; static const int EDGE_ID = 200; static const int CIRCLE_ID = 300; static const int PLANE_ID = 400; -static const int SELECTION_1_ID = 501; -static const int SELECTION_2_ID = 502; +static const int SEL_SPHERE_1_ID = 501; +static const int SEL_SPHERE_2_ID = 502; static const float TRIANGLE_BASE = 10.0f; static const float TRIANGLE_HEIGHT = TRIANGLE_BASE * 1.618033f; @@ -164,6 +165,41 @@ static GLModel::Geometry init_torus_data(unsigned int primary_resolution, unsign return data; } +static bool is_feature_with_center(const Measure::SurfaceFeature& feature) +{ + const Measure::SurfaceFeatureType type = feature.get_type(); + return (type == Measure::SurfaceFeatureType::Circle || (type == Measure::SurfaceFeatureType::Edge && feature.get_extra_point().has_value())); +} + +static Vec3d get_feature_offset(const Measure::SurfaceFeature& feature) +{ + Vec3d ret; + switch (feature.get_type()) + { + case Measure::SurfaceFeatureType::Circle: + { + const auto [center, radius, normal] = feature.get_circle(); + ret = center; + break; + } + case Measure::SurfaceFeatureType::Edge: + { + std::optional p = feature.get_extra_point(); + assert(p.has_value()); + ret = *p; + break; + } + case Measure::SurfaceFeatureType::Point: + { + ret = feature.get_point(); + break; + } + default: { assert(false); } + } + + return ret; +} + class TransformHelper { struct Cache @@ -265,109 +301,125 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) // Ctrl is pressed or the mouse is not hovering a selected volume bool unlock_dragging = mouse_event.CmdDown() || (m_hover_id == -1 && !m_parent.get_selection().contains_volume(m_parent.get_first_hover_volume_idx())); // mode is not center selection or mouse is not hovering a center - unlock_dragging &= !mouse_event.ShiftDown() || (m_hover_id != SELECTION_1_ID && m_hover_id != SELECTION_2_ID && m_hover_id != POINT_ID); + unlock_dragging &= !mouse_event.ShiftDown() || (m_hover_id != SEL_SPHERE_1_ID && m_hover_id != SEL_SPHERE_2_ID && m_hover_id != POINT_ID); return !unlock_dragging; } else if (mouse_event.LeftDown()) { // let the event pass through to allow panning/rotating the 3D scene - if ((m_mode != EMode::CenterSelection && mouse_event.CmdDown()) || - (m_mode == EMode::CenterSelection && m_hover_id != SELECTION_1_ID && m_hover_id != SELECTION_2_ID && m_hover_id != POINT_ID)) { + if (mouse_event.CmdDown()) return false; - } if (m_hover_id != -1) { SelectedFeatures selected_features_old = m_selected_features; m_mouse_left_down = true; - auto item_from_feature = [this]() { + auto detect_current_item = [this]() { SelectedFeatures::Item item; - if (m_hover_id == SELECTION_1_ID && m_selected_features.first.feature.has_value()) - item = m_selected_features.first; - else if (m_hover_id == SELECTION_2_ID && m_selected_features.second.feature.has_value()) - item = m_selected_features.second; + if (m_hover_id == SEL_SPHERE_1_ID) { + if (m_selected_features.first.is_center) + // mouse is hovering over a selected center + item = { true, m_selected_features.first.source, { Measure::SurfaceFeature(get_feature_offset(*m_selected_features.first.source)) } }; + else if (is_feature_with_center(*m_selected_features.first.feature)) + // mouse is hovering over a unselected center + item = { true, m_selected_features.first.feature, { Measure::SurfaceFeature(get_feature_offset(*m_selected_features.first.feature)) } }; + else + // mouse is hovering over a point + item = m_selected_features.first; + } + else if (m_hover_id == SEL_SPHERE_2_ID) { + if (m_selected_features.second.is_center) + // mouse is hovering over a selected center + item = { true, m_selected_features.second.source, { Measure::SurfaceFeature(get_feature_offset(*m_selected_features.second.source)) } }; + else if (is_feature_with_center(*m_selected_features.second.feature)) + // mouse is hovering over a center + item = { true, m_selected_features.second.feature, { Measure::SurfaceFeature(get_feature_offset(*m_selected_features.second.feature)) } }; + else + // mouse is hovering over a point + item = m_selected_features.second; + } else { switch (m_mode) { - case EMode::FeatureSelection: - { - item = { surface_feature_type_as_string(m_curr_feature->get_type()), m_curr_feature }; - break; - } - case EMode::PointSelection: - { - item = { point_on_feature_type_as_string(m_curr_feature->get_type(), m_hover_id), Measure::SurfaceFeature(*m_curr_point_on_feature_position) }; - break; - } - case EMode::CenterSelection: - { - Vec3d position; - switch (m_curr_feature->get_type()) - { - case Measure::SurfaceFeatureType::Circle: - { - position = std::get<0>(m_curr_feature->get_circle()); - break; - } - case Measure::SurfaceFeatureType::Edge: - { - assert(m_curr_feature->get_extra_point().has_value()); - position = *m_curr_feature->get_extra_point(); - break; - } - default: { assert(false); break; } - } - - item = { center_on_feature_type_as_string(m_curr_feature->get_type()), Measure::SurfaceFeature(position) }; - break; - } + case EMode::FeatureSelection: { item = { false, m_curr_feature, m_curr_feature }; break; } + case EMode::PointSelection: { item = { false, m_curr_feature, Measure::SurfaceFeature(*m_curr_point_on_feature_position) }; break; } } } return item; }; - if (m_selected_features.first.feature.has_value()) { - auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), - [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_2_ID; }); - if (it != m_selection_raycasters.end()) - m_selection_raycasters.erase(it); - m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, SELECTION_2_ID); + auto requires_sphere_raycaster_for_picking = [this](const SelectedFeatures::Item& item) { + if (m_mode == EMode::PointSelection) + return true; + else if (m_mode == EMode::FeatureSelection) { + if (is_feature_with_center(*item.feature)) + return true; + } + return false; + }; - const SelectedFeatures::Item item = item_from_feature(); + if (m_selected_features.first.feature.has_value()) { + const SelectedFeatures::Item item = detect_current_item(); if (m_selected_features.first != item) { - if (m_selected_features.second == item) - m_selected_features.second.reset(); - else { - m_selected_features.second = item; - if (m_mode == EMode::PointSelection || m_mode == EMode::CenterSelection) - m_selection_raycasters.push_back(m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, SELECTION_2_ID, *m_sphere.mesh_raycaster)); - if (m_mode == EMode::CenterSelection) { - // Fake ctrl up event to exit the center selection mode - gizmo_event(SLAGizmoEventType::CtrlUp, Vec2d::Zero(), true, false, false); - // increase counter to avoid that keeping the ctrl key pressed triggers a ctrl down event - m_ctrl_kar_filter.increase_count(); + bool processed = false; + if (item.is_center) { + if (item.source == m_selected_features.first.feature) { + // switch 1st selection from feature to its center + m_selected_features.first = item; + processed = true; + } + else if (item.source == m_selected_features.second.feature) { + // switch 2nd selection from feature to its center + m_selected_features.second = item; + processed = true; + } + } + else if (is_feature_with_center(*item.feature)) { + if (m_selected_features.first.is_center && m_selected_features.first.source == item.feature) { + // switch 1st selection from center to its feature + m_selected_features.first = item; + processed = true; + } + else if (m_selected_features.second.is_center && m_selected_features.second.source == item.feature) { + // switch 2nd selection from center to its feature + m_selected_features.second = item; + processed = true; + } + } + + if (!processed) { + remove_selected_sphere_raycaster(SEL_SPHERE_2_ID); + if (m_selected_features.second == item) + // 2nd feature deselection + m_selected_features.second.reset(); + else { + // 2nd feature selection + m_selected_features.second = item; + if (requires_sphere_raycaster_for_picking(item)) + m_selected_sphere_raycasters.push_back(m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, SEL_SPHERE_2_ID, *m_sphere.mesh_raycaster)); } } } else { - if (!m_selected_features.second.feature.has_value()) - m_selected_features.first.reset(); - else { + remove_selected_sphere_raycaster(SEL_SPHERE_1_ID); + if (m_selected_features.second.feature.has_value()) { + // promote 2nd feature to 1st feature + remove_selected_sphere_raycaster(SEL_SPHERE_2_ID); m_selected_features.first = m_selected_features.second; + if (requires_sphere_raycaster_for_picking(m_selected_features.first)) + m_selected_sphere_raycasters.push_back(m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, SEL_SPHERE_1_ID, *m_sphere.mesh_raycaster)); m_selected_features.second.reset(); } + else + // 1st feature deselection + m_selected_features.first.reset(); } } else { - const SelectedFeatures::Item item = item_from_feature(); + // 1st feature selection + const SelectedFeatures::Item item = detect_current_item(); m_selected_features.first = item; - if (m_mode == EMode::PointSelection || m_mode == EMode::CenterSelection) - m_selection_raycasters.push_back(m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, SELECTION_1_ID, *m_sphere.mesh_raycaster)); - if (m_mode == EMode::CenterSelection) { - // Fake ctrl up event to exit the center selection mode - gizmo_event(SLAGizmoEventType::CtrlUp, Vec2d::Zero(), true, false, false); - // increase counter to avoid that keeping the ctrl key pressed triggers a ctrl down event - m_ctrl_kar_filter.increase_count(); - } + if (requires_sphere_raycaster_for_picking(item)) + m_selected_sphere_raycasters.push_back(m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, SEL_SPHERE_1_ID, *m_sphere.mesh_raycaster)); } if (m_selected_features != selected_features_old && m_selected_features.second.feature.has_value()) @@ -399,9 +451,8 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) } else if (mouse_event.RightDown()) { // let the event pass through to allow panning/rotating the 3D scene - if ((m_mode != EMode::CenterSelection && mouse_event.CmdDown()) || (m_mode == EMode::CenterSelection && m_hover_id != SELECTION_1_ID && m_hover_id != SELECTION_2_ID)) { + if (mouse_event.CmdDown()) return false; - } } else if (mouse_event.Leaving()) m_mouse_left_down = false; @@ -423,7 +474,7 @@ void GLGizmoMeasure::data_changed() } else m_selected_features.reset(); - m_selection_raycasters.clear(); + m_selected_sphere_raycasters.clear(); m_editing_distance = false; m_is_editing_distance_first_frame = true; } @@ -450,7 +501,7 @@ bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_po if (action == SLAGizmoEventType::ShiftDown) { if (m_shift_kar_filter.is_first()) { - m_mode = activate_center_selection(SLAGizmoEventType::ShiftDown) ? EMode::CenterSelection : EMode::PointSelection; + m_mode = EMode::PointSelection; disable_scene_raycasters(); } m_shift_kar_filter.increase_count(); @@ -460,33 +511,23 @@ bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_po m_mode = EMode::FeatureSelection; restore_scene_raycasters_state(); } - else if (action == SLAGizmoEventType::CtrlDown) { - if (m_ctrl_kar_filter.is_first()) { - if (activate_center_selection(SLAGizmoEventType::CtrlDown)) { - m_mode = EMode::CenterSelection; - disable_scene_raycasters(); - } - } - m_ctrl_kar_filter.increase_count(); - } - else if (action == SLAGizmoEventType::CtrlUp) { - m_ctrl_kar_filter.reset_count(); - m_mode = control_down ? EMode::PointSelection : EMode::FeatureSelection; - restore_scene_raycasters_state(); - } else if (action == SLAGizmoEventType::Delete) { m_selected_features.reset(); - m_selection_raycasters.clear(); + m_selected_sphere_raycasters.clear(); m_parent.request_extra_frame(); } else if (action == SLAGizmoEventType::Escape) { if (!m_selected_features.first.feature.has_value()) return false; else { - if (m_selected_features.second.feature.has_value()) - m_selected_features.second.feature.reset(); - else - m_selected_features.first.feature.reset(); + if (m_selected_features.second.feature.has_value()) { + remove_selected_sphere_raycaster(SEL_SPHERE_2_ID); + m_selected_features.second.feature.reset(); + } + else { + remove_selected_sphere_raycaster(SEL_SPHERE_1_ID); + m_selected_features.first.feature.reset(); + } } } @@ -503,7 +544,6 @@ void GLGizmoMeasure::on_set_state() { if (m_state == Off) { m_parent.toggle_sla_auxiliaries_visibility(true, nullptr, -1); - m_ctrl_kar_filter.reset_count(); m_shift_kar_filter.reset_count(); m_curr_feature.reset(); m_curr_point_on_feature_position.reset(); @@ -566,7 +606,7 @@ void GLGizmoMeasure::on_render() Vec3f normal_on_model; size_t model_facet_idx; const bool mouse_on_object = m_raycaster->unproject_on_mesh(m_mouse_pos, Transform3d::Identity(), camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); - const bool is_hovering_on_feature = (m_mode == EMode::PointSelection || m_mode == EMode::CenterSelection) && m_hover_id != -1; + const bool is_hovering_on_feature = m_mode == EMode::PointSelection && m_hover_id != -1; auto update_circle = [this, inv_zoom]() { if (m_last_inv_zoom != inv_zoom || m_last_circle != m_curr_feature) { @@ -583,14 +623,13 @@ void GLGizmoMeasure::on_render() }; if (m_mode == EMode::FeatureSelection || m_mode == EMode::PointSelection) { - if ((m_hover_id == SELECTION_1_ID && boost::algorithm::istarts_with(m_selected_features.first.source, _u8L("Center"))) || - (m_hover_id == SELECTION_2_ID && boost::algorithm::istarts_with(m_selected_features.second.source, _u8L("Center")))) { - // Skip feature detection if hovering on a selected center - m_curr_feature.reset(); + if (m_hover_id == SEL_SPHERE_1_ID || m_hover_id == SEL_SPHERE_2_ID) { + // Skip feature detection if hovering on a selected point/center m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID); m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID); m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, PLANE_ID); m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID); + m_curr_feature.reset(); m_curr_point_on_feature_position.reset(); } else { @@ -618,15 +657,12 @@ void GLGizmoMeasure::on_render() case Measure::SurfaceFeatureType::Edge: { m_raycasters.insert({ EDGE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID, *m_cylinder.mesh_raycaster) }); - if (m_curr_feature->get_extra_point().has_value()) - m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); break; } case Measure::SurfaceFeatureType::Circle: { update_circle(); m_raycasters.insert({ CIRCLE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID, *m_circle.mesh_raycaster) }); - m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); break; } case Measure::SurfaceFeatureType::Plane: @@ -781,72 +817,69 @@ void GLGizmoMeasure::on_render() case Measure::SurfaceFeatureType::Circle: { const auto& [center, radius, normal] = feature.get_circle(); - // render center + // render circle + const Transform3d circle_matrix = Transform3d::Identity(); + set_matrix_uniforms(circle_matrix); if (update_raycasters_transform) { + set_emission_uniform(colors.front(), hover); + m_circle.model.set_color(colors.front()); + m_circle.model.render(); + auto it = m_raycasters.find(CIRCLE_ID); + if (it != m_raycasters.end() && it->second != nullptr) + it->second->set_transform(circle_matrix); + } + else { + GLModel circle; + GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); + circle.init_from(std::move(circle_geometry)); + set_emission_uniform(colors.front(), hover); + circle.set_color(colors.front()); + circle.render(); + } + // render center + if (colors.size() > 1) { const Transform3d center_matrix = Geometry::translation_transform(center) * Geometry::scale_transform(inv_zoom); set_matrix_uniforms(center_matrix); - set_emission_uniform(colors.front(), hover); - m_sphere.model.set_color(colors.front()); + set_emission_uniform(colors.back(), hover); + m_sphere.model.set_color(colors.back()); m_sphere.model.render(); auto it = m_raycasters.find(POINT_ID); if (it != m_raycasters.end() && it->second != nullptr) it->second->set_transform(center_matrix); } - // render circle - if (m_mode != EMode::CenterSelection) { - const Transform3d circle_matrix = Transform3d::Identity(); - set_matrix_uniforms(circle_matrix); - if (update_raycasters_transform) { - set_emission_uniform(colors.back(), hover); - m_circle.model.set_color(colors.back()); - m_circle.model.render(); - auto it = m_raycasters.find(CIRCLE_ID); - if (it != m_raycasters.end() && it->second != nullptr) - it->second->set_transform(circle_matrix); - } - else { - GLModel circle; - GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); - circle.init_from(std::move(circle_geometry)); - set_emission_uniform(colors.back(), hover); - circle.set_color(colors.back()); - circle.render(); - } - } break; } case Measure::SurfaceFeatureType::Edge: { const auto& [from, to] = feature.get_edge(); - // render extra point + // render edge + const Transform3d edge_matrix = Geometry::translation_transform(from) * + Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), to - from) * + Geometry::scale_transform({ (double)inv_zoom, (double)inv_zoom, (to - from).norm() }); + set_matrix_uniforms(edge_matrix); + set_emission_uniform(colors.front(), hover); + m_cylinder.model.set_color(colors.front()); + m_cylinder.model.render(); if (update_raycasters_transform) { + auto it = m_raycasters.find(EDGE_ID); + if (it != m_raycasters.end() && it->second != nullptr) + it->second->set_transform(edge_matrix); + } + + // render extra point + if (colors.size() > 1) { const std::optional extra = feature.get_extra_point(); if (extra.has_value()) { const Transform3d point_matrix = Geometry::translation_transform(*extra) * Geometry::scale_transform(inv_zoom); set_matrix_uniforms(point_matrix); - set_emission_uniform(colors.front(), hover); - m_sphere.model.set_color(colors.front()); + set_emission_uniform(colors.back(), hover); + m_sphere.model.set_color(colors.back()); m_sphere.model.render(); auto it = m_raycasters.find(POINT_ID); if (it != m_raycasters.end() && it->second != nullptr) it->second->set_transform(point_matrix); } } - // render edge - if (m_mode != EMode::CenterSelection) { - const Transform3d edge_matrix = Geometry::translation_transform(from) * - Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), to - from) * - Geometry::scale_transform({ (double)inv_zoom, (double)inv_zoom, (to - from).norm() }); - set_matrix_uniforms(edge_matrix); - set_emission_uniform(colors.back(), hover); - m_cylinder.model.set_color(colors.back()); - m_cylinder.model.render(); - if (update_raycasters_transform) { - auto it = m_raycasters.find(EDGE_ID); - if (it != m_raycasters.end() && it->second != nullptr) - it->second->set_transform(edge_matrix); - } - } break; } case Measure::SurfaceFeatureType::Plane: @@ -878,11 +911,31 @@ void GLGizmoMeasure::on_render() }; if (m_curr_feature.has_value()) { + // render hovered feature + std::vector colors; - if (m_selected_features.first.feature.has_value() && *m_curr_feature == *m_selected_features.first.feature) - colors.emplace_back(hovering_color()); - else if (m_selected_features.second.feature.has_value() && *m_curr_feature == *m_selected_features.second.feature) - colors.emplace_back(hovering_color()); + if (m_selected_features.first.feature.has_value() && *m_curr_feature == *m_selected_features.first.feature) { + // hovering over the 1st selected feature + if (m_selected_features.first.is_center) + // hovering over a center + colors = { NEUTRAL_COLOR, hovering_color() }; + else if (is_feature_with_center(*m_selected_features.first.feature)) + // hovering over a feature with center + colors = { hovering_color(), NEUTRAL_COLOR }; + else + colors = { hovering_color() }; + } + else if (m_selected_features.second.feature.has_value() && *m_curr_feature == *m_selected_features.second.feature) { + // hovering over the 2nd selected feature + if (m_selected_features.second.is_center) + // hovering over a center + colors = { NEUTRAL_COLOR, hovering_color() }; + else if (is_feature_with_center(*m_selected_features.second.feature)) + // hovering over a feature with center + colors = { hovering_color(), NEUTRAL_COLOR }; + else + colors = { hovering_color() }; + } else { switch (m_curr_feature->get_type()) { @@ -895,8 +948,12 @@ void GLGizmoMeasure::on_render() case Measure::SurfaceFeatureType::Edge: case Measure::SurfaceFeatureType::Circle: { - colors.emplace_back((m_hover_id == POINT_ID) ? hover_selection_color() : hovering_color()); - colors.emplace_back(hovering_color()); + if (m_selected_features.first.is_center && m_curr_feature == m_selected_features.first.source) + colors = { SELECTED_1ST_COLOR, NEUTRAL_COLOR }; + else if (m_selected_features.second.is_center && m_curr_feature == m_selected_features.second.source) + colors = { SELECTED_2ND_COLOR, NEUTRAL_COLOR }; + else + colors = { hovering_color(), hovering_color() }; break; } case Measure::SurfaceFeatureType::Plane: @@ -911,28 +968,76 @@ void GLGizmoMeasure::on_render() } if (m_selected_features.first.feature.has_value() && (!m_curr_feature.has_value() || *m_curr_feature != *m_selected_features.first.feature)) { - const std::vector colors = { SELECTED_1ST_COLOR }; - render_feature(*m_selected_features.first.feature, colors, inv_zoom, m_hover_id == SELECTION_1_ID, false); - if (m_selected_features.first.feature->get_type() == Measure::SurfaceFeatureType::Point) { - auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), - [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_1_ID; }); - if (it != m_selection_raycasters.end()) - (*it)->set_transform(Geometry::translation_transform(m_selected_features.first.feature->get_point()) * Geometry::scale_transform(inv_zoom)); + // render 1st selected feature + + std::optional feature_to_render; + std::vector colors; + bool requires_raycaster_update = false; + if (m_hover_id == SEL_SPHERE_1_ID && (m_selected_features.first.is_center || is_feature_with_center(*m_selected_features.first.feature))) { + // hovering over a center + feature_to_render = m_selected_features.first.source; + colors = { NEUTRAL_COLOR, SELECTED_1ST_COLOR }; + requires_raycaster_update = true; + } + else if (is_feature_with_center(*m_selected_features.first.feature)) { + // hovering over a feature with center + feature_to_render = m_selected_features.first.feature; + colors = { SELECTED_1ST_COLOR, NEUTRAL_COLOR }; + requires_raycaster_update = true; + } + else { + feature_to_render = m_selected_features.first.feature; + colors = { SELECTED_1ST_COLOR }; + requires_raycaster_update = m_selected_features.first.feature->get_type() == Measure::SurfaceFeatureType::Point; + } + + render_feature(*feature_to_render, colors, inv_zoom, m_hover_id == SEL_SPHERE_1_ID, false); + + if (requires_raycaster_update) { + auto it = std::find_if(m_selected_sphere_raycasters.begin(), m_selected_sphere_raycasters.end(), + [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SEL_SPHERE_1_ID; }); + if (it != m_selected_sphere_raycasters.end()) + (*it)->set_transform(Geometry::translation_transform(get_feature_offset(*m_selected_features.first.feature)) * Geometry::scale_transform(inv_zoom)); } } + if (m_selected_features.second.feature.has_value() && (!m_curr_feature.has_value() || *m_curr_feature != *m_selected_features.second.feature)) { - const std::vector colors = { SELECTED_2ND_COLOR }; - render_feature(*m_selected_features.second.feature, colors, inv_zoom, m_hover_id == SELECTION_2_ID, false); - if (m_selected_features.second.feature->get_type() == Measure::SurfaceFeatureType::Point) { - auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), - [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_2_ID; }); - if (it != m_selection_raycasters.end()) - (*it)->set_transform(Geometry::translation_transform(m_selected_features.second.feature->get_point()) * Geometry::scale_transform(inv_zoom)); + // render 2nd selected feature + + std::optional feature_to_render; + std::vector colors; + bool requires_raycaster_update = false; + if (m_hover_id == SEL_SPHERE_2_ID && (m_selected_features.second.is_center || is_feature_with_center(*m_selected_features.second.feature))) { + // hovering over a center + feature_to_render = m_selected_features.second.source; + colors = { NEUTRAL_COLOR, SELECTED_2ND_COLOR }; + requires_raycaster_update = true; + } + else if (is_feature_with_center(*m_selected_features.second.feature)) { + // hovering over a feature with center + feature_to_render = m_selected_features.second.feature; + colors = { SELECTED_2ND_COLOR, NEUTRAL_COLOR }; + requires_raycaster_update = true; + } + else { + feature_to_render = m_selected_features.second.feature; + colors = { SELECTED_2ND_COLOR }; + requires_raycaster_update = m_selected_features.second.feature->get_type() == Measure::SurfaceFeatureType::Point; + } + + render_feature(*feature_to_render, colors, inv_zoom, m_hover_id == SEL_SPHERE_2_ID, false); + + if (requires_raycaster_update) { + auto it = std::find_if(m_selected_sphere_raycasters.begin(), m_selected_sphere_raycasters.end(), + [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SEL_SPHERE_2_ID; }); + if (it != m_selected_sphere_raycasters.end()) + (*it)->set_transform(Geometry::translation_transform(get_feature_offset(*m_selected_features.second.feature)) * Geometry::scale_transform(inv_zoom)); } } if (is_hovering_on_feature && m_curr_point_on_feature_position.has_value()) { if (m_hover_id != POINT_ID) { + // render point on feature while SHIFT is pressed const Transform3d matrix = Geometry::translation_transform(*m_curr_point_on_feature_position) * Geometry::scale_transform(inv_zoom); set_matrix_uniforms(matrix); const ColorRGBA color = hover_selection_color(); @@ -1597,7 +1702,8 @@ static void add_strings_row_to_table(ImGuiWrapper& imgui, const std::string& col void GLGizmoMeasure::render_debug_dialog() { auto add_feature_data = [this](const SelectedFeatures::Item& item) { - add_strings_row_to_table(*m_imgui, "Type", ImGuiWrapper::COL_ORANGE_LIGHT, item.source, ImGui::GetStyleColorVec4(ImGuiCol_Text)); + const std::string text = (item.source == item.feature) ? surface_feature_type_as_string(item.feature->get_type()) : point_on_feature_type_as_string(item.source->get_type(), m_hover_id); + add_strings_row_to_table(*m_imgui, "Type", ImGuiWrapper::COL_ORANGE_LIGHT, text, ImGui::GetStyleColorVec4(ImGuiCol_Text)); switch (item.feature->get_type()) { case Measure::SurfaceFeatureType::Point: @@ -1643,7 +1749,6 @@ void GLGizmoMeasure::render_debug_dialog() { case EMode::FeatureSelection: { txt = "Feature selection"; break; } case EMode::PointSelection: { txt = "Point selection"; break; } - case EMode::CenterSelection: { txt = "Center selection"; break; } default: { assert(false); break; } } add_strings_row_to_table(*m_imgui, "Mode", ImGuiWrapper::COL_ORANGE_LIGHT, txt, ImGui::GetStyleColorVec4(ImGuiCol_Text)); @@ -1727,17 +1832,16 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit text = _u8L("Unselect feature"); color = SELECTED_2ND_COLOR; } - else if (m_hover_id == SELECTION_1_ID) { - text = (m_mode == EMode::CenterSelection) ? _u8L("Unselect center") : _u8L("Unselect point"); + else if (m_hover_id == SEL_SPHERE_1_ID) { + text = _u8L("Unselect point"); color = SELECTED_1ST_COLOR; } - else if (m_hover_id == SELECTION_2_ID) { - text = (m_mode == EMode::CenterSelection) ? _u8L("Unselect center") : _u8L("Unselect point"); + else if (m_hover_id == SEL_SPHERE_2_ID) { + text = _u8L("Unselect point"); color = SELECTED_2ND_COLOR; } else { - text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : - (m_mode == EMode::CenterSelection) ? _u8L("Select center") : _u8L("Select feature"); + text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : _u8L("Select feature"); color = SELECTED_2ND_COLOR; } } @@ -1747,14 +1851,13 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit text = _u8L("Unselect feature"); color = SELECTED_1ST_COLOR; } - else if (m_hover_id == SELECTION_1_ID) { - text = (m_mode == EMode::CenterSelection) ? _u8L("Unselect center") : _u8L("Unselect point"); + else if (m_hover_id == SEL_SPHERE_1_ID) { + text = _u8L("Unselect point"); color = SELECTED_1ST_COLOR; } } if (text.empty()) { - text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : - (m_mode == EMode::CenterSelection) ? _u8L("Select center") : _u8L("Select feature"); + text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : _u8L("Select feature"); color = m_selected_features.first.feature.has_value() ? SELECTED_2ND_COLOR : SELECTED_1ST_COLOR; } } @@ -1773,11 +1876,6 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit ++row_count; } - if (m_mode != EMode::CenterSelection && feature_has_center(m_curr_feature)) { - add_strings_row_to_table(*m_imgui, _u8L("Shift") + "+" + CTRL_STR, ImGuiWrapper::COL_ORANGE_LIGHT, _u8L("Enable center selection"), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - ++row_count; - } - if (m_selected_features.first.feature.has_value()) { add_strings_row_to_table(*m_imgui, _u8L("Delete"), ImGuiWrapper::COL_ORANGE_LIGHT, _u8L("Restart selection"), ImGui::GetStyleColorVec4(ImGuiCol_Text)); ++row_count; @@ -1803,7 +1901,7 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit } // add dummy rows to keep dialog size fixed - for (unsigned int i = row_count; i < 5; ++i) { + for (unsigned int i = row_count; i < 4; ++i) { add_strings_row_to_table(*m_imgui, " ", ImGuiWrapper::COL_ORANGE_LIGHT, " ", ImGui::GetStyleColorVec4(ImGuiCol_Text)); } @@ -1816,17 +1914,20 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit ImGui::Separator(); const ImGuiTableFlags flags = ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersH; if (ImGui::BeginTable("Selection", 2, flags)) { - auto format_item_text = [use_inches, &units](const SelectedFeatures::Item& item) { - std::string txt = item.feature.has_value() ? item.source : _u8L("None"); - if (item.feature.has_value() && item.feature->get_type() == Measure::SurfaceFeatureType::Circle) { - auto [center, radius, normal] = item.feature->get_circle(); - const Vec3d on_circle = center + radius * Measure::get_orthogonal(normal, true); - radius = (on_circle - center).norm(); - if (use_inches) - radius = ObjectManipulation::mm_to_in * radius; - txt += " (" + _u8L("Diameter:") + " " + format_double(2.0 * radius) + units + ")"; - } - return txt; + auto format_item_text = [this, use_inches, &units](const SelectedFeatures::Item& item) { + if (!item.feature.has_value()) + return _u8L("None"); + + std::string text = (item.source == item.feature) ? surface_feature_type_as_string(item.feature->get_type()) : point_on_feature_type_as_string(item.source->get_type(), m_hover_id); + if (item.feature.has_value() && item.feature->get_type() == Measure::SurfaceFeatureType::Circle) { + auto [center, radius, normal] = item.feature->get_circle(); + const Vec3d on_circle = center + radius * Measure::get_orthogonal(normal, true); + radius = (on_circle - center).norm(); + if (use_inches) + radius = ObjectManipulation::mm_to_in * radius; + text += " (" + _u8L("Diameter:") + " " + format_double(2.0 * radius) + units + ")"; + } + return text; }; add_strings_row_to_table(*m_imgui, _u8L("Selection") + " 1:", ImGuiWrapper::to_ImVec4(SELECTED_1ST_COLOR), format_item_text(m_selected_features.first), @@ -1839,7 +1940,7 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit m_imgui->disabled_begin(!m_selected_features.first.feature.has_value()); if (m_imgui->button(_u8L("Restart selection"))) { m_selected_features.reset(); - m_selection_raycasters.clear(); + m_selected_sphere_raycasters.clear(); m_imgui->set_requires_extra_frame(); } m_imgui->disabled_end(); @@ -1935,7 +2036,16 @@ void GLGizmoMeasure::on_unregister_raycasters_for_picking() m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo); m_parent.set_raycaster_gizmos_on_top(false); m_raycasters.clear(); - m_selection_raycasters.clear(); + m_selected_sphere_raycasters.clear(); +} + +void GLGizmoMeasure::remove_selected_sphere_raycaster(int id) +{ + auto it = std::find_if(m_selected_sphere_raycasters.begin(), m_selected_sphere_raycasters.end(), + [id](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == id; }); + if (it != m_selected_sphere_raycasters.end()) + m_selected_sphere_raycasters.erase(it); + m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, id); } } // namespace GUI diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp index 1672e8b74e..1e4330e955 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp @@ -24,20 +24,19 @@ class GLGizmoMeasure : public GLGizmoBase enum class EMode : unsigned char { FeatureSelection, - PointSelection, - CenterSelection + PointSelection }; struct SelectedFeatures { struct Item { - std::string source; + bool is_center{ false }; + std::optional source; std::optional feature; bool operator == (const Item& other) const { - if (this->source != other.source) return false; - return this->feature == other.feature; + return this->is_center == other.is_center && this->source == other.source && this->feature == other.feature; } bool operator != (const Item& other) const { @@ -45,7 +44,8 @@ class GLGizmoMeasure : public GLGizmoBase } void reset() { - source.clear(); + is_center = false; + source.reset(); feature.reset(); } }; @@ -106,7 +106,8 @@ class GLGizmoMeasure : public GLGizmoBase std::vector m_plane_models_cache; std::map> m_raycasters; - std::vector> m_selection_raycasters; + // used to keep the raycasters for point/center spheres + std::vector> m_selected_sphere_raycasters; std::optional m_curr_feature; std::optional m_curr_point_on_feature_position; struct SceneRaycasterState @@ -126,7 +127,6 @@ class GLGizmoMeasure : public GLGizmoBase Vec2d m_mouse_pos{ Vec2d::Zero() }; - KeyAutoRepeatFilter m_ctrl_kar_filter; KeyAutoRepeatFilter m_shift_kar_filter; SelectedFeatures m_selected_features; @@ -174,6 +174,8 @@ protected: virtual void on_render_input_window(float x, float y, float bottom_limit) override; virtual void on_register_raycasters_for_picking() override; virtual void on_unregister_raycasters_for_picking() override; + + void remove_selected_sphere_raycaster(int id); }; } // namespace GUI From b3db407327ba5318ad5665de00489f93b20bff1a Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 30 Nov 2022 12:51:37 +0100 Subject: [PATCH 035/109] Gizmo measure - Show radius of single selected circle, to allow for object scaling --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 105 ++++++++++++++--------- src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp | 1 + 2 files changed, 67 insertions(+), 39 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index eb1a7162eb..04c257e78a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -422,8 +422,7 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) m_selected_sphere_raycasters.push_back(m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, SEL_SPHERE_1_ID, *m_sphere.mesh_raycaster)); } - if (m_selected_features != selected_features_old && m_selected_features.second.feature.has_value()) - m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); + update_measurement_result(); m_imgui->set_requires_extra_frame(); @@ -469,7 +468,7 @@ void GLGizmoMeasure::data_changed() m_last_inv_zoom = 0.0f; m_last_plane_idx = -1; if (m_pending_scale) { - m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); + update_measurement_result(); m_pending_scale = false; } else @@ -517,8 +516,10 @@ bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_po m_parent.request_extra_frame(); } else if (action == SLAGizmoEventType::Escape) { - if (!m_selected_features.first.feature.has_value()) + if (!m_selected_features.first.feature.has_value()) { + update_measurement_result(); return false; + } else { if (m_selected_features.second.feature.has_value()) { remove_selected_sphere_raycaster(SEL_SPHERE_2_ID); @@ -528,6 +529,8 @@ bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_po remove_selected_sphere_raycaster(SEL_SPHERE_1_ID); m_selected_features.first.feature.reset(); } + + update_measurement_result(); } } @@ -1132,7 +1135,10 @@ void GLGizmoMeasure::render_dimensioning() { static SelectedFeatures last_selected_features; - if (!m_selected_features.first.feature.has_value() || !m_selected_features.second.feature.has_value()) + if (!m_selected_features.first.feature.has_value()) + return; + + if (!m_selected_features.second.feature.has_value() && m_selected_features.first.feature->get_type() != Measure::SurfaceFeatureType::Circle) return; GLShaderProgram* shader = wxGetApp().get_shader("flat"); @@ -1340,7 +1346,8 @@ void GLGizmoMeasure::render_dimensioning() const Vec3d new_center = selection.get_bounding_box().center(); const TrafoData trafo_data(ratio, old_center, new_center); scale_feature(*m_selected_features.first.feature, trafo_data); - scale_feature(*m_selected_features.second.feature, trafo_data); + if (m_selected_features.second.feature.has_value()) + scale_feature(*m_selected_features.second.feature, trafo_data); // update measure on next call to data_changed() m_pending_scale = true; @@ -1643,41 +1650,51 @@ void GLGizmoMeasure::render_dimensioning() glsafe(::glDisable(GL_DEPTH_TEST)); - if (m_selected_features.second.feature.has_value()) { - const bool has_distance = m_measurement_result.has_distance_data(); + const bool has_distance = m_measurement_result.has_distance_data(); - const Measure::SurfaceFeature* f1 = &(*m_selected_features.first.feature); - const Measure::SurfaceFeature* f2 = &(*m_selected_features.second.feature); - Measure::SurfaceFeatureType ft1 = f1->get_type(); - Measure::SurfaceFeatureType ft2 = f2->get_type(); - - // Order features by type so following conditions are simple. - if (ft1 > ft2) { - std::swap(ft1, ft2); - std::swap(f1, f2); - } - - // If there is an angle to show, draw the arc: - if (ft1 == Measure::SurfaceFeatureType::Edge && ft2 == Measure::SurfaceFeatureType::Edge) - arc_edge_edge(*f1, *f2); - else if (ft1 == Measure::SurfaceFeatureType::Edge && ft2 == Measure::SurfaceFeatureType::Plane) - arc_edge_plane(*f1, *f2); - else if (ft1 == Measure::SurfaceFeatureType::Plane && ft2 == Measure::SurfaceFeatureType::Plane) - arc_plane_plane(*f1, *f2); - - if (has_distance){ - // Where needed, draw the extension of the edge to where the dist is measured: - if (ft1 == Measure::SurfaceFeatureType::Point && ft2 == Measure::SurfaceFeatureType::Edge) - point_edge(*f1, *f2); - - // Render the arrow between the points that the backend passed: - const Measure::DistAndPoints& dap = m_measurement_result.distance_infinite.has_value() - ? *m_measurement_result.distance_infinite - : *m_measurement_result.distance_strict; - point_point(dap.from, dap.to, dap.dist); - } + const Measure::SurfaceFeature* f1 = &(*m_selected_features.first.feature); + const Measure::SurfaceFeature* f2 = nullptr; + std::unique_ptr temp_feature; + if (m_selected_features.second.feature.has_value()) + f2 = &(*m_selected_features.second.feature); + else { + assert(m_selected_features.first.feature->get_type() == Measure::SurfaceFeatureType::Circle); + temp_feature = std::make_unique(std::get<0>(m_selected_features.first.feature->get_circle())); + f2 = temp_feature.get(); } - + + if (!m_selected_features.second.feature.has_value() && m_selected_features.first.feature->get_type() != Measure::SurfaceFeatureType::Circle) + return; + + Measure::SurfaceFeatureType ft1 = f1->get_type(); + Measure::SurfaceFeatureType ft2 = f2->get_type(); + + // Order features by type so following conditions are simple. + if (ft1 > ft2) { + std::swap(ft1, ft2); + std::swap(f1, f2); + } + + // If there is an angle to show, draw the arc: + if (ft1 == Measure::SurfaceFeatureType::Edge && ft2 == Measure::SurfaceFeatureType::Edge) + arc_edge_edge(*f1, *f2); + else if (ft1 == Measure::SurfaceFeatureType::Edge && ft2 == Measure::SurfaceFeatureType::Plane) + arc_edge_plane(*f1, *f2); + else if (ft1 == Measure::SurfaceFeatureType::Plane && ft2 == Measure::SurfaceFeatureType::Plane) + arc_plane_plane(*f1, *f2); + + if (has_distance){ + // Where needed, draw the extension of the edge to where the dist is measured: + if (ft1 == Measure::SurfaceFeatureType::Point && ft2 == Measure::SurfaceFeatureType::Edge) + point_edge(*f1, *f2); + + // Render the arrow between the points that the backend passed: + const Measure::DistAndPoints& dap = m_measurement_result.distance_infinite.has_value() + ? *m_measurement_result.distance_infinite + : *m_measurement_result.distance_strict; + point_point(dap.from, dap.to, dap.dist); + } + glsafe(::glEnable(GL_DEPTH_TEST)); shader->stop_using(); @@ -2048,5 +2065,15 @@ void GLGizmoMeasure::remove_selected_sphere_raycaster(int id) m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, id); } +void GLGizmoMeasure::update_measurement_result() +{ + if (!m_selected_features.first.feature.has_value()) + m_measurement_result = Measure::MeasurementResult(); + else if (m_selected_features.second.feature.has_value()) + m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); + else if (!m_selected_features.second.feature.has_value() && m_selected_features.first.feature->get_type() == Measure::SurfaceFeatureType::Circle) + m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, Measure::SurfaceFeature(std::get<0>(m_selected_features.first.feature->get_circle())), m_measuring.get()); +} + } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp index 1e4330e955..4652a171b7 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp @@ -176,6 +176,7 @@ protected: virtual void on_unregister_raycasters_for_picking() override; void remove_selected_sphere_raycaster(int id); + void update_measurement_result(); }; } // namespace GUI From e6cbf3a215ff6f69e2e8b9060d182c06d180257d Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 30 Nov 2022 13:04:48 +0100 Subject: [PATCH 036/109] Fixed warnings --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 04c257e78a..6782d47f19 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -487,17 +487,6 @@ static bool feature_has_center(std::optional feature) bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down) { - auto activate_center_selection = [this, shift_down, control_down](SLAGizmoEventType action) { - bool ret = false; - switch (action) - { - case SLAGizmoEventType::CtrlDown: { ret = shift_down && feature_has_center(m_curr_feature); break; } - case SLAGizmoEventType::ShiftDown: { ret = control_down && feature_has_center(m_curr_feature); break; } - default: { break; } - } - return ret; - }; - if (action == SLAGizmoEventType::ShiftDown) { if (m_shift_kar_filter.is_first()) { m_mode = EMode::PointSelection; @@ -598,8 +587,6 @@ void GLGizmoMeasure::on_render() // if (m_parent.is_mouse_dragging()) // return; - const Selection& selection = m_parent.get_selection(); - update_if_needed(); const Camera& camera = wxGetApp().plater()->get_camera(); From 681216447fbe9d7fa6182e4c2cdf4427eb3a23ec Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 30 Nov 2022 13:07:49 +0100 Subject: [PATCH 037/109] Fixed warning --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 6782d47f19..4ce33f7cfe 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -310,7 +310,6 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) return false; if (m_hover_id != -1) { - SelectedFeatures selected_features_old = m_selected_features; m_mouse_left_down = true; auto detect_current_item = [this]() { From 85195ac79fb2b7016b05ffff5eb33a483a4d06c2 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 1 Dec 2022 12:47:06 +0100 Subject: [PATCH 038/109] Measure gizmo - Fixed sychronization of imgui dialog with current hovering/selection state --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 94 +++++++++++++++++++++--- 1 file changed, 82 insertions(+), 12 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 4ce33f7cfe..2b848bd985 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1828,22 +1828,61 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit ColorRGBA color; if (m_selected_features.second.feature.has_value()) { if (m_selected_features.first.feature == m_curr_feature && m_mode == EMode::FeatureSelection) { + // hovering over 1st selected feature text = _u8L("Unselect feature"); color = SELECTED_1ST_COLOR; } + else if (m_hover_id == SEL_SPHERE_1_ID) { + if (m_selected_features.first.is_center) { + // hovering over center selected as 1st feature + text = _u8L("Unselect center"); + color = SELECTED_1ST_COLOR; + } + else if (is_feature_with_center(*m_selected_features.first.feature)) { + // hovering over center of 1st selected feature + text = _u8L("Select center"); + color = SELECTED_1ST_COLOR; + } + else { + // hovering over point selected as 1st feature + text = _u8L("Unselect point"); + color = SELECTED_1ST_COLOR; + } + } + else if (m_selected_features.first.is_center && m_selected_features.first.source == m_curr_feature) { + // hovering over feature whose center is selected as 1st feature + text = _u8L("Select feature"); + color = SELECTED_1ST_COLOR; + } else if (m_selected_features.second.feature == m_curr_feature && m_mode == EMode::FeatureSelection) { + // hovering over 2nd selected feature text = _u8L("Unselect feature"); color = SELECTED_2ND_COLOR; } - else if (m_hover_id == SEL_SPHERE_1_ID) { - text = _u8L("Unselect point"); - color = SELECTED_1ST_COLOR; - } else if (m_hover_id == SEL_SPHERE_2_ID) { - text = _u8L("Unselect point"); + if (m_selected_features.second.is_center) { + // hovering over center selected as 2nd feature + text = _u8L("Unselect feature"); + color = SELECTED_2ND_COLOR; + } + else if (is_feature_with_center(*m_selected_features.second.feature)) { + // hovering over center of 2nd selected feature + text = _u8L("Select center"); + color = SELECTED_2ND_COLOR; + } + else { + // hovering over point selected as 2nd feature + text = _u8L("Unselect point"); + color = SELECTED_2ND_COLOR; + } + } + else if (m_selected_features.second.is_center && m_selected_features.second.source == m_curr_feature) { + // hovering over feature whose center is selected as 2nd feature + text = _u8L("Select feature"); color = SELECTED_2ND_COLOR; } else { + // 1st feature selected text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : _u8L("Select feature"); color = SELECTED_2ND_COLOR; } @@ -1851,20 +1890,51 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit else { if (m_selected_features.first.feature.has_value()) { if (m_selected_features.first.feature == m_curr_feature && m_mode == EMode::FeatureSelection) { + // hovering over 1st selected feature text = _u8L("Unselect feature"); color = SELECTED_1ST_COLOR; } - else if (m_hover_id == SEL_SPHERE_1_ID) { - text = _u8L("Unselect point"); - color = SELECTED_1ST_COLOR; + else { + if (m_hover_id == SEL_SPHERE_1_ID) { + if (m_selected_features.first.is_center) { + // hovering over center selected as 1st feature + text = _u8L("Unselect feature"); + color = SELECTED_1ST_COLOR; + } + else if (is_feature_with_center(*m_selected_features.first.feature)) { + // hovering over center of 1st selected feature + text = _u8L("Select center"); + color = SELECTED_1ST_COLOR; + } + else { + // hovering over point selected as 1st feature + text = _u8L("Unselect point"); + color = SELECTED_1ST_COLOR; + } + } + else { + if (m_selected_features.first.is_center && m_selected_features.first.source == m_curr_feature) { + // hovering over feature whose center is selected as 1st feature + text = _u8L("Select feature"); + color = SELECTED_1ST_COLOR; + } + else { + // 1st feature selected + text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : _u8L("Select feature"); + color = SELECTED_2ND_COLOR; + } + } } } - if (text.empty()) { + else { + // nothing is selected text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : _u8L("Select feature"); - color = m_selected_features.first.feature.has_value() ? SELECTED_2ND_COLOR : SELECTED_1ST_COLOR; + color = SELECTED_1ST_COLOR; } } + assert(!text.empty()); + m_imgui->text_colored(ImGui::GetStyleColorVec4(ImGuiCol_Text), text); ImGui::SameLine(); const ImVec2 pos = ImGui::GetCursorScreenPos(); @@ -1982,7 +2052,7 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit if (use_inches) distance = ObjectManipulation::mm_to_in * distance; ImGui::PushID("ClipboardDistanceInfinite"); - add_measure_row_to_table(_u8L("Distance Infinite"), ImGuiWrapper::COL_ORANGE_LIGHT, format_double(distance) + units, + add_measure_row_to_table(_u8L("Distance"), ImGuiWrapper::COL_ORANGE_LIGHT, format_double(distance) + units, ImGui::GetStyleColorVec4(ImGuiCol_Text)); ++measure_row_count; ImGui::PopID(); @@ -1993,7 +2063,7 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit if (use_inches) distance = ObjectManipulation::mm_to_in * distance; ImGui::PushID("ClipboardDistanceStrict"); - add_measure_row_to_table(_u8L("Distance Strict"), ImGuiWrapper::COL_ORANGE_LIGHT, format_double(distance) + units, + add_measure_row_to_table(_u8L("Distance"), ImGuiWrapper::COL_ORANGE_LIGHT, format_double(distance) + units, ImGui::GetStyleColorVec4(ImGuiCol_Text)); ++measure_row_count; ImGui::PopID(); From 1974a56fab76357a6752b106a8e0554b8de1a844 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Thu, 1 Dec 2022 13:31:22 +0100 Subject: [PATCH 039/109] Measurement: tweaking of the tolerances, ransacing the whole border --- src/libslic3r/Measure.cpp | 324 ++++++++++++++++++++------------------ 1 file changed, 175 insertions(+), 149 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 5b9a75c045..76accc1f37 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -16,7 +16,7 @@ static std::pair get_center_and_radius(const std::vector& { Vec2ds out; double z = 0.; - for (const Vec3d pt : points) { + for (const Vec3d& pt : points) { Vec3d pt_transformed = trafo * pt; z = pt_transformed.z(); out.emplace_back(pt_transformed.x(), pt_transformed.y()); @@ -27,6 +27,14 @@ static std::pair get_center_and_radius(const std::vector& return std::make_pair(trafo.inverse() * Vec3d(circle.center.x(), circle.center.y(), z), circle.radius); } +static bool circle_fit_is_ok(const std::vector& pts, const Vec3d& center, double radius) +{ + for (const Vec3d& pt : pts) + if (std::abs((pt - center).norm() - radius) > 0.05) + return false; + return true; +} + static std::array orthonormal_basis(const Vec3d& v) { std::array ret; @@ -244,10 +252,7 @@ void MeasuringImpl::update_planes() void MeasuringImpl::extract_features() { - auto are_angles_same = [](double a, double b) { return Slic3r::is_approx(a,b); }; - auto are_lengths_same = [](double a, double b) { return Slic3r::is_approx(a,b); }; - - std::vector angles; + std::vector angles; // placed in outer scope to prevent reallocations std::vector lengths; @@ -265,175 +270,196 @@ void MeasuringImpl::extract_features() if (border.size() <= 1) continue; - // Given an idx into border, return the index that is idx+offset position, - // while taking into account the need for warp-around and the fact that - // the first and last point are the same. - auto offset_to_index = [border_size = int(border.size())](int idx, int offset) -> int { - assert(std::abs(offset) < border_size); - int out = idx+offset; - if (out >= border_size) - out = out - border_size; - else if (out < 0) - out = border_size + out; + bool done = false; - return out; - }; + if (const auto& [center, radius] = get_center_and_radius(border, trafo); + (border.size()>4) && circle_fit_is_ok(border, center, radius)) { + // The whole border is one circle. Just add it into the list of features + // and we are done. - // First calculate angles at all the vertices. - angles.clear(); - lengths.clear(); - int first_different_angle_idx = 0; - for (int i=0; i M_PI) - angle = 2*M_PI - angle; + bool is_polygon = border.size()>4 && border.size()<=8; + bool lengths_match = std::all_of(border.begin()+2, border.end(), [is_polygon](const Vec3d& pt) { + return Slic3r::is_approx((pt - *((&pt)-1)).squaredNorm(), (*((&pt)-1) - *((&pt)-2)).squaredNorm(), is_polygon ? 0.01 : 0.01); + }); - angles.push_back(angle); - lengths.push_back(v2.norm()); - if (first_different_angle_idx == 0 && angles.size() > 1) { - if (! are_angles_same(angles.back(), angles[angles.size()-2])) - first_different_angle_idx = angles.size()-1; + if (lengths_match && (is_polygon || border.size() > 8)) { + if (is_polygon) { + // This is a polygon, add the separate edges with the center. + for (int j=0; j circles; - std::vector edges; - std::vector> circles_idxs; - //std::vector circles_lengths; - std::vector single_circle; // could be in loop-scope, but reallocations - double single_circle_length = 0.; - int first_pt_idx = offset_to_index(first_different_angle_idx, 1); - int i = first_pt_idx; - while (i != first_pt_idx || first_iter) { - if (are_angles_same(angles[i], angles[offset_to_index(i,-1)]) - && i != offset_to_index(first_pt_idx, -1) // not the last point - && i != start_idx ) { - // circle - if (! circle) { - circle = true; - single_circle.clear(); - single_circle_length = 0.; - start_idx = offset_to_index(i, -2); - single_circle = { border[start_idx], border[offset_to_index(start_idx,1)] }; - single_circle_length += lengths[offset_to_index(i, -1)]; + if (! done) { + // In this case, the border is not a circle and may contain circular + // segments. Try to find them and then add all remaining edges as edges. + + auto are_angles_same = [](double a, double b) { return Slic3r::is_approx(a,b,0.01); }; + auto are_lengths_same = [](double a, double b) { return Slic3r::is_approx(a,b,0.01); }; + + + // Given an idx into border, return the index that is idx+offset position, + // while taking into account the need for wrap-around and the fact that + // the first and last point are the same. + auto offset_to_index = [border_size = int(border.size())](int idx, int offset) -> int { + assert(std::abs(offset) < border_size); + int out = idx+offset; + if (out >= border_size) + out = out - border_size; + else if (out < 0) + out = border_size + out; + + return out; + }; + + // First calculate angles at all the vertices. + angles.clear(); + lengths.clear(); + int first_different_angle_idx = 0; + for (int i=0; i M_PI) + angle = 2*M_PI - angle; + + angles.push_back(angle); + lengths.push_back(v2.norm()); + if (first_different_angle_idx == 0 && angles.size() > 1) { + if (! are_angles_same(angles.back(), angles[angles.size()-2])) + first_different_angle_idx = angles.size()-1; } - single_circle.emplace_back(border[i]); - single_circle_length += lengths[i]; - } else { - if (circle && single_circle.size() >= 5) { // Less than 5 vertices? Not a circle. + } + assert(border.size() == angles.size()); + assert(border.size() == lengths.size()); + + // First go around the border and pick what might be circular segments. + // Save pair of indices to where such potential segments start and end. + // Also remember the length of these segments. + int start_idx = -1; + bool circle = false; + bool first_iter = true; + std::vector circles; + std::vector edges; + std::vector> circles_idxs; + //std::vector circles_lengths; + std::vector single_circle; // could be in loop-scope, but reallocations + double single_circle_length = 0.; + int first_pt_idx = offset_to_index(first_different_angle_idx, 1); + int i = first_pt_idx; + while (i != first_pt_idx || first_iter) { + if (are_angles_same(angles[i], angles[offset_to_index(i,-1)]) + && i != offset_to_index(first_pt_idx, -1) // not the last point + && i != start_idx ) { + // circle + if (! circle) { + circle = true; + single_circle.clear(); + single_circle_length = 0.; + start_idx = offset_to_index(i, -2); + single_circle = { border[start_idx], border[offset_to_index(start_idx,1)] }; + single_circle_length += lengths[offset_to_index(i, -1)]; + } single_circle.emplace_back(border[i]); single_circle_length += lengths[i]; + } else { + if (circle && single_circle.size() >= 5) { // Less than 5 vertices? Not a circle. + single_circle.emplace_back(border[i]); + single_circle_length += lengths[i]; - bool accept_circle = true; - { - // Check that lengths of internal (!!!) edges match. - int j = offset_to_index(start_idx, 3); - while (j != i) { - if (! are_lengths_same(lengths[offset_to_index(j,-1)], lengths[j])) { - accept_circle = false; - break; - } - j = offset_to_index(j, 1); - } - } - - if (accept_circle) { - const auto& [center, radius] = get_center_and_radius(single_circle, trafo); - - // Check that the fit went well. The tolerance is high, only to - // reject complete failures. - for (const Vec3d& pt : single_circle) { - if (std::abs((pt - center).norm() - radius) > 0.5) { - accept_circle = false; - break; + bool accept_circle = true; + { + // Check that lengths of internal (!!!) edges match. + int j = offset_to_index(start_idx, 3); + while (j != i) { + if (! are_lengths_same(lengths[offset_to_index(j,-1)], lengths[j])) { + accept_circle = false; + break; + } + j = offset_to_index(j, 1); } } - // If the segment subtends less than 90 degrees, throw it away. - accept_circle &= single_circle_length / radius > 0.9*M_PI/2.; - - // If this is all-around and 5 to 8 vertices, consider it a polygon. - bool is_polygon = start_idx == i && single_circle.size() <= 9 && single_circle.size() >= 6; - if (accept_circle) { - // Add the circle and remember indices into borders. - circles_idxs.emplace_back(start_idx, i); - if (is_polygon) { - for (int j=0; j<=i; ++j) // No wrap-around handling needed here. - edges.emplace_back(SurfaceFeature(SurfaceFeatureType::Edge, - border[j==0 ? border.size()-1 : j-1], border[j], - std::make_optional(center))); - } - else + const auto& [center, radius] = get_center_and_radius(single_circle, trafo); + + // Check that the fit went well. The tolerance is high, only to + // reject complete failures. + accept_circle &= circle_fit_is_ok(single_circle, center, radius); + + // If the segment subtends less than 90 degrees, throw it away. + accept_circle &= single_circle_length / radius > 0.9*M_PI/2.; + + if (accept_circle) { + // Add the circle and remember indices into borders. + circles_idxs.emplace_back(start_idx, i); circles.emplace_back(SurfaceFeature(SurfaceFeatureType::Circle, center, plane.normal, std::nullopt, radius)); + } } } + circle = false; } - circle = false; - } - // Take care of the wrap around. - first_iter = false; - i = offset_to_index(i, 1); - } - - // We have the circles. Now go around again and pick edges, while jumping over circles. - if (circles_idxs.empty()) { - // Just add all edges. - for (int i=1; i 1 || circles_idxs.front().first != circles_idxs.front().second) { + // There is at least one circular segment. Start at its end and add edges until the start of the next one. + int i = circles_idxs.front().second; + int circle_idx = 1; + while (true) { + i = offset_to_index(i, 1); + edges.emplace_back(SurfaceFeature(SurfaceFeatureType::Edge, border[offset_to_index(i,-1)], border[i])); + if (circle_idx < int(circles_idxs.size()) && i == circles_idxs[circle_idx].first) { + i = circles_idxs[circle_idx].second; + ++circle_idx; + } + if (i == circles_idxs.front().first) + break; } - if (i == circles_idxs.front().first) - break; } - } - // Merge adjacent edges where needed. - assert(std::all_of(edges.begin(), edges.end(), - [](const SurfaceFeature& f) { return f.get_type() == SurfaceFeatureType::Edge; })); - for (int i=edges.size()-1; i>=0; --i) { - const auto& [first_start, first_end] = edges[i==0 ? edges.size()-1 : i-1].get_edge(); - const auto& [second_start, second_end] = edges[i].get_edge(); + // Merge adjacent edges where needed. + assert(std::all_of(edges.begin(), edges.end(), + [](const SurfaceFeature& f) { return f.get_type() == SurfaceFeatureType::Edge; })); + for (int i=edges.size()-1; i>=0; --i) { + const auto& [first_start, first_end] = edges[i==0 ? edges.size()-1 : i-1].get_edge(); + const auto& [second_start, second_end] = edges[i].get_edge(); - if (Slic3r::is_approx(first_end, second_start) - && Slic3r::is_approx((first_end-first_start).normalized().dot((second_end-second_start).normalized()), 1.)) { - // The edges have the same direction and share a point. Merge them. - edges[i==0 ? edges.size()-1 : i-1] = SurfaceFeature(SurfaceFeatureType::Edge, first_start, second_end); - edges.erase(edges.begin() + i); + if (Slic3r::is_approx(first_end, second_start) + && Slic3r::is_approx((first_end-first_start).normalized().dot((second_end-second_start).normalized()), 1.)) { + // The edges have the same direction and share a point. Merge them. + edges[i==0 ? edges.size()-1 : i-1] = SurfaceFeature(SurfaceFeatureType::Edge, first_start, second_end); + edges.erase(edges.begin() + i); + } } - } - // Now move the circles and edges into the feature list for the plane. - assert(std::all_of(circles.begin(), circles.end(), [](const SurfaceFeature& f) { - return f.get_type() == SurfaceFeatureType::Circle; - })); - assert(std::all_of(edges.begin(), edges.end(), [](const SurfaceFeature& f) { - return f.get_type() == SurfaceFeatureType::Edge; - })); - plane.surface_features.insert(plane.surface_features.end(), std::make_move_iterator(circles.begin()), - std::make_move_iterator(circles.end())); - plane.surface_features.insert(plane.surface_features.end(), std::make_move_iterator(edges.begin()), - std::make_move_iterator(edges.end())); + // Now move the circles and edges into the feature list for the plane. + assert(std::all_of(circles.begin(), circles.end(), [](const SurfaceFeature& f) { + return f.get_type() == SurfaceFeatureType::Circle; + })); + assert(std::all_of(edges.begin(), edges.end(), [](const SurfaceFeature& f) { + return f.get_type() == SurfaceFeatureType::Edge; + })); + plane.surface_features.insert(plane.surface_features.end(), std::make_move_iterator(circles.begin()), + std::make_move_iterator(circles.end())); + plane.surface_features.insert(plane.surface_features.end(), std::make_move_iterator(edges.begin()), + std::make_move_iterator(edges.end())); + } } // The last surface feature is the plane itself. From e0ba6c69f4a959e6e04cc1bfe1a0d6f81f46242c Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 1 Dec 2022 13:34:29 +0100 Subject: [PATCH 040/109] Fixed warnings --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 2b848bd985..a0ebc832c7 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -82,17 +82,6 @@ static std::string point_on_feature_type_as_string(Measure::SurfaceFeatureType t return ret; } -static std::string center_on_feature_type_as_string(Measure::SurfaceFeatureType type) -{ - std::string ret; - switch (type) { - case Measure::SurfaceFeatureType::Edge: { ret = _u8L("Center of edge"); break; } - case Measure::SurfaceFeatureType::Circle: { ret = _u8L("Center of circle"); break; } - default: { assert(false); break; } - } - return ret; -} - static GLModel::Geometry init_plane_data(const indexed_triangle_set& its, const std::vector>& planes_triangles, int idx) { assert(0 <= idx && idx < (int)planes_triangles.size()); @@ -477,13 +466,6 @@ void GLGizmoMeasure::data_changed() m_is_editing_distance_first_frame = true; } -static bool feature_has_center(std::optional feature) -{ - return feature.has_value() ? - (feature->get_type() == Measure::SurfaceFeatureType::Circle || (feature->get_type() == Measure::SurfaceFeatureType::Edge && feature->get_extra_point().has_value())) - : false; -} - bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down) { if (action == SLAGizmoEventType::ShiftDown) { From 048fb10c311e2492f8275ad7261fc9d4f5bbd197 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 1 Dec 2022 14:56:33 +0100 Subject: [PATCH 041/109] Measure gizmo - Fixed missing raycaster when promoting a point as 1st selected feature --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index a0ebc832c7..21955d5ccd 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -336,7 +336,7 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) }; auto requires_sphere_raycaster_for_picking = [this](const SelectedFeatures::Item& item) { - if (m_mode == EMode::PointSelection) + if (m_mode == EMode::PointSelection || item.feature->get_type() == Measure::SurfaceFeatureType::Point) return true; else if (m_mode == EMode::FeatureSelection) { if (is_feature_with_center(*item.feature)) From 8aa62b88f641b1e5b1ede0930f4ce298f654ab7e Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 2 Dec 2022 07:42:02 +0100 Subject: [PATCH 042/109] Measurement: Fixed edge detection on single-triangle planes --- src/libslic3r/Measure.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 76accc1f37..919c55503e 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -225,7 +225,7 @@ void MeasuringImpl::update_planes() // In case of broken meshes, this loop might be infinite. Break // out in case it is clearly going bad. - if (last_border.size() > 3*facets.size()) + if (last_border.size() > 3*facets.size()+1) goto PLANE_FAILURE; } while (he != he_start); From 9964c47fbdd86a584a2c15998b73e9740f1abe07 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 2 Dec 2022 07:56:11 +0100 Subject: [PATCH 043/109] Follow-up of 85195ac79fb2b7016b05ffff5eb33a483a4d06c2 - Fixed synch of selected features in imgui dialog --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 21955d5ccd..a2d2518d6a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -82,6 +82,17 @@ static std::string point_on_feature_type_as_string(Measure::SurfaceFeatureType t return ret; } +static std::string center_on_feature_type_as_string(Measure::SurfaceFeatureType type) +{ + std::string ret; + switch (type) { + case Measure::SurfaceFeatureType::Edge: { ret = _u8L("Center of edge"); break; } + case Measure::SurfaceFeatureType::Circle: { ret = _u8L("Center of circle"); break; } + default: { assert(false); break; } + } + return ret; +} + static GLModel::Geometry init_plane_data(const indexed_triangle_set& its, const std::vector>& planes_triangles, int idx) { assert(0 <= idx && idx < (int)planes_triangles.size()); @@ -1973,7 +1984,8 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit if (!item.feature.has_value()) return _u8L("None"); - std::string text = (item.source == item.feature) ? surface_feature_type_as_string(item.feature->get_type()) : point_on_feature_type_as_string(item.source->get_type(), m_hover_id); + std::string text = (item.source == item.feature) ? surface_feature_type_as_string(item.feature->get_type()) : + item.is_center ? center_on_feature_type_as_string(item.source->get_type()) : point_on_feature_type_as_string(item.source->get_type(), m_hover_id); if (item.feature.has_value() && item.feature->get_type() == Measure::SurfaceFeatureType::Circle) { auto [center, radius, normal] = item.feature->get_circle(); const Vec3d on_circle = center + radius * Measure::get_orthogonal(normal, true); From fc2f0bad6e3e9ba08c65aacd52396cf6136e1df4 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 15 Nov 2022 12:17:18 +0100 Subject: [PATCH 044/109] Gizmo measure modified to accept single full instance selection, to combine the volumes meshes into a single mesh and pass it to the back end after transform it in world coordinates Changes embedded into tech ENABLE_GIZMO_MEASURE_WORLD_COORDINATES Fixed conflicts during rebase to master --- src/libslic3r/Measure.cpp | 37 ++++ src/libslic3r/Measure.hpp | 19 +- src/libslic3r/Technologies.hpp | 2 + src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 230 ++++++++++++++++++++++- src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp | 35 ++++ src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp | 13 ++ src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp | 7 + src/slic3r/GUI/Selection.cpp | 13 ++ src/slic3r/GUI/Selection.hpp | 4 + 9 files changed, 347 insertions(+), 13 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index badb3b2c5f..9b930df9aa 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -47,6 +47,9 @@ public: std::optional get_feature(size_t face_idx, const Vec3d& point) const; std::vector> get_planes_triangle_indices() const; const std::vector& get_plane_features(unsigned int plane_id) const; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const TriangleMesh& get_mesh() const; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES private: void update_planes(); @@ -54,7 +57,11 @@ private: std::vector m_planes; std::vector m_face_to_plane; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + TriangleMesh m_mesh; +#else const indexed_triangle_set& m_its; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES }; @@ -63,7 +70,11 @@ private: MeasuringImpl::MeasuringImpl(const indexed_triangle_set& its) +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +: m_mesh(its) +#else : m_its{its} +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES { update_planes(); extract_features(); @@ -76,10 +87,17 @@ void MeasuringImpl::update_planes() // Now we'll go through all the facets and append Points of facets sharing the same normal. // This part is still performed in mesh coordinate system. +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const size_t num_of_facets = m_mesh.its.indices.size(); + m_face_to_plane.resize(num_of_facets, size_t(-1)); + const std::vector face_normals = its_face_normals(m_mesh.its); + const std::vector face_neighbors = its_face_neighbors(m_mesh.its); +#else const size_t num_of_facets = m_its.indices.size(); m_face_to_plane.resize(num_of_facets, size_t(-1)); const std::vector face_normals = its_face_normals(m_its); const std::vector face_neighbors = its_face_neighbors(m_its); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES std::vector facet_queue(num_of_facets, 0); int facet_queue_cnt = 0; const stl_normal* normal_ptr = nullptr; @@ -128,7 +146,11 @@ void MeasuringImpl::update_planes() assert(std::none_of(m_face_to_plane.begin(), m_face_to_plane.end(), [](size_t val) { return val == size_t(-1); })); // Now we will walk around each of the planes and save vertices which form the border. +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + SurfaceMesh sm(m_mesh.its); +#else SurfaceMesh sm(m_its); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES for (int plane_id=0; plane_id < int(m_planes.size()); ++plane_id) { const auto& facets = m_planes[plane_id].facets; m_planes[plane_id].borders.clear(); @@ -510,6 +532,12 @@ const std::vector& MeasuringImpl::get_plane_features(unsigned in return m_planes[plane_id].surface_features; } +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +const TriangleMesh& MeasuringImpl::get_mesh() const +{ + return this->m_mesh; +} +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES @@ -551,6 +579,13 @@ const std::vector& Measuring::get_plane_features(unsigned int pl return priv->get_plane_features(plane_id); } +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +const TriangleMesh& Measuring::get_mesh() const +{ + return priv->get_mesh(); +} +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const AngleAndEdges AngleAndEdges::Dummy = { 0.0, Vec3d::Zero(), { Vec3d::Zero(), Vec3d::Zero() }, { Vec3d::Zero(), Vec3d::Zero() }, 0.0, true }; static AngleAndEdges angle_edge_edge(const std::pair& e1, const std::pair& e2) @@ -1149,6 +1184,7 @@ MeasurementResult get_measurement(const SurfaceFeature& a, const SurfaceFeature& return result; } +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES void DistAndPoints::transform(const Transform3d& trafo) { from = trafo * from; to = trafo * to; @@ -1169,6 +1205,7 @@ void AngleAndEdges::transform(const Transform3d& trafo) { const double average_scale = 0.5 * (new_e1.norm() / old_e1.norm() + new_e2.norm() / old_e2.norm()); radius = average_scale * radius; } +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES diff --git a/src/libslic3r/Measure.hpp b/src/libslic3r/Measure.hpp index ede8c634ee..b2e2008d15 100644 --- a/src/libslic3r/Measure.hpp +++ b/src/libslic3r/Measure.hpp @@ -87,9 +87,11 @@ class MeasuringImpl; class Measuring { public: - // Construct the measurement object on a given its. The its must remain - // valid and unchanged during the whole lifetime of the object. - explicit Measuring(const indexed_triangle_set& its); + // Construct the measurement object on a given its. +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + // The its must remain valid and unchanged during the whole lifetime of the object. +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + explicit Measuring(const indexed_triangle_set& its); ~Measuring(); // Return a reference to a list of all features identified on the its. @@ -108,6 +110,11 @@ public: // Returns the surface features of the plane with the given index const std::vector& get_plane_features(unsigned int plane_id) const; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + // Returns the mesh used for measuring + const TriangleMesh& get_mesh() const; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + private: std::unique_ptr priv; }; @@ -119,7 +126,9 @@ struct DistAndPoints { Vec3d from; Vec3d to; +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES void transform(const Transform3d& trafo); +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES }; struct AngleAndEdges { @@ -132,7 +141,9 @@ struct AngleAndEdges { double radius; bool coplanar; +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES void transform(const Transform3d& trafo); +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES static const AngleAndEdges Dummy; }; @@ -151,6 +162,7 @@ struct MeasurementResult { return angle.has_value() || distance_infinite.has_value() || distance_strict.has_value() || distance_xyz.has_value(); } +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES void transform(const Transform3d& trafo) { if (angle.has_value()) angle->transform(trafo); @@ -161,6 +173,7 @@ struct MeasurementResult { distance_xyz = (distance_strict->to - distance_strict->from).cwiseAbs(); } } +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES }; // Returns distance/angle between two SurfaceFeatures. diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index f707b0f21d..759871c60d 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -64,6 +64,8 @@ // Enable picking using raytracing #define ENABLE_RAYCAST_PICKING (1 && ENABLE_LEGACY_OPENGL_REMOVAL) #define ENABLE_RAYCAST_PICKING_DEBUG (0 && ENABLE_RAYCAST_PICKING) +// Enable gizmo measure combining volumes meshes and passing them to the backend in world coordinates +#define ENABLE_GIZMO_MEASURE_WORLD_COORDINATES (1 && ENABLE_2_5_0_ALPHA1) #endif // _prusaslicer_technologies_h_ diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index a026ae2552..5ae906eac9 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -5,9 +5,11 @@ #include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/GUI_ObjectManipulation.hpp" -#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" #include "libslic3r/Model.hpp" +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES #include "libslic3r/PresetBundle.hpp" #include "libslic3r/MeasureUtils.hpp" @@ -242,7 +244,10 @@ private: TransformHelper::Cache TransformHelper::s_cache = { { 0, 0, 0, 0 }, Matrix4d::Identity(), Transform3d::Identity() }; GLGizmoMeasure::GLGizmoMeasure(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) - : GLGizmoBase(parent, icon_filename, sprite_id) +: GLGizmoBase(parent, icon_filename, sprite_id) +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +, m_raycaster(nullptr) +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES { GLModel::Geometry sphere_geometry = smooth_sphere(16, 7.5f); m_sphere.mesh_raycaster = std::make_unique(std::make_shared(sphere_geometry.get_as_indexed_triangle_set())); @@ -370,8 +375,10 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) if (m_selected_features != selected_features_old && m_selected_features.second.feature.has_value()) { m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // transform to world coordinates m_measurement_result.transform(m_volume_matrix); +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } m_imgui->set_requires_extra_frame(); @@ -419,6 +426,9 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) void GLGizmoMeasure::data_changed() { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + update_if_needed(); +#else const Selection& selection = m_parent.get_selection(); const ModelObject* model_object = nullptr; const ModelVolume* model_volume = nullptr; @@ -429,13 +439,16 @@ void GLGizmoMeasure::data_changed() } if (model_object != m_old_model_object || model_volume != m_old_model_volume) update_if_needed(); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES m_last_inv_zoom = 0.0f; m_last_plane_idx = -1; if (m_pending_scale) { m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // transform to world coordinates m_measurement_result.transform(m_volume_matrix); +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES m_pending_scale = false; } else @@ -512,6 +525,9 @@ void GLGizmoMeasure::on_set_state() m_editing_distance = false; m_is_editing_distance_first_frame = true; m_measuring.reset(); +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + m_raycaster.release(); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } else { m_mode = EMode::FeatureSelection; @@ -528,10 +544,12 @@ void GLGizmoMeasure::on_set_state() } } +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES CommonGizmosDataID GLGizmoMeasure::on_get_requirements() const { return CommonGizmosDataID(int(CommonGizmosDataID::SelectionInfo) | int(CommonGizmosDataID::Raycaster)); } +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES std::string GLGizmoMeasure::on_get_name() const { @@ -543,9 +561,15 @@ bool GLGizmoMeasure::on_is_activable() const const Selection& selection = m_parent.get_selection(); bool res = (wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA) ? selection.is_single_full_instance() : +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + selection.is_single_full_instance() || selection.is_single_volume() || selection.is_single_modifier(); + if (res) + res &= !selection.contains_sinking_volumes(); +#else selection.is_single_volume() || selection.is_single_volume_instance(); if (res) res &= !selection.get_first_volume()->is_sinking(); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES return res; } @@ -562,8 +586,10 @@ void GLGizmoMeasure::on_render() const Selection& selection = m_parent.get_selection(); +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES if ((wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA && selection.is_single_full_instance()) || (selection.is_single_volume() || selection.is_single_volume_instance())) { +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES update_if_needed(); const Camera& camera = wxGetApp().plater()->get_camera(); @@ -572,7 +598,11 @@ void GLGizmoMeasure::on_render() Vec3f position_on_model; Vec3f normal_on_model; size_t model_facet_idx; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const bool mouse_on_object = m_raycaster.raycaster()->unproject_on_mesh(m_mouse_pos, Transform3d::Identity(), camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); +#else const bool mouse_on_object = m_c->raycaster()->raycasters().front()->unproject_on_mesh(m_mouse_pos, m_volume_matrix, camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const bool is_hovering_on_feature = (m_mode == EMode::PointSelection || m_mode == EMode::CenterSelection) && m_hover_id != -1; auto update_circle = [this, inv_zoom]() { @@ -581,7 +611,11 @@ void GLGizmoMeasure::on_render() m_last_circle = m_curr_feature; m_circle.reset(); const auto [center, radius, normal] = m_curr_feature->get_circle(); +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); +#else GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), m_volume_matrix.cast()); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES m_circle.mesh_raycaster = std::make_unique(std::make_shared(circle_geometry.get_as_indexed_triangle_set())); m_circle.model.init_from(std::move(circle_geometry)); return true; @@ -639,7 +673,11 @@ void GLGizmoMeasure::on_render() const auto [idx, normal, point] = m_curr_feature->get_plane(); if (m_last_plane_idx != idx) { m_last_plane_idx = idx; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const indexed_triangle_set& its = m_measuring->get_mesh().its; +#else const indexed_triangle_set its = (m_old_model_volume != nullptr) ? m_old_model_volume->mesh().its : m_old_model_object->volumes.front()->mesh().its; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const std::vector> planes_triangles = m_measuring->get_planes_triangle_indices(); GLModel::Geometry init_data = init_plane_data(its, planes_triangles, idx); m_plane.reset(); @@ -689,12 +727,20 @@ void GLGizmoMeasure::on_render() if (extra.has_value() && m_hover_id == POINT_ID) m_curr_point_on_feature_position = *extra; else +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + m_curr_point_on_feature_position = position_on_feature(EDGE_ID, camera, [](const Vec3f& v) { return Vec3f(0.0f, 0.0f, v.z()); }); +#else m_curr_point_on_feature_position = m_volume_matrix.inverse() * position_on_feature(EDGE_ID, camera, [](const Vec3f& v) { return Vec3f(0.0f, 0.0f, v.z()); }); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES break; } case Measure::SurfaceFeatureType::Plane: { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + m_curr_point_on_feature_position = position_on_feature(PLANE_ID, camera); +#else m_curr_point_on_feature_position = m_volume_matrix.inverse() * position_on_feature(PLANE_ID, camera); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES break; } case Measure::SurfaceFeatureType::Circle: @@ -704,9 +750,17 @@ void GLGizmoMeasure::on_render() m_curr_point_on_feature_position = center; else { const Vec3d world_pof = position_on_feature(CIRCLE_ID, camera, [](const Vec3f& v) { return v; }); +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Eigen::Hyperplane plane(normal, center); +#else const Eigen::Hyperplane plane(m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal, m_volume_matrix * center); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const Transform3d local_to_model_matrix = Geometry::translation_transform(center) * Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), normal); +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Vec3d local_proj = local_to_model_matrix.inverse() * plane.projection(world_pof); +#else const Vec3d local_proj = local_to_model_matrix.inverse() * m_volume_matrix.inverse() * plane.projection(world_pof); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES double angle = std::atan2(local_proj.y(), local_proj.x()); if (angle < 0.0) angle += 2.0 * double(M_PI); @@ -767,8 +821,12 @@ void GLGizmoMeasure::on_render() default: { assert(false); break; } case Measure::SurfaceFeatureType::Point: { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Transform3d feature_matrix = Geometry::translation_transform(feature.get_point()) * Geometry::scale_transform(inv_zoom); +#else const Vec3d position = TransformHelper::model_to_world(feature.get_point(), m_volume_matrix); const Transform3d feature_matrix = Geometry::translation_transform(position) * Geometry::scale_transform(inv_zoom); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES set_matrix_uniforms(feature_matrix); set_emission_uniform(colors.front(), hover); m_sphere.model.set_color(colors.front()); @@ -785,8 +843,12 @@ void GLGizmoMeasure::on_render() const auto& [center, radius, normal] = feature.get_circle(); // render center if (update_raycasters_transform) { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Transform3d center_matrix = Geometry::translation_transform(center) * Geometry::scale_transform(inv_zoom); +#else const Vec3d center_world = TransformHelper::model_to_world(center, m_volume_matrix); const Transform3d center_matrix = Geometry::translation_transform(center_world) * Geometry::scale_transform(inv_zoom); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES set_matrix_uniforms(center_matrix); set_emission_uniform(colors.front(), hover); m_sphere.model.set_color(colors.front()); @@ -809,7 +871,11 @@ void GLGizmoMeasure::on_render() } else { GLModel circle; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); +#else GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), m_volume_matrix.cast()); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES circle.init_from(std::move(circle_geometry)); set_emission_uniform(colors.back(), hover); circle.set_color(colors.back()); @@ -825,8 +891,12 @@ void GLGizmoMeasure::on_render() if (update_raycasters_transform) { const std::optional extra = feature.get_extra_point(); if (extra.has_value()) { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Transform3d point_matrix = Geometry::translation_transform(*extra) * Geometry::scale_transform(inv_zoom); +#else const Vec3d extra_world = TransformHelper::model_to_world(*extra, m_volume_matrix); const Transform3d point_matrix = Geometry::translation_transform(extra_world) * Geometry::scale_transform(inv_zoom); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES set_matrix_uniforms(point_matrix); set_emission_uniform(colors.front(), hover); m_sphere.model.set_color(colors.front()); @@ -838,11 +908,17 @@ void GLGizmoMeasure::on_render() } // render edge if (m_mode != EMode::CenterSelection) { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Transform3d edge_matrix = Geometry::translation_transform(from) * + Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), to - from) * + Geometry::scale_transform({ (double)inv_zoom, (double)inv_zoom, (to - from).norm() }); +#else const Vec3d from_world = TransformHelper::model_to_world(from, m_volume_matrix); const Vec3d to_world = TransformHelper::model_to_world(to, m_volume_matrix); const Transform3d edge_matrix = Geometry::translation_transform(from_world) * Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), to_world - from_world) * Geometry::scale_transform({ (double)inv_zoom, (double)inv_zoom, (to_world - from_world).norm() }); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES set_matrix_uniforms(edge_matrix); set_emission_uniform(colors.back(), hover); m_cylinder.model.set_color(colors.back()); @@ -857,16 +933,27 @@ void GLGizmoMeasure::on_render() } case Measure::SurfaceFeatureType::Plane: { - const auto& [idx, normal, pt] = feature.get_plane(); - assert(idx < m_plane_models_cache.size()); - set_matrix_uniforms(m_volume_matrix); - set_emission_uniform(colors.front(), hover); - m_plane_models_cache[idx].set_color(colors.front()); - m_plane_models_cache[idx].render(); + // no need to render the plane in case it is rendered with the same color as the volume in the 3D scene + if (colors.front() != m_parent.get_selection().get_first_volume()->render_color) { + const auto& [idx, normal, pt] = feature.get_plane(); + assert(idx < m_plane_models_cache.size()); +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + set_matrix_uniforms(Transform3d::Identity()); +#else + set_matrix_uniforms(m_volume_matrix); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + set_emission_uniform(colors.front(), hover); + m_plane_models_cache[idx].set_color(colors.front()); + m_plane_models_cache[idx].render(); + } if (update_raycasters_transform) { auto it = m_raycasters.find(PLANE_ID); if (it != m_raycasters.end() && it->second != nullptr) +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + it->second->set_transform(Transform3d::Identity()); +#else it->second->set_transform(m_volume_matrix); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } break; } @@ -921,7 +1008,11 @@ void GLGizmoMeasure::on_render() auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_1_ID; }); if (it != m_selection_raycasters.end()) +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + (*it)->set_transform(Geometry::translation_transform(m_selected_features.first.feature->get_point()) * Geometry::scale_transform(inv_zoom)); +#else (*it)->set_transform(m_volume_matrix * Geometry::translation_transform(m_selected_features.first.feature->get_point()) * Geometry::scale_transform(inv_zoom)); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } } if (m_selected_features.second.feature.has_value() && (!m_curr_feature.has_value() || *m_curr_feature != *m_selected_features.second.feature)) { @@ -931,14 +1022,22 @@ void GLGizmoMeasure::on_render() auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_2_ID; }); if (it != m_selection_raycasters.end()) +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + (*it)->set_transform(Geometry::translation_transform(m_selected_features.second.feature->get_point()) * Geometry::scale_transform(inv_zoom)); +#else (*it)->set_transform(m_volume_matrix * Geometry::translation_transform(m_selected_features.second.feature->get_point()) * Geometry::scale_transform(inv_zoom)); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } } if (is_hovering_on_feature && m_curr_point_on_feature_position.has_value()) { if (m_hover_id != POINT_ID) { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Transform3d matrix = Geometry::translation_transform(*m_curr_point_on_feature_position) * Geometry::scale_transform(inv_zoom); +#else const Vec3d position = TransformHelper::model_to_world(*m_curr_point_on_feature_position, m_volume_matrix); const Transform3d matrix = Geometry::translation_transform(position) * Geometry::scale_transform(inv_zoom); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES set_matrix_uniforms(matrix); const ColorRGBA color = hover_selection_color(); set_emission_uniform(color, true); @@ -951,7 +1050,9 @@ void GLGizmoMeasure::on_render() if (old_cullface) glsafe(::glEnable(GL_CULL_FACE)); +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES render_dimensioning(); } @@ -968,6 +1069,24 @@ void GLGizmoMeasure::update_if_needed() } }; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + auto do_update = [this, update_plane_models_cache](const std::vector& volumes_cache, const Selection& selection) { + TriangleMesh composite_mesh; + for (const auto& vol : volumes_cache) { +// if (selection.is_single_full_instance() && vol.volume->is_modifier()) +// continue; + + TriangleMesh volume_mesh = vol.volume->mesh(); + volume_mesh.transform(vol.instance->get_transformation().get_matrix() * vol.volume->get_transformation().get_matrix()); + composite_mesh.merge(volume_mesh); + } + + m_measuring.reset(new Measure::Measuring(composite_mesh.its)); + update_plane_models_cache(m_measuring->get_mesh().its); + m_raycaster.update_from(m_measuring->get_mesh()); + m_volumes_cache = volumes_cache; + }; +#else auto do_update = [this, update_plane_models_cache](const ModelObject* object, const ModelVolume* volume) { const indexed_triangle_set& its = (volume != nullptr) ? volume->mesh().its : object->volumes.front()->mesh().its; m_measuring.reset(new Measure::Measuring(its)); @@ -977,24 +1096,44 @@ void GLGizmoMeasure::update_if_needed() // Let's save what we calculated it from: m_volumes_matrices.clear(); m_volumes_types.clear(); - m_first_instance_scale = Vec3d::Ones(); + m_first_instance_scale = Vec3d::Ones(); m_first_instance_mirror = Vec3d::Ones(); if (object != nullptr) { for (const ModelVolume* vol : object->volumes) { m_volumes_matrices.push_back(vol->get_matrix()); m_volumes_types.push_back(vol->type()); } - m_first_instance_scale = object->instances.front()->get_scaling_factor(); + m_first_instance_scale = object->instances.front()->get_scaling_factor(); m_first_instance_mirror = object->instances.front()->get_mirror(); } m_old_model_object = object; m_old_model_volume = volume; }; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const Selection& selection = m_parent.get_selection(); if (selection.is_empty()) return; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Selection::IndicesList& idxs = selection.get_volume_idxs(); + std::vector volumes_cache; + volumes_cache.reserve(idxs.size()); + for (unsigned int idx : idxs) { + const GLVolume* v = selection.get_volume(idx); + const ModelObject* obj = selection.get_model()->objects[v->object_idx()]; + const ModelInstance* inst = obj->instances[v->instance_idx()]; + const ModelVolume* vol = obj->volumes[v->volume_idx()]; + const VolumeCacheItem item = { obj, inst, vol, inst->get_matrix() * vol->get_matrix() }; + volumes_cache.emplace_back(item); + } + + if (m_state != On || volumes_cache.empty()) + return; + + if (m_measuring == nullptr || m_volumes_cache != volumes_cache) + do_update(volumes_cache, selection); +#else m_volume_matrix = selection.get_first_volume()->world_matrix(); const ModelObject* mo = m_c->selection_info()->model_object(); @@ -1023,6 +1162,7 @@ void GLGizmoMeasure::update_if_needed() break; } } +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } void GLGizmoMeasure::disable_scene_raycasters() @@ -1142,6 +1282,62 @@ void GLGizmoMeasure::render_dimensioning() const double ratio = new_value / old_value; wxGetApp().plater()->take_snapshot(_L("Scale")); +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + struct TrafoData + { + double ratio; + Vec3d old_pivot; + Vec3d new_pivot; + Transform3d scale_matrix; + + TrafoData(double ratio, const Vec3d& pivot) { + this->ratio = ratio; + this->scale_matrix = Geometry::scale_transform(ratio); + this->old_pivot = pivot; + this->new_pivot = { pivot.x(), pivot.y(), (this->scale_matrix * pivot).z() }; + } + + Vec3d transform(const Vec3d& point) const { + return this->scale_matrix * (point - this->old_pivot) + this->new_pivot; + } + }; + + auto scale_feature = [this](Measure::SurfaceFeature& feature, const TrafoData& trafo_data) { + switch (feature.get_type()) + { + case Measure::SurfaceFeatureType::Point: + { + feature = Measure::SurfaceFeature(trafo_data.transform(feature.get_point())); + break; + } + case Measure::SurfaceFeatureType::Edge: + { + const auto [from, to] = feature.get_edge(); + const std::optional extra = feature.get_extra_point(); + const std::optional new_extra = extra.has_value() ? trafo_data.transform(*extra) : extra; + feature = Measure::SurfaceFeature(Measure::SurfaceFeatureType::Edge, trafo_data.transform(from), trafo_data.transform(to), new_extra); + break; + } + case Measure::SurfaceFeatureType::Circle: + { + const auto [center, radius, normal] = feature.get_circle(); + feature = Measure::SurfaceFeature(Measure::SurfaceFeatureType::Circle, trafo_data.transform(center), normal, std::nullopt, trafo_data.ratio * radius); + break; + } + case Measure::SurfaceFeatureType::Plane: + { + const auto [idx, normal, origin] = feature.get_plane(); + feature = Measure::SurfaceFeature(Measure::SurfaceFeatureType::Plane, normal, trafo_data.transform(origin), std::nullopt, idx); + break; + } + } + }; + + const TrafoData trafo_data(ratio, m_parent.get_selection().get_bounding_box().center()); + scale_feature(*m_selected_features.first.feature, trafo_data); + scale_feature(*m_selected_features.second.feature, trafo_data); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + TransformationType type; type.set_world(); type.set_relative(); @@ -1200,8 +1396,10 @@ void GLGizmoMeasure::render_dimensioning() assert(f1.get_type() == Measure::SurfaceFeatureType::Point && f2.get_type() == Measure::SurfaceFeatureType::Edge); std::pair e = f2.get_edge(); // Transform to world coordinates +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES e.first = TransformHelper::model_to_world(e.first, m_volume_matrix); e.second = TransformHelper::model_to_world(e.second, m_volume_matrix); +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const Vec3d v_proj = m_measurement_result.distance_infinite->to; @@ -1482,15 +1680,21 @@ void GLGizmoMeasure::render_debug_dialog() { case Measure::SurfaceFeatureType::Point: { +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(item.feature->get_point()), ImGui::GetStyleColorVec4(ImGuiCol_Text)); +#else const Vec3d position = m_volume_matrix * item.feature->get_point(); add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(position), ImGui::GetStyleColorVec4(ImGuiCol_Text)); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES break; } case Measure::SurfaceFeatureType::Edge: { auto [from, to] = item.feature->get_edge(); +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES from = m_volume_matrix * from; to = m_volume_matrix * to; +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(from), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_pt2", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(to), ImGui::GetStyleColorVec4(ImGuiCol_Text)); break; @@ -1498,8 +1702,10 @@ void GLGizmoMeasure::render_debug_dialog() case Measure::SurfaceFeatureType::Plane: { auto [idx, normal, origin] = item.feature->get_plane(); +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES origin = m_volume_matrix * origin; normal = m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal; +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(normal), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_pt2", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(origin), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_value", ImGuiWrapper::COL_ORANGE_LIGHT, format_double(idx), ImGui::GetStyleColorVec4(ImGuiCol_Text)); @@ -1508,9 +1714,13 @@ void GLGizmoMeasure::render_debug_dialog() case Measure::SurfaceFeatureType::Circle: { auto [center, radius, normal] = item.feature->get_circle(); +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + const Vec3d on_circle = center + radius * Measure::get_orthogonal(normal, true); +#else const Vec3d on_circle = m_volume_matrix * (center + radius * Measure::get_orthogonal(normal, true)); center = m_volume_matrix * center; normal = (m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal).normalized(); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES radius = (on_circle - center).norm(); add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(center), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_pt2", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(normal), ImGui::GetStyleColorVec4(ImGuiCol_Text)); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp index 7bfc2e8c93..606012f7c4 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp @@ -5,10 +5,16 @@ #include "slic3r/GUI/GLModel.hpp" #include "slic3r/GUI/GUI_Utils.hpp" #include "libslic3r/Measure.hpp" +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" +#include "libslic3r/Model.hpp" +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES namespace Slic3r { +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES class ModelVolume; +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES enum class ModelVolumeType : int; @@ -68,6 +74,23 @@ class GLGizmoMeasure : public GLGizmoBase } }; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + struct VolumeCacheItem + { + const ModelObject* object{ nullptr }; + const ModelInstance* instance{ nullptr }; + const ModelVolume* volume{ nullptr }; + Transform3d world_trafo; + + bool operator == (const VolumeCacheItem& other) const { + return this->object == other.object && this->instance == other.instance && this->volume == other.volume && + this->world_trafo.isApprox(other.world_trafo); + } + }; + + std::vector m_volumes_cache; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + EMode m_mode{ EMode::FeatureSelection }; Measure::MeasurementResult m_measurement_result; @@ -85,7 +108,13 @@ class GLGizmoMeasure : public GLGizmoBase }; Dimensioning m_dimensioning; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + // Uses a standalone raycaster and not the shared one because of the + // difference in how the mesh is updated + CommonGizmosDataObjects::Raycaster m_raycaster; +#else Transform3d m_volume_matrix{ Transform3d::Identity() }; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES std::vector m_plane_models_cache; std::map> m_raycasters; std::vector> m_selection_raycasters; @@ -100,17 +129,21 @@ class GLGizmoMeasure : public GLGizmoBase std::vector m_scene_raycasters; // These hold information to decide whether recalculation is necessary: +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES std::vector m_volumes_matrices; std::vector m_volumes_types; Vec3d m_first_instance_scale{ Vec3d::Ones() }; Vec3d m_first_instance_mirror{ Vec3d::Ones() }; +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES float m_last_inv_zoom{ 0.0f }; std::optional m_last_circle; int m_last_plane_idx{ -1 }; bool m_mouse_left_down{ false }; // for detection left_up of this gizmo +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const ModelObject* m_old_model_object{ nullptr }; const ModelVolume* m_old_model_volume{ nullptr }; +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES Vec2d m_mouse_pos{ Vec2d::Zero() }; @@ -153,7 +186,9 @@ protected: bool on_is_activable() const override; void on_render() override; void on_set_state() override; +#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES CommonGizmosDataID on_get_requirements() const override; +#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES virtual void on_render_input_window(float x, float y, float bottom_limit) override; virtual void on_register_raycasters_for_picking() override; diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp index 394e879b7c..dca64a5266 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp @@ -327,6 +327,19 @@ const TriangleMesh* HollowedMesh::get_hollowed_interior() const } +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +void Raycaster::update_from(const TriangleMesh& mesh) +{ + std::vector meshes = { &mesh }; + if (meshes != m_old_meshes) { + wxBusyCursor wait; + m_raycasters.clear(); + m_raycasters.emplace_back(new MeshRaycaster(std::make_shared(mesh))); + m_old_meshes = meshes; + } + validate(); +} +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES void Raycaster::on_update() diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp index 42faa25f84..b02e3a920c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp @@ -137,6 +137,9 @@ protected: virtual void on_update() = 0; CommonGizmosDataPool* get_pool() const { return m_common; } +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + void validate() { m_is_valid = true; } +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES private: bool m_is_valid = false; @@ -242,6 +245,10 @@ public: const MeshRaycaster* raycaster() const { assert(m_raycasters.size() == 1); return m_raycasters.front().get(); } std::vector raycasters() const; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + void update_from(const TriangleMesh& mesh); +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + protected: void on_update() override; void on_release() override; diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index b27f7a7381..0e893fb16c 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -613,6 +613,19 @@ bool Selection::contains_any_volume(const std::vector& volume_idxs return false; } +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +bool Selection::contains_sinking_volumes(bool ignore_modifiers) const +{ + for (const GLVolume* v : *m_volumes) { + if (!ignore_modifiers || !v->is_modifier) { + if (v->is_sinking()) + return true; + } + } + return false; +} +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + bool Selection::matches(const std::vector& volume_idxs) const { unsigned int count = 0; diff --git a/src/slic3r/GUI/Selection.hpp b/src/slic3r/GUI/Selection.hpp index 34b88f1606..cf9d26fc7d 100644 --- a/src/slic3r/GUI/Selection.hpp +++ b/src/slic3r/GUI/Selection.hpp @@ -338,6 +338,10 @@ public: bool contains_all_volumes(const std::vector& volume_idxs) const; // returns true if the selection contains at least one of the given indices bool contains_any_volume(const std::vector& volume_idxs) const; +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + // returns true if the selection contains any sinking volume + bool contains_sinking_volumes(bool ignore_modifiers = true) const; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // returns true if the selection contains all and only the given indices bool matches(const std::vector& volume_idxs) const; From 4606d8266a87e92c75701adfb4ece322534555d6 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 15 Nov 2022 12:42:22 +0100 Subject: [PATCH 045/109] Added missing declaration --- src/libslic3r/Measure.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libslic3r/Measure.hpp b/src/libslic3r/Measure.hpp index b2e2008d15..9cc380dd2b 100644 --- a/src/libslic3r/Measure.hpp +++ b/src/libslic3r/Measure.hpp @@ -12,6 +12,11 @@ struct indexed_triangle_set; namespace Slic3r { + +#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES +class TriangleMesh; +#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + namespace Measure { From 268365b92db90084f9b142c7bd46ebf3b708ec1d Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 15 Nov 2022 16:07:38 +0100 Subject: [PATCH 046/109] Measurement: refactoring - do not touch common raycaster interface when there is no need --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 9 +++------ src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp | 4 ++-- src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp | 15 --------------- src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp | 8 -------- 4 files changed, 5 insertions(+), 31 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 5ae906eac9..8cfbf634eb 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -245,9 +245,6 @@ TransformHelper::Cache TransformHelper::s_cache = { { 0, 0, 0, 0 }, Matrix4d::Id GLGizmoMeasure::GLGizmoMeasure(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) : GLGizmoBase(parent, icon_filename, sprite_id) -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES -, m_raycaster(nullptr) -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES { GLModel::Geometry sphere_geometry = smooth_sphere(16, 7.5f); m_sphere.mesh_raycaster = std::make_unique(std::make_shared(sphere_geometry.get_as_indexed_triangle_set())); @@ -526,7 +523,7 @@ void GLGizmoMeasure::on_set_state() m_is_editing_distance_first_frame = true; m_measuring.reset(); #if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - m_raycaster.release(); + m_raycaster.reset(); #endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } else { @@ -599,7 +596,7 @@ void GLGizmoMeasure::on_render() Vec3f normal_on_model; size_t model_facet_idx; #if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const bool mouse_on_object = m_raycaster.raycaster()->unproject_on_mesh(m_mouse_pos, Transform3d::Identity(), camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); + const bool mouse_on_object = m_raycaster->unproject_on_mesh(m_mouse_pos, Transform3d::Identity(), camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); #else const bool mouse_on_object = m_c->raycaster()->raycasters().front()->unproject_on_mesh(m_mouse_pos, m_volume_matrix, camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); #endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES @@ -1083,7 +1080,7 @@ void GLGizmoMeasure::update_if_needed() m_measuring.reset(new Measure::Measuring(composite_mesh.its)); update_plane_models_cache(m_measuring->get_mesh().its); - m_raycaster.update_from(m_measuring->get_mesh()); + m_raycaster.reset(new MeshRaycaster(std::make_shared(m_measuring->get_mesh()))); m_volumes_cache = volumes_cache; }; #else diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp index 606012f7c4..fbbf30da78 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp @@ -4,9 +4,9 @@ #include "GLGizmoBase.hpp" #include "slic3r/GUI/GLModel.hpp" #include "slic3r/GUI/GUI_Utils.hpp" +#include "slic3r/GUI/MeshUtils.hpp" #include "libslic3r/Measure.hpp" #if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES -#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" #include "libslic3r/Model.hpp" #endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES @@ -111,7 +111,7 @@ class GLGizmoMeasure : public GLGizmoBase #if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // Uses a standalone raycaster and not the shared one because of the // difference in how the mesh is updated - CommonGizmosDataObjects::Raycaster m_raycaster; + std::unique_ptr m_raycaster; #else Transform3d m_volume_matrix{ Transform3d::Identity() }; #endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp index dca64a5266..11c44113bc 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp @@ -327,21 +327,6 @@ const TriangleMesh* HollowedMesh::get_hollowed_interior() const } -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES -void Raycaster::update_from(const TriangleMesh& mesh) -{ - std::vector meshes = { &mesh }; - if (meshes != m_old_meshes) { - wxBusyCursor wait; - m_raycasters.clear(); - m_raycasters.emplace_back(new MeshRaycaster(std::make_shared(mesh))); - m_old_meshes = meshes; - } - validate(); -} -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - - void Raycaster::on_update() { wxBusyCursor wait; diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp index b02e3a920c..3878c6b25a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp @@ -137,10 +137,6 @@ protected: virtual void on_update() = 0; CommonGizmosDataPool* get_pool() const { return m_common; } -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - void validate() { m_is_valid = true; } -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - private: bool m_is_valid = false; CommonGizmosDataPool* m_common = nullptr; @@ -245,10 +241,6 @@ public: const MeshRaycaster* raycaster() const { assert(m_raycasters.size() == 1); return m_raycasters.front().get(); } std::vector raycasters() const; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - void update_from(const TriangleMesh& mesh); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - protected: void on_update() override; void on_release() override; From 5382f4077ac88c988647979c4cb792a4cf475892 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 15 Nov 2022 16:08:27 +0100 Subject: [PATCH 047/109] Measurement: Partially fixed the common gizmo raycaster for self-intersecting meshes --- src/slic3r/GUI/MeshUtils.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/MeshUtils.cpp b/src/slic3r/GUI/MeshUtils.cpp index 0483d2bf0a..94375a6e34 100644 --- a/src/slic3r/GUI/MeshUtils.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -409,6 +409,12 @@ bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& Vec3d direction; line_from_mouse_pos(mouse_pos, trafo, camera, point, direction); + if (rand()%100 == 0) { + int a=5; + int b=6; + int c=7; + } + std::vector hits = m_emesh.query_ray_hits(point, direction); if (hits.empty()) @@ -429,10 +435,10 @@ bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& // All hits are clipped. return false; } - if ((hits.size()-i) % 2 != 0) { + if (clipping_plane && (hits.size()-i) % 2 != 0) { // There is an odd number of unclipped hits - meaning the nearest must be from inside the mesh. // In that case, calculate intersection with the clipping place. - if (clipping_plane && was_clipping_plane_hit) { + if (was_clipping_plane_hit) { direction = direction + point; point = trafo * point; // transform to world coords direction = trafo * direction - point; From 075c24190691f90ac85d1544a295a80bbf26c4eb Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 16 Nov 2022 08:53:02 +0100 Subject: [PATCH 048/109] Tech ENABLE_GIZMO_MEASURE_WORLD_COORDINATES set as default Fixed conflicts during rebase to master --- src/libslic3r/Measure.cpp | 48 -- src/libslic3r/Measure.hpp | 30 +- src/libslic3r/Technologies.hpp | 2 - src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 850 +++++++++-------------- src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp | 26 +- src/slic3r/GUI/Selection.cpp | 2 - src/slic3r/GUI/Selection.hpp | 2 - 7 files changed, 323 insertions(+), 637 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 9b930df9aa..4e3bcaa822 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -47,9 +47,7 @@ public: std::optional get_feature(size_t face_idx, const Vec3d& point) const; std::vector> get_planes_triangle_indices() const; const std::vector& get_plane_features(unsigned int plane_id) const; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const TriangleMesh& get_mesh() const; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES private: void update_planes(); @@ -57,11 +55,7 @@ private: std::vector m_planes; std::vector m_face_to_plane; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES TriangleMesh m_mesh; -#else - const indexed_triangle_set& m_its; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES }; @@ -70,11 +64,7 @@ private: MeasuringImpl::MeasuringImpl(const indexed_triangle_set& its) -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES : m_mesh(its) -#else -: m_its{its} -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES { update_planes(); extract_features(); @@ -87,17 +77,10 @@ void MeasuringImpl::update_planes() // Now we'll go through all the facets and append Points of facets sharing the same normal. // This part is still performed in mesh coordinate system. -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const size_t num_of_facets = m_mesh.its.indices.size(); m_face_to_plane.resize(num_of_facets, size_t(-1)); const std::vector face_normals = its_face_normals(m_mesh.its); const std::vector face_neighbors = its_face_neighbors(m_mesh.its); -#else - const size_t num_of_facets = m_its.indices.size(); - m_face_to_plane.resize(num_of_facets, size_t(-1)); - const std::vector face_normals = its_face_normals(m_its); - const std::vector face_neighbors = its_face_neighbors(m_its); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES std::vector facet_queue(num_of_facets, 0); int facet_queue_cnt = 0; const stl_normal* normal_ptr = nullptr; @@ -146,11 +129,7 @@ void MeasuringImpl::update_planes() assert(std::none_of(m_face_to_plane.begin(), m_face_to_plane.end(), [](size_t val) { return val == size_t(-1); })); // Now we will walk around each of the planes and save vertices which form the border. -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES SurfaceMesh sm(m_mesh.its); -#else - SurfaceMesh sm(m_its); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES for (int plane_id=0; plane_id < int(m_planes.size()); ++plane_id) { const auto& facets = m_planes[plane_id].facets; m_planes[plane_id].borders.clear(); @@ -532,12 +511,10 @@ const std::vector& MeasuringImpl::get_plane_features(unsigned in return m_planes[plane_id].surface_features; } -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const TriangleMesh& MeasuringImpl::get_mesh() const { return this->m_mesh; } -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES @@ -579,12 +556,10 @@ const std::vector& Measuring::get_plane_features(unsigned int pl return priv->get_plane_features(plane_id); } -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const TriangleMesh& Measuring::get_mesh() const { return priv->get_mesh(); } -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const AngleAndEdges AngleAndEdges::Dummy = { 0.0, Vec3d::Zero(), { Vec3d::Zero(), Vec3d::Zero() }, { Vec3d::Zero(), Vec3d::Zero() }, 0.0, true }; @@ -1184,29 +1159,6 @@ MeasurementResult get_measurement(const SurfaceFeature& a, const SurfaceFeature& return result; } -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES -void DistAndPoints::transform(const Transform3d& trafo) { - from = trafo * from; - to = trafo * to; - dist = (to - from).norm(); -} - -void AngleAndEdges::transform(const Transform3d& trafo) { - const Vec3d old_e1 = e1.second - e1.first; - const Vec3d old_e2 = e2.second - e2.first; - center = trafo * center; - e1.first = trafo * e1.first; - e1.second = trafo * e1.second; - e2.first = trafo * e2.first; - e2.second = trafo * e2.second; - angle = std::acos(std::clamp(Measure::edge_direction(e1).dot(Measure::edge_direction(e2)), -1.0, 1.0)); - const Vec3d new_e1 = e1.second - e1.first; - const Vec3d new_e2 = e2.second - e2.first; - const double average_scale = 0.5 * (new_e1.norm() / old_e1.norm() + new_e2.norm() / old_e2.norm()); - radius = average_scale * radius; -} -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - diff --git a/src/libslic3r/Measure.hpp b/src/libslic3r/Measure.hpp index 9cc380dd2b..3a1a4b89d9 100644 --- a/src/libslic3r/Measure.hpp +++ b/src/libslic3r/Measure.hpp @@ -13,9 +13,7 @@ struct indexed_triangle_set; namespace Slic3r { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES class TriangleMesh; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES namespace Measure { @@ -93,10 +91,7 @@ class MeasuringImpl; class Measuring { public: // Construct the measurement object on a given its. -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - // The its must remain valid and unchanged during the whole lifetime of the object. -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - explicit Measuring(const indexed_triangle_set& its); + explicit Measuring(const indexed_triangle_set& its); ~Measuring(); // Return a reference to a list of all features identified on the its. @@ -115,10 +110,8 @@ public: // Returns the surface features of the plane with the given index const std::vector& get_plane_features(unsigned int plane_id) const; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // Returns the mesh used for measuring const TriangleMesh& get_mesh() const; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES private: std::unique_ptr priv; @@ -130,10 +123,6 @@ struct DistAndPoints { double dist; Vec3d from; Vec3d to; - -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - void transform(const Transform3d& trafo); -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES }; struct AngleAndEdges { @@ -146,10 +135,6 @@ struct AngleAndEdges { double radius; bool coplanar; -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - void transform(const Transform3d& trafo); -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - static const AngleAndEdges Dummy; }; @@ -166,19 +151,6 @@ struct MeasurementResult { bool has_any_data() const { return angle.has_value() || distance_infinite.has_value() || distance_strict.has_value() || distance_xyz.has_value(); } - -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - void transform(const Transform3d& trafo) { - if (angle.has_value()) - angle->transform(trafo); - if (distance_infinite.has_value()) - distance_infinite->transform(trafo); - if (distance_strict.has_value()) { - distance_strict->transform(trafo); - distance_xyz = (distance_strict->to - distance_strict->from).cwiseAbs(); - } - } -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES }; // Returns distance/angle between two SurfaceFeatures. diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 759871c60d..f707b0f21d 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -64,8 +64,6 @@ // Enable picking using raytracing #define ENABLE_RAYCAST_PICKING (1 && ENABLE_LEGACY_OPENGL_REMOVAL) #define ENABLE_RAYCAST_PICKING_DEBUG (0 && ENABLE_RAYCAST_PICKING) -// Enable gizmo measure combining volumes meshes and passing them to the backend in world coordinates -#define ENABLE_GIZMO_MEASURE_WORLD_COORDINATES (1 && ENABLE_2_5_0_ALPHA1) #endif // _prusaslicer_technologies_h_ diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 8cfbf634eb..35767121d7 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -6,10 +6,6 @@ #include "slic3r/GUI/GUI_ObjectManipulation.hpp" -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES -#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" -#include "libslic3r/Model.hpp" -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES #include "libslic3r/PresetBundle.hpp" #include "libslic3r/MeasureUtils.hpp" @@ -370,13 +366,8 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) } } - if (m_selected_features != selected_features_old && m_selected_features.second.feature.has_value()) { + if (m_selected_features != selected_features_old && m_selected_features.second.feature.has_value()) m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - // transform to world coordinates - m_measurement_result.transform(m_volume_matrix); -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - } m_imgui->set_requires_extra_frame(); @@ -423,29 +414,12 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) void GLGizmoMeasure::data_changed() { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES update_if_needed(); -#else - const Selection& selection = m_parent.get_selection(); - const ModelObject* model_object = nullptr; - const ModelVolume* model_volume = nullptr; - if (selection.is_single_full_instance() || - selection.is_from_single_object() ) { - model_object = selection.get_model()->objects[selection.get_object_idx()]; - model_volume = model_object->volumes[selection.get_first_volume()->volume_idx()]; - } - if (model_object != m_old_model_object || model_volume != m_old_model_volume) - update_if_needed(); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES m_last_inv_zoom = 0.0f; m_last_plane_idx = -1; if (m_pending_scale) { m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - // transform to world coordinates - m_measurement_result.transform(m_volume_matrix); -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES m_pending_scale = false; } else @@ -522,9 +496,7 @@ void GLGizmoMeasure::on_set_state() m_editing_distance = false; m_is_editing_distance_first_frame = true; m_measuring.reset(); -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES m_raycaster.reset(); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } else { m_mode = EMode::FeatureSelection; @@ -541,13 +513,6 @@ void GLGizmoMeasure::on_set_state() } } -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES -CommonGizmosDataID GLGizmoMeasure::on_get_requirements() const -{ - return CommonGizmosDataID(int(CommonGizmosDataID::SelectionInfo) | int(CommonGizmosDataID::Raycaster)); -} -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - std::string GLGizmoMeasure::on_get_name() const { return _u8L("Measure"); @@ -558,15 +523,9 @@ bool GLGizmoMeasure::on_is_activable() const const Selection& selection = m_parent.get_selection(); bool res = (wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA) ? selection.is_single_full_instance() : -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES selection.is_single_full_instance() || selection.is_single_volume() || selection.is_single_modifier(); if (res) res &= !selection.contains_sinking_volumes(); -#else - selection.is_single_volume() || selection.is_single_volume_instance(); - if (res) - res &= !selection.get_first_volume()->is_sinking(); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES return res; } @@ -583,473 +542,390 @@ void GLGizmoMeasure::on_render() const Selection& selection = m_parent.get_selection(); -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - if ((wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA && selection.is_single_full_instance()) || - (selection.is_single_volume() || selection.is_single_volume_instance())) { -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - update_if_needed(); + update_if_needed(); - const Camera& camera = wxGetApp().plater()->get_camera(); - const float inv_zoom = (float)camera.get_inv_zoom(); + const Camera& camera = wxGetApp().plater()->get_camera(); + const float inv_zoom = (float)camera.get_inv_zoom(); - Vec3f position_on_model; - Vec3f normal_on_model; - size_t model_facet_idx; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const bool mouse_on_object = m_raycaster->unproject_on_mesh(m_mouse_pos, Transform3d::Identity(), camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); -#else - const bool mouse_on_object = m_c->raycaster()->raycasters().front()->unproject_on_mesh(m_mouse_pos, m_volume_matrix, camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const bool is_hovering_on_feature = (m_mode == EMode::PointSelection || m_mode == EMode::CenterSelection) && m_hover_id != -1; + Vec3f position_on_model; + Vec3f normal_on_model; + size_t model_facet_idx; + const bool mouse_on_object = m_raycaster->unproject_on_mesh(m_mouse_pos, Transform3d::Identity(), camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); + const bool is_hovering_on_feature = (m_mode == EMode::PointSelection || m_mode == EMode::CenterSelection) && m_hover_id != -1; - auto update_circle = [this, inv_zoom]() { - if (m_last_inv_zoom != inv_zoom || m_last_circle != m_curr_feature) { - m_last_inv_zoom = inv_zoom; - m_last_circle = m_curr_feature; - m_circle.reset(); - const auto [center, radius, normal] = m_curr_feature->get_circle(); -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); -#else - GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), m_volume_matrix.cast()); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - m_circle.mesh_raycaster = std::make_unique(std::make_shared(circle_geometry.get_as_indexed_triangle_set())); - m_circle.model.init_from(std::move(circle_geometry)); - return true; - } - return false; - }; + auto update_circle = [this, inv_zoom]() { + if (m_last_inv_zoom != inv_zoom || m_last_circle != m_curr_feature) { + m_last_inv_zoom = inv_zoom; + m_last_circle = m_curr_feature; + m_circle.reset(); + const auto [center, radius, normal] = m_curr_feature->get_circle(); + GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); + m_circle.mesh_raycaster = std::make_unique(std::make_shared(circle_geometry.get_as_indexed_triangle_set())); + m_circle.model.init_from(std::move(circle_geometry)); + return true; + } + return false; + }; - if (m_mode == EMode::FeatureSelection || m_mode == EMode::PointSelection) { - if ((m_hover_id == SELECTION_1_ID && boost::algorithm::istarts_with(m_selected_features.first.source, _u8L("Center"))) || - (m_hover_id == SELECTION_2_ID && boost::algorithm::istarts_with(m_selected_features.second.source, _u8L("Center")))) { - // Skip feature detection if hovering on a selected center - m_curr_feature.reset(); + if (m_mode == EMode::FeatureSelection || m_mode == EMode::PointSelection) { + if ((m_hover_id == SELECTION_1_ID && boost::algorithm::istarts_with(m_selected_features.first.source, _u8L("Center"))) || + (m_hover_id == SELECTION_2_ID && boost::algorithm::istarts_with(m_selected_features.second.source, _u8L("Center")))) { + // Skip feature detection if hovering on a selected center + m_curr_feature.reset(); + m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID); + m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID); + m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, PLANE_ID); + m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID); + m_curr_point_on_feature_position.reset(); + } + else { + std::optional curr_feature = mouse_on_object ? m_measuring->get_feature(model_facet_idx, position_on_model.cast()) : std::nullopt; + if (m_curr_feature != curr_feature || + (curr_feature.has_value() && curr_feature->get_type() == Measure::SurfaceFeatureType::Circle && (m_curr_feature != curr_feature || m_last_inv_zoom != inv_zoom))) { m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID); m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID); m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, PLANE_ID); m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID); - m_curr_point_on_feature_position.reset(); - } - else { - std::optional curr_feature = mouse_on_object ? m_measuring->get_feature(model_facet_idx, position_on_model.cast()) : std::nullopt; - if (m_curr_feature != curr_feature || - (curr_feature.has_value() && curr_feature->get_type() == Measure::SurfaceFeatureType::Circle && (m_curr_feature != curr_feature || m_last_inv_zoom != inv_zoom))) { - m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID); - m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID); - m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, PLANE_ID); - m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID); - m_raycasters.clear(); - m_curr_feature = curr_feature; - if (!m_curr_feature.has_value()) - return; + m_raycasters.clear(); + m_curr_feature = curr_feature; + if (!m_curr_feature.has_value()) + return; - switch (m_curr_feature->get_type()) { - default: { assert(false); break; } - case Measure::SurfaceFeatureType::Point: - { - m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); - break; - } - case Measure::SurfaceFeatureType::Edge: - { - m_raycasters.insert({ EDGE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID, *m_cylinder.mesh_raycaster) }); - if (m_curr_feature->get_extra_point().has_value()) - m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); - break; - } - case Measure::SurfaceFeatureType::Circle: - { - update_circle(); - m_raycasters.insert({ CIRCLE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID, *m_circle.mesh_raycaster) }); - m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); - break; - } - case Measure::SurfaceFeatureType::Plane: - { - const auto [idx, normal, point] = m_curr_feature->get_plane(); - if (m_last_plane_idx != idx) { - m_last_plane_idx = idx; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const indexed_triangle_set& its = m_measuring->get_mesh().its; -#else - const indexed_triangle_set its = (m_old_model_volume != nullptr) ? m_old_model_volume->mesh().its : m_old_model_object->volumes.front()->mesh().its; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const std::vector> planes_triangles = m_measuring->get_planes_triangle_indices(); - GLModel::Geometry init_data = init_plane_data(its, planes_triangles, idx); - m_plane.reset(); - m_plane.mesh_raycaster = std::make_unique(std::make_shared(init_data.get_as_indexed_triangle_set())); - m_plane.model.init_from(std::move(init_data)); - } - - m_raycasters.insert({ PLANE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, PLANE_ID, *m_plane.mesh_raycaster) }); - break; - } - } - } - } - } - - if (m_mode != EMode::PointSelection) - m_curr_point_on_feature_position.reset(); - else if (is_hovering_on_feature) { - auto position_on_feature = [this](int feature_type_id, const Camera& camera, std::function callback = nullptr) -> Vec3d { - auto it = m_raycasters.find(feature_type_id); - if (it != m_raycasters.end() && it->second != nullptr) { - Vec3f p; - Vec3f n; - const Transform3d& trafo = it->second->get_transform(); - bool res = it->second->get_raycaster()->closest_hit(m_mouse_pos, trafo, camera, p, n); - if (res) { - if (callback) - p = callback(p); - return trafo * p.cast(); - } - } - return Vec3d::Zero(); - }; - - if (m_curr_feature.has_value()) { - switch (m_curr_feature->get_type()) - { + switch (m_curr_feature->get_type()) { default: { assert(false); break; } case Measure::SurfaceFeatureType::Point: { - m_curr_point_on_feature_position = m_curr_feature->get_point(); + m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); break; } case Measure::SurfaceFeatureType::Edge: { - const std::optional extra = m_curr_feature->get_extra_point(); - if (extra.has_value() && m_hover_id == POINT_ID) - m_curr_point_on_feature_position = *extra; - else -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - m_curr_point_on_feature_position = position_on_feature(EDGE_ID, camera, [](const Vec3f& v) { return Vec3f(0.0f, 0.0f, v.z()); }); -#else - m_curr_point_on_feature_position = m_volume_matrix.inverse() * position_on_feature(EDGE_ID, camera, [](const Vec3f& v) { return Vec3f(0.0f, 0.0f, v.z()); }); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + m_raycasters.insert({ EDGE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID, *m_cylinder.mesh_raycaster) }); + if (m_curr_feature->get_extra_point().has_value()) + m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); + break; + } + case Measure::SurfaceFeatureType::Circle: + { + update_circle(); + m_raycasters.insert({ CIRCLE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID, *m_circle.mesh_raycaster) }); + m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); break; } case Measure::SurfaceFeatureType::Plane: { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - m_curr_point_on_feature_position = position_on_feature(PLANE_ID, camera); -#else - m_curr_point_on_feature_position = m_volume_matrix.inverse() * position_on_feature(PLANE_ID, camera); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - break; - } - case Measure::SurfaceFeatureType::Circle: - { - const auto [center, radius, normal] = m_curr_feature->get_circle(); - if (m_hover_id == POINT_ID) - m_curr_point_on_feature_position = center; - else { - const Vec3d world_pof = position_on_feature(CIRCLE_ID, camera, [](const Vec3f& v) { return v; }); -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Eigen::Hyperplane plane(normal, center); -#else - const Eigen::Hyperplane plane(m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal, m_volume_matrix * center); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Transform3d local_to_model_matrix = Geometry::translation_transform(center) * Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), normal); -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Vec3d local_proj = local_to_model_matrix.inverse() * plane.projection(world_pof); -#else - const Vec3d local_proj = local_to_model_matrix.inverse() * m_volume_matrix.inverse() * plane.projection(world_pof); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - double angle = std::atan2(local_proj.y(), local_proj.x()); - if (angle < 0.0) - angle += 2.0 * double(M_PI); - - const Vec3d local_pos = radius * Vec3d(std::cos(angle), std::sin(angle), 0.0); - m_curr_point_on_feature_position = local_to_model_matrix * local_pos; + const auto [idx, normal, point] = m_curr_feature->get_plane(); + if (m_last_plane_idx != idx) { + m_last_plane_idx = idx; + const indexed_triangle_set& its = m_measuring->get_mesh().its; + const std::vector> planes_triangles = m_measuring->get_planes_triangle_indices(); + GLModel::Geometry init_data = init_plane_data(its, planes_triangles, idx); + m_plane.reset(); + m_plane.mesh_raycaster = std::make_unique(std::make_shared(init_data.get_as_indexed_triangle_set())); + m_plane.model.init_from(std::move(init_data)); } + + m_raycasters.insert({ PLANE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, PLANE_ID, *m_plane.mesh_raycaster) }); break; } } } } - else { - if (m_curr_feature.has_value() && m_curr_feature->get_type() == Measure::SurfaceFeatureType::Circle) { - if (update_circle()) { - m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID); - auto it = m_raycasters.find(CIRCLE_ID); - if (it != m_raycasters.end()) - m_raycasters.erase(it); - m_raycasters.insert({ CIRCLE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID, *m_circle.mesh_raycaster) }); + } + + if (m_mode != EMode::PointSelection) + m_curr_point_on_feature_position.reset(); + else if (is_hovering_on_feature) { + auto position_on_feature = [this](int feature_type_id, const Camera& camera, std::function callback = nullptr) -> Vec3d { + auto it = m_raycasters.find(feature_type_id); + if (it != m_raycasters.end() && it->second != nullptr) { + Vec3f p; + Vec3f n; + const Transform3d& trafo = it->second->get_transform(); + bool res = it->second->get_raycaster()->closest_hit(m_mouse_pos, trafo, camera, p, n); + if (res) { + if (callback) + p = callback(p); + return trafo * p.cast(); } } + return Vec3d::Zero(); + }; + + if (m_curr_feature.has_value()) { + switch (m_curr_feature->get_type()) + { + default: { assert(false); break; } + case Measure::SurfaceFeatureType::Point: + { + m_curr_point_on_feature_position = m_curr_feature->get_point(); + break; + } + case Measure::SurfaceFeatureType::Edge: + { + const std::optional extra = m_curr_feature->get_extra_point(); + if (extra.has_value() && m_hover_id == POINT_ID) + m_curr_point_on_feature_position = *extra; + else + m_curr_point_on_feature_position = position_on_feature(EDGE_ID, camera, [](const Vec3f& v) { return Vec3f(0.0f, 0.0f, v.z()); }); + break; + } + case Measure::SurfaceFeatureType::Plane: + { + m_curr_point_on_feature_position = position_on_feature(PLANE_ID, camera); + break; + } + case Measure::SurfaceFeatureType::Circle: + { + const auto [center, radius, normal] = m_curr_feature->get_circle(); + if (m_hover_id == POINT_ID) + m_curr_point_on_feature_position = center; + else { + const Vec3d world_pof = position_on_feature(CIRCLE_ID, camera, [](const Vec3f& v) { return v; }); + const Eigen::Hyperplane plane(normal, center); + const Transform3d local_to_model_matrix = Geometry::translation_transform(center) * Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), normal); + const Vec3d local_proj = local_to_model_matrix.inverse() * plane.projection(world_pof); + double angle = std::atan2(local_proj.y(), local_proj.x()); + if (angle < 0.0) + angle += 2.0 * double(M_PI); + + const Vec3d local_pos = radius * Vec3d(std::cos(angle), std::sin(angle), 0.0); + m_curr_point_on_feature_position = local_to_model_matrix * local_pos; + } + break; + } + } } + } + else { + if (m_curr_feature.has_value() && m_curr_feature->get_type() == Measure::SurfaceFeatureType::Circle) { + if (update_circle()) { + m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID); + auto it = m_raycasters.find(CIRCLE_ID); + if (it != m_raycasters.end()) + m_raycasters.erase(it); + m_raycasters.insert({ CIRCLE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID, *m_circle.mesh_raycaster) }); + } + } + } - if (!m_curr_feature.has_value() && !m_selected_features.first.feature.has_value()) - return; + if (!m_curr_feature.has_value() && !m_selected_features.first.feature.has_value()) + return; - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); - if (shader == nullptr) - return; + GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); + if (shader == nullptr) + return; - shader->start_using(); - shader->set_uniform("projection_matrix", camera.get_projection_matrix()); + shader->start_using(); + shader->set_uniform("projection_matrix", camera.get_projection_matrix()); - glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); - glsafe(::glEnable(GL_DEPTH_TEST)); - const bool old_cullface = ::glIsEnabled(GL_CULL_FACE); - glsafe(::glDisable(GL_CULL_FACE)); + glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); + glsafe(::glEnable(GL_DEPTH_TEST)); + const bool old_cullface = ::glIsEnabled(GL_CULL_FACE); + glsafe(::glDisable(GL_CULL_FACE)); - const Transform3d& view_matrix = camera.get_view_matrix(); + const Transform3d& view_matrix = camera.get_view_matrix(); - auto set_matrix_uniforms = [shader, &view_matrix](const Transform3d& model_matrix) { - const Transform3d view_model_matrix = view_matrix * model_matrix; - shader->set_uniform("view_model_matrix", view_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(); - shader->set_uniform("view_normal_matrix", view_normal_matrix); - }; + auto set_matrix_uniforms = [shader, &view_matrix](const Transform3d& model_matrix) { + const Transform3d view_model_matrix = view_matrix * model_matrix; + shader->set_uniform("view_model_matrix", view_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(); + shader->set_uniform("view_normal_matrix", view_normal_matrix); + }; - auto set_emission_uniform = [this, shader](const ColorRGBA& color, bool hover) { - shader->set_uniform("emission_factor", (color == m_parent.get_selection().get_first_volume()->render_color) ? 0.0f : - hover ? 0.5f : 0.25f); - }; + auto set_emission_uniform = [this, shader](const ColorRGBA& color, bool hover) { + shader->set_uniform("emission_factor", (color == m_parent.get_selection().get_first_volume()->render_color) ? 0.0f : + hover ? 0.5f : 0.25f); + }; - auto render_feature = [this, set_matrix_uniforms, set_emission_uniform](const Measure::SurfaceFeature& feature, const std::vector& colors, - float inv_zoom, bool hover, bool update_raycasters_transform) { - switch (feature.get_type()) - { - default: { assert(false); break; } - case Measure::SurfaceFeatureType::Point: - { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Transform3d feature_matrix = Geometry::translation_transform(feature.get_point()) * Geometry::scale_transform(inv_zoom); -#else - const Vec3d position = TransformHelper::model_to_world(feature.get_point(), m_volume_matrix); - const Transform3d feature_matrix = Geometry::translation_transform(position) * Geometry::scale_transform(inv_zoom); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - set_matrix_uniforms(feature_matrix); + auto render_feature = [this, set_matrix_uniforms, set_emission_uniform](const Measure::SurfaceFeature& feature, const std::vector& colors, + float inv_zoom, bool hover, bool update_raycasters_transform) { + switch (feature.get_type()) + { + default: { assert(false); break; } + case Measure::SurfaceFeatureType::Point: + { + const Transform3d feature_matrix = Geometry::translation_transform(feature.get_point()) * Geometry::scale_transform(inv_zoom); + set_matrix_uniforms(feature_matrix); + set_emission_uniform(colors.front(), hover); + m_sphere.model.set_color(colors.front()); + m_sphere.model.render(); + if (update_raycasters_transform) { + auto it = m_raycasters.find(POINT_ID); + if (it != m_raycasters.end() && it->second != nullptr) + it->second->set_transform(feature_matrix); + } + break; + } + case Measure::SurfaceFeatureType::Circle: + { + const auto& [center, radius, normal] = feature.get_circle(); + // render center + if (update_raycasters_transform) { + const Transform3d center_matrix = Geometry::translation_transform(center) * Geometry::scale_transform(inv_zoom); + set_matrix_uniforms(center_matrix); set_emission_uniform(colors.front(), hover); m_sphere.model.set_color(colors.front()); m_sphere.model.render(); - if (update_raycasters_transform) { - auto it = m_raycasters.find(POINT_ID); - if (it != m_raycasters.end() && it->second != nullptr) - it->second->set_transform(feature_matrix); - } - break; + auto it = m_raycasters.find(POINT_ID); + if (it != m_raycasters.end() && it->second != nullptr) + it->second->set_transform(center_matrix); } - case Measure::SurfaceFeatureType::Circle: - { - const auto& [center, radius, normal] = feature.get_circle(); - // render center + // render circle + if (m_mode != EMode::CenterSelection) { + const Transform3d circle_matrix = Transform3d::Identity(); + set_matrix_uniforms(circle_matrix); if (update_raycasters_transform) { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Transform3d center_matrix = Geometry::translation_transform(center) * Geometry::scale_transform(inv_zoom); -#else - const Vec3d center_world = TransformHelper::model_to_world(center, m_volume_matrix); - const Transform3d center_matrix = Geometry::translation_transform(center_world) * Geometry::scale_transform(inv_zoom); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - set_matrix_uniforms(center_matrix); + set_emission_uniform(colors.back(), hover); + m_circle.model.set_color(colors.back()); + m_circle.model.render(); + auto it = m_raycasters.find(CIRCLE_ID); + if (it != m_raycasters.end() && it->second != nullptr) + it->second->set_transform(circle_matrix); + } + else { + GLModel circle; + GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); + circle.init_from(std::move(circle_geometry)); + set_emission_uniform(colors.back(), hover); + circle.set_color(colors.back()); + circle.render(); + } + } + break; + } + case Measure::SurfaceFeatureType::Edge: + { + const auto& [from, to] = feature.get_edge(); + // render extra point + if (update_raycasters_transform) { + const std::optional extra = feature.get_extra_point(); + if (extra.has_value()) { + const Transform3d point_matrix = Geometry::translation_transform(*extra) * Geometry::scale_transform(inv_zoom); + set_matrix_uniforms(point_matrix); set_emission_uniform(colors.front(), hover); m_sphere.model.set_color(colors.front()); m_sphere.model.render(); auto it = m_raycasters.find(POINT_ID); if (it != m_raycasters.end() && it->second != nullptr) - it->second->set_transform(center_matrix); + it->second->set_transform(point_matrix); } - // render circle - if (m_mode != EMode::CenterSelection) { - const Transform3d circle_matrix = Transform3d::Identity(); - set_matrix_uniforms(circle_matrix); - if (update_raycasters_transform) { - set_emission_uniform(colors.back(), hover); - m_circle.model.set_color(colors.back()); - m_circle.model.render(); - auto it = m_raycasters.find(CIRCLE_ID); - if (it != m_raycasters.end() && it->second != nullptr) - it->second->set_transform(circle_matrix); - } - else { - GLModel circle; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); -#else - GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), m_volume_matrix.cast()); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - circle.init_from(std::move(circle_geometry)); - set_emission_uniform(colors.back(), hover); - circle.set_color(colors.back()); - circle.render(); - } - } - break; } - case Measure::SurfaceFeatureType::Edge: - { - const auto& [from, to] = feature.get_edge(); - // render extra point + // render edge + if (m_mode != EMode::CenterSelection) { + const Transform3d edge_matrix = Geometry::translation_transform(from) * + Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), to - from) * + Geometry::scale_transform({ (double)inv_zoom, (double)inv_zoom, (to - from).norm() }); + set_matrix_uniforms(edge_matrix); + set_emission_uniform(colors.back(), hover); + m_cylinder.model.set_color(colors.back()); + m_cylinder.model.render(); if (update_raycasters_transform) { - const std::optional extra = feature.get_extra_point(); - if (extra.has_value()) { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Transform3d point_matrix = Geometry::translation_transform(*extra) * Geometry::scale_transform(inv_zoom); -#else - const Vec3d extra_world = TransformHelper::model_to_world(*extra, m_volume_matrix); - const Transform3d point_matrix = Geometry::translation_transform(extra_world) * Geometry::scale_transform(inv_zoom); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - set_matrix_uniforms(point_matrix); - set_emission_uniform(colors.front(), hover); - m_sphere.model.set_color(colors.front()); - m_sphere.model.render(); - auto it = m_raycasters.find(POINT_ID); - if (it != m_raycasters.end() && it->second != nullptr) - it->second->set_transform(point_matrix); - } - } - // render edge - if (m_mode != EMode::CenterSelection) { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Transform3d edge_matrix = Geometry::translation_transform(from) * - Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), to - from) * - Geometry::scale_transform({ (double)inv_zoom, (double)inv_zoom, (to - from).norm() }); -#else - const Vec3d from_world = TransformHelper::model_to_world(from, m_volume_matrix); - const Vec3d to_world = TransformHelper::model_to_world(to, m_volume_matrix); - const Transform3d edge_matrix = Geometry::translation_transform(from_world) * - Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), to_world - from_world) * - Geometry::scale_transform({ (double)inv_zoom, (double)inv_zoom, (to_world - from_world).norm() }); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - set_matrix_uniforms(edge_matrix); - set_emission_uniform(colors.back(), hover); - m_cylinder.model.set_color(colors.back()); - m_cylinder.model.render(); - if (update_raycasters_transform) { - auto it = m_raycasters.find(EDGE_ID); - if (it != m_raycasters.end() && it->second != nullptr) - it->second->set_transform(edge_matrix); - } - } - break; - } - case Measure::SurfaceFeatureType::Plane: - { - // no need to render the plane in case it is rendered with the same color as the volume in the 3D scene - if (colors.front() != m_parent.get_selection().get_first_volume()->render_color) { - const auto& [idx, normal, pt] = feature.get_plane(); - assert(idx < m_plane_models_cache.size()); -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - set_matrix_uniforms(Transform3d::Identity()); -#else - set_matrix_uniforms(m_volume_matrix); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - set_emission_uniform(colors.front(), hover); - m_plane_models_cache[idx].set_color(colors.front()); - m_plane_models_cache[idx].render(); - } - if (update_raycasters_transform) { - auto it = m_raycasters.find(PLANE_ID); + auto it = m_raycasters.find(EDGE_ID); if (it != m_raycasters.end() && it->second != nullptr) -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - it->second->set_transform(Transform3d::Identity()); -#else - it->second->set_transform(m_volume_matrix); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + it->second->set_transform(edge_matrix); } - break; } + break; + } + case Measure::SurfaceFeatureType::Plane: + { + // no need to render the plane in case it is rendered with the same color as the volume in the 3D scene + if (colors.front() != m_parent.get_selection().get_first_volume()->render_color) { + const auto& [idx, normal, pt] = feature.get_plane(); + assert(idx < m_plane_models_cache.size()); + set_matrix_uniforms(Transform3d::Identity()); + set_emission_uniform(colors.front(), hover); + m_plane_models_cache[idx].set_color(colors.front()); + m_plane_models_cache[idx].render(); } - }; + if (update_raycasters_transform) { + auto it = m_raycasters.find(PLANE_ID); + if (it != m_raycasters.end() && it->second != nullptr) + it->second->set_transform(Transform3d::Identity()); + } + break; + } + } + }; - auto hover_selection_color = [this]() { - return !m_selected_features.first.feature.has_value() ? SELECTED_1ST_COLOR : SELECTED_2ND_COLOR; - }; + auto hover_selection_color = [this]() { + return !m_selected_features.first.feature.has_value() ? SELECTED_1ST_COLOR : SELECTED_2ND_COLOR; + }; - auto hovering_color = [this, hover_selection_color, &selection]() { - return (m_mode == EMode::PointSelection) ? selection.get_first_volume()->render_color : hover_selection_color(); - }; + auto hovering_color = [this, hover_selection_color, &selection]() { + return (m_mode == EMode::PointSelection) ? selection.get_first_volume()->render_color : hover_selection_color(); + }; - if (m_curr_feature.has_value()) { - std::vector colors; - if (m_selected_features.first.feature.has_value() && *m_curr_feature == *m_selected_features.first.feature) + if (m_curr_feature.has_value()) { + std::vector colors; + if (m_selected_features.first.feature.has_value() && *m_curr_feature == *m_selected_features.first.feature) + colors.emplace_back(hovering_color()); + else if (m_selected_features.second.feature.has_value() && *m_curr_feature == *m_selected_features.second.feature) + colors.emplace_back(hovering_color()); + else { + switch (m_curr_feature->get_type()) + { + default: { assert(false); break; } + case Measure::SurfaceFeatureType::Point: + { + colors.emplace_back(hover_selection_color()); + break; + } + case Measure::SurfaceFeatureType::Edge: + case Measure::SurfaceFeatureType::Circle: + { + colors.emplace_back((m_hover_id == POINT_ID) ? hover_selection_color() : hovering_color()); colors.emplace_back(hovering_color()); - else if (m_selected_features.second.feature.has_value() && *m_curr_feature == *m_selected_features.second.feature) + break; + } + case Measure::SurfaceFeatureType::Plane: + { colors.emplace_back(hovering_color()); - else { - switch (m_curr_feature->get_type()) - { - default: { assert(false); break; } - case Measure::SurfaceFeatureType::Point: - { - colors.emplace_back(hover_selection_color()); - break; - } - case Measure::SurfaceFeatureType::Edge: - case Measure::SurfaceFeatureType::Circle: - { - colors.emplace_back((m_hover_id == POINT_ID) ? hover_selection_color() : hovering_color()); - colors.emplace_back(hovering_color()); - break; - } - case Measure::SurfaceFeatureType::Plane: - { - colors.emplace_back(hovering_color()); - break; - } - } + break; } - - render_feature(*m_curr_feature, colors, inv_zoom, true, true); - } - - if (m_selected_features.first.feature.has_value() && (!m_curr_feature.has_value() || *m_curr_feature != *m_selected_features.first.feature)) { - const std::vector colors = { SELECTED_1ST_COLOR }; - render_feature(*m_selected_features.first.feature, colors, inv_zoom, m_hover_id == SELECTION_1_ID, false); - if (m_selected_features.first.feature->get_type() == Measure::SurfaceFeatureType::Point) { - auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), - [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_1_ID; }); - if (it != m_selection_raycasters.end()) -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - (*it)->set_transform(Geometry::translation_transform(m_selected_features.first.feature->get_point()) * Geometry::scale_transform(inv_zoom)); -#else - (*it)->set_transform(m_volume_matrix * Geometry::translation_transform(m_selected_features.first.feature->get_point()) * Geometry::scale_transform(inv_zoom)); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - } - } - if (m_selected_features.second.feature.has_value() && (!m_curr_feature.has_value() || *m_curr_feature != *m_selected_features.second.feature)) { - const std::vector colors = { SELECTED_2ND_COLOR }; - render_feature(*m_selected_features.second.feature, colors, inv_zoom, m_hover_id == SELECTION_2_ID, false); - if (m_selected_features.second.feature->get_type() == Measure::SurfaceFeatureType::Point) { - auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), - [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_2_ID; }); - if (it != m_selection_raycasters.end()) -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - (*it)->set_transform(Geometry::translation_transform(m_selected_features.second.feature->get_point()) * Geometry::scale_transform(inv_zoom)); -#else - (*it)->set_transform(m_volume_matrix * Geometry::translation_transform(m_selected_features.second.feature->get_point()) * Geometry::scale_transform(inv_zoom)); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } } - if (is_hovering_on_feature && m_curr_point_on_feature_position.has_value()) { - if (m_hover_id != POINT_ID) { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Transform3d matrix = Geometry::translation_transform(*m_curr_point_on_feature_position) * Geometry::scale_transform(inv_zoom); -#else - const Vec3d position = TransformHelper::model_to_world(*m_curr_point_on_feature_position, m_volume_matrix); - const Transform3d matrix = Geometry::translation_transform(position) * Geometry::scale_transform(inv_zoom); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - set_matrix_uniforms(matrix); - const ColorRGBA color = hover_selection_color(); - set_emission_uniform(color, true); - m_sphere.model.set_color(color); - m_sphere.model.render(); - } - } - - shader->stop_using(); - - if (old_cullface) - glsafe(::glEnable(GL_CULL_FACE)); -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + render_feature(*m_curr_feature, colors, inv_zoom, true, true); } -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + + if (m_selected_features.first.feature.has_value() && (!m_curr_feature.has_value() || *m_curr_feature != *m_selected_features.first.feature)) { + const std::vector colors = { SELECTED_1ST_COLOR }; + render_feature(*m_selected_features.first.feature, colors, inv_zoom, m_hover_id == SELECTION_1_ID, false); + if (m_selected_features.first.feature->get_type() == Measure::SurfaceFeatureType::Point) { + auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), + [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_1_ID; }); + if (it != m_selection_raycasters.end()) + (*it)->set_transform(Geometry::translation_transform(m_selected_features.first.feature->get_point()) * Geometry::scale_transform(inv_zoom)); + } + } + if (m_selected_features.second.feature.has_value() && (!m_curr_feature.has_value() || *m_curr_feature != *m_selected_features.second.feature)) { + const std::vector colors = { SELECTED_2ND_COLOR }; + render_feature(*m_selected_features.second.feature, colors, inv_zoom, m_hover_id == SELECTION_2_ID, false); + if (m_selected_features.second.feature->get_type() == Measure::SurfaceFeatureType::Point) { + auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), + [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_2_ID; }); + if (it != m_selection_raycasters.end()) + (*it)->set_transform(Geometry::translation_transform(m_selected_features.second.feature->get_point()) * Geometry::scale_transform(inv_zoom)); + } + } + + if (is_hovering_on_feature && m_curr_point_on_feature_position.has_value()) { + if (m_hover_id != POINT_ID) { + const Transform3d matrix = Geometry::translation_transform(*m_curr_point_on_feature_position) * Geometry::scale_transform(inv_zoom); + set_matrix_uniforms(matrix); + const ColorRGBA color = hover_selection_color(); + set_emission_uniform(color, true); + m_sphere.model.set_color(color); + m_sphere.model.render(); + } + } + + shader->stop_using(); + + if (old_cullface) + glsafe(::glEnable(GL_CULL_FACE)); render_dimensioning(); } @@ -1066,7 +942,6 @@ void GLGizmoMeasure::update_if_needed() } }; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES auto do_update = [this, update_plane_models_cache](const std::vector& volumes_cache, const Selection& selection) { TriangleMesh composite_mesh; for (const auto& vol : volumes_cache) { @@ -1083,36 +958,11 @@ void GLGizmoMeasure::update_if_needed() m_raycaster.reset(new MeshRaycaster(std::make_shared(m_measuring->get_mesh()))); m_volumes_cache = volumes_cache; }; -#else - auto do_update = [this, update_plane_models_cache](const ModelObject* object, const ModelVolume* volume) { - const indexed_triangle_set& its = (volume != nullptr) ? volume->mesh().its : object->volumes.front()->mesh().its; - m_measuring.reset(new Measure::Measuring(its)); - - update_plane_models_cache(its); - - // Let's save what we calculated it from: - m_volumes_matrices.clear(); - m_volumes_types.clear(); - m_first_instance_scale = Vec3d::Ones(); - m_first_instance_mirror = Vec3d::Ones(); - if (object != nullptr) { - for (const ModelVolume* vol : object->volumes) { - m_volumes_matrices.push_back(vol->get_matrix()); - m_volumes_types.push_back(vol->type()); - } - m_first_instance_scale = object->instances.front()->get_scaling_factor(); - m_first_instance_mirror = object->instances.front()->get_mirror(); - } - m_old_model_object = object; - m_old_model_volume = volume; - }; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const Selection& selection = m_parent.get_selection(); if (selection.is_empty()) return; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const Selection::IndicesList& idxs = selection.get_volume_idxs(); std::vector volumes_cache; volumes_cache.reserve(idxs.size()); @@ -1130,36 +980,6 @@ void GLGizmoMeasure::update_if_needed() if (m_measuring == nullptr || m_volumes_cache != volumes_cache) do_update(volumes_cache, selection); -#else - m_volume_matrix = selection.get_first_volume()->world_matrix(); - - const ModelObject* mo = m_c->selection_info()->model_object(); - const ModelVolume* mv = m_c->selection_info()->model_volume(); - if (m_state != On || (mo == nullptr && mv == nullptr)) - return; - - if (mo == nullptr) - mo = mv->get_object(); - - if (mo->instances.empty()) - return; - - if (!m_measuring || mo != m_old_model_object || mv != m_old_model_volume || mo->volumes.size() != m_volumes_matrices.size()) - do_update(mo, mv); - - // We want to recalculate when the scale changes - some planes could (dis)appear. - if (!mo->instances.front()->get_scaling_factor().isApprox(m_first_instance_scale) || - !mo->instances.front()->get_mirror().isApprox(m_first_instance_mirror)) - do_update(mo, mv); - - for (unsigned int i = 0; i < mo->volumes.size(); ++i) { - if (!mo->volumes[i]->get_matrix().isApprox(m_volumes_matrices[i]) || - mo->volumes[i]->type() != m_volumes_types[i]) { - do_update(mo, mv); - break; - } - } -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES } void GLGizmoMeasure::disable_scene_raycasters() @@ -1279,7 +1099,6 @@ void GLGizmoMeasure::render_dimensioning() const double ratio = new_value / old_value; wxGetApp().plater()->take_snapshot(_L("Scale")); -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES struct TrafoData { double ratio; @@ -1333,7 +1152,6 @@ void GLGizmoMeasure::render_dimensioning() const TrafoData trafo_data(ratio, m_parent.get_selection().get_bounding_box().center()); scale_feature(*m_selected_features.first.feature, trafo_data); scale_feature(*m_selected_features.second.feature, trafo_data); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES TransformationType type; type.set_world(); @@ -1392,14 +1210,7 @@ void GLGizmoMeasure::render_dimensioning() auto point_edge = [this, shader](const Measure::SurfaceFeature& f1, const Measure::SurfaceFeature& f2) { assert(f1.get_type() == Measure::SurfaceFeatureType::Point && f2.get_type() == Measure::SurfaceFeatureType::Edge); std::pair e = f2.get_edge(); - // Transform to world coordinates -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - e.first = TransformHelper::model_to_world(e.first, m_volume_matrix); - e.second = TransformHelper::model_to_world(e.second, m_volume_matrix); -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const Vec3d v_proj = m_measurement_result.distance_infinite->to; - const Vec3d e1e2 = e.second - e.first; const Vec3d v_proje1 = v_proj - e.first; const bool on_e1_side = v_proje1.dot(e1e2) < -EPSILON; @@ -1677,21 +1488,12 @@ void GLGizmoMeasure::render_debug_dialog() { case Measure::SurfaceFeatureType::Point: { -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(item.feature->get_point()), ImGui::GetStyleColorVec4(ImGuiCol_Text)); -#else - const Vec3d position = m_volume_matrix * item.feature->get_point(); - add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(position), ImGui::GetStyleColorVec4(ImGuiCol_Text)); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES break; } case Measure::SurfaceFeatureType::Edge: { auto [from, to] = item.feature->get_edge(); -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - from = m_volume_matrix * from; - to = m_volume_matrix * to; -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(from), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_pt2", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(to), ImGui::GetStyleColorVec4(ImGuiCol_Text)); break; @@ -1699,10 +1501,6 @@ void GLGizmoMeasure::render_debug_dialog() case Measure::SurfaceFeatureType::Plane: { auto [idx, normal, origin] = item.feature->get_plane(); -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - origin = m_volume_matrix * origin; - normal = m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal; -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(normal), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_pt2", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(origin), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_value", ImGuiWrapper::COL_ORANGE_LIGHT, format_double(idx), ImGui::GetStyleColorVec4(ImGuiCol_Text)); @@ -1711,13 +1509,7 @@ void GLGizmoMeasure::render_debug_dialog() case Measure::SurfaceFeatureType::Circle: { auto [center, radius, normal] = item.feature->get_circle(); -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES const Vec3d on_circle = center + radius * Measure::get_orthogonal(normal, true); -#else - const Vec3d on_circle = m_volume_matrix * (center + radius * Measure::get_orthogonal(normal, true)); - center = m_volume_matrix * center; - normal = (m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal).normalized(); -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES radius = (on_circle - center).norm(); add_strings_row_to_table(*m_imgui, "m_pt1", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(center), ImGui::GetStyleColorVec4(ImGuiCol_Text)); add_strings_row_to_table(*m_imgui, "m_pt2", ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(normal), ImGui::GetStyleColorVec4(ImGuiCol_Text)); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp index fbbf30da78..9699d73cc8 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp @@ -6,16 +6,10 @@ #include "slic3r/GUI/GUI_Utils.hpp" #include "slic3r/GUI/MeshUtils.hpp" #include "libslic3r/Measure.hpp" -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES #include "libslic3r/Model.hpp" -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES namespace Slic3r { -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES -class ModelVolume; -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - enum class ModelVolumeType : int; namespace Measure { class Measuring; } @@ -74,7 +68,6 @@ class GLGizmoMeasure : public GLGizmoBase } }; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES struct VolumeCacheItem { const ModelObject* object{ nullptr }; @@ -89,7 +82,6 @@ class GLGizmoMeasure : public GLGizmoBase }; std::vector m_volumes_cache; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES EMode m_mode{ EMode::FeatureSelection }; Measure::MeasurementResult m_measurement_result; @@ -108,13 +100,10 @@ class GLGizmoMeasure : public GLGizmoBase }; Dimensioning m_dimensioning; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // Uses a standalone raycaster and not the shared one because of the // difference in how the mesh is updated std::unique_ptr m_raycaster; -#else - Transform3d m_volume_matrix{ Transform3d::Identity() }; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES + std::vector m_plane_models_cache; std::map> m_raycasters; std::vector> m_selection_raycasters; @@ -129,21 +118,11 @@ class GLGizmoMeasure : public GLGizmoBase std::vector m_scene_raycasters; // These hold information to decide whether recalculation is necessary: -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - std::vector m_volumes_matrices; - std::vector m_volumes_types; - Vec3d m_first_instance_scale{ Vec3d::Ones() }; - Vec3d m_first_instance_mirror{ Vec3d::Ones() }; -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES float m_last_inv_zoom{ 0.0f }; std::optional m_last_circle; int m_last_plane_idx{ -1 }; bool m_mouse_left_down{ false }; // for detection left_up of this gizmo -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - const ModelObject* m_old_model_object{ nullptr }; - const ModelVolume* m_old_model_volume{ nullptr }; -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES Vec2d m_mouse_pos{ Vec2d::Zero() }; @@ -186,9 +165,6 @@ protected: bool on_is_activable() const override; void on_render() override; void on_set_state() override; -#if !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES - CommonGizmosDataID on_get_requirements() const override; -#endif // !ENABLE_GIZMO_MEASURE_WORLD_COORDINATES virtual void on_render_input_window(float x, float y, float bottom_limit) override; virtual void on_register_raycasters_for_picking() override; diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index 0e893fb16c..c3a7ec18be 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -613,7 +613,6 @@ bool Selection::contains_any_volume(const std::vector& volume_idxs return false; } -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES bool Selection::contains_sinking_volumes(bool ignore_modifiers) const { for (const GLVolume* v : *m_volumes) { @@ -624,7 +623,6 @@ bool Selection::contains_sinking_volumes(bool ignore_modifiers) const } return false; } -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES bool Selection::matches(const std::vector& volume_idxs) const { diff --git a/src/slic3r/GUI/Selection.hpp b/src/slic3r/GUI/Selection.hpp index cf9d26fc7d..6468f6a87d 100644 --- a/src/slic3r/GUI/Selection.hpp +++ b/src/slic3r/GUI/Selection.hpp @@ -338,10 +338,8 @@ public: bool contains_all_volumes(const std::vector& volume_idxs) const; // returns true if the selection contains at least one of the given indices bool contains_any_volume(const std::vector& volume_idxs) const; -#if ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // returns true if the selection contains any sinking volume bool contains_sinking_volumes(bool ignore_modifiers = true) const; -#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES // returns true if the selection contains all and only the given indices bool matches(const std::vector& volume_idxs) const; From 6dd8199edf518f5a83ee2de7d338b78c002f477d Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 16 Nov 2022 09:38:19 +0100 Subject: [PATCH 049/109] Gizmo measure - Fixed orientation of arrows in arc dimensioning --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 35767121d7..423c23edd2 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1295,7 +1295,7 @@ void GLGizmoMeasure::render_dimensioning() const double angle = (endpoint_id == 1) ? 0.0 : step * double(resolution); const Vec3d position_model = Geometry::translation_transform(center) * (draw_radius * (Eigen::Quaternion(Eigen::AngleAxisd(angle, normal)) * e1_unit)); const Vec3d direction_model = (endpoint_id == 1) ? -normal.cross(position_model - center).normalized() : normal.cross(position_model - center).normalized(); - const auto qz = Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), normal); + const auto qz = Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), (endpoint_id == 1) ? normal : -normal); const auto qx = Eigen::Quaternion::FromTwoVectors(qz * Vec3d::UnitX(), direction_model); const Transform3d view_model_matrix = camera.get_view_matrix() * Geometry::translation_transform(position_model) * qx * qz * Geometry::scale_transform(camera.get_inv_zoom()); From e6b2467f44623f59cba5ca8355eb5484ff8744ee Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 16 Nov 2022 09:42:55 +0100 Subject: [PATCH 050/109] Fixed warnings --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 423c23edd2..b2edc0b979 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1118,7 +1118,7 @@ void GLGizmoMeasure::render_dimensioning() } }; - auto scale_feature = [this](Measure::SurfaceFeature& feature, const TrafoData& trafo_data) { + auto scale_feature = [](Measure::SurfaceFeature& feature, const TrafoData& trafo_data) { switch (feature.get_type()) { case Measure::SurfaceFeatureType::Point: @@ -1146,6 +1146,7 @@ void GLGizmoMeasure::render_dimensioning() feature = Measure::SurfaceFeature(Measure::SurfaceFeatureType::Plane, normal, trafo_data.transform(origin), std::nullopt, idx); break; } + default: { break; } } }; From 832b0a69e8efea32de28f44d098df6275f0310ee Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 16 Nov 2022 09:46:50 +0100 Subject: [PATCH 051/109] Fixed warnings --- src/libslic3r/Measure.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 4e3bcaa822..ffb8f953a0 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -291,14 +291,14 @@ void MeasuringImpl::extract_features() // point happened to be inside the segment. The discrimination of too small segments // will follow, so we need a complete picture before that. if (circles_idxs.size() > 1 - && circles_idxs.back().second == angles.size()-1 + && circles_idxs.back().second == (int)angles.size()-1 && circles_idxs.front().first == 0) { // Possibly the same circle. Check that the angle and length criterion holds along the combined segment. bool same = true; double last_len = -1.; double last_angle = 0.; for (int i=circles_idxs.back().first + 1; i != circles_idxs.front().second; ++i) { - if (i == angles.size()) + if (i == (int)angles.size()) i = 1; if (last_len == -1.) { last_len = lengths[i]; @@ -347,12 +347,12 @@ void MeasuringImpl::extract_features() for (int i=int(circles_idxs.size())-1; i>=0; --i) { const auto& [start, end] = circles_idxs[i]; int N = start >= 0 - ? end - start + (start == 0 && end == border.size()-1 ? 0 : 1) // last point is the same as first + ? end - start + (start == 0 && end == (int)border.size()-1 ? 0 : 1) // last point is the same as first : end + (border.size() + start); if (N < 5) { circles.erase(circles.begin() + i); circles_idxs.erase(circles_idxs.begin() + i); - } else if (N <= 8 && start == 0 && end == border.size()-1) { + } else if (N <= 8 && start == 0 && end == (int)border.size()-1) { // This is a regular 5-8 polygon. Add the edges as edges with a special // point and remove the circle. Leave the indices in circles_idxs, so // the edges are not picked up again later. From ce46a1d03d21654a8a891a9eee295ea6617eda4c Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 16 Nov 2022 10:04:25 +0100 Subject: [PATCH 052/109] Removed debug code --- src/slic3r/GUI/MeshUtils.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/slic3r/GUI/MeshUtils.cpp b/src/slic3r/GUI/MeshUtils.cpp index 94375a6e34..68572c801e 100644 --- a/src/slic3r/GUI/MeshUtils.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -409,12 +409,6 @@ bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& Vec3d direction; line_from_mouse_pos(mouse_pos, trafo, camera, point, direction); - if (rand()%100 == 0) { - int a=5; - int b=6; - int c=7; - } - std::vector hits = m_emesh.query_ray_hits(point, direction); if (hits.empty()) From 305ea0da27ea499230d4f4d6ee7b7e929f60ecc3 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 16 Nov 2022 12:04:38 +0100 Subject: [PATCH 053/109] Gizmo measure - Fixed angle for perpendicular edge-plane use case --- src/libslic3r/Measure.cpp | 53 +++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index ffb8f953a0..8213f9778d 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -29,6 +29,21 @@ static std::pair get_center_and_radius(const std::vector& return std::make_pair(trafo.inverse() * Vec3d(circle.center.x(), circle.center.y(), z), circle.radius); } +static std::array orthonormal_basis(const Vec3d& v) +{ + std::array ret; + ret[2] = v.normalized(); + int index; + ret[2].maxCoeff(&index); + switch (index) + { + case 0: { ret[0] = Vec3d(ret[2].y(), -ret[2].x(), 0.0).normalized(); break; } + case 1: { ret[0] = Vec3d(0.0, ret[2].z(), -ret[2].y()).normalized(); break; } + case 2: { ret[0] = Vec3d(-ret[2].z(), 0.0, ret[2].x()).normalized(); break; } + } + ret[1] = ret[2].cross(ret[0]).normalized(); + return ret; +} @@ -630,8 +645,8 @@ static AngleAndEdges angle_edge_edge(const std::pair& e1, const st static AngleAndEdges angle_edge_plane(const std::pair& e, const std::tuple& p) { const auto& [idx, normal, origin] = p; - const Vec3d e1e2_unit = edge_direction(e); - if (are_parallel(e1e2_unit, normal) || are_perpendicular(e1e2_unit, normal)) + Vec3d e1e2_unit = edge_direction(e); + if (are_perpendicular(e1e2_unit, normal)) return AngleAndEdges::Dummy; // ensure the edge is pointing away from the intersection @@ -643,8 +658,22 @@ static AngleAndEdges angle_edge_plane(const std::pair& e, const st // then verify edge direction and revert it, if needed Vec3d e1 = e.first; Vec3d e2 = e.second; - if ((e1 - inters).squaredNorm() > (e2 - inters).squaredNorm()) + if ((e1 - inters).squaredNorm() > (e2 - inters).squaredNorm()) { std::swap(e1, e2); + e1e2_unit = -e1e2_unit; + } + + if (are_parallel(e1e2_unit, normal)) { + const std::array basis = orthonormal_basis(e1e2_unit); + const double radius = (0.5 * (e1 + e2) - inters).norm(); + const Vec3d edge_on_plane_dir = (basis[1].dot(origin - inters) >= 0.0) ? basis[1] : -basis[1]; + std::pair edge_on_plane = std::make_pair(inters, inters + radius * edge_on_plane_dir); + if (!inters.isApprox(e1)) { + edge_on_plane.first += radius * edge_on_plane_dir; + edge_on_plane.second += radius * edge_on_plane_dir; + } + return AngleAndEdges(0.5 * double(PI), inters, std::make_pair(e1, e2), edge_on_plane, radius, inters.isApprox(e1)); + } const Vec3d e1e2 = e2 - e1; const double e1e2_len = e1e2.norm(); @@ -773,7 +802,8 @@ MeasurementResult get_measurement(const SurfaceFeature& a, const SurfaceFeature& /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// - } else if (f1.get_type() == SurfaceFeatureType::Edge) { + } + else if (f1.get_type() == SurfaceFeatureType::Edge) { if (f2.get_type() == SurfaceFeatureType::Edge) { std::vector distances; @@ -900,21 +930,6 @@ MeasurementResult get_measurement(const SurfaceFeature& a, const SurfaceFeature& const Vec3d D = c1 - c0; if (!are_parallel(n0, n1)) { - auto orthonormal_basis = [](const Vec3d& v) { - std::array ret; - ret[2] = v.normalized(); - int index; - ret[2].maxCoeff(&index); - switch (index) - { - case 0: { ret[0] = Vec3d(ret[2].y(), -ret[2].x(), 0.0).normalized(); break; } - case 1: { ret[0] = Vec3d(0.0, ret[2].z(), -ret[2].y()).normalized(); break; } - case 2: { ret[0] = Vec3d(-ret[2].z(), 0.0, ret[2].x()).normalized(); break; } - } - ret[1] = ret[2].cross(ret[0]).normalized(); - return ret; - }; - // Get parameters for constructing the degree-8 polynomial phi. const double one = 1.0; const double two = 2.0; From 89bae8606b774f505f21831d4c96b8d26b8a0445 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 16 Nov 2022 15:44:01 +0100 Subject: [PATCH 054/109] Removed debug code --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index b2edc0b979..1d71232fb0 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -396,7 +396,6 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) else if (mouse_event.RightDown()) { // let the event pass through to allow panning/rotating the 3D scene if ((m_mode != EMode::CenterSelection && mouse_event.CmdDown()) || (m_mode == EMode::CenterSelection && m_hover_id != SELECTION_1_ID && m_hover_id != SELECTION_2_ID)) { - std::cout << "RightDown -> false\n"; return false; } From 534d0353eb7b473284443a3424b5bb50fc4062f3 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 18 Nov 2022 08:42:47 +0100 Subject: [PATCH 055/109] Gizmo measure - Draw background for dimensioning labels --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 1d71232fb0..2f04e43a64 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1071,8 +1071,17 @@ void GLGizmoMeasure::render_dimensioning() ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 1.0f, 1.0f }); m_imgui->begin(std::string("distance"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration); + ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow()); ImGui::AlignTextToFramePadding(); - m_imgui->text(curr_value_str + " " + units); + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + const ImVec2 pos = ImGui::GetCursorScreenPos(); + const std::string txt = curr_value_str + " " + units; + ImVec2 txt_size = ImGui::CalcTextSize(txt.c_str()); + const ImGuiStyle& style = ImGui::GetStyle(); + draw_list->AddRectFilled({ pos.x - style.FramePadding.x, pos.y + style.FramePadding.y }, { pos.x + txt_size.x + 2.0f * style.FramePadding.x , pos.y + txt_size.y + 2.0f * style.FramePadding.y }, + ImGuiWrapper::to_ImU32(ColorRGBA(0.5f, 0.5f, 0.5f, 0.5f))); + ImGui::SetCursorScreenPos({ pos.x + style.FramePadding.x, pos.y }); + m_imgui->text(txt); ImGui::SameLine(); if (m_imgui->image_button(ImGui::SliderFloatEditBtnIcon, _L("Edit to scale"))) { m_editing_distance = true; @@ -1345,7 +1354,16 @@ void GLGizmoMeasure::render_dimensioning() ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); m_imgui->begin(_L("##angle"), ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove); ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow()); - m_imgui->text(format_double(Geometry::rad2deg(angle)) + "°"); + ImGui::AlignTextToFramePadding(); + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + const ImVec2 pos = ImGui::GetCursorScreenPos(); + const std::string txt = format_double(Geometry::rad2deg(angle)) + "°"; + ImVec2 txt_size = ImGui::CalcTextSize(txt.c_str()); + const ImGuiStyle& style = ImGui::GetStyle(); + draw_list->AddRectFilled({ pos.x - style.FramePadding.x, pos.y + style.FramePadding.y }, { pos.x + txt_size.x + 2.0f * style.FramePadding.x , pos.y + txt_size.y + 2.0f * style.FramePadding.y }, + ImGuiWrapper::to_ImU32(ColorRGBA(0.5f, 0.5f, 0.5f, 0.5f))); + ImGui::SetCursorScreenPos({ pos.x + style.FramePadding.x, pos.y }); + m_imgui->text(txt); m_imgui->end(); ImGui::PopStyleVar(); }; From 1ba80257028a844cc75ca927c0363195f8ceb641 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 18 Nov 2022 10:53:42 +0100 Subject: [PATCH 056/109] Gizmo measure - Show diameter of selected circles into imgui dialog --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 2f04e43a64..ac957887dc 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1789,10 +1789,23 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit ImGui::Separator(); const ImGuiTableFlags flags = ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersH; if (ImGui::BeginTable("Selection", 2, flags)) { - add_strings_row_to_table(*m_imgui, _u8L("Selection") + " 1:", ImGuiWrapper::to_ImVec4(SELECTED_1ST_COLOR), m_selected_features.first.feature.has_value() ? - m_selected_features.first.source : _u8L("None"), ImGuiWrapper::to_ImVec4(SELECTED_1ST_COLOR)); - add_strings_row_to_table(*m_imgui, _u8L("Selection") + " 2:", ImGuiWrapper::to_ImVec4(SELECTED_2ND_COLOR), m_selected_features.second.feature.has_value() ? - m_selected_features.second.source : _u8L("None"), ImGuiWrapper::to_ImVec4(SELECTED_2ND_COLOR)); + auto format_item_text = [use_inches, &units](const SelectedFeatures::Item& item) { + std::string txt = item.feature.has_value() ? item.source : _u8L("None"); + if (item.feature.has_value() && item.feature->get_type() == Measure::SurfaceFeatureType::Circle) { + auto [center, radius, normal] = item.feature->get_circle(); + const Vec3d on_circle = center + radius * Measure::get_orthogonal(normal, true); + radius = (on_circle - center).norm(); + if (use_inches) + radius = ObjectManipulation::mm_to_in * radius; + txt += " (" + _u8L("Diameter:") + " " + format_double(2.0 * radius) + units + ")"; + } + return txt; + }; + + add_strings_row_to_table(*m_imgui, _u8L("Selection") + " 1:", ImGuiWrapper::to_ImVec4(SELECTED_1ST_COLOR), format_item_text(m_selected_features.first), + ImGuiWrapper::to_ImVec4(SELECTED_1ST_COLOR)); + add_strings_row_to_table(*m_imgui, _u8L("Selection") + " 2:", ImGuiWrapper::to_ImVec4(SELECTED_2ND_COLOR), format_item_text(m_selected_features.second), + ImGuiWrapper::to_ImVec4(SELECTED_2ND_COLOR)); ImGui::EndTable(); } From 62d683b50c0d3b5c93af290a825036070ac273d6 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 18 Nov 2022 11:17:20 +0100 Subject: [PATCH 057/109] Removed commented out code --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 104 ----------------------- 1 file changed, 104 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index ac957887dc..358ccd87f3 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1682,110 +1682,6 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit const bool use_inches = wxGetApp().app_config->get("use_inches") == "1"; const std::string units = use_inches ? " " + _u8L("in") : " " + _u8L("mm"); - //const Measure::SurfaceFeatureType feature_type = m_curr_feature.has_value() ? m_curr_feature->get_type() : Measure::SurfaceFeatureType::Undef; - //bool data_text_set = false; - //ImGui::Separator(); - //if (feature_type != Measure::SurfaceFeatureType::Undef) { - // if (m_mode == EMode::FeatureSelection) { - // m_imgui->text(surface_feature_type_as_string(feature_type)); - // data_text_set = true; - // } - // else if (m_mode == EMode::PointSelection) { - // if (m_hover_id != -1 && m_curr_point_on_feature_position.has_value()) { - // m_imgui->text(point_on_feature_type_as_string(feature_type, m_hover_id)); - // data_text_set = true; - // } - // } - // else if (m_mode == EMode::CenterSelection) { - // if (m_hover_id != -1 && m_curr_point_on_feature_position.has_value()) { - // m_imgui->text(center_on_feature_type_as_string(feature_type)); - // data_text_set = true; - // } - // } - //} - //if (!data_text_set) - // m_imgui->text(_u8L("No feature")); - - //const unsigned int max_data_row_count = 3; - //unsigned int data_row_count = 0; - //if (ImGui::BeginTable("Data", 2)) { - // if (m_mode == EMode::FeatureSelection) { - // switch (feature_type) - // { - // default: { break; } - // case Measure::SurfaceFeatureType::Point: - // { - // Vec3d position = m_volume_matrix * m_curr_feature->get_point(); - // if (use_inches) - // position = ObjectManipulation::mm_to_in * position; - // add_strings_row_to_table(*m_imgui, _u8L("Position"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(position), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // data_row_count = 1; - // break; - // } - // case Measure::SurfaceFeatureType::Edge: - // { - // auto [from, to] = m_curr_feature->get_edge(); - // from = m_volume_matrix * from; - // to = m_volume_matrix * to; - // if (use_inches) { - // from = ObjectManipulation::mm_to_in * from; - // to = ObjectManipulation::mm_to_in * to; - // } - // add_strings_row_to_table(*m_imgui, _u8L("From"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(from), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // add_strings_row_to_table(*m_imgui, _u8L("To"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(to), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // add_strings_row_to_table(*m_imgui, _u8L("Length"), ImGuiWrapper::COL_ORANGE_LIGHT, format_double((to - from).norm()) + units, ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // data_row_count = 3; - // break; - // } - // case Measure::SurfaceFeatureType::Circle: - // { - // auto [center, radius, normal] = m_curr_feature->get_circle(); - // // generic point on circle, used to recalculate radius after transformation - // const Vec3d on_circle = m_volume_matrix * (center + radius * Measure::get_orthogonal(normal, true)); - // center = m_volume_matrix * center; - // normal = (m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal).normalized(); - // radius = (on_circle - center).norm(); - // if (use_inches) { - // center = ObjectManipulation::mm_to_in * center; - // radius = ObjectManipulation::mm_to_in * radius; - // } - // add_strings_row_to_table(*m_imgui, _u8L("Center"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(center), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // add_strings_row_to_table(*m_imgui, _u8L("Radius"), ImGuiWrapper::COL_ORANGE_LIGHT, format_double(radius) + units, ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // add_strings_row_to_table(*m_imgui, _u8L("Normal"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(normal), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // data_row_count = 3; - // break; - // } - // case Measure::SurfaceFeatureType::Plane: - // { - // auto [idx, normal, origin] = m_curr_feature->get_plane(); - // origin = m_volume_matrix * origin; - // normal = m_volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal; - // if (use_inches) - // origin = ObjectManipulation::mm_to_in * origin; - // add_strings_row_to_table(*m_imgui, _u8L("Origin"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(origin), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // add_strings_row_to_table(*m_imgui, _u8L("Normal"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(normal), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // data_row_count = 2; - // break; - // } - // } - // } - // else { - // if (m_hover_id != -1 && m_curr_point_on_feature_position.has_value()) { - // Vec3d position = m_volume_matrix * *m_curr_point_on_feature_position; - // if (use_inches) - // position = ObjectManipulation::mm_to_in * position; - // add_strings_row_to_table(*m_imgui, _u8L("Position"), ImGuiWrapper::COL_ORANGE_LIGHT, format_vec3(position), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // data_row_count = 1; - // } - // } - - // // add dummy rows to keep dialog size fixed - // for (unsigned int i = data_row_count; i < max_data_row_count; ++i) { - // add_strings_row_to_table(*m_imgui, " ", ImGuiWrapper::COL_ORANGE_LIGHT, " ", ImGui::GetStyleColorVec4(ImGuiCol_Text)); - // } - // ImGui::EndTable(); - //} - ImGui::Separator(); const ImGuiTableFlags flags = ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersH; if (ImGui::BeginTable("Selection", 2, flags)) { From cf2a7608d3e35e21c1e49bdaa428519f3afe8c98 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 18 Nov 2022 14:53:19 +0100 Subject: [PATCH 058/109] Gizmo measure - Render dimensioning thicker main lines --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 72 +++++++++++++++++++++++- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 358ccd87f3..d85408f99c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1006,7 +1006,7 @@ void GLGizmoMeasure::render_dimensioning() if (shader == nullptr) return; - auto point_point = [this, shader](const Vec3d& v1, const Vec3d& v2, float distance) { + auto point_point = [this, &shader](const Vec3d& v1, const Vec3d& v2, float distance) { if ((v2 - v1).squaredNorm() < 0.000001 || distance < 0.001f) return; @@ -1036,6 +1036,25 @@ void GLGizmoMeasure::render_dimensioning() const Transform3d ss_to_ndc_matrix = TransformHelper::ndc_to_ss_matrix_inverse(viewport); +#if ENABLE_GL_CORE_PROFILE + if (OpenGLManager::get_gl_info().is_core_profile()) { + shader->stop_using(); + + shader = wxGetApp().get_shader("dashed_thick_lines"); + if (shader == nullptr) + return; + + shader->start_using(); + shader->set_uniform("projection_matrix", Transform3d::Identity()); + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 1.0f); + shader->set_uniform("gap_size", 0.0f); + } + else +#endif // ENABLE_GL_CORE_PROFILE + glsafe(::glLineWidth(2.0f)); + // stem shader->set_uniform("view_model_matrix", overlap ? ss_to_ndc_matrix * Geometry::translation_transform(v1ss_3) * q12ss * Geometry::translation_transform(-2.0 * TRIANGLE_HEIGHT * Vec3d::UnitX()) * Geometry::scale_transform({ v12ss_len + 4.0 * TRIANGLE_HEIGHT, 1.0f, 1.0f }) : @@ -1043,6 +1062,20 @@ void GLGizmoMeasure::render_dimensioning() m_dimensioning.line.set_color(ColorRGBA::WHITE()); m_dimensioning.line.render(); +#if ENABLE_GL_CORE_PROFILE + if (OpenGLManager::get_gl_info().is_core_profile()) { + shader->stop_using(); + + shader = wxGetApp().get_shader("flat"); + if (shader == nullptr) + return; + + shader->start_using(); + } + else +#endif // ENABLE_GL_CORE_PROFILE + glsafe(::glLineWidth(1.0f)); + // arrow 1 shader->set_uniform("view_model_matrix", overlap ? ss_to_ndc_matrix * Geometry::translation_transform(v1ss_3) * q12ss : @@ -1251,7 +1284,7 @@ void GLGizmoMeasure::render_dimensioning() } }; - auto arc_edge_edge = [this, shader](const Measure::SurfaceFeature& f1, const Measure::SurfaceFeature& f2, double radius = 0.0) { + auto arc_edge_edge = [this, &shader](const Measure::SurfaceFeature& f1, const Measure::SurfaceFeature& f2, double radius = 0.0) { assert(f1.get_type() == Measure::SurfaceFeatureType::Edge && f2.get_type() == Measure::SurfaceFeatureType::Edge); if (!m_measurement_result.angle.has_value()) return; @@ -1293,12 +1326,45 @@ void GLGizmoMeasure::render_dimensioning() m_dimensioning.arc.init_from(std::move(init_data)); } - // arc const Camera& camera = wxGetApp().plater()->get_camera(); +#if ENABLE_GL_CORE_PROFILE + if (OpenGLManager::get_gl_info().is_core_profile()) { + shader->stop_using(); + + shader = wxGetApp().get_shader("dashed_thick_lines"); + if (shader == nullptr) + return; + + shader->start_using(); + shader->set_uniform("projection_matrix", Transform3d::Identity()); + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 1.0f); + shader->set_uniform("gap_size", 0.0f); + } + else +#endif // ENABLE_GL_CORE_PROFILE + glsafe(::glLineWidth(2.0f)); + + // arc shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * Geometry::translation_transform(center)); m_dimensioning.arc.render(); +#if ENABLE_GL_CORE_PROFILE + if (OpenGLManager::get_gl_info().is_core_profile()) { + shader->stop_using(); + + shader = wxGetApp().get_shader("flat"); + if (shader == nullptr) + return; + + shader->start_using(); + } + else +#endif // ENABLE_GL_CORE_PROFILE + glsafe(::glLineWidth(1.0f)); + // arrows auto render_arrow = [this, shader, &camera, &normal, ¢er, &e1_unit, draw_radius, step, resolution](unsigned int endpoint_id) { const double angle = (endpoint_id == 1) ? 0.0 : step * double(resolution); From 5d6346f27508b35c58157b9fd11a684971183e73 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 21 Nov 2022 08:37:58 +0100 Subject: [PATCH 059/109] Gizmo Measure - When CTRL+dragging to pan/rotate the scene, do not select the hovered feature, if any --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index d85408f99c..77d816aa76 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -254,6 +254,7 @@ GLGizmoMeasure::GLGizmoMeasure(GLCanvas3D& parent, const std::string& icon_filen bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) { m_mouse_pos = { double(mouse_event.GetX()), double(mouse_event.GetY()) }; + m_dragging = false; if (mouse_event.Moving()) { // only for sure @@ -261,6 +262,8 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) return false; } else if (mouse_event.Dragging()) { + m_dragging = true; + // Enable/Disable panning/rotating the 3D scene // Ctrl is pressed or the mouse is not hovering a selected volume bool unlock_dragging = mouse_event.CmdDown() || (m_hover_id == -1 && !m_parent.get_selection().contains_volume(m_parent.get_first_hover_volume_idx())); @@ -578,7 +581,9 @@ void GLGizmoMeasure::on_render() m_curr_point_on_feature_position.reset(); } else { - std::optional curr_feature = mouse_on_object ? m_measuring->get_feature(model_facet_idx, position_on_model.cast()) : std::nullopt; + std::optional curr_feature = m_dragging ? m_curr_feature : + mouse_on_object ? m_measuring->get_feature(model_facet_idx, position_on_model.cast()) : std::nullopt; + if (m_curr_feature != curr_feature || (curr_feature.has_value() && curr_feature->get_type() == Measure::SurfaceFeatureType::Circle && (m_curr_feature != curr_feature || m_last_inv_zoom != inv_zoom))) { m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID); From 543950bf4bc3dcead2696a555cbe4430226da6dc Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 21 Nov 2022 09:13:28 +0100 Subject: [PATCH 060/109] Gizmo Measure - Use [Delete] key in place of Shift+Right mouse to restart selection --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 13 ++++++------- src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 77d816aa76..2440b5f0a1 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -401,12 +401,6 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) if ((m_mode != EMode::CenterSelection && mouse_event.CmdDown()) || (m_mode == EMode::CenterSelection && m_hover_id != SELECTION_1_ID && m_hover_id != SELECTION_2_ID)) { return false; } - - if (mouse_event.ShiftDown()) { - m_selected_features.reset(); - m_selection_raycasters.clear(); - m_parent.request_extra_frame(); - } } else if (mouse_event.Leaving()) m_mouse_left_down = false; @@ -477,6 +471,11 @@ bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_po m_mode = control_down ? EMode::PointSelection : EMode::FeatureSelection; restore_scene_raycasters_state(); } + else if (action == SLAGizmoEventType::Delete) { + m_selected_features.reset(); + m_selection_raycasters.clear(); + m_parent.request_extra_frame(); + } return true; } @@ -1738,7 +1737,7 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit } if (m_selected_features.first.feature.has_value()) { - add_strings_row_to_table(*m_imgui, _u8L("Shift") + "+" + _u8L("Right mouse button"), ImGuiWrapper::COL_ORANGE_LIGHT, _u8L("Restart selection"), ImGui::GetStyleColorVec4(ImGuiCol_Text)); + add_strings_row_to_table(*m_imgui, _u8L("Delete"), ImGuiWrapper::COL_ORANGE_LIGHT, _u8L("Restart selection"), ImGui::GetStyleColorVec4(ImGuiCol_Text)); ++row_count; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 37d1d3de4c..c10741a14e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -554,7 +554,7 @@ bool GLGizmosManager::on_char(wxKeyEvent& evt) case WXK_BACK: case WXK_DELETE: { - if ((m_current == SlaSupports || m_current == Hollow || m_current == Cut) && gizmo_event(SLAGizmoEventType::Delete)) + if ((m_current == SlaSupports || m_current == Hollow || m_current == Cut || m_current == Measure) && gizmo_event(SLAGizmoEventType::Delete)) processed = true; break; From a03528e55a402358540ad588b3772608ace0355f Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 21 Nov 2022 09:46:30 +0100 Subject: [PATCH 061/109] Gizmo Measure - Added [Restart selection] button to imgui dialog --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 2440b5f0a1..d01b74518d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1775,13 +1775,13 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit ImGui::EndTable(); } - //if (m_selected_features.first.feature.has_value()) { - // if (m_imgui->button(_u8L("Restart"))) { - // m_selected_features.reset(); - // m_selection_raycasters.clear(); - // m_imgui->set_requires_extra_frame(); - // } - //} + m_imgui->disabled_begin(!m_selected_features.first.feature.has_value()); + if (m_imgui->button(_u8L("Restart selection"))) { + m_selected_features.reset(); + m_selection_raycasters.clear(); + m_imgui->set_requires_extra_frame(); + } + m_imgui->disabled_end(); auto add_measure_row_to_table = [this](const std::string& col_1, const ImVec4& col_1_color, const std::string& col_2, const ImVec4& col_2_color) { ImGui::TableNextRow(); From ef018318bd8464b5b8a105adf7c8b7b141463900 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 21 Nov 2022 10:26:53 +0100 Subject: [PATCH 062/109] Gizmo Measure - Clicking on 1st selected let second selected to be promoted as first selected --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 27 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index d01b74518d..0c8d83fdb6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -354,6 +354,10 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) else { if (!m_selected_features.second.feature.has_value()) m_selected_features.first.reset(); + else { + m_selected_features.first = m_selected_features.second; + m_selected_features.second.reset(); + } } } else { @@ -853,7 +857,7 @@ void GLGizmoMeasure::on_render() }; auto hover_selection_color = [this]() { - return !m_selected_features.first.feature.has_value() ? SELECTED_1ST_COLOR : SELECTED_2ND_COLOR; + return (!m_selected_features.first.feature.has_value() || *m_curr_feature == *m_selected_features.first.feature) ? SELECTED_1ST_COLOR : SELECTED_2ND_COLOR; }; auto hovering_color = [this, hover_selection_color, &selection]() { @@ -1693,14 +1697,27 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit std::string text; ColorRGBA color; if (m_selected_features.second.feature.has_value()) { - if (m_selected_features.second.feature == m_curr_feature && m_mode == EMode::FeatureSelection) + if (m_selected_features.first.feature == m_curr_feature && m_mode == EMode::FeatureSelection) { text = _u8L("Unselect feature"); - else if (m_hover_id == SELECTION_2_ID) + color = SELECTED_1ST_COLOR; + } + else if (m_selected_features.second.feature == m_curr_feature && m_mode == EMode::FeatureSelection) { + text = _u8L("Unselect feature"); + color = SELECTED_2ND_COLOR; + } + else if (m_hover_id == SELECTION_1_ID) { text = (m_mode == EMode::CenterSelection) ? _u8L("Unselect center") : _u8L("Unselect point"); - else + color = SELECTED_1ST_COLOR; + } + else if (m_hover_id == SELECTION_2_ID) { + text = (m_mode == EMode::CenterSelection) ? _u8L("Unselect center") : _u8L("Unselect point"); + color = SELECTED_2ND_COLOR; + } + else { text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : (m_mode == EMode::CenterSelection) ? _u8L("Select center") : _u8L("Select feature"); - color = SELECTED_2ND_COLOR; + color = SELECTED_2ND_COLOR; + } } else { if (m_selected_features.first.feature.has_value()) { From 38d2e0605a405c703c5a671aad284a9077a966b3 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 21 Nov 2022 11:20:14 +0100 Subject: [PATCH 063/109] Gizmo Measure - Handling of [ESC] key When two features are selected -> unselected second feature When one feature is selected -> unselect first feature When no feature is selected -> close gizmo --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 31 ++++++++++++++++++++++- src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp | 1 + src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 5 +++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 0c8d83fdb6..30602b1d49 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -480,6 +480,16 @@ bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_po m_selection_raycasters.clear(); m_parent.request_extra_frame(); } + else if (action == SLAGizmoEventType::Escape) { + if (!m_selected_features.first.feature.has_value()) + return false; + else { + if (m_selected_features.second.feature.has_value()) + m_selected_features.second.feature.reset(); + else + m_selected_features.first.feature.reset(); + } + } return true; } @@ -1758,8 +1768,27 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit ++row_count; } + if (m_selected_features.first.feature.has_value() || m_selected_features.second.feature.has_value()) { + add_row_to_table( + [this]() { + m_imgui->text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, _u8L("Esc")); + }, + [this]() { + m_imgui->text_colored(ImGui::GetStyleColorVec4(ImGuiCol_Text), _u8L("Unselect")); + ImGui::SameLine(); + const ImVec2 pos = ImGui::GetCursorScreenPos(); + const float rect_size = ImGui::GetTextLineHeight(); + const ColorRGBA color = m_selected_features.second.feature.has_value() ? SELECTED_2ND_COLOR : SELECTED_1ST_COLOR; + ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(pos.x + 1.0f, pos.y + 1.0f), ImVec2(pos.x + rect_size, pos.y + rect_size), ImGuiWrapper::to_ImU32(color)); + ImGui::Dummy(ImVec2(rect_size, rect_size)); + } + ); + + ++row_count; + } + // add dummy rows to keep dialog size fixed - for (unsigned int i = row_count; i < 4; ++i) { + for (unsigned int i = row_count; i < 5; ++i) { add_strings_row_to_table(*m_imgui, " ", ImGuiWrapper::COL_ORANGE_LIGHT, " ", ImGui::GetStyleColorVec4(ImGuiCol_Text)); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp index 3878c6b25a..c1b605726c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp @@ -29,6 +29,7 @@ enum class SLAGizmoEventType : unsigned char { ShiftDown, ShiftUp, AltUp, + Escape, ApplyChanges, DiscardChanges, AutomaticGeneration, diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index c10741a14e..c68a510276 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -526,7 +526,10 @@ bool GLGizmosManager::on_char(wxKeyEvent& evt) case WXK_ESCAPE: { if (m_current != Undefined) { - if ((m_current != SlaSupports) || !gizmo_event(SLAGizmoEventType::DiscardChanges)) + if (m_current == Measure && gizmo_event(SLAGizmoEventType::Escape)) { + // do nothing + } + else if (m_current != SlaSupports || !gizmo_event(SLAGizmoEventType::DiscardChanges)) reset_all_states(); processed = true; From ab5c81a2ef0cac6d688f1b660e76324637ab75ef Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 21 Nov 2022 12:01:22 +0100 Subject: [PATCH 064/109] Gizmo Measure - Fixed point color and hint in dialog when adding a point on a selected feature --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 30602b1d49..29475105df 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -867,7 +867,9 @@ void GLGizmoMeasure::on_render() }; auto hover_selection_color = [this]() { - return (!m_selected_features.first.feature.has_value() || *m_curr_feature == *m_selected_features.first.feature) ? SELECTED_1ST_COLOR : SELECTED_2ND_COLOR; + return ((m_mode == EMode::PointSelection && !m_selected_features.first.feature.has_value()) || + (m_mode != EMode::PointSelection && (!m_selected_features.first.feature.has_value() || *m_curr_feature == *m_selected_features.first.feature))) ? + SELECTED_1ST_COLOR : SELECTED_2ND_COLOR; }; auto hovering_color = [this, hover_selection_color, &selection]() { @@ -1731,11 +1733,14 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit } else { if (m_selected_features.first.feature.has_value()) { - if (m_selected_features.first.feature == m_curr_feature) + if (m_selected_features.first.feature == m_curr_feature && m_mode == EMode::FeatureSelection) { text = _u8L("Unselect feature"); - else if (m_hover_id == SELECTION_1_ID) + color = SELECTED_1ST_COLOR; + } + else if (m_hover_id == SELECTION_1_ID) { text = (m_mode == EMode::CenterSelection) ? _u8L("Unselect center") : _u8L("Unselect point"); - color = SELECTED_1ST_COLOR; + color = SELECTED_1ST_COLOR; + } } if (text.empty()) { text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : From df266798a63d94ee0fc2853b398edee4e3fce330 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 21 Nov 2022 14:44:31 +0100 Subject: [PATCH 065/109] Fixed crash when opening Measure Gizmo after slicing in SLA mode --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 29475105df..6f398d111b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -968,7 +968,7 @@ void GLGizmoMeasure::update_if_needed() // continue; TriangleMesh volume_mesh = vol.volume->mesh(); - volume_mesh.transform(vol.instance->get_transformation().get_matrix() * vol.volume->get_transformation().get_matrix()); + volume_mesh.transform(vol.world_trafo); composite_mesh.merge(volume_mesh); } @@ -987,10 +987,17 @@ void GLGizmoMeasure::update_if_needed() volumes_cache.reserve(idxs.size()); for (unsigned int idx : idxs) { const GLVolume* v = selection.get_volume(idx); + const int volume_idx = v->volume_idx(); + if (volume_idx < 0) + continue; + const ModelObject* obj = selection.get_model()->objects[v->object_idx()]; const ModelInstance* inst = obj->instances[v->instance_idx()]; - const ModelVolume* vol = obj->volumes[v->volume_idx()]; - const VolumeCacheItem item = { obj, inst, vol, inst->get_matrix() * vol->get_matrix() }; + const ModelVolume* vol = obj->volumes[volume_idx]; + const VolumeCacheItem item = { + obj, inst, vol, + Geometry::translation_transform(selection.get_first_volume()->get_sla_shift_z() * Vec3d::UnitZ()) * inst->get_matrix() * vol->get_matrix() + }; volumes_cache.emplace_back(item); } From cc0901228beecaa3a3187a57b5d3d58737bd4fa8 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 22 Nov 2022 08:34:12 +0100 Subject: [PATCH 066/109] Gizmo measure - Fixed dimensioning after scaling a part of a multipart object --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 6f398d111b..8e32e7e3a5 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1174,16 +1174,14 @@ void GLGizmoMeasure::render_dimensioning() Vec3d new_pivot; Transform3d scale_matrix; - TrafoData(double ratio, const Vec3d& pivot) { + TrafoData(double ratio, const Vec3d& old_pivot, const Vec3d& new_pivot) { this->ratio = ratio; this->scale_matrix = Geometry::scale_transform(ratio); - this->old_pivot = pivot; - this->new_pivot = { pivot.x(), pivot.y(), (this->scale_matrix * pivot).z() }; + this->old_pivot = old_pivot; + this->new_pivot = new_pivot; } - Vec3d transform(const Vec3d& point) const { - return this->scale_matrix * (point - this->old_pivot) + this->new_pivot; - } + Vec3d transform(const Vec3d& point) const { return this->scale_matrix * (point - this->old_pivot) + this->new_pivot; } }; auto scale_feature = [](Measure::SurfaceFeature& feature, const TrafoData& trafo_data) { @@ -1218,22 +1216,26 @@ void GLGizmoMeasure::render_dimensioning() } }; - const TrafoData trafo_data(ratio, m_parent.get_selection().get_bounding_box().center()); - scale_feature(*m_selected_features.first.feature, trafo_data); - scale_feature(*m_selected_features.second.feature, trafo_data); - + // apply scale TransformationType type; type.set_world(); type.set_relative(); type.set_joint(); - // apply scale + // scale selection Selection& selection = m_parent.get_selection(); + const Vec3d old_center = selection.get_bounding_box().center(); selection.setup_cache(); selection.scale(ratio * Vec3d::Ones(), type); wxGetApp().plater()->canvas3D()->do_scale(""); // avoid storing another snapshot wxGetApp().obj_manipul()->set_dirty(); + // scale dimensioning + const Vec3d new_center = selection.get_bounding_box().center(); + const TrafoData trafo_data(ratio, old_center, new_center); + scale_feature(*m_selected_features.first.feature, trafo_data); + scale_feature(*m_selected_features.second.feature, trafo_data); + // update measure on next call to data_changed() m_pending_scale = true; }; From 87fb1604d88e65b25260a5bdb82f8bcc5c0c86b1 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 22 Nov 2022 12:36:51 +0100 Subject: [PATCH 067/109] Gizmo measure - Fixed incorrect point on feature detection --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 8e32e7e3a5..f4c85a1b54 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -666,7 +666,7 @@ void GLGizmoMeasure::on_render() return trafo * p.cast(); } } - return Vec3d::Zero(); + return Vec3d(DBL_MAX, DBL_MAX, DBL_MAX); }; if (m_curr_feature.has_value()) { @@ -683,8 +683,11 @@ void GLGizmoMeasure::on_render() const std::optional extra = m_curr_feature->get_extra_point(); if (extra.has_value() && m_hover_id == POINT_ID) m_curr_point_on_feature_position = *extra; - else - m_curr_point_on_feature_position = position_on_feature(EDGE_ID, camera, [](const Vec3f& v) { return Vec3f(0.0f, 0.0f, v.z()); }); + else { + const Vec3d pos = position_on_feature(EDGE_ID, camera, [](const Vec3f& v) { return Vec3f(0.0f, 0.0f, v.z()); }); + if (!pos.isApprox(Vec3d(DBL_MAX, DBL_MAX, DBL_MAX))) + m_curr_point_on_feature_position = pos; + } break; } case Measure::SurfaceFeatureType::Plane: @@ -715,6 +718,7 @@ void GLGizmoMeasure::on_render() } } else { + m_curr_point_on_feature_position.reset(); if (m_curr_feature.has_value() && m_curr_feature->get_type() == Measure::SurfaceFeatureType::Circle) { if (update_circle()) { m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID); From 36b4a149a48e4f1a3922572656a13c884dc1c5ad Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 22 Nov 2022 13:13:25 +0100 Subject: [PATCH 068/109] Gizmo measure - Fixed calculation of angle edge-plane --- src/libslic3r/Measure.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 8213f9778d..9105d65c85 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -34,7 +34,7 @@ static std::array orthonormal_basis(const Vec3d& v) std::array ret; ret[2] = v.normalized(); int index; - ret[2].maxCoeff(&index); + ret[2].cwiseAbs().maxCoeff(&index); switch (index) { case 0: { ret[0] = Vec3d(ret[2].y(), -ret[2].x(), 0.0).normalized(); break; } From 786eb4dc530377e67ec62c76b8808c494581475b Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 22 Nov 2022 14:40:35 +0100 Subject: [PATCH 069/109] Follow-up of fdc9c73340060cea7d8335e1211836681e18cae0 - Alternate implementation of 'When panning/rotating the scene, do not select the hovered feature, if any' --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index f4c85a1b54..05374124e6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -254,7 +254,6 @@ GLGizmoMeasure::GLGizmoMeasure(GLCanvas3D& parent, const std::string& icon_filen bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) { m_mouse_pos = { double(mouse_event.GetX()), double(mouse_event.GetY()) }; - m_dragging = false; if (mouse_event.Moving()) { // only for sure @@ -262,8 +261,6 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) return false; } else if (mouse_event.Dragging()) { - m_dragging = true; - // Enable/Disable panning/rotating the 3D scene // Ctrl is pressed or the mouse is not hovering a selected volume bool unlock_dragging = mouse_event.CmdDown() || (m_hover_id == -1 && !m_parent.get_selection().contains_volume(m_parent.get_first_hover_volume_idx())); @@ -594,7 +591,7 @@ void GLGizmoMeasure::on_render() m_curr_point_on_feature_position.reset(); } else { - std::optional curr_feature = m_dragging ? m_curr_feature : + std::optional curr_feature = wxGetMouseState().LeftIsDown() ? m_curr_feature : mouse_on_object ? m_measuring->get_feature(model_facet_idx, position_on_model.cast()) : std::nullopt; if (m_curr_feature != curr_feature || From dedaa7b49b164717943729f35c5d6f6b9009635c Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 23 Nov 2022 08:24:08 +0100 Subject: [PATCH 070/109] Gizmo measure - Fixed color of hovered features when part of the object is outside the printbed --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 05374124e6..fa8240f8d6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -752,7 +752,7 @@ void GLGizmoMeasure::on_render() }; auto set_emission_uniform = [this, shader](const ColorRGBA& color, bool hover) { - shader->set_uniform("emission_factor", (color == m_parent.get_selection().get_first_volume()->render_color) ? 0.0f : + shader->set_uniform("emission_factor", (color == GLVolume::SELECTED_COLOR) ? 0.0f : hover ? 0.5f : 0.25f); }; @@ -874,7 +874,7 @@ void GLGizmoMeasure::on_render() }; auto hovering_color = [this, hover_selection_color, &selection]() { - return (m_mode == EMode::PointSelection) ? selection.get_first_volume()->render_color : hover_selection_color(); + return (m_mode == EMode::PointSelection) ? GLVolume::SELECTED_COLOR : hover_selection_color(); }; if (m_curr_feature.has_value()) { From 946bbd285a54ecd389a7f2ef859ca4f82ce9808b Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 23 Nov 2022 09:10:56 +0100 Subject: [PATCH 071/109] Fixed warnings --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index fa8240f8d6..89e6b63ef1 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -751,7 +751,7 @@ void GLGizmoMeasure::on_render() shader->set_uniform("view_normal_matrix", view_normal_matrix); }; - auto set_emission_uniform = [this, shader](const ColorRGBA& color, bool hover) { + auto set_emission_uniform = [shader](const ColorRGBA& color, bool hover) { shader->set_uniform("emission_factor", (color == GLVolume::SELECTED_COLOR) ? 0.0f : hover ? 0.5f : 0.25f); }; @@ -873,7 +873,7 @@ void GLGizmoMeasure::on_render() SELECTED_1ST_COLOR : SELECTED_2ND_COLOR; }; - auto hovering_color = [this, hover_selection_color, &selection]() { + auto hovering_color = [this, hover_selection_color]() { return (m_mode == EMode::PointSelection) ? GLVolume::SELECTED_COLOR : hover_selection_color(); }; From 2b155d593292c78f51e69118fa6fc79cc119cdbc Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 23 Nov 2022 12:03:36 +0100 Subject: [PATCH 072/109] Gizmo measure - Hide SLA supports and pad when opening the gizmo --- src/slic3r/GUI/GLCanvas3D.cpp | 19 +++++++++++++++++-- src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp | 5 +++++ src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 3 +++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 991bbead28..345beb4434 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1346,11 +1346,26 @@ void GLCanvas3D::toggle_sla_auxiliaries_visibility(bool visible, const ModelObje m_render_sla_auxiliaries = visible; +#if ENABLE_RAYCAST_PICKING + std::vector>* raycasters = get_raycasters_for_picking(SceneRaycaster::EType::Volume); +#endif // ENABLE_RAYCAST_PICKING + for (GLVolume* vol : m_volumes.volumes) { +#if ENABLE_RAYCAST_PICKING 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) + && (instance_idx == -1 || vol->composite_id.instance_id == instance_idx) + && vol->composite_id.volume_id < 0) { vol->is_active = visible; + auto it = std::find_if(raycasters->begin(), raycasters->end(), [vol](std::shared_ptr item) { return item->get_raycaster() == vol->mesh_raycaster.get(); }); + if (it != raycasters->end()) + (*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 } } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp index 1ce118d71d..51ea56c821 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp @@ -900,6 +900,11 @@ RENDER_AGAIN: bool show_sups = m_c->instances_hider()->are_supports_shown(); if (m_imgui->checkbox(m_desc["show_supports"], show_sups)) { m_c->instances_hider()->show_supports(show_sups); +#if ENABLE_RAYCAST_PICKING + if (show_sups) + // ensure supports and pad are disabled from picking even when they are visible + set_sla_auxiliary_volumes_picking_state(false); +#endif // ENABLE_RAYCAST_PICKING force_refresh = true; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 89e6b63ef1..2de29087b8 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -411,6 +411,8 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) void GLGizmoMeasure::data_changed() { + m_parent.toggle_sla_auxiliaries_visibility(false, nullptr, -1); + update_if_needed(); m_last_inv_zoom = 0.0f; @@ -500,6 +502,7 @@ bool GLGizmoMeasure::on_init() void GLGizmoMeasure::on_set_state() { if (m_state == Off) { + m_parent.toggle_sla_auxiliaries_visibility(true, nullptr, -1); m_ctrl_kar_filter.reset_count(); m_shift_kar_filter.reset_count(); m_curr_feature.reset(); From 3bdd548358735fa75987a6560234470525b649b4 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 23 Nov 2022 12:37:54 +0100 Subject: [PATCH 073/109] Gizmo measure - Undo/Redo related fix --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp index 9699d73cc8..1672e8b74e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp @@ -159,6 +159,11 @@ public: bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down); + bool wants_enter_leave_snapshots() const override { return true; } + std::string get_gizmo_entering_text() const override { return _u8L("Entering Measure gizmo"); } + std::string get_gizmo_leaving_text() const override { return _u8L("Leaving Measure gizmo"); } + std::string get_action_snapshot_name() override { return _u8L("Measure gizmo editing"); } + protected: bool on_init() override; std::string on_get_name() const override; From d4ad4aff01598d60ce0d9e3114e47cd704083b4d Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 22 Nov 2022 09:49:10 +0100 Subject: [PATCH 074/109] Measurement: Fixed and refactored circle detection: - first/last segment of a circular segment was sometimes separated - circles were sometimes shown where they shouldn't be --- src/libslic3r/Measure.cpp | 236 +++++++++++++++++++------------------- 1 file changed, 120 insertions(+), 116 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 9105d65c85..a9cea06bdd 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -14,17 +14,17 @@ namespace Measure { constexpr double feature_hover_limit = 0.5; // how close to a feature the mouse must be to highlight it -static std::pair get_center_and_radius(const std::vector& border, int start_idx, int end_idx, const Transform3d& trafo) +static std::pair get_center_and_radius(const std::vector& points, const Transform3d& trafo) { - Vec2ds pts; + Vec2ds out; double z = 0.; - for (int i=start_idx; i<=end_idx; ++i) { - Vec3d pt_transformed = trafo * border[i]; + for (const Vec3d pt : points) { + Vec3d pt_transformed = trafo * pt; z = pt_transformed.z(); - pts.emplace_back(pt_transformed.x(), pt_transformed.y()); + out.emplace_back(pt_transformed.x(), pt_transformed.y()); } - auto circle = Geometry::circle_ransac(pts, 20); // FIXME: iterations? + auto circle = Geometry::circle_ransac(out, 20); // FIXME: iterations? return std::make_pair(trafo.inverse() * Vec3d(circle.center.x(), circle.center.y(), z), circle.radius); } @@ -216,6 +216,7 @@ void MeasuringImpl::update_planes() m_planes[plane_id].borders.pop_back(); else { assert(last_border.front() == last_border.back()); + last_border.pop_back(); } } } @@ -233,6 +234,9 @@ void MeasuringImpl::update_planes() void MeasuringImpl::extract_features() { + auto are_angles_same = [](double a, double b) { return Slic3r::is_approx(a,b); }; + auto are_lengths_same = [](double a, double b) { return Slic3r::is_approx(a,b); }; + std::vector angles; std::vector lengths; @@ -246,152 +250,152 @@ void MeasuringImpl::extract_features() q.setFromTwoVectors(plane.normal, Vec3d::UnitZ()); Transform3d trafo = Transform3d::Identity(); trafo.rotate(q); - + for (const std::vector& border : plane.borders) { if (border.size() <= 1) continue; - assert(border.front() == border.back()); - int start_idx = -1; - std::vector edges; + // Given an idx into border, return the index that is idx+offset position, + // while taking into account the need for warp-around and the fact that + // the first and last point are the same. + auto offset_to_index = [border_size = int(border.size())](int idx, int offset) -> int { + assert(std::abs(offset) < border_size); + int out = idx+offset; + if (out >= border_size) + out = out - border_size; + else if (out < 0) + out = border_size + out; + + return out; + }; // First calculate angles at all the vertices. angles.clear(); lengths.clear(); - for (int i=0; i M_PI) angle = 2*M_PI - angle; angles.push_back(angle); lengths.push_back(v2.norm()); + if (first_different_angle_idx == 0 && angles.size() > 1) { + if (! are_angles_same(angles.back(), angles[angles.size()-2])) + first_different_angle_idx = angles.size()-1; + } } assert(border.size() == angles.size()); assert(border.size() == lengths.size()); - // First go around the border and pick what might be circular segments. // Save pair of indices to where such potential segments start and end. // Also remember the length of these segments. + int start_idx = -1; bool circle = false; + bool first_iter = true; std::vector circles; + std::vector edges; std::vector> circles_idxs; - std::vector circles_lengths; - for (int i=1; i<(int)angles.size(); ++i) { - if (Slic3r::is_approx(lengths[i], lengths[i-1]) - && Slic3r::is_approx(angles[i], angles[i-1]) - && i != (int)angles.size()-1 ) { + //std::vector circles_lengths; + std::vector single_circle; // could be in loop-scope, but reallocations + double single_circle_length = 0.; + int first_pt_idx = offset_to_index(first_different_angle_idx, 1); + int i = first_pt_idx; + while (i != first_pt_idx || first_iter) { + if (are_angles_same(angles[i], angles[offset_to_index(i,-1)]) + && i != offset_to_index(first_pt_idx, -1) // not the last point + && i != start_idx ) { // circle if (! circle) { circle = true; - start_idx = std::max(0, i-2); + single_circle.clear(); + single_circle_length = 0.; + start_idx = offset_to_index(i, -2); + single_circle = { border[start_idx], border[offset_to_index(start_idx,1)] }; + single_circle_length += lengths[offset_to_index(i, -1)]; } + single_circle.emplace_back(border[i]); + single_circle_length += lengths[i]; } else { - if (circle) { - const auto& [center, radius] = get_center_and_radius(border, start_idx, i, trafo); - // Add the circle and remember indices into borders. - circles_idxs.emplace_back(start_idx, i); - circles.emplace_back(SurfaceFeature(SurfaceFeatureType::Circle, center, plane.normal, std::nullopt, radius)); - circles_lengths.emplace_back(std::accumulate(lengths.begin() + start_idx + 1, lengths.begin() + i + 1, 0.)); - circle = false; - } - } - } + if (circle && single_circle.size() >= 5) { // Less than 5 vertices? Not a circle. + single_circle.emplace_back(border[i]); + single_circle_length += lengths[i]; - // At this point we might need to merge the first and last segment, if the starting - // point happened to be inside the segment. The discrimination of too small segments - // will follow, so we need a complete picture before that. - if (circles_idxs.size() > 1 - && circles_idxs.back().second == (int)angles.size()-1 - && circles_idxs.front().first == 0) { - // Possibly the same circle. Check that the angle and length criterion holds along the combined segment. - bool same = true; - double last_len = -1.; - double last_angle = 0.; - for (int i=circles_idxs.back().first + 1; i != circles_idxs.front().second; ++i) { - if (i == (int)angles.size()) - i = 1; - if (last_len == -1.) { - last_len = lengths[i]; - last_angle = angles[i]; - } else { - if (! Slic3r::is_approx(lengths[i], last_len) || ! Slic3r::is_approx(angles[i], last_angle)) { - same = false; - break; + bool accept_circle = true; + { + // Check that lengths of internal (!!!) edges match. + int j = offset_to_index(start_idx, 3); + while (j != i) { + if (! are_lengths_same(lengths[offset_to_index(j,-1)], lengths[j])) { + accept_circle = false; + break; + } + j = offset_to_index(j, 1); + } + } + + if (accept_circle) { + const auto& [center, radius] = get_center_and_radius(single_circle, trafo); + + // Check that the fit went well. The tolerance is high, only to + // reject complete failures. + for (const Vec3d& pt : single_circle) { + if (std::abs((pt - center).norm() - radius) > 0.5) { + accept_circle = false; + break; + } + } + + // If the segment subtends less than 90 degrees, throw it away. + accept_circle &= single_circle_length / radius > 0.9*M_PI/2.; + + // If this is all-around and 5 to 8 vertices, consider it a polygon. + bool is_polygon = start_idx == i && single_circle.size() <= 9 && single_circle.size() >= 6; + + if (accept_circle) { + // Add the circle and remember indices into borders. + circles_idxs.emplace_back(start_idx, i); + if (is_polygon) { + for (int j=0; j<=i; ++j) // No wrap-around handling needed here. + edges.emplace_back(SurfaceFeature(SurfaceFeatureType::Edge, + border[j==0 ? border.size()-1 : j-1], border[j], + std::make_optional(center))); + } + else + circles.emplace_back(SurfaceFeature(SurfaceFeatureType::Circle, center, plane.normal, std::nullopt, radius)); + } } } + circle = false; } - if (same) { - // This seems to really be the same circle. Better apply ransac again. The parts can be small and inexact. - std::vector points(border.begin() + circles_idxs.back().first, border.end()); - points.insert(points.end(), border.begin(), border.begin() + circles_idxs.front().second+1); - auto [c, radius] = get_center_and_radius(points, 0, points.size()-1, trafo); - - // Now replace the first circle with the combined one, remove the last circle. - // First index of the first circle is saved negative - we are going to pick edges - // from the border later, we will need to know where the merged in segment was. - // The sign simplifies the algorithm that picks the remaining edges - see below. - circles.front() = SurfaceFeature(SurfaceFeatureType::Circle, c, plane.normal, std::nullopt, radius); - circles_idxs.front().first = - circles_idxs.back().first; - circles_lengths.front() += circles_lengths.back(); - circles.pop_back(); - circles_idxs.pop_back(); - circles_lengths.pop_back(); - } - } - - // Now throw away all circles that subtend less than 90 deg. - assert(circles.size() == circles_lengths.size()); - for (int i=0; i(circles[i].get_circle()); - if (circles_lengths[i] / r < 0.9*M_PI/2.) { - circles_lengths.erase(circles_lengths.begin() + i); - circles.erase(circles.begin() + i); - circles_idxs.erase(circles_idxs.begin() + i); - --i; - } + // Take care of the wrap around. + first_iter = false; + i = offset_to_index(i, 1); } - circles_lengths.clear(); // no longer needed, make it obvious - - // Anything under 5 vertices shall not be considered a circle. - assert(circles_idxs.size() == circles.size()); - for (int i=int(circles_idxs.size())-1; i>=0; --i) { - const auto& [start, end] = circles_idxs[i]; - int N = start >= 0 - ? end - start + (start == 0 && end == (int)border.size()-1 ? 0 : 1) // last point is the same as first - : end + (border.size() + start); - if (N < 5) { - circles.erase(circles.begin() + i); - circles_idxs.erase(circles_idxs.begin() + i); - } else if (N <= 8 && start == 0 && end == (int)border.size()-1) { - // This is a regular 5-8 polygon. Add the edges as edges with a special - // point and remove the circle. Leave the indices in circles_idxs, so - // the edges are not picked up again later. - const Vec3d center = std::get<0>(circles[i].get_circle()); - for (int j=1; j<=end; ++j) - edges.emplace_back(SurfaceFeature(SurfaceFeatureType::Edge, - border[j - 1], border[j], std::make_optional(center))); - circles.erase(circles.begin() + i); - } - } - // We have the circles. Now go around again and pick edges, while jumping over circles. - // If the first index of the first circle is negative, it means that it was merged - // with a segment that was originally at the back and is no longer there. Ressurect - // its pair of indices so that edges are not picked again. - if (! circles_idxs.empty() && circles_idxs.front().first < 0) - circles_idxs.emplace_back(-circles_idxs.front().first, int(border.size())); - int cidx = 0; // index of next circle to jump over - for (int i=1; i (int)circles_idxs[cidx].first) - i = circles_idxs[cidx++].second; - else - edges.emplace_back(SurfaceFeature(SurfaceFeatureType::Edge, border[i - 1], border[i])); + if (circles_idxs.empty()) { + // Just add all edges. + for (int i=1; i Date: Fri, 25 Nov 2022 13:45:23 +0100 Subject: [PATCH 075/109] Measurement: prevent ending up in an infinite loop with broken models --- src/libslic3r/Measure.cpp | 16 ++++++++++++++-- src/libslic3r/SurfaceMesh.hpp | 9 +++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index a9cea06bdd..37bf68e83d 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -189,10 +189,16 @@ void MeasuringImpl::update_planes() he = sm.next_around_target(he); if (he.is_invalid()) goto PLANE_FAILURE; + + // For broken meshes, the iteration might never get back to he_orig. + // Remember all halfedges we saw to break out of such infinite loops. + boost::container::small_vector he_seen; + while ( (int)m_face_to_plane[sm.face(he)] == plane_id && he != he_orig) { + he_seen.emplace_back(he); he = sm.next_around_target(he); - if (he.is_invalid()) - goto PLANE_FAILURE; + if (he.is_invalid() || std::find(he_seen.begin(), he_seen.end(), he) != he_seen.end()) + goto PLANE_FAILURE; } he = sm.opposite(he); if (he.is_invalid()) @@ -210,6 +216,12 @@ void MeasuringImpl::update_planes() visited[face_it - facets.begin()][he.side()] = true; last_border.emplace_back(sm.point(sm.source(he)).cast()); + + // In case of broken meshes, this loop might be infinite. Break + // out in case it is clearly going bad. + if (last_border.size() > 3*facets.size()) + goto PLANE_FAILURE; + } while (he != he_start); if (last_border.size() == 1) diff --git a/src/libslic3r/SurfaceMesh.hpp b/src/libslic3r/SurfaceMesh.hpp index 9e547eec49..93eb9fdaa6 100644 --- a/src/libslic3r/SurfaceMesh.hpp +++ b/src/libslic3r/SurfaceMesh.hpp @@ -4,6 +4,8 @@ #include #include +#include "boost/container/small_vector.hpp" + namespace Slic3r { class TriangleMesh; @@ -115,11 +117,18 @@ public: size_t degree(Vertex_index v) const { + // In case the mesh is broken badly, the loop might end up to be infinite, + // never getting back to the first halfedge. Remember list of all half-edges + // and trip if any is encountered for the second time. Halfedge_index h_first = halfedge(v); + boost::container::small_vector he_visited; Halfedge_index h = next_around_target(h_first); size_t degree = 2; while (! h.is_invalid() && h != h_first) { + he_visited.emplace_back(h); h = next_around_target(h); + if (std::find(he_visited.begin(), he_visited.end(), h) == he_visited.end()) + return 0; ++degree; } return h.is_invalid() ? 0 : degree - 1; From 8ef55ff82eabe498e0f08fe1cd7f02afedda20de Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 29 Nov 2022 11:13:09 +0100 Subject: [PATCH 076/109] Tech ENABLE_RAYCAST_PICKING_DEBUG - Extended data shown into debug imgui dialog --- src/slic3r/GUI/GLCanvas3D.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 345beb4434..9f2e7c0dad 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5542,12 +5542,17 @@ void GLCanvas3D::_picking_pass() default: { break; } } - auto add_strings_row_to_table = [&imgui](const std::string& col_1, const ImVec4& col_1_color, const std::string& col_2, const ImVec4& col_2_color) { + auto add_strings_row_to_table = [&imgui](const std::string& col_1, const ImVec4& col_1_color, const std::string& col_2, const ImVec4& col_2_color, + const std::string& col_3 = "", const ImVec4& col_3_color = ImGui::GetStyleColorVec4(ImGuiCol_Text)) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); imgui.text_colored(col_1_color, col_1.c_str()); ImGui::TableSetColumnIndex(1); imgui.text_colored(col_2_color, col_2.c_str()); + if (!col_3.empty()) { + ImGui::TableSetColumnIndex(2); + imgui.text_colored(col_3_color, col_3.c_str()); + } }; char buf[1024]; @@ -5576,6 +5581,21 @@ void GLCanvas3D::_picking_pass() add_strings_row_to_table("Gizmo elements", ImGuiWrapper::COL_ORANGE_LIGHT, std::string(buf), ImGui::GetStyleColorVec4(ImGuiCol_Text)); ImGui::EndTable(); } + + std::vector>* gizmo_raycasters = m_scene_raycaster.get_raycasters(SceneRaycaster::EType::Gizmo); + if (gizmo_raycasters != nullptr && !gizmo_raycasters->empty()) { + ImGui::Separator(); + imgui.text("Gizmo raycasters IDs:"); + if (ImGui::BeginTable("GizmoRaycasters", 3)) { + for (size_t i = 0; i < gizmo_raycasters->size(); ++i) { + add_strings_row_to_table(std::to_string(i), ImGuiWrapper::COL_ORANGE_LIGHT, + std::to_string(SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, (*gizmo_raycasters)[i]->get_id())), ImGui::GetStyleColorVec4(ImGuiCol_Text), + to_string(Geometry::Transformation((*gizmo_raycasters)[i]->get_transform()).get_offset()), ImGui::GetStyleColorVec4(ImGuiCol_Text)); + } + ImGui::EndTable(); + } + } + imgui.end(); #endif // ENABLE_RAYCAST_PICKING_DEBUG } From b45ae31af3be42f5b04dd0c6ea87cb0db505c044 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 30 Nov 2022 11:58:02 +0100 Subject: [PATCH 077/109] Gizmo measure - Modified circle and edge with extra point selection Fixed conflicts during rebase to master --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 510 ++++++++++++++--------- src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp | 18 +- 2 files changed, 320 insertions(+), 208 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 2de29087b8..43d55addda 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -20,15 +20,16 @@ namespace Slic3r { namespace GUI { -static const Slic3r::ColorRGBA SELECTED_1ST_COLOR = { 0.25f, 0.75f, 0.75f, 1.0f }; -static const Slic3r::ColorRGBA SELECTED_2ND_COLOR = { 0.75f, 0.25f, 0.75f, 1.0f }; +static const Slic3r::ColorRGBA SELECTED_1ST_COLOR = { 0.25f, 0.75f, 0.75f, 1.0f }; +static const Slic3r::ColorRGBA SELECTED_2ND_COLOR = { 0.75f, 0.25f, 0.75f, 1.0f }; +static const Slic3r::ColorRGBA NEUTRAL_COLOR = { 0.5f, 0.5f, 0.5f, 1.0f }; static const int POINT_ID = 100; static const int EDGE_ID = 200; static const int CIRCLE_ID = 300; static const int PLANE_ID = 400; -static const int SELECTION_1_ID = 501; -static const int SELECTION_2_ID = 502; +static const int SEL_SPHERE_1_ID = 501; +static const int SEL_SPHERE_2_ID = 502; static const float TRIANGLE_BASE = 10.0f; static const float TRIANGLE_HEIGHT = TRIANGLE_BASE * 1.618033f; @@ -164,6 +165,41 @@ static GLModel::Geometry init_torus_data(unsigned int primary_resolution, unsign return data; } +static bool is_feature_with_center(const Measure::SurfaceFeature& feature) +{ + const Measure::SurfaceFeatureType type = feature.get_type(); + return (type == Measure::SurfaceFeatureType::Circle || (type == Measure::SurfaceFeatureType::Edge && feature.get_extra_point().has_value())); +} + +static Vec3d get_feature_offset(const Measure::SurfaceFeature& feature) +{ + Vec3d ret; + switch (feature.get_type()) + { + case Measure::SurfaceFeatureType::Circle: + { + const auto [center, radius, normal] = feature.get_circle(); + ret = center; + break; + } + case Measure::SurfaceFeatureType::Edge: + { + std::optional p = feature.get_extra_point(); + assert(p.has_value()); + ret = *p; + break; + } + case Measure::SurfaceFeatureType::Point: + { + ret = feature.get_point(); + break; + } + default: { assert(false); } + } + + return ret; +} + class TransformHelper { struct Cache @@ -265,109 +301,125 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) // Ctrl is pressed or the mouse is not hovering a selected volume bool unlock_dragging = mouse_event.CmdDown() || (m_hover_id == -1 && !m_parent.get_selection().contains_volume(m_parent.get_first_hover_volume_idx())); // mode is not center selection or mouse is not hovering a center - unlock_dragging &= !mouse_event.ShiftDown() || (m_hover_id != SELECTION_1_ID && m_hover_id != SELECTION_2_ID && m_hover_id != POINT_ID); + unlock_dragging &= !mouse_event.ShiftDown() || (m_hover_id != SEL_SPHERE_1_ID && m_hover_id != SEL_SPHERE_2_ID && m_hover_id != POINT_ID); return !unlock_dragging; } else if (mouse_event.LeftDown()) { // let the event pass through to allow panning/rotating the 3D scene - if ((m_mode != EMode::CenterSelection && mouse_event.CmdDown()) || - (m_mode == EMode::CenterSelection && m_hover_id != SELECTION_1_ID && m_hover_id != SELECTION_2_ID && m_hover_id != POINT_ID)) { + if (mouse_event.CmdDown()) return false; - } if (m_hover_id != -1) { SelectedFeatures selected_features_old = m_selected_features; m_mouse_left_down = true; - auto item_from_feature = [this]() { + auto detect_current_item = [this]() { SelectedFeatures::Item item; - if (m_hover_id == SELECTION_1_ID && m_selected_features.first.feature.has_value()) - item = m_selected_features.first; - else if (m_hover_id == SELECTION_2_ID && m_selected_features.second.feature.has_value()) - item = m_selected_features.second; + if (m_hover_id == SEL_SPHERE_1_ID) { + if (m_selected_features.first.is_center) + // mouse is hovering over a selected center + item = { true, m_selected_features.first.source, { Measure::SurfaceFeature(get_feature_offset(*m_selected_features.first.source)) } }; + else if (is_feature_with_center(*m_selected_features.first.feature)) + // mouse is hovering over a unselected center + item = { true, m_selected_features.first.feature, { Measure::SurfaceFeature(get_feature_offset(*m_selected_features.first.feature)) } }; + else + // mouse is hovering over a point + item = m_selected_features.first; + } + else if (m_hover_id == SEL_SPHERE_2_ID) { + if (m_selected_features.second.is_center) + // mouse is hovering over a selected center + item = { true, m_selected_features.second.source, { Measure::SurfaceFeature(get_feature_offset(*m_selected_features.second.source)) } }; + else if (is_feature_with_center(*m_selected_features.second.feature)) + // mouse is hovering over a center + item = { true, m_selected_features.second.feature, { Measure::SurfaceFeature(get_feature_offset(*m_selected_features.second.feature)) } }; + else + // mouse is hovering over a point + item = m_selected_features.second; + } else { switch (m_mode) { - case EMode::FeatureSelection: - { - item = { surface_feature_type_as_string(m_curr_feature->get_type()), m_curr_feature }; - break; - } - case EMode::PointSelection: - { - item = { point_on_feature_type_as_string(m_curr_feature->get_type(), m_hover_id), Measure::SurfaceFeature(*m_curr_point_on_feature_position) }; - break; - } - case EMode::CenterSelection: - { - Vec3d position; - switch (m_curr_feature->get_type()) - { - case Measure::SurfaceFeatureType::Circle: - { - position = std::get<0>(m_curr_feature->get_circle()); - break; - } - case Measure::SurfaceFeatureType::Edge: - { - assert(m_curr_feature->get_extra_point().has_value()); - position = *m_curr_feature->get_extra_point(); - break; - } - default: { assert(false); break; } - } - - item = { center_on_feature_type_as_string(m_curr_feature->get_type()), Measure::SurfaceFeature(position) }; - break; - } + case EMode::FeatureSelection: { item = { false, m_curr_feature, m_curr_feature }; break; } + case EMode::PointSelection: { item = { false, m_curr_feature, Measure::SurfaceFeature(*m_curr_point_on_feature_position) }; break; } } } return item; }; - if (m_selected_features.first.feature.has_value()) { - auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), - [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_2_ID; }); - if (it != m_selection_raycasters.end()) - m_selection_raycasters.erase(it); - m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, SELECTION_2_ID); + auto requires_sphere_raycaster_for_picking = [this](const SelectedFeatures::Item& item) { + if (m_mode == EMode::PointSelection) + return true; + else if (m_mode == EMode::FeatureSelection) { + if (is_feature_with_center(*item.feature)) + return true; + } + return false; + }; - const SelectedFeatures::Item item = item_from_feature(); + if (m_selected_features.first.feature.has_value()) { + const SelectedFeatures::Item item = detect_current_item(); if (m_selected_features.first != item) { - if (m_selected_features.second == item) - m_selected_features.second.reset(); - else { - m_selected_features.second = item; - if (m_mode == EMode::PointSelection || m_mode == EMode::CenterSelection) - m_selection_raycasters.push_back(m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, SELECTION_2_ID, *m_sphere.mesh_raycaster)); - if (m_mode == EMode::CenterSelection) { - // Fake ctrl up event to exit the center selection mode - gizmo_event(SLAGizmoEventType::CtrlUp, Vec2d::Zero(), true, false, false); - // increase counter to avoid that keeping the ctrl key pressed triggers a ctrl down event - m_ctrl_kar_filter.increase_count(); + bool processed = false; + if (item.is_center) { + if (item.source == m_selected_features.first.feature) { + // switch 1st selection from feature to its center + m_selected_features.first = item; + processed = true; + } + else if (item.source == m_selected_features.second.feature) { + // switch 2nd selection from feature to its center + m_selected_features.second = item; + processed = true; + } + } + else if (is_feature_with_center(*item.feature)) { + if (m_selected_features.first.is_center && m_selected_features.first.source == item.feature) { + // switch 1st selection from center to its feature + m_selected_features.first = item; + processed = true; + } + else if (m_selected_features.second.is_center && m_selected_features.second.source == item.feature) { + // switch 2nd selection from center to its feature + m_selected_features.second = item; + processed = true; + } + } + + if (!processed) { + remove_selected_sphere_raycaster(SEL_SPHERE_2_ID); + if (m_selected_features.second == item) + // 2nd feature deselection + m_selected_features.second.reset(); + else { + // 2nd feature selection + m_selected_features.second = item; + if (requires_sphere_raycaster_for_picking(item)) + m_selected_sphere_raycasters.push_back(m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, SEL_SPHERE_2_ID, *m_sphere.mesh_raycaster)); } } } else { - if (!m_selected_features.second.feature.has_value()) - m_selected_features.first.reset(); - else { + remove_selected_sphere_raycaster(SEL_SPHERE_1_ID); + if (m_selected_features.second.feature.has_value()) { + // promote 2nd feature to 1st feature + remove_selected_sphere_raycaster(SEL_SPHERE_2_ID); m_selected_features.first = m_selected_features.second; + if (requires_sphere_raycaster_for_picking(m_selected_features.first)) + m_selected_sphere_raycasters.push_back(m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, SEL_SPHERE_1_ID, *m_sphere.mesh_raycaster)); m_selected_features.second.reset(); } + else + // 1st feature deselection + m_selected_features.first.reset(); } } else { - const SelectedFeatures::Item item = item_from_feature(); + // 1st feature selection + const SelectedFeatures::Item item = detect_current_item(); m_selected_features.first = item; - if (m_mode == EMode::PointSelection || m_mode == EMode::CenterSelection) - m_selection_raycasters.push_back(m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, SELECTION_1_ID, *m_sphere.mesh_raycaster)); - if (m_mode == EMode::CenterSelection) { - // Fake ctrl up event to exit the center selection mode - gizmo_event(SLAGizmoEventType::CtrlUp, Vec2d::Zero(), true, false, false); - // increase counter to avoid that keeping the ctrl key pressed triggers a ctrl down event - m_ctrl_kar_filter.increase_count(); - } + if (requires_sphere_raycaster_for_picking(item)) + m_selected_sphere_raycasters.push_back(m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, SEL_SPHERE_1_ID, *m_sphere.mesh_raycaster)); } if (m_selected_features != selected_features_old && m_selected_features.second.feature.has_value()) @@ -399,9 +451,8 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) } else if (mouse_event.RightDown()) { // let the event pass through to allow panning/rotating the 3D scene - if ((m_mode != EMode::CenterSelection && mouse_event.CmdDown()) || (m_mode == EMode::CenterSelection && m_hover_id != SELECTION_1_ID && m_hover_id != SELECTION_2_ID)) { + if (mouse_event.CmdDown()) return false; - } } else if (mouse_event.Leaving()) m_mouse_left_down = false; @@ -423,7 +474,7 @@ void GLGizmoMeasure::data_changed() } else m_selected_features.reset(); - m_selection_raycasters.clear(); + m_selected_sphere_raycasters.clear(); m_editing_distance = false; m_is_editing_distance_first_frame = true; } @@ -450,7 +501,7 @@ bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_po if (action == SLAGizmoEventType::ShiftDown) { if (m_shift_kar_filter.is_first()) { - m_mode = activate_center_selection(SLAGizmoEventType::ShiftDown) ? EMode::CenterSelection : EMode::PointSelection; + m_mode = EMode::PointSelection; disable_scene_raycasters(); } m_shift_kar_filter.increase_count(); @@ -460,33 +511,23 @@ bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_po m_mode = EMode::FeatureSelection; restore_scene_raycasters_state(); } - else if (action == SLAGizmoEventType::CtrlDown) { - if (m_ctrl_kar_filter.is_first()) { - if (activate_center_selection(SLAGizmoEventType::CtrlDown)) { - m_mode = EMode::CenterSelection; - disable_scene_raycasters(); - } - } - m_ctrl_kar_filter.increase_count(); - } - else if (action == SLAGizmoEventType::CtrlUp) { - m_ctrl_kar_filter.reset_count(); - m_mode = control_down ? EMode::PointSelection : EMode::FeatureSelection; - restore_scene_raycasters_state(); - } else if (action == SLAGizmoEventType::Delete) { m_selected_features.reset(); - m_selection_raycasters.clear(); + m_selected_sphere_raycasters.clear(); m_parent.request_extra_frame(); } else if (action == SLAGizmoEventType::Escape) { if (!m_selected_features.first.feature.has_value()) return false; else { - if (m_selected_features.second.feature.has_value()) - m_selected_features.second.feature.reset(); - else - m_selected_features.first.feature.reset(); + if (m_selected_features.second.feature.has_value()) { + remove_selected_sphere_raycaster(SEL_SPHERE_2_ID); + m_selected_features.second.feature.reset(); + } + else { + remove_selected_sphere_raycaster(SEL_SPHERE_1_ID); + m_selected_features.first.feature.reset(); + } } } @@ -503,7 +544,6 @@ void GLGizmoMeasure::on_set_state() { if (m_state == Off) { m_parent.toggle_sla_auxiliaries_visibility(true, nullptr, -1); - m_ctrl_kar_filter.reset_count(); m_shift_kar_filter.reset_count(); m_curr_feature.reset(); m_curr_point_on_feature_position.reset(); @@ -566,7 +606,7 @@ void GLGizmoMeasure::on_render() Vec3f normal_on_model; size_t model_facet_idx; const bool mouse_on_object = m_raycaster->unproject_on_mesh(m_mouse_pos, Transform3d::Identity(), camera, position_on_model, normal_on_model, nullptr, &model_facet_idx); - const bool is_hovering_on_feature = (m_mode == EMode::PointSelection || m_mode == EMode::CenterSelection) && m_hover_id != -1; + const bool is_hovering_on_feature = m_mode == EMode::PointSelection && m_hover_id != -1; auto update_circle = [this, inv_zoom]() { if (m_last_inv_zoom != inv_zoom || m_last_circle != m_curr_feature) { @@ -583,14 +623,13 @@ void GLGizmoMeasure::on_render() }; if (m_mode == EMode::FeatureSelection || m_mode == EMode::PointSelection) { - if ((m_hover_id == SELECTION_1_ID && boost::algorithm::istarts_with(m_selected_features.first.source, _u8L("Center"))) || - (m_hover_id == SELECTION_2_ID && boost::algorithm::istarts_with(m_selected_features.second.source, _u8L("Center")))) { - // Skip feature detection if hovering on a selected center - m_curr_feature.reset(); + if (m_hover_id == SEL_SPHERE_1_ID || m_hover_id == SEL_SPHERE_2_ID) { + // Skip feature detection if hovering on a selected point/center m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID); m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID); m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, PLANE_ID); m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID); + m_curr_feature.reset(); m_curr_point_on_feature_position.reset(); } else { @@ -618,15 +657,12 @@ void GLGizmoMeasure::on_render() case Measure::SurfaceFeatureType::Edge: { m_raycasters.insert({ EDGE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID, *m_cylinder.mesh_raycaster) }); - if (m_curr_feature->get_extra_point().has_value()) - m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); break; } case Measure::SurfaceFeatureType::Circle: { update_circle(); m_raycasters.insert({ CIRCLE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID, *m_circle.mesh_raycaster) }); - m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) }); break; } case Measure::SurfaceFeatureType::Plane: @@ -781,72 +817,69 @@ void GLGizmoMeasure::on_render() case Measure::SurfaceFeatureType::Circle: { const auto& [center, radius, normal] = feature.get_circle(); - // render center + // render circle + const Transform3d circle_matrix = Transform3d::Identity(); + set_matrix_uniforms(circle_matrix); if (update_raycasters_transform) { + set_emission_uniform(colors.front(), hover); + m_circle.model.set_color(colors.front()); + m_circle.model.render(); + auto it = m_raycasters.find(CIRCLE_ID); + if (it != m_raycasters.end() && it->second != nullptr) + it->second->set_transform(circle_matrix); + } + else { + GLModel circle; + GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); + circle.init_from(std::move(circle_geometry)); + set_emission_uniform(colors.front(), hover); + circle.set_color(colors.front()); + circle.render(); + } + // render center + if (colors.size() > 1) { const Transform3d center_matrix = Geometry::translation_transform(center) * Geometry::scale_transform(inv_zoom); set_matrix_uniforms(center_matrix); - set_emission_uniform(colors.front(), hover); - m_sphere.model.set_color(colors.front()); + set_emission_uniform(colors.back(), hover); + m_sphere.model.set_color(colors.back()); m_sphere.model.render(); auto it = m_raycasters.find(POINT_ID); if (it != m_raycasters.end() && it->second != nullptr) it->second->set_transform(center_matrix); } - // render circle - if (m_mode != EMode::CenterSelection) { - const Transform3d circle_matrix = Transform3d::Identity(); - set_matrix_uniforms(circle_matrix); - if (update_raycasters_transform) { - set_emission_uniform(colors.back(), hover); - m_circle.model.set_color(colors.back()); - m_circle.model.render(); - auto it = m_raycasters.find(CIRCLE_ID); - if (it != m_raycasters.end() && it->second != nullptr) - it->second->set_transform(circle_matrix); - } - else { - GLModel circle; - GLModel::Geometry circle_geometry = init_torus_data(64, 16, center.cast(), float(radius), 5.0f * inv_zoom, normal.cast(), Transform3f::Identity()); - circle.init_from(std::move(circle_geometry)); - set_emission_uniform(colors.back(), hover); - circle.set_color(colors.back()); - circle.render(); - } - } break; } case Measure::SurfaceFeatureType::Edge: { const auto& [from, to] = feature.get_edge(); - // render extra point + // render edge + const Transform3d edge_matrix = Geometry::translation_transform(from) * + Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), to - from) * + Geometry::scale_transform({ (double)inv_zoom, (double)inv_zoom, (to - from).norm() }); + set_matrix_uniforms(edge_matrix); + set_emission_uniform(colors.front(), hover); + m_cylinder.model.set_color(colors.front()); + m_cylinder.model.render(); if (update_raycasters_transform) { + auto it = m_raycasters.find(EDGE_ID); + if (it != m_raycasters.end() && it->second != nullptr) + it->second->set_transform(edge_matrix); + } + + // render extra point + if (colors.size() > 1) { const std::optional extra = feature.get_extra_point(); if (extra.has_value()) { const Transform3d point_matrix = Geometry::translation_transform(*extra) * Geometry::scale_transform(inv_zoom); set_matrix_uniforms(point_matrix); - set_emission_uniform(colors.front(), hover); - m_sphere.model.set_color(colors.front()); + set_emission_uniform(colors.back(), hover); + m_sphere.model.set_color(colors.back()); m_sphere.model.render(); auto it = m_raycasters.find(POINT_ID); if (it != m_raycasters.end() && it->second != nullptr) it->second->set_transform(point_matrix); } } - // render edge - if (m_mode != EMode::CenterSelection) { - const Transform3d edge_matrix = Geometry::translation_transform(from) * - Eigen::Quaternion::FromTwoVectors(Vec3d::UnitZ(), to - from) * - Geometry::scale_transform({ (double)inv_zoom, (double)inv_zoom, (to - from).norm() }); - set_matrix_uniforms(edge_matrix); - set_emission_uniform(colors.back(), hover); - m_cylinder.model.set_color(colors.back()); - m_cylinder.model.render(); - if (update_raycasters_transform) { - auto it = m_raycasters.find(EDGE_ID); - if (it != m_raycasters.end() && it->second != nullptr) - it->second->set_transform(edge_matrix); - } - } break; } case Measure::SurfaceFeatureType::Plane: @@ -881,11 +914,31 @@ void GLGizmoMeasure::on_render() }; if (m_curr_feature.has_value()) { + // render hovered feature + std::vector colors; - if (m_selected_features.first.feature.has_value() && *m_curr_feature == *m_selected_features.first.feature) - colors.emplace_back(hovering_color()); - else if (m_selected_features.second.feature.has_value() && *m_curr_feature == *m_selected_features.second.feature) - colors.emplace_back(hovering_color()); + if (m_selected_features.first.feature.has_value() && *m_curr_feature == *m_selected_features.first.feature) { + // hovering over the 1st selected feature + if (m_selected_features.first.is_center) + // hovering over a center + colors = { NEUTRAL_COLOR, hovering_color() }; + else if (is_feature_with_center(*m_selected_features.first.feature)) + // hovering over a feature with center + colors = { hovering_color(), NEUTRAL_COLOR }; + else + colors = { hovering_color() }; + } + else if (m_selected_features.second.feature.has_value() && *m_curr_feature == *m_selected_features.second.feature) { + // hovering over the 2nd selected feature + if (m_selected_features.second.is_center) + // hovering over a center + colors = { NEUTRAL_COLOR, hovering_color() }; + else if (is_feature_with_center(*m_selected_features.second.feature)) + // hovering over a feature with center + colors = { hovering_color(), NEUTRAL_COLOR }; + else + colors = { hovering_color() }; + } else { switch (m_curr_feature->get_type()) { @@ -898,8 +951,12 @@ void GLGizmoMeasure::on_render() case Measure::SurfaceFeatureType::Edge: case Measure::SurfaceFeatureType::Circle: { - colors.emplace_back((m_hover_id == POINT_ID) ? hover_selection_color() : hovering_color()); - colors.emplace_back(hovering_color()); + if (m_selected_features.first.is_center && m_curr_feature == m_selected_features.first.source) + colors = { SELECTED_1ST_COLOR, NEUTRAL_COLOR }; + else if (m_selected_features.second.is_center && m_curr_feature == m_selected_features.second.source) + colors = { SELECTED_2ND_COLOR, NEUTRAL_COLOR }; + else + colors = { hovering_color(), hovering_color() }; break; } case Measure::SurfaceFeatureType::Plane: @@ -914,28 +971,76 @@ void GLGizmoMeasure::on_render() } if (m_selected_features.first.feature.has_value() && (!m_curr_feature.has_value() || *m_curr_feature != *m_selected_features.first.feature)) { - const std::vector colors = { SELECTED_1ST_COLOR }; - render_feature(*m_selected_features.first.feature, colors, inv_zoom, m_hover_id == SELECTION_1_ID, false); - if (m_selected_features.first.feature->get_type() == Measure::SurfaceFeatureType::Point) { - auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), - [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_1_ID; }); - if (it != m_selection_raycasters.end()) - (*it)->set_transform(Geometry::translation_transform(m_selected_features.first.feature->get_point()) * Geometry::scale_transform(inv_zoom)); + // render 1st selected feature + + std::optional feature_to_render; + std::vector colors; + bool requires_raycaster_update = false; + if (m_hover_id == SEL_SPHERE_1_ID && (m_selected_features.first.is_center || is_feature_with_center(*m_selected_features.first.feature))) { + // hovering over a center + feature_to_render = m_selected_features.first.source; + colors = { NEUTRAL_COLOR, SELECTED_1ST_COLOR }; + requires_raycaster_update = true; + } + else if (is_feature_with_center(*m_selected_features.first.feature)) { + // hovering over a feature with center + feature_to_render = m_selected_features.first.feature; + colors = { SELECTED_1ST_COLOR, NEUTRAL_COLOR }; + requires_raycaster_update = true; + } + else { + feature_to_render = m_selected_features.first.feature; + colors = { SELECTED_1ST_COLOR }; + requires_raycaster_update = m_selected_features.first.feature->get_type() == Measure::SurfaceFeatureType::Point; + } + + render_feature(*feature_to_render, colors, inv_zoom, m_hover_id == SEL_SPHERE_1_ID, false); + + if (requires_raycaster_update) { + auto it = std::find_if(m_selected_sphere_raycasters.begin(), m_selected_sphere_raycasters.end(), + [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SEL_SPHERE_1_ID; }); + if (it != m_selected_sphere_raycasters.end()) + (*it)->set_transform(Geometry::translation_transform(get_feature_offset(*m_selected_features.first.feature)) * Geometry::scale_transform(inv_zoom)); } } + if (m_selected_features.second.feature.has_value() && (!m_curr_feature.has_value() || *m_curr_feature != *m_selected_features.second.feature)) { - const std::vector colors = { SELECTED_2ND_COLOR }; - render_feature(*m_selected_features.second.feature, colors, inv_zoom, m_hover_id == SELECTION_2_ID, false); - if (m_selected_features.second.feature->get_type() == Measure::SurfaceFeatureType::Point) { - auto it = std::find_if(m_selection_raycasters.begin(), m_selection_raycasters.end(), - [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SELECTION_2_ID; }); - if (it != m_selection_raycasters.end()) - (*it)->set_transform(Geometry::translation_transform(m_selected_features.second.feature->get_point()) * Geometry::scale_transform(inv_zoom)); + // render 2nd selected feature + + std::optional feature_to_render; + std::vector colors; + bool requires_raycaster_update = false; + if (m_hover_id == SEL_SPHERE_2_ID && (m_selected_features.second.is_center || is_feature_with_center(*m_selected_features.second.feature))) { + // hovering over a center + feature_to_render = m_selected_features.second.source; + colors = { NEUTRAL_COLOR, SELECTED_2ND_COLOR }; + requires_raycaster_update = true; + } + else if (is_feature_with_center(*m_selected_features.second.feature)) { + // hovering over a feature with center + feature_to_render = m_selected_features.second.feature; + colors = { SELECTED_2ND_COLOR, NEUTRAL_COLOR }; + requires_raycaster_update = true; + } + else { + feature_to_render = m_selected_features.second.feature; + colors = { SELECTED_2ND_COLOR }; + requires_raycaster_update = m_selected_features.second.feature->get_type() == Measure::SurfaceFeatureType::Point; + } + + render_feature(*feature_to_render, colors, inv_zoom, m_hover_id == SEL_SPHERE_2_ID, false); + + if (requires_raycaster_update) { + auto it = std::find_if(m_selected_sphere_raycasters.begin(), m_selected_sphere_raycasters.end(), + [](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == SEL_SPHERE_2_ID; }); + if (it != m_selected_sphere_raycasters.end()) + (*it)->set_transform(Geometry::translation_transform(get_feature_offset(*m_selected_features.second.feature)) * Geometry::scale_transform(inv_zoom)); } } if (is_hovering_on_feature && m_curr_point_on_feature_position.has_value()) { if (m_hover_id != POINT_ID) { + // render point on feature while SHIFT is pressed const Transform3d matrix = Geometry::translation_transform(*m_curr_point_on_feature_position) * Geometry::scale_transform(inv_zoom); set_matrix_uniforms(matrix); const ColorRGBA color = hover_selection_color(); @@ -1600,7 +1705,8 @@ static void add_strings_row_to_table(ImGuiWrapper& imgui, const std::string& col void GLGizmoMeasure::render_debug_dialog() { auto add_feature_data = [this](const SelectedFeatures::Item& item) { - add_strings_row_to_table(*m_imgui, "Type", ImGuiWrapper::COL_ORANGE_LIGHT, item.source, ImGui::GetStyleColorVec4(ImGuiCol_Text)); + const std::string text = (item.source == item.feature) ? surface_feature_type_as_string(item.feature->get_type()) : point_on_feature_type_as_string(item.source->get_type(), m_hover_id); + add_strings_row_to_table(*m_imgui, "Type", ImGuiWrapper::COL_ORANGE_LIGHT, text, ImGui::GetStyleColorVec4(ImGuiCol_Text)); switch (item.feature->get_type()) { case Measure::SurfaceFeatureType::Point: @@ -1646,7 +1752,6 @@ void GLGizmoMeasure::render_debug_dialog() { case EMode::FeatureSelection: { txt = "Feature selection"; break; } case EMode::PointSelection: { txt = "Point selection"; break; } - case EMode::CenterSelection: { txt = "Center selection"; break; } default: { assert(false); break; } } add_strings_row_to_table(*m_imgui, "Mode", ImGuiWrapper::COL_ORANGE_LIGHT, txt, ImGui::GetStyleColorVec4(ImGuiCol_Text)); @@ -1730,17 +1835,16 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit text = _u8L("Unselect feature"); color = SELECTED_2ND_COLOR; } - else if (m_hover_id == SELECTION_1_ID) { - text = (m_mode == EMode::CenterSelection) ? _u8L("Unselect center") : _u8L("Unselect point"); + else if (m_hover_id == SEL_SPHERE_1_ID) { + text = _u8L("Unselect point"); color = SELECTED_1ST_COLOR; } - else if (m_hover_id == SELECTION_2_ID) { - text = (m_mode == EMode::CenterSelection) ? _u8L("Unselect center") : _u8L("Unselect point"); + else if (m_hover_id == SEL_SPHERE_2_ID) { + text = _u8L("Unselect point"); color = SELECTED_2ND_COLOR; } else { - text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : - (m_mode == EMode::CenterSelection) ? _u8L("Select center") : _u8L("Select feature"); + text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : _u8L("Select feature"); color = SELECTED_2ND_COLOR; } } @@ -1750,14 +1854,13 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit text = _u8L("Unselect feature"); color = SELECTED_1ST_COLOR; } - else if (m_hover_id == SELECTION_1_ID) { - text = (m_mode == EMode::CenterSelection) ? _u8L("Unselect center") : _u8L("Unselect point"); + else if (m_hover_id == SEL_SPHERE_1_ID) { + text = _u8L("Unselect point"); color = SELECTED_1ST_COLOR; } } if (text.empty()) { - text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : - (m_mode == EMode::CenterSelection) ? _u8L("Select center") : _u8L("Select feature"); + text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : _u8L("Select feature"); color = m_selected_features.first.feature.has_value() ? SELECTED_2ND_COLOR : SELECTED_1ST_COLOR; } } @@ -1776,11 +1879,6 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit ++row_count; } - if (m_mode != EMode::CenterSelection && feature_has_center(m_curr_feature)) { - add_strings_row_to_table(*m_imgui, _u8L("Shift") + "+" + CTRL_STR, ImGuiWrapper::COL_ORANGE_LIGHT, _u8L("Enable center selection"), ImGui::GetStyleColorVec4(ImGuiCol_Text)); - ++row_count; - } - if (m_selected_features.first.feature.has_value()) { add_strings_row_to_table(*m_imgui, _u8L("Delete"), ImGuiWrapper::COL_ORANGE_LIGHT, _u8L("Restart selection"), ImGui::GetStyleColorVec4(ImGuiCol_Text)); ++row_count; @@ -1806,7 +1904,7 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit } // add dummy rows to keep dialog size fixed - for (unsigned int i = row_count; i < 5; ++i) { + for (unsigned int i = row_count; i < 4; ++i) { add_strings_row_to_table(*m_imgui, " ", ImGuiWrapper::COL_ORANGE_LIGHT, " ", ImGui::GetStyleColorVec4(ImGuiCol_Text)); } @@ -1819,17 +1917,20 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit ImGui::Separator(); const ImGuiTableFlags flags = ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersH; if (ImGui::BeginTable("Selection", 2, flags)) { - auto format_item_text = [use_inches, &units](const SelectedFeatures::Item& item) { - std::string txt = item.feature.has_value() ? item.source : _u8L("None"); - if (item.feature.has_value() && item.feature->get_type() == Measure::SurfaceFeatureType::Circle) { - auto [center, radius, normal] = item.feature->get_circle(); - const Vec3d on_circle = center + radius * Measure::get_orthogonal(normal, true); - radius = (on_circle - center).norm(); - if (use_inches) - radius = ObjectManipulation::mm_to_in * radius; - txt += " (" + _u8L("Diameter:") + " " + format_double(2.0 * radius) + units + ")"; - } - return txt; + auto format_item_text = [this, use_inches, &units](const SelectedFeatures::Item& item) { + if (!item.feature.has_value()) + return _u8L("None"); + + std::string text = (item.source == item.feature) ? surface_feature_type_as_string(item.feature->get_type()) : point_on_feature_type_as_string(item.source->get_type(), m_hover_id); + if (item.feature.has_value() && item.feature->get_type() == Measure::SurfaceFeatureType::Circle) { + auto [center, radius, normal] = item.feature->get_circle(); + const Vec3d on_circle = center + radius * Measure::get_orthogonal(normal, true); + radius = (on_circle - center).norm(); + if (use_inches) + radius = ObjectManipulation::mm_to_in * radius; + text += " (" + _u8L("Diameter:") + " " + format_double(2.0 * radius) + units + ")"; + } + return text; }; add_strings_row_to_table(*m_imgui, _u8L("Selection") + " 1:", ImGuiWrapper::to_ImVec4(SELECTED_1ST_COLOR), format_item_text(m_selected_features.first), @@ -1842,7 +1943,7 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit m_imgui->disabled_begin(!m_selected_features.first.feature.has_value()); if (m_imgui->button(_u8L("Restart selection"))) { m_selected_features.reset(); - m_selection_raycasters.clear(); + m_selected_sphere_raycasters.clear(); m_imgui->set_requires_extra_frame(); } m_imgui->disabled_end(); @@ -1938,7 +2039,16 @@ void GLGizmoMeasure::on_unregister_raycasters_for_picking() m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo); m_parent.set_raycaster_gizmos_on_top(false); m_raycasters.clear(); - m_selection_raycasters.clear(); + m_selected_sphere_raycasters.clear(); +} + +void GLGizmoMeasure::remove_selected_sphere_raycaster(int id) +{ + auto it = std::find_if(m_selected_sphere_raycasters.begin(), m_selected_sphere_raycasters.end(), + [id](std::shared_ptr item) { return SceneRaycaster::decode_id(SceneRaycaster::EType::Gizmo, item->get_id()) == id; }); + if (it != m_selected_sphere_raycasters.end()) + m_selected_sphere_raycasters.erase(it); + m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, id); } } // namespace GUI diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp index 1672e8b74e..1e4330e955 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp @@ -24,20 +24,19 @@ class GLGizmoMeasure : public GLGizmoBase enum class EMode : unsigned char { FeatureSelection, - PointSelection, - CenterSelection + PointSelection }; struct SelectedFeatures { struct Item { - std::string source; + bool is_center{ false }; + std::optional source; std::optional feature; bool operator == (const Item& other) const { - if (this->source != other.source) return false; - return this->feature == other.feature; + return this->is_center == other.is_center && this->source == other.source && this->feature == other.feature; } bool operator != (const Item& other) const { @@ -45,7 +44,8 @@ class GLGizmoMeasure : public GLGizmoBase } void reset() { - source.clear(); + is_center = false; + source.reset(); feature.reset(); } }; @@ -106,7 +106,8 @@ class GLGizmoMeasure : public GLGizmoBase std::vector m_plane_models_cache; std::map> m_raycasters; - std::vector> m_selection_raycasters; + // used to keep the raycasters for point/center spheres + std::vector> m_selected_sphere_raycasters; std::optional m_curr_feature; std::optional m_curr_point_on_feature_position; struct SceneRaycasterState @@ -126,7 +127,6 @@ class GLGizmoMeasure : public GLGizmoBase Vec2d m_mouse_pos{ Vec2d::Zero() }; - KeyAutoRepeatFilter m_ctrl_kar_filter; KeyAutoRepeatFilter m_shift_kar_filter; SelectedFeatures m_selected_features; @@ -174,6 +174,8 @@ protected: virtual void on_render_input_window(float x, float y, float bottom_limit) override; virtual void on_register_raycasters_for_picking() override; virtual void on_unregister_raycasters_for_picking() override; + + void remove_selected_sphere_raycaster(int id); }; } // namespace GUI From 93a3ee501980c70e0a3805fe798c0392c601b24f Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 30 Nov 2022 12:51:37 +0100 Subject: [PATCH 078/109] Gizmo measure - Show radius of single selected circle, to allow for object scaling --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 105 ++++++++++++++--------- src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp | 1 + 2 files changed, 67 insertions(+), 39 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 43d55addda..27051a8e6d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -422,8 +422,7 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) m_selected_sphere_raycasters.push_back(m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, SEL_SPHERE_1_ID, *m_sphere.mesh_raycaster)); } - if (m_selected_features != selected_features_old && m_selected_features.second.feature.has_value()) - m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); + update_measurement_result(); m_imgui->set_requires_extra_frame(); @@ -469,7 +468,7 @@ void GLGizmoMeasure::data_changed() m_last_inv_zoom = 0.0f; m_last_plane_idx = -1; if (m_pending_scale) { - m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); + update_measurement_result(); m_pending_scale = false; } else @@ -517,8 +516,10 @@ bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_po m_parent.request_extra_frame(); } else if (action == SLAGizmoEventType::Escape) { - if (!m_selected_features.first.feature.has_value()) + if (!m_selected_features.first.feature.has_value()) { + update_measurement_result(); return false; + } else { if (m_selected_features.second.feature.has_value()) { remove_selected_sphere_raycaster(SEL_SPHERE_2_ID); @@ -528,6 +529,8 @@ bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_po remove_selected_sphere_raycaster(SEL_SPHERE_1_ID); m_selected_features.first.feature.reset(); } + + update_measurement_result(); } } @@ -1135,7 +1138,10 @@ void GLGizmoMeasure::render_dimensioning() { static SelectedFeatures last_selected_features; - if (!m_selected_features.first.feature.has_value() || !m_selected_features.second.feature.has_value()) + if (!m_selected_features.first.feature.has_value()) + return; + + if (!m_selected_features.second.feature.has_value() && m_selected_features.first.feature->get_type() != Measure::SurfaceFeatureType::Circle) return; GLShaderProgram* shader = wxGetApp().get_shader("flat"); @@ -1343,7 +1349,8 @@ void GLGizmoMeasure::render_dimensioning() const Vec3d new_center = selection.get_bounding_box().center(); const TrafoData trafo_data(ratio, old_center, new_center); scale_feature(*m_selected_features.first.feature, trafo_data); - scale_feature(*m_selected_features.second.feature, trafo_data); + if (m_selected_features.second.feature.has_value()) + scale_feature(*m_selected_features.second.feature, trafo_data); // update measure on next call to data_changed() m_pending_scale = true; @@ -1646,41 +1653,51 @@ void GLGizmoMeasure::render_dimensioning() glsafe(::glDisable(GL_DEPTH_TEST)); - if (m_selected_features.second.feature.has_value()) { - const bool has_distance = m_measurement_result.has_distance_data(); + const bool has_distance = m_measurement_result.has_distance_data(); - const Measure::SurfaceFeature* f1 = &(*m_selected_features.first.feature); - const Measure::SurfaceFeature* f2 = &(*m_selected_features.second.feature); - Measure::SurfaceFeatureType ft1 = f1->get_type(); - Measure::SurfaceFeatureType ft2 = f2->get_type(); - - // Order features by type so following conditions are simple. - if (ft1 > ft2) { - std::swap(ft1, ft2); - std::swap(f1, f2); - } - - // If there is an angle to show, draw the arc: - if (ft1 == Measure::SurfaceFeatureType::Edge && ft2 == Measure::SurfaceFeatureType::Edge) - arc_edge_edge(*f1, *f2); - else if (ft1 == Measure::SurfaceFeatureType::Edge && ft2 == Measure::SurfaceFeatureType::Plane) - arc_edge_plane(*f1, *f2); - else if (ft1 == Measure::SurfaceFeatureType::Plane && ft2 == Measure::SurfaceFeatureType::Plane) - arc_plane_plane(*f1, *f2); - - if (has_distance){ - // Where needed, draw the extension of the edge to where the dist is measured: - if (ft1 == Measure::SurfaceFeatureType::Point && ft2 == Measure::SurfaceFeatureType::Edge) - point_edge(*f1, *f2); - - // Render the arrow between the points that the backend passed: - const Measure::DistAndPoints& dap = m_measurement_result.distance_infinite.has_value() - ? *m_measurement_result.distance_infinite - : *m_measurement_result.distance_strict; - point_point(dap.from, dap.to, dap.dist); - } + const Measure::SurfaceFeature* f1 = &(*m_selected_features.first.feature); + const Measure::SurfaceFeature* f2 = nullptr; + std::unique_ptr temp_feature; + if (m_selected_features.second.feature.has_value()) + f2 = &(*m_selected_features.second.feature); + else { + assert(m_selected_features.first.feature->get_type() == Measure::SurfaceFeatureType::Circle); + temp_feature = std::make_unique(std::get<0>(m_selected_features.first.feature->get_circle())); + f2 = temp_feature.get(); } - + + if (!m_selected_features.second.feature.has_value() && m_selected_features.first.feature->get_type() != Measure::SurfaceFeatureType::Circle) + return; + + Measure::SurfaceFeatureType ft1 = f1->get_type(); + Measure::SurfaceFeatureType ft2 = f2->get_type(); + + // Order features by type so following conditions are simple. + if (ft1 > ft2) { + std::swap(ft1, ft2); + std::swap(f1, f2); + } + + // If there is an angle to show, draw the arc: + if (ft1 == Measure::SurfaceFeatureType::Edge && ft2 == Measure::SurfaceFeatureType::Edge) + arc_edge_edge(*f1, *f2); + else if (ft1 == Measure::SurfaceFeatureType::Edge && ft2 == Measure::SurfaceFeatureType::Plane) + arc_edge_plane(*f1, *f2); + else if (ft1 == Measure::SurfaceFeatureType::Plane && ft2 == Measure::SurfaceFeatureType::Plane) + arc_plane_plane(*f1, *f2); + + if (has_distance){ + // Where needed, draw the extension of the edge to where the dist is measured: + if (ft1 == Measure::SurfaceFeatureType::Point && ft2 == Measure::SurfaceFeatureType::Edge) + point_edge(*f1, *f2); + + // Render the arrow between the points that the backend passed: + const Measure::DistAndPoints& dap = m_measurement_result.distance_infinite.has_value() + ? *m_measurement_result.distance_infinite + : *m_measurement_result.distance_strict; + point_point(dap.from, dap.to, dap.dist); + } + glsafe(::glEnable(GL_DEPTH_TEST)); shader->stop_using(); @@ -2051,5 +2068,15 @@ void GLGizmoMeasure::remove_selected_sphere_raycaster(int id) m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, id); } +void GLGizmoMeasure::update_measurement_result() +{ + if (!m_selected_features.first.feature.has_value()) + m_measurement_result = Measure::MeasurementResult(); + else if (m_selected_features.second.feature.has_value()) + m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); + else if (!m_selected_features.second.feature.has_value() && m_selected_features.first.feature->get_type() == Measure::SurfaceFeatureType::Circle) + m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, Measure::SurfaceFeature(std::get<0>(m_selected_features.first.feature->get_circle())), m_measuring.get()); +} + } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp index 1e4330e955..4652a171b7 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp @@ -176,6 +176,7 @@ protected: virtual void on_unregister_raycasters_for_picking() override; void remove_selected_sphere_raycaster(int id); + void update_measurement_result(); }; } // namespace GUI From 6533eb2a53edf28313bd07da0526b66cbd0e9c60 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 30 Nov 2022 13:04:48 +0100 Subject: [PATCH 079/109] Fixed warnings --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 27051a8e6d..c1e153c886 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -487,17 +487,6 @@ static bool feature_has_center(std::optional feature) bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down) { - auto activate_center_selection = [this, shift_down, control_down](SLAGizmoEventType action) { - bool ret = false; - switch (action) - { - case SLAGizmoEventType::CtrlDown: { ret = shift_down && feature_has_center(m_curr_feature); break; } - case SLAGizmoEventType::ShiftDown: { ret = control_down && feature_has_center(m_curr_feature); break; } - default: { break; } - } - return ret; - }; - if (action == SLAGizmoEventType::ShiftDown) { if (m_shift_kar_filter.is_first()) { m_mode = EMode::PointSelection; @@ -598,8 +587,6 @@ void GLGizmoMeasure::on_render() // if (m_parent.is_mouse_dragging()) // return; - const Selection& selection = m_parent.get_selection(); - update_if_needed(); const Camera& camera = wxGetApp().plater()->get_camera(); From f0811873563e1d7f2923dccb4e7a7d4ff5f7ec71 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 30 Nov 2022 13:07:49 +0100 Subject: [PATCH 080/109] Fixed warning --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index c1e153c886..bf321bb785 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -310,7 +310,6 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) return false; if (m_hover_id != -1) { - SelectedFeatures selected_features_old = m_selected_features; m_mouse_left_down = true; auto detect_current_item = [this]() { From 220104dbe22dde4a82a4d84b5bef63bed2178a6a Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 1 Dec 2022 12:47:06 +0100 Subject: [PATCH 081/109] Measure gizmo - Fixed sychronization of imgui dialog with current hovering/selection state --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 94 +++++++++++++++++++++--- 1 file changed, 82 insertions(+), 12 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index bf321bb785..1ddd805b71 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1831,22 +1831,61 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit ColorRGBA color; if (m_selected_features.second.feature.has_value()) { if (m_selected_features.first.feature == m_curr_feature && m_mode == EMode::FeatureSelection) { + // hovering over 1st selected feature text = _u8L("Unselect feature"); color = SELECTED_1ST_COLOR; } + else if (m_hover_id == SEL_SPHERE_1_ID) { + if (m_selected_features.first.is_center) { + // hovering over center selected as 1st feature + text = _u8L("Unselect center"); + color = SELECTED_1ST_COLOR; + } + else if (is_feature_with_center(*m_selected_features.first.feature)) { + // hovering over center of 1st selected feature + text = _u8L("Select center"); + color = SELECTED_1ST_COLOR; + } + else { + // hovering over point selected as 1st feature + text = _u8L("Unselect point"); + color = SELECTED_1ST_COLOR; + } + } + else if (m_selected_features.first.is_center && m_selected_features.first.source == m_curr_feature) { + // hovering over feature whose center is selected as 1st feature + text = _u8L("Select feature"); + color = SELECTED_1ST_COLOR; + } else if (m_selected_features.second.feature == m_curr_feature && m_mode == EMode::FeatureSelection) { + // hovering over 2nd selected feature text = _u8L("Unselect feature"); color = SELECTED_2ND_COLOR; } - else if (m_hover_id == SEL_SPHERE_1_ID) { - text = _u8L("Unselect point"); - color = SELECTED_1ST_COLOR; - } else if (m_hover_id == SEL_SPHERE_2_ID) { - text = _u8L("Unselect point"); + if (m_selected_features.second.is_center) { + // hovering over center selected as 2nd feature + text = _u8L("Unselect feature"); + color = SELECTED_2ND_COLOR; + } + else if (is_feature_with_center(*m_selected_features.second.feature)) { + // hovering over center of 2nd selected feature + text = _u8L("Select center"); + color = SELECTED_2ND_COLOR; + } + else { + // hovering over point selected as 2nd feature + text = _u8L("Unselect point"); + color = SELECTED_2ND_COLOR; + } + } + else if (m_selected_features.second.is_center && m_selected_features.second.source == m_curr_feature) { + // hovering over feature whose center is selected as 2nd feature + text = _u8L("Select feature"); color = SELECTED_2ND_COLOR; } else { + // 1st feature selected text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : _u8L("Select feature"); color = SELECTED_2ND_COLOR; } @@ -1854,20 +1893,51 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit else { if (m_selected_features.first.feature.has_value()) { if (m_selected_features.first.feature == m_curr_feature && m_mode == EMode::FeatureSelection) { + // hovering over 1st selected feature text = _u8L("Unselect feature"); color = SELECTED_1ST_COLOR; } - else if (m_hover_id == SEL_SPHERE_1_ID) { - text = _u8L("Unselect point"); - color = SELECTED_1ST_COLOR; + else { + if (m_hover_id == SEL_SPHERE_1_ID) { + if (m_selected_features.first.is_center) { + // hovering over center selected as 1st feature + text = _u8L("Unselect feature"); + color = SELECTED_1ST_COLOR; + } + else if (is_feature_with_center(*m_selected_features.first.feature)) { + // hovering over center of 1st selected feature + text = _u8L("Select center"); + color = SELECTED_1ST_COLOR; + } + else { + // hovering over point selected as 1st feature + text = _u8L("Unselect point"); + color = SELECTED_1ST_COLOR; + } + } + else { + if (m_selected_features.first.is_center && m_selected_features.first.source == m_curr_feature) { + // hovering over feature whose center is selected as 1st feature + text = _u8L("Select feature"); + color = SELECTED_1ST_COLOR; + } + else { + // 1st feature selected + text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : _u8L("Select feature"); + color = SELECTED_2ND_COLOR; + } + } } } - if (text.empty()) { + else { + // nothing is selected text = (m_mode == EMode::PointSelection) ? _u8L("Select point") : _u8L("Select feature"); - color = m_selected_features.first.feature.has_value() ? SELECTED_2ND_COLOR : SELECTED_1ST_COLOR; + color = SELECTED_1ST_COLOR; } } + assert(!text.empty()); + m_imgui->text_colored(ImGui::GetStyleColorVec4(ImGuiCol_Text), text); ImGui::SameLine(); const ImVec2 pos = ImGui::GetCursorScreenPos(); @@ -1985,7 +2055,7 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit if (use_inches) distance = ObjectManipulation::mm_to_in * distance; ImGui::PushID("ClipboardDistanceInfinite"); - add_measure_row_to_table(_u8L("Distance Infinite"), ImGuiWrapper::COL_ORANGE_LIGHT, format_double(distance) + units, + add_measure_row_to_table(_u8L("Distance"), ImGuiWrapper::COL_ORANGE_LIGHT, format_double(distance) + units, ImGui::GetStyleColorVec4(ImGuiCol_Text)); ++measure_row_count; ImGui::PopID(); @@ -1996,7 +2066,7 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit if (use_inches) distance = ObjectManipulation::mm_to_in * distance; ImGui::PushID("ClipboardDistanceStrict"); - add_measure_row_to_table(_u8L("Distance Strict"), ImGuiWrapper::COL_ORANGE_LIGHT, format_double(distance) + units, + add_measure_row_to_table(_u8L("Distance"), ImGuiWrapper::COL_ORANGE_LIGHT, format_double(distance) + units, ImGui::GetStyleColorVec4(ImGuiCol_Text)); ++measure_row_count; ImGui::PopID(); From eeea803be576f266cc2be36e10f55273cd3fa6ee Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Thu, 1 Dec 2022 13:31:22 +0100 Subject: [PATCH 082/109] Measurement: tweaking of the tolerances, ransacing the whole border --- src/libslic3r/Measure.cpp | 324 ++++++++++++++++++++------------------ 1 file changed, 175 insertions(+), 149 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 37bf68e83d..3d96c351c5 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -18,7 +18,7 @@ static std::pair get_center_and_radius(const std::vector& { Vec2ds out; double z = 0.; - for (const Vec3d pt : points) { + for (const Vec3d& pt : points) { Vec3d pt_transformed = trafo * pt; z = pt_transformed.z(); out.emplace_back(pt_transformed.x(), pt_transformed.y()); @@ -29,6 +29,14 @@ static std::pair get_center_and_radius(const std::vector& return std::make_pair(trafo.inverse() * Vec3d(circle.center.x(), circle.center.y(), z), circle.radius); } +static bool circle_fit_is_ok(const std::vector& pts, const Vec3d& center, double radius) +{ + for (const Vec3d& pt : pts) + if (std::abs((pt - center).norm() - radius) > 0.05) + return false; + return true; +} + static std::array orthonormal_basis(const Vec3d& v) { std::array ret; @@ -246,10 +254,7 @@ void MeasuringImpl::update_planes() void MeasuringImpl::extract_features() { - auto are_angles_same = [](double a, double b) { return Slic3r::is_approx(a,b); }; - auto are_lengths_same = [](double a, double b) { return Slic3r::is_approx(a,b); }; - - std::vector angles; + std::vector angles; // placed in outer scope to prevent reallocations std::vector lengths; @@ -267,175 +272,196 @@ void MeasuringImpl::extract_features() if (border.size() <= 1) continue; - // Given an idx into border, return the index that is idx+offset position, - // while taking into account the need for warp-around and the fact that - // the first and last point are the same. - auto offset_to_index = [border_size = int(border.size())](int idx, int offset) -> int { - assert(std::abs(offset) < border_size); - int out = idx+offset; - if (out >= border_size) - out = out - border_size; - else if (out < 0) - out = border_size + out; + bool done = false; - return out; - }; + if (const auto& [center, radius] = get_center_and_radius(border, trafo); + (border.size()>4) && circle_fit_is_ok(border, center, radius)) { + // The whole border is one circle. Just add it into the list of features + // and we are done. - // First calculate angles at all the vertices. - angles.clear(); - lengths.clear(); - int first_different_angle_idx = 0; - for (int i=0; i M_PI) - angle = 2*M_PI - angle; + bool is_polygon = border.size()>4 && border.size()<=8; + bool lengths_match = std::all_of(border.begin()+2, border.end(), [is_polygon](const Vec3d& pt) { + return Slic3r::is_approx((pt - *((&pt)-1)).squaredNorm(), (*((&pt)-1) - *((&pt)-2)).squaredNorm(), is_polygon ? 0.01 : 0.01); + }); - angles.push_back(angle); - lengths.push_back(v2.norm()); - if (first_different_angle_idx == 0 && angles.size() > 1) { - if (! are_angles_same(angles.back(), angles[angles.size()-2])) - first_different_angle_idx = angles.size()-1; + if (lengths_match && (is_polygon || border.size() > 8)) { + if (is_polygon) { + // This is a polygon, add the separate edges with the center. + for (int j=0; j circles; - std::vector edges; - std::vector> circles_idxs; - //std::vector circles_lengths; - std::vector single_circle; // could be in loop-scope, but reallocations - double single_circle_length = 0.; - int first_pt_idx = offset_to_index(first_different_angle_idx, 1); - int i = first_pt_idx; - while (i != first_pt_idx || first_iter) { - if (are_angles_same(angles[i], angles[offset_to_index(i,-1)]) - && i != offset_to_index(first_pt_idx, -1) // not the last point - && i != start_idx ) { - // circle - if (! circle) { - circle = true; - single_circle.clear(); - single_circle_length = 0.; - start_idx = offset_to_index(i, -2); - single_circle = { border[start_idx], border[offset_to_index(start_idx,1)] }; - single_circle_length += lengths[offset_to_index(i, -1)]; + if (! done) { + // In this case, the border is not a circle and may contain circular + // segments. Try to find them and then add all remaining edges as edges. + + auto are_angles_same = [](double a, double b) { return Slic3r::is_approx(a,b,0.01); }; + auto are_lengths_same = [](double a, double b) { return Slic3r::is_approx(a,b,0.01); }; + + + // Given an idx into border, return the index that is idx+offset position, + // while taking into account the need for wrap-around and the fact that + // the first and last point are the same. + auto offset_to_index = [border_size = int(border.size())](int idx, int offset) -> int { + assert(std::abs(offset) < border_size); + int out = idx+offset; + if (out >= border_size) + out = out - border_size; + else if (out < 0) + out = border_size + out; + + return out; + }; + + // First calculate angles at all the vertices. + angles.clear(); + lengths.clear(); + int first_different_angle_idx = 0; + for (int i=0; i M_PI) + angle = 2*M_PI - angle; + + angles.push_back(angle); + lengths.push_back(v2.norm()); + if (first_different_angle_idx == 0 && angles.size() > 1) { + if (! are_angles_same(angles.back(), angles[angles.size()-2])) + first_different_angle_idx = angles.size()-1; } - single_circle.emplace_back(border[i]); - single_circle_length += lengths[i]; - } else { - if (circle && single_circle.size() >= 5) { // Less than 5 vertices? Not a circle. + } + assert(border.size() == angles.size()); + assert(border.size() == lengths.size()); + + // First go around the border and pick what might be circular segments. + // Save pair of indices to where such potential segments start and end. + // Also remember the length of these segments. + int start_idx = -1; + bool circle = false; + bool first_iter = true; + std::vector circles; + std::vector edges; + std::vector> circles_idxs; + //std::vector circles_lengths; + std::vector single_circle; // could be in loop-scope, but reallocations + double single_circle_length = 0.; + int first_pt_idx = offset_to_index(first_different_angle_idx, 1); + int i = first_pt_idx; + while (i != first_pt_idx || first_iter) { + if (are_angles_same(angles[i], angles[offset_to_index(i,-1)]) + && i != offset_to_index(first_pt_idx, -1) // not the last point + && i != start_idx ) { + // circle + if (! circle) { + circle = true; + single_circle.clear(); + single_circle_length = 0.; + start_idx = offset_to_index(i, -2); + single_circle = { border[start_idx], border[offset_to_index(start_idx,1)] }; + single_circle_length += lengths[offset_to_index(i, -1)]; + } single_circle.emplace_back(border[i]); single_circle_length += lengths[i]; + } else { + if (circle && single_circle.size() >= 5) { // Less than 5 vertices? Not a circle. + single_circle.emplace_back(border[i]); + single_circle_length += lengths[i]; - bool accept_circle = true; - { - // Check that lengths of internal (!!!) edges match. - int j = offset_to_index(start_idx, 3); - while (j != i) { - if (! are_lengths_same(lengths[offset_to_index(j,-1)], lengths[j])) { - accept_circle = false; - break; - } - j = offset_to_index(j, 1); - } - } - - if (accept_circle) { - const auto& [center, radius] = get_center_and_radius(single_circle, trafo); - - // Check that the fit went well. The tolerance is high, only to - // reject complete failures. - for (const Vec3d& pt : single_circle) { - if (std::abs((pt - center).norm() - radius) > 0.5) { - accept_circle = false; - break; + bool accept_circle = true; + { + // Check that lengths of internal (!!!) edges match. + int j = offset_to_index(start_idx, 3); + while (j != i) { + if (! are_lengths_same(lengths[offset_to_index(j,-1)], lengths[j])) { + accept_circle = false; + break; + } + j = offset_to_index(j, 1); } } - // If the segment subtends less than 90 degrees, throw it away. - accept_circle &= single_circle_length / radius > 0.9*M_PI/2.; - - // If this is all-around and 5 to 8 vertices, consider it a polygon. - bool is_polygon = start_idx == i && single_circle.size() <= 9 && single_circle.size() >= 6; - if (accept_circle) { - // Add the circle and remember indices into borders. - circles_idxs.emplace_back(start_idx, i); - if (is_polygon) { - for (int j=0; j<=i; ++j) // No wrap-around handling needed here. - edges.emplace_back(SurfaceFeature(SurfaceFeatureType::Edge, - border[j==0 ? border.size()-1 : j-1], border[j], - std::make_optional(center))); - } - else + const auto& [center, radius] = get_center_and_radius(single_circle, trafo); + + // Check that the fit went well. The tolerance is high, only to + // reject complete failures. + accept_circle &= circle_fit_is_ok(single_circle, center, radius); + + // If the segment subtends less than 90 degrees, throw it away. + accept_circle &= single_circle_length / radius > 0.9*M_PI/2.; + + if (accept_circle) { + // Add the circle and remember indices into borders. + circles_idxs.emplace_back(start_idx, i); circles.emplace_back(SurfaceFeature(SurfaceFeatureType::Circle, center, plane.normal, std::nullopt, radius)); + } } } + circle = false; } - circle = false; - } - // Take care of the wrap around. - first_iter = false; - i = offset_to_index(i, 1); - } - - // We have the circles. Now go around again and pick edges, while jumping over circles. - if (circles_idxs.empty()) { - // Just add all edges. - for (int i=1; i 1 || circles_idxs.front().first != circles_idxs.front().second) { + // There is at least one circular segment. Start at its end and add edges until the start of the next one. + int i = circles_idxs.front().second; + int circle_idx = 1; + while (true) { + i = offset_to_index(i, 1); + edges.emplace_back(SurfaceFeature(SurfaceFeatureType::Edge, border[offset_to_index(i,-1)], border[i])); + if (circle_idx < int(circles_idxs.size()) && i == circles_idxs[circle_idx].first) { + i = circles_idxs[circle_idx].second; + ++circle_idx; + } + if (i == circles_idxs.front().first) + break; } - if (i == circles_idxs.front().first) - break; } - } - // Merge adjacent edges where needed. - assert(std::all_of(edges.begin(), edges.end(), - [](const SurfaceFeature& f) { return f.get_type() == SurfaceFeatureType::Edge; })); - for (int i=edges.size()-1; i>=0; --i) { - const auto& [first_start, first_end] = edges[i==0 ? edges.size()-1 : i-1].get_edge(); - const auto& [second_start, second_end] = edges[i].get_edge(); + // Merge adjacent edges where needed. + assert(std::all_of(edges.begin(), edges.end(), + [](const SurfaceFeature& f) { return f.get_type() == SurfaceFeatureType::Edge; })); + for (int i=edges.size()-1; i>=0; --i) { + const auto& [first_start, first_end] = edges[i==0 ? edges.size()-1 : i-1].get_edge(); + const auto& [second_start, second_end] = edges[i].get_edge(); - if (Slic3r::is_approx(first_end, second_start) - && Slic3r::is_approx((first_end-first_start).normalized().dot((second_end-second_start).normalized()), 1.)) { - // The edges have the same direction and share a point. Merge them. - edges[i==0 ? edges.size()-1 : i-1] = SurfaceFeature(SurfaceFeatureType::Edge, first_start, second_end); - edges.erase(edges.begin() + i); + if (Slic3r::is_approx(first_end, second_start) + && Slic3r::is_approx((first_end-first_start).normalized().dot((second_end-second_start).normalized()), 1.)) { + // The edges have the same direction and share a point. Merge them. + edges[i==0 ? edges.size()-1 : i-1] = SurfaceFeature(SurfaceFeatureType::Edge, first_start, second_end); + edges.erase(edges.begin() + i); + } } - } - // Now move the circles and edges into the feature list for the plane. - assert(std::all_of(circles.begin(), circles.end(), [](const SurfaceFeature& f) { - return f.get_type() == SurfaceFeatureType::Circle; - })); - assert(std::all_of(edges.begin(), edges.end(), [](const SurfaceFeature& f) { - return f.get_type() == SurfaceFeatureType::Edge; - })); - plane.surface_features.insert(plane.surface_features.end(), std::make_move_iterator(circles.begin()), - std::make_move_iterator(circles.end())); - plane.surface_features.insert(plane.surface_features.end(), std::make_move_iterator(edges.begin()), - std::make_move_iterator(edges.end())); + // Now move the circles and edges into the feature list for the plane. + assert(std::all_of(circles.begin(), circles.end(), [](const SurfaceFeature& f) { + return f.get_type() == SurfaceFeatureType::Circle; + })); + assert(std::all_of(edges.begin(), edges.end(), [](const SurfaceFeature& f) { + return f.get_type() == SurfaceFeatureType::Edge; + })); + plane.surface_features.insert(plane.surface_features.end(), std::make_move_iterator(circles.begin()), + std::make_move_iterator(circles.end())); + plane.surface_features.insert(plane.surface_features.end(), std::make_move_iterator(edges.begin()), + std::make_move_iterator(edges.end())); + } } // The last surface feature is the plane itself. From 954cd105e03945d2cfc96a0df5c4bd24b8d6e1b2 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 1 Dec 2022 13:34:29 +0100 Subject: [PATCH 083/109] Fixed warnings --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 1ddd805b71..31cd005bec 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -82,17 +82,6 @@ static std::string point_on_feature_type_as_string(Measure::SurfaceFeatureType t return ret; } -static std::string center_on_feature_type_as_string(Measure::SurfaceFeatureType type) -{ - std::string ret; - switch (type) { - case Measure::SurfaceFeatureType::Edge: { ret = _u8L("Center of edge"); break; } - case Measure::SurfaceFeatureType::Circle: { ret = _u8L("Center of circle"); break; } - default: { assert(false); break; } - } - return ret; -} - static GLModel::Geometry init_plane_data(const indexed_triangle_set& its, const std::vector>& planes_triangles, int idx) { assert(0 <= idx && idx < (int)planes_triangles.size()); @@ -477,13 +466,6 @@ void GLGizmoMeasure::data_changed() m_is_editing_distance_first_frame = true; } -static bool feature_has_center(std::optional feature) -{ - return feature.has_value() ? - (feature->get_type() == Measure::SurfaceFeatureType::Circle || (feature->get_type() == Measure::SurfaceFeatureType::Edge && feature->get_extra_point().has_value())) - : false; -} - bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down) { if (action == SLAGizmoEventType::ShiftDown) { From 2f8e2c5e8006274d1bf89ca3e59be655e44faf85 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 1 Dec 2022 14:56:33 +0100 Subject: [PATCH 084/109] Measure gizmo - Fixed missing raycaster when promoting a point as 1st selected feature --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 31cd005bec..05da490825 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -336,7 +336,7 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) }; auto requires_sphere_raycaster_for_picking = [this](const SelectedFeatures::Item& item) { - if (m_mode == EMode::PointSelection) + if (m_mode == EMode::PointSelection || item.feature->get_type() == Measure::SurfaceFeatureType::Point) return true; else if (m_mode == EMode::FeatureSelection) { if (is_feature_with_center(*item.feature)) From cc8a6a3fff0280b99e947aa7f22c33b04e864bae Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 2 Dec 2022 07:56:11 +0100 Subject: [PATCH 085/109] Follow-up of 85195ac79fb2b7016b05ffff5eb33a483a4d06c2 - Fixed synch of selected features in imgui dialog --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 05da490825..4cb9682b6f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -82,6 +82,17 @@ static std::string point_on_feature_type_as_string(Measure::SurfaceFeatureType t return ret; } +static std::string center_on_feature_type_as_string(Measure::SurfaceFeatureType type) +{ + std::string ret; + switch (type) { + case Measure::SurfaceFeatureType::Edge: { ret = _u8L("Center of edge"); break; } + case Measure::SurfaceFeatureType::Circle: { ret = _u8L("Center of circle"); break; } + default: { assert(false); break; } + } + return ret; +} + static GLModel::Geometry init_plane_data(const indexed_triangle_set& its, const std::vector>& planes_triangles, int idx) { assert(0 <= idx && idx < (int)planes_triangles.size()); @@ -1976,7 +1987,8 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit if (!item.feature.has_value()) return _u8L("None"); - std::string text = (item.source == item.feature) ? surface_feature_type_as_string(item.feature->get_type()) : point_on_feature_type_as_string(item.source->get_type(), m_hover_id); + std::string text = (item.source == item.feature) ? surface_feature_type_as_string(item.feature->get_type()) : + item.is_center ? center_on_feature_type_as_string(item.source->get_type()) : point_on_feature_type_as_string(item.source->get_type(), m_hover_id); if (item.feature.has_value() && item.feature->get_type() == Measure::SurfaceFeatureType::Circle) { auto [center, radius, normal] = item.feature->get_circle(); const Vec3d on_circle = center + radius * Measure::get_orthogonal(normal, true); From 456e61c7d3bafaed03d00b8b8e895470a8e5fa9c Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 2 Dec 2022 07:42:02 +0100 Subject: [PATCH 086/109] Measurement: Fixed edge detection on single-triangle planes --- src/libslic3r/Measure.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 3d96c351c5..6368f30f57 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -227,7 +227,7 @@ void MeasuringImpl::update_planes() // In case of broken meshes, this loop might be infinite. Break // out in case it is clearly going bad. - if (last_border.size() > 3*facets.size()) + if (last_border.size() > 3*facets.size()+1) goto PLANE_FAILURE; } while (he != he_start); From 210273e12fc29c8274f9d17a991f83230c8d9470 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 2 Dec 2022 12:39:49 +0100 Subject: [PATCH 087/109] Fixed differences after rebase to master --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 4cb9682b6f..a2d2518d6a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -866,15 +866,12 @@ void GLGizmoMeasure::on_render() } case Measure::SurfaceFeatureType::Plane: { - // no need to render the plane in case it is rendered with the same color as the volume in the 3D scene - if (colors.front() != m_parent.get_selection().get_first_volume()->render_color) { - const auto& [idx, normal, pt] = feature.get_plane(); - assert(idx < m_plane_models_cache.size()); - set_matrix_uniforms(Transform3d::Identity()); - set_emission_uniform(colors.front(), hover); - m_plane_models_cache[idx].set_color(colors.front()); - m_plane_models_cache[idx].render(); - } + const auto& [idx, normal, pt] = feature.get_plane(); + assert(idx < m_plane_models_cache.size()); + set_matrix_uniforms(Transform3d::Identity()); + set_emission_uniform(colors.front(), hover); + m_plane_models_cache[idx].set_color(colors.front()); + m_plane_models_cache[idx].render(); if (update_raycasters_transform) { auto it = m_raycasters.find(PLANE_ID); if (it != m_raycasters.end() && it->second != nullptr) From e04e8c55cfc0498bb665f6fb515f3a8fcea64796 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 2 Dec 2022 14:21:18 +0100 Subject: [PATCH 088/109] Improved performance of GLModel::render: The way the OpenGL version was checked was quite inefficient --- src/slic3r/GUI/OpenGLManager.cpp | 47 +++++++++++++------------ src/slic3r/GUI/OpenGLManager.hpp | 13 ++++--- src/slic3r/GUI/SendSystemInfoDialog.cpp | 4 +-- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/slic3r/GUI/OpenGLManager.cpp b/src/slic3r/GUI/OpenGLManager.cpp index 2924470e07..0366031d29 100644 --- a/src/slic3r/GUI/OpenGLManager.cpp +++ b/src/slic3r/GUI/OpenGLManager.cpp @@ -37,20 +37,20 @@ std::string gl_get_string_safe(GLenum param, const std::string& default_value) return std::string((value != nullptr) ? value : default_value); } -const std::string& OpenGLManager::GLInfo::get_version() const +const std::string& OpenGLManager::GLInfo::get_version_string() const { if (!m_detected) detect(); - return m_version; + return m_version_string; } -const std::string& OpenGLManager::GLInfo::get_glsl_version() const +const std::string& OpenGLManager::GLInfo::get_glsl_version_string() const { if (!m_detected) detect(); - return m_glsl_version; + return m_glsl_version_string; } const std::string& OpenGLManager::GLInfo::get_vendor() const @@ -71,7 +71,7 @@ const std::string& OpenGLManager::GLInfo::get_renderer() const bool OpenGLManager::GLInfo::is_mesa() const { - return boost::icontains(m_version, "mesa"); + return m_version_is_mesa; } int OpenGLManager::GLInfo::get_max_tex_size() const @@ -97,13 +97,19 @@ float OpenGLManager::GLInfo::get_max_anisotropy() const return m_max_anisotropy; } +static Semver parse_version_string(const std::string& version); + void OpenGLManager::GLInfo::detect() const { - *const_cast(&m_version) = gl_get_string_safe(GL_VERSION, "N/A"); - *const_cast(&m_glsl_version) = gl_get_string_safe(GL_SHADING_LANGUAGE_VERSION, "N/A"); + *const_cast(&m_version_string) = gl_get_string_safe(GL_VERSION, "N/A"); + *const_cast(&m_glsl_version_string) = gl_get_string_safe(GL_SHADING_LANGUAGE_VERSION, "N/A"); *const_cast(&m_vendor) = gl_get_string_safe(GL_VENDOR, "N/A"); *const_cast(&m_renderer) = gl_get_string_safe(GL_RENDERER, "N/A"); + *const_cast(&m_version) = parse_version_string(m_version_string); + *const_cast(&m_version_is_mesa) = boost::icontains(m_version_string, "mesa"); + *const_cast(&m_glsl_version) = parse_version_string(m_glsl_version_string); + int* max_tex_size = const_cast(&m_max_tex_size); glsafe(::glGetIntegerv(GL_MAX_TEXTURE_SIZE, max_tex_size)); @@ -119,16 +125,16 @@ void OpenGLManager::GLInfo::detect() const *const_cast(&m_detected) = true; } -static bool version_greater_or_equal_to(const std::string& version, unsigned int major, unsigned int minor) +static Semver parse_version_string(const std::string& version) { if (version == "N/A") - return false; + return Semver::invalid(); std::vector tokens; boost::split(tokens, version, boost::is_any_of(" "), boost::token_compress_on); if (tokens.empty()) - return false; + return Semver::invalid(); #if ENABLE_OPENGL_ES const std::string version_container = (tokens.size() > 1 && boost::istarts_with(tokens[1], "ES")) ? tokens[2] : tokens[0]; @@ -150,20 +156,15 @@ static bool version_greater_or_equal_to(const std::string& version, unsigned int if (numbers.size() > 1) gl_minor = ::atoi(numbers[1].c_str()); - if (gl_major < major) - return false; - else if (gl_major > major) - return true; - else - return gl_minor >= minor; + return Semver(gl_major, gl_minor, 0); } bool OpenGLManager::GLInfo::is_version_greater_or_equal_to(unsigned int major, unsigned int minor) const { if (!m_detected) detect(); - - return version_greater_or_equal_to(m_version, major, minor); + + return m_version >= Semver(major, minor, 0); } bool OpenGLManager::GLInfo::is_glsl_version_greater_or_equal_to(unsigned int major, unsigned int minor) const @@ -171,7 +172,7 @@ bool OpenGLManager::GLInfo::is_glsl_version_greater_or_equal_to(unsigned int maj if (!m_detected) detect(); - return version_greater_or_equal_to(m_glsl_version, major, minor); + return m_glsl_version >= Semver(major, minor, 0); } // If formatted for github, plaintext with OpenGL extensions enclosed into
. @@ -378,13 +379,13 @@ bool OpenGLManager::init_gl() wxString message = from_u8((boost::format( #if ENABLE_OPENGL_ES _utf8(L("PrusaSlicer requires OpenGL ES 2.0 capable graphics driver to run correctly, \n" - "while OpenGL version %s, render %s, vendor %s was detected."))) % s_gl_info.get_version() % s_gl_info.get_renderer() % s_gl_info.get_vendor()).str()); + "while OpenGL version %s, render %s, vendor %s was detected."))) % s_gl_info.get_version_string() % s_gl_info.get_renderer() % s_gl_info.get_vendor()).str()); #elif ENABLE_GL_CORE_PROFILE _utf8(L("PrusaSlicer requires OpenGL %s capable graphics driver to run correctly, \n" - "while OpenGL version %s, render %s, vendor %s was detected."))) % (s_gl_info.is_core_profile() ? "3.3" : "2.0") % s_gl_info.get_version() % s_gl_info.get_renderer() % s_gl_info.get_vendor()).str()); + "while OpenGL version %s, render %s, vendor %s was detected."))) % (s_gl_info.is_core_profile() ? "3.3" : "2.0") % s_gl_info.get_version_string() % s_gl_info.get_renderer() % s_gl_info.get_vendor()).str()); #else _utf8(L("PrusaSlicer requires OpenGL 2.0 capable graphics driver to run correctly, \n" - "while OpenGL version %s, render %s, vendor %s was detected."))) % s_gl_info.get_version() % s_gl_info.get_renderer() % s_gl_info.get_vendor()).str()); + "while OpenGL version %s, render %s, vendor %s was detected."))) % s_gl_info.get_version_string() % s_gl_info.get_renderer() % s_gl_info.get_vendor()).str()); #endif // ENABLE_OPENGL_ES message += "\n"; message += _L("You may need to update your graphics card driver."); @@ -423,7 +424,7 @@ bool OpenGLManager::init_gl() // WHQL: 4.6.14800 Compatibility Profile Context 22.6.1 30.0.21023.1015 // Non-WHQL: 4.6.0 Compatibility Profile Context 22.8.1.220810 std::regex version_rgx(R"(Compatibility\sProfile\sContext\s(\d+)\.(\d+)\.(\d+))"); - if (std::smatch matches; std::regex_search(gl_info.get_version(), matches, version_rgx) && matches.size() == 4) { + if (std::smatch matches; std::regex_search(gl_info.get_version_string(), matches, version_rgx) && matches.size() == 4) { int version_major = std::stoi(matches[1].str()); int version_minor = std::stoi(matches[2].str()); int version_patch = std::stoi(matches[3].str()); diff --git a/src/slic3r/GUI/OpenGLManager.hpp b/src/slic3r/GUI/OpenGLManager.hpp index 5c810d83ef..ece9009622 100644 --- a/src/slic3r/GUI/OpenGLManager.hpp +++ b/src/slic3r/GUI/OpenGLManager.hpp @@ -31,16 +31,21 @@ public: int m_max_tex_size{ 0 }; float m_max_anisotropy{ 0.0f }; - std::string m_version; - std::string m_glsl_version; + std::string m_version_string; + Semver m_version = Semver::invalid(); + bool m_version_is_mesa = false; + + std::string m_glsl_version_string; + Semver m_glsl_version = Semver::invalid(); + std::string m_vendor; std::string m_renderer; public: GLInfo() = default; - const std::string& get_version() const; - const std::string& get_glsl_version() const; + const std::string& get_version_string() const; + const std::string& get_glsl_version_string() const; const std::string& get_vendor() const; const std::string& get_renderer() const; diff --git a/src/slic3r/GUI/SendSystemInfoDialog.cpp b/src/slic3r/GUI/SendSystemInfoDialog.cpp index 298b3242d5..dfb442d18c 100644 --- a/src/slic3r/GUI/SendSystemInfoDialog.cpp +++ b/src/slic3r/GUI/SendSystemInfoDialog.cpp @@ -504,8 +504,8 @@ static std::string generate_system_info_json() #endif // _WIN32 pt::ptree opengl_node; - opengl_node.put("Version", OpenGLManager::get_gl_info().get_version()); - opengl_node.put("GLSLVersion", OpenGLManager::get_gl_info().get_glsl_version()); + opengl_node.put("Version", OpenGLManager::get_gl_info().get_version_string()); + opengl_node.put("GLSLVersion", OpenGLManager::get_gl_info().get_glsl_version_string()); opengl_node.put("Vendor", OpenGLManager::get_gl_info().get_vendor()); opengl_node.put("Renderer", OpenGLManager::get_gl_info().get_renderer()); // Generate list of OpenGL extensions: From 6f18f8f7845e52699efa3e3f8ac2fcdadd0ffe12 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 5 Dec 2022 10:24:30 +0100 Subject: [PATCH 089/109] Tech ENABLE_RAYCAST_PICKING set as default --- src/libslic3r/Model.hpp | 2 - src/libslic3r/Technologies.hpp | 5 +- src/slic3r/GUI/3DBed.cpp | 56 ------ src/slic3r/GUI/3DBed.hpp | 8 - src/slic3r/GUI/3DScene.cpp | 48 ----- src/slic3r/GUI/3DScene.hpp | 4 - src/slic3r/GUI/Camera.cpp | 46 ----- src/slic3r/GUI/Camera.hpp | 9 - src/slic3r/GUI/GLCanvas3D.cpp | 194 +------------------ src/slic3r/GUI/GLCanvas3D.hpp | 10 - src/slic3r/GUI/GLSelectionRectangle.cpp | 11 -- src/slic3r/GUI/GLSelectionRectangle.hpp | 6 - src/slic3r/GUI/Gizmos/GLGizmoBase.cpp | 119 +----------- src/slic3r/GUI/Gizmos/GLGizmoBase.hpp | 37 ---- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 6 - src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp | 4 - src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp | 78 -------- src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp | 14 -- src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp | 81 +------- src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp | 16 -- src/slic3r/GUI/Gizmos/GLGizmoMove.cpp | 27 --- src/slic3r/GUI/Gizmos/GLGizmoMove.hpp | 4 - src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp | 3 - src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp | 29 --- src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp | 11 -- src/slic3r/GUI/Gizmos/GLGizmoScale.cpp | 24 --- src/slic3r/GUI/Gizmos/GLGizmoScale.hpp | 4 - src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp | 3 - src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 120 ++---------- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp | 15 -- src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp | 4 - src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 15 -- src/slic3r/GUI/Gizmos/GLGizmosManager.hpp | 3 - src/slic3r/GUI/MeshUtils.cpp | 7 - src/slic3r/GUI/MeshUtils.hpp | 25 --- src/slic3r/GUI/SceneRaycaster.cpp | 4 - src/slic3r/GUI/SceneRaycaster.hpp | 4 - src/slic3r/Utils/RaycastManager.cpp | 4 - tests/libslic3r/test_color.cpp | 16 -- 39 files changed, 30 insertions(+), 1046 deletions(-) diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 6fb2bc923d..1cd6c34143 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -762,9 +762,7 @@ public: // The triangular model. const TriangleMesh& mesh() const { return *m_mesh.get(); } -#if ENABLE_RAYCAST_PICKING std::shared_ptr mesh_ptr() const { return m_mesh; } -#endif // ENABLE_RAYCAST_PICKING void set_mesh(const TriangleMesh &mesh) { m_mesh = std::make_shared(mesh); } void set_mesh(TriangleMesh &&mesh) { m_mesh = std::make_shared(std::move(mesh)); } void set_mesh(const indexed_triangle_set &mesh) { m_mesh = std::make_shared(mesh); } diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index f707b0f21d..4e6d2106b1 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -28,6 +28,8 @@ #define DISABLE_GCODEVIEWER_INSTANCED_MODELS 1 // Enable Measure Gizmo debug window #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 @@ -61,9 +63,6 @@ #define ENABLE_PROCESS_G2_G3_LINES (1 && ENABLE_2_6_0_ALPHA1) // Enable fix of used filament data exported to gcode file #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_ diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index 1402584028..a7e70bc430 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -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(GROUND_Z) }); m_axes.set_stem_length(0.1f * static_cast(m_build_volume.bounding_volume().max_size())); -#if ENABLE_RAYCAST_PICKING // unregister from picking wxGetApp().plater()->canvas3D()->remove_raycasters_for_picking(SceneRaycaster::EType::Bed); -#endif // ENABLE_RAYCAST_PICKING // Let the calee to update the UI. return true; @@ -309,11 +307,7 @@ void Bed3D::render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor, glsafe(::glEnable(GL_DEPTH_TEST)); #if ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING 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 m_model.set_color(-1, picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR); #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())); #endif // ENABLE_WORLD_COORDINATE // extend to contain model, if any -#if ENABLE_RAYCAST_PICKING 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) { model_bb.translate(m_model_offset); 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); } -#if ENABLE_RAYCAST_PICKING if (m_model.model.get_filename().empty() && m_model.mesh_raycaster == nullptr) // register for picking register_raycasters_for_picking(init_data, Transform3d::Identity()); -#endif // ENABLE_RAYCAST_PICKING m_triangles.init_from(std::move(init_data)); -#if ENABLE_RAYCAST_PICKING m_triangles.set_color(DEFAULT_MODEL_COLOR); -#endif // ENABLE_RAYCAST_PICKING } void Bed3D::init_gridlines() @@ -798,17 +784,9 @@ void Bed3D::render_model() if (m_model_filename.empty()) return; -#if ENABLE_RAYCAST_PICKING 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_RAYCAST_PICKING m_model.model.set_color(DEFAULT_MODEL_COLOR); -#else - m_model.set_color(DEFAULT_MODEL_COLOR); -#endif // ENABLE_RAYCAST_PICKING #else m_model.set_color(-1, DEFAULT_MODEL_COLOR); #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 m_model_offset = to_3d(m_build_volume.bounding_volume2d().center(), -0.03); -#if ENABLE_RAYCAST_PICKING // register for picking register_raycasters_for_picking(m_model.model.get_geometry(), Geometry::translation_transform(m_model_offset)); -#endif // ENABLE_RAYCAST_PICKING // update extended bounding box m_extended_bounding_box = this->calc_extended_bounding_box(); } -#if ENABLE_RAYCAST_PICKING 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"); if (shader != nullptr) { shader->start_using(); @@ -844,11 +816,7 @@ void Bed3D::render_model() glsafe(::glPushMatrix()); glsafe(::glTranslated(m_model_offset.x(), m_model_offset.y(), m_model_offset.z())); #endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING m_model.model.render(); -#else - m_model.render(); -#endif // ENABLE_RAYCAST_PICKING #if !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glPopMatrix()); #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(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); -#if ENABLE_RAYCAST_PICKING 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) { // draw background 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(); glsafe(::glDepthMask(GL_TRUE)); } -#if ENABLE_RAYCAST_PICKING if (show_texture) { // draw grid #if ENABLE_GL_CORE_PROFILE @@ -942,19 +901,6 @@ void Bed3D::render_default(bool bottom, bool picking, bool show_texture) } else 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)); @@ -1047,7 +993,6 @@ void Bed3D::release_VBOs() } #endif // !ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING void Bed3D::register_raycasters_for_picking(const GLModel::Geometry& geometry, const Transform3d& trafo) { 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(std::make_shared(std::move(its))); wxGetApp().plater()->canvas3D()->add_raycaster_for_picking(SceneRaycaster::EType::Bed, 0, *m_model.mesh_raycaster, trafo); } -#endif // ENABLE_RAYCAST_PICKING } // GUI } // Slic3r diff --git a/src/slic3r/GUI/3DBed.hpp b/src/slic3r/GUI/3DBed.hpp index 7f0dff19d0..c12674b4a7 100644 --- a/src/slic3r/GUI/3DBed.hpp +++ b/src/slic3r/GUI/3DBed.hpp @@ -8,9 +8,7 @@ #else #include "GLModel.hpp" #endif // ENABLE_WORLD_COORDINATE -#if ENABLE_RAYCAST_PICKING #include "MeshUtils.hpp" -#endif // ENABLE_RAYCAST_PICKING #include "libslic3r/BuildVolume.hpp" #if ENABLE_LEGACY_OPENGL_REMOVAL @@ -111,11 +109,7 @@ private: GLTexture m_texture; // temporary texture shown until the main texture has still no levels compressed GLTexture m_temp_texture; -#if ENABLE_RAYCAST_PICKING PickingModel m_model; -#else - GLModel m_model; -#endif // ENABLE_RAYCAST_PICKING Vec3d m_model_offset{ Vec3d::Zero() }; #if !ENABLE_LEGACY_OPENGL_REMOVAL unsigned int m_vbo_id{ 0 }; @@ -205,9 +199,7 @@ private: void release_VBOs(); #endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING void register_raycasters_for_picking(const GLModel::Geometry& geometry, const Transform3d& trafo); -#endif // ENABLE_RAYCAST_PICKING }; } // GUI diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 7ab01bebf4..4bf05555c8 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -807,27 +807,17 @@ int GLVolumeCollection::load_object_volume( const ModelVolume *model_volume = model_object->volumes[volume_idx]; const int extruder_id = model_volume->extruder_id(); const ModelInstance *instance = model_object->instances[instance_idx]; -#if ENABLE_RAYCAST_PICKING std::shared_ptr mesh = model_volume->mesh_ptr(); -#else - const TriangleMesh &mesh = model_volume->mesh(); -#endif // ENABLE_RAYCAST_PICKING this->volumes.emplace_back(new GLVolume()); GLVolume& v = *this->volumes.back(); v.set_color(color_from_model_volume(*model_volume)); #if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_SMOOTH_NORMALS v.model.init_from(*mesh, true); -#if ENABLE_RAYCAST_PICKING v.mesh_raycaster = std::make_unique(mesh); -#endif // ENABLE_RAYCAST_PICKING #else -#if ENABLE_RAYCAST_PICKING v.model.init_from(*mesh); v.mesh_raycaster = std::make_unique(mesh); -#else - v.model.init_from(mesh); -#endif // ENABLE_RAYCAST_PICKING #endif // ENABLE_SMOOTH_NORMALS #else #if ENABLE_SMOOTH_NORMALS @@ -893,9 +883,7 @@ void GLVolumeCollection::load_object_auxiliary( #else v.model.init_from(mesh); v.model.set_color((milestone == slaposPad) ? GLVolume::SLA_PAD_COLOR : GLVolume::SLA_SUPPORT_COLOR); -#if ENABLE_RAYCAST_PICKING v.mesh_raycaster = std::make_unique(std::make_shared(mesh)); -#endif // ENABLE_RAYCAST_PICKING #endif // ENABLE_SMOOTH_NORMALS #else #if ENABLE_SMOOTH_NORMALS @@ -954,13 +942,10 @@ int GLVolumeCollection::load_wipe_tower_preview( depth = std::max(depth, 10.f); float min_width = 30.f; -#if ENABLE_RAYCAST_PICKING 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 // 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, // 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))); data = generate_lateral(61.547f, 100.0f); 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 // 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? for (size_t i = 0; i < n; ++i) { mesh.merge(tooth_mesh); -#if ENABLE_RAYCAST_PICKING 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 const float scaled_brim_width_x = brim_width * n * width / min_width; auto generate_negx_cap = [&]() { @@ -1166,20 +1130,10 @@ int GLVolumeCollection::load_wipe_tower_preview( data = generate_posx_cap(); mesh.merge(TriangleMesh(std::move(data))); 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 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)); GLVolume& v = *volumes.back(); #if ENABLE_LEGACY_OPENGL_REMOVAL @@ -1189,9 +1143,7 @@ int GLVolumeCollection::load_wipe_tower_preview( #endif // ENABLE_OPENGL_ES v.model.init_from(mesh); v.model.set_color(color); -#if ENABLE_RAYCAST_PICKING v.mesh_raycaster = std::make_unique(std::make_shared(mesh)); -#endif // ENABLE_RAYCAST_PICKING #else v.indexed_vertex_array.load_mesh(mesh); #endif // ENABLE_LEGACY_OPENGL_REMOVAL diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index 1e8897c4e0..a7146d61cf 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -10,9 +10,7 @@ #include "libslic3r/Color.hpp" #include "GLModel.hpp" -#if ENABLE_RAYCAST_PICKING #include "MeshUtils.hpp" -#endif // ENABLE_RAYCAST_PICKING #include #include @@ -393,10 +391,8 @@ public: #if ENABLE_LEGACY_OPENGL_REMOVAL GUI::GLModel model; -#if ENABLE_RAYCAST_PICKING // raycaster used for picking std::unique_ptr mesh_raycaster; -#endif // ENABLE_RAYCAST_PICKING #else // Interleaved triangles & normals with indexed triangles & quads. GLIndexedVertexArray indexed_vertex_array; diff --git a/src/slic3r/GUI/Camera.cpp b/src/slic3r/GUI/Camera.cpp index 56980c43a5..a549d87da8 100644 --- a/src/slic3r/GUI/Camera.cpp +++ b/src/slic3r/GUI/Camera.cpp @@ -91,7 +91,6 @@ void Camera::select_view(const std::string& direction) look_at(m_target + m_distance * Vec3d::UnitY(), m_target, Vec3d::UnitZ()); } -#if ENABLE_RAYCAST_PICKING double Camera::get_near_left() const { switch (m_type) @@ -163,7 +162,6 @@ double Camera::get_near_height() const return 2.0 / m_projection_matrix.matrix()(1, 1); } } -#endif // ENABLE_RAYCAST_PICKING 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) { #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])); } -#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 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_RAYCAST_PICKING 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 glsafe(::glMatrixMode(GL_PROJECTION)); glsafe(::glLoadIdentity()); @@ -315,7 +271,6 @@ void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double fa #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) { 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) { diff --git a/src/slic3r/GUI/Camera.hpp b/src/slic3r/GUI/Camera.hpp index b2672e14e5..dca7ba642e 100644 --- a/src/slic3r/GUI/Camera.hpp +++ b/src/slic3r/GUI/Camera.hpp @@ -89,33 +89,24 @@ public: double get_far_z() const { return m_frustrum_zs.second; } const std::pair& get_z_range() const { return m_frustrum_zs; } -#if ENABLE_RAYCAST_PICKING double get_near_left() const; double get_near_right() const; double get_near_top() const; double get_near_bottom() const; double get_near_width() const; double get_near_height() const; -#endif // ENABLE_RAYCAST_PICKING double get_fov() const; -#if ENABLE_RAYCAST_PICKING void set_viewport(int x, int y, unsigned int w, unsigned int h); 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 void apply_view_matrix(); #endif // !ENABLE_LEGACY_OPENGL_REMOVAL // 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) 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); -#endif // ENABLE_RAYCAST_PICKING void zoom_to_box(const BoundingBoxf3& box, double margin_factor = DefaultZoomToBoxMarginFactor); void zoom_to_volumes(const GLVolumePtrs& volumes, double margin_factor = DefaultZoomToVolumesMarginFactor); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 9f2e7c0dad..0c505bc0b2 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1346,13 +1346,10 @@ void GLCanvas3D::toggle_sla_auxiliaries_visibility(bool visible, const ModelObje m_render_sla_auxiliaries = visible; -#if ENABLE_RAYCAST_PICKING std::vector>* raycasters = get_raycasters_for_picking(SceneRaycaster::EType::Volume); -#endif // ENABLE_RAYCAST_PICKING 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) && vol->composite_id.volume_id < 0) { vol->is_active = visible; @@ -1360,20 +1357,12 @@ void GLCanvas3D::toggle_sla_auxiliaries_visibility(bool visible, const ModelObje if (it != raycasters->end()) (*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) { -#if ENABLE_RAYCAST_PICKING std::vector>* raycasters = get_raycasters_for_picking(SceneRaycaster::EType::Volume); -#endif // ENABLE_RAYCAST_PICKING for (GLVolume* vol : m_volumes.volumes) { if (vol->is_wipe_tower) 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 item) { return item->get_raycaster() == vol->mesh_raycaster.get(); }); if (it != raycasters->end()) (*it)->set_active(vol->is_active); -#endif // ENABLE_RAYCAST_PICKING } if (visible && !mo) @@ -1666,12 +1654,8 @@ void GLCanvas3D::render() // 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. 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.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) { zoom_to_bed(); @@ -2266,9 +2250,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re #else #if ENABLE_LEGACY_OPENGL_REMOVAL volume.model.init_from(mesh); -#if ENABLE_RAYCAST_PICKING volume.mesh_raycaster = std::make_unique(std::make_shared(mesh)); -#endif // ENABLE_RAYCAST_PICKING #else volume.indexed_vertex_array.load_mesh(mesh); #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 #else #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.mesh_raycaster = std::make_unique(std::make_shared(new_mesh)); -#else - volume.model.init_from(m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh()); -#endif // ENABLE_RAYCAST_PICKING #else volume.indexed_vertex_array.load_mesh(m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh()); #endif // ENABLE_LEGACY_OPENGL_REMOVAL @@ -2447,7 +2425,6 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re manip->set_dirty(); } -#if ENABLE_RAYCAST_PICKING // refresh volume raycasters for picking m_scene_raycaster.remove_raycasters(SceneRaycaster::EType::Volume); 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); if (curr_gizmo != nullptr && !m_selection.is_empty()) curr_gizmo->register_raycasters_for_picking(); -#endif // ENABLE_RAYCAST_PICKING // and force this canvas to be redrawn. m_dirty = true; @@ -3010,11 +2986,7 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) // set_cursor(Standard); } else if (keyCode == WXK_CONTROL) { -#if ENABLE_RAYCAST_PICKING - if (m_mouse.dragging && !m_moving) { -#else - if (m_mouse.dragging) { -#endif // ENABLE_RAYCAST_PICKING + if (m_mouse.dragging && !m_moving) { // if the user releases CTRL while rotating the 3D scene // prevent from moving the selected volume m_mouse.drag.move_volume_idx = -1; @@ -3530,9 +3502,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) if (!evt.CmdDown()) m_mouse.drag.start_position_3D = m_mouse.scene_position; 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_RAYCAST_PICKING m_moving = true; -#endif // ENABLE_RAYCAST_PICKING TransformationType trafo_type; trafo_type.set_relative(); 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 else if (evt.LeftIsDown()) { // if dragging over blank area with left button, rotate -#if ENABLE_RAYCAST_PICKING 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()) { 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") @@ -3630,9 +3595,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_dirty = true; } 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()) { // 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()) { -#if ENABLE_RAYCAST_PICKING m_mouse.position = pos.cast(); -#endif // ENABLE_RAYCAST_PICKING if (m_layers_editing.state != LayersEditing::Unknown) { m_layers_editing.state = LayersEditing::Unknown; @@ -3685,9 +3646,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) deselect_all(); } else if (evt.RightUp()) { -#if !ENABLE_RAYCAST_PICKING - m_mouse.position = pos.cast(); -#endif // !ENABLE_RAYCAST_PICKING // 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 render(); @@ -4678,12 +4636,8 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const Camera camera; camera.set_type(camera_type); camera.set_scene_box(scene_bounding_box()); -#if ENABLE_RAYCAST_PICKING camera.set_viewport(0, 0, thumbnail_data.width, thumbnail_data.height); 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); #if ENABLE_LEGACY_OPENGL_REMOVAL @@ -4985,11 +4939,7 @@ void GLCanvas3D::_render_thumbnail_legacy(ThumbnailData& thumbnail_data, unsigne #endif // ENABLE_THUMBNAIL_GENERATOR_DEBUG_OUTPUT // restore the default framebuffer size to avoid flickering on the 3D scene -#if ENABLE_RAYCAST_PICKING 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() @@ -5456,7 +5406,6 @@ void GLCanvas3D::_refresh_if_shown_on_screen() } } -#if ENABLE_RAYCAST_PICKING void GLCanvas3D::_picking_pass() { 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(); #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 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() { @@ -5683,7 +5556,6 @@ void GLCanvas3D::_rectangular_selection_picking_pass() std::set idxs; if (m_picking_enabled) { -#if ENABLE_RAYCAST_PICKING const size_t width = std::max(m_rectangle_selection.get_width(), 1); const size_t height = std::max(m_rectangle_selection.get_height(), 1); @@ -5737,7 +5609,6 @@ void GLCanvas3D::_rectangular_selection_picking_pass() use_framebuffer = false; } } -#endif // ENABLE_RAYCAST_PICKING if (m_multisample_allowed) // 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)); -#if ENABLE_RAYCAST_PICKING const Camera& main_camera = wxGetApp().plater()->get_camera(); Camera framebuffer_camera; framebuffer_camera.set_type(main_camera.get_type()); @@ -5782,16 +5652,8 @@ void GLCanvas3D::_rectangular_selection_picking_pass() } _render_volumes_for_picking(*camera); -#else - _render_volumes_for_picking(); -#endif // ENABLE_RAYCAST_PICKING #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()); -#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 _render_bed_for_picking(!wxGetApp().plater()->get_camera().is_looking_downward()); #endif // ENABLE_LEGACY_OPENGL_REMOVAL @@ -5799,20 +5661,10 @@ void GLCanvas3D::_rectangular_selection_picking_pass() if (m_multisample_allowed) glsafe(::glEnable(GL_MULTISAMPLE)); -#if ENABLE_RAYCAST_PICKING const size_t px_count = width * height; 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(); -#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 #if USE_PARALLEL struct Pixel @@ -5846,15 +5698,13 @@ void GLCanvas3D::_rectangular_selection_picking_pass() std::vector frame(4 * px_count); 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 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()) idxs.insert(volume_id); } #endif // USE_PARALLEL -#if ENABLE_RAYCAST_PICKING if (camera != &main_camera) main_camera.apply_viewport(); @@ -5875,9 +5725,6 @@ void GLCanvas3D::_rectangular_selection_picking_pass() if (render_tex != 0) glsafe(::glDeleteTextures(1, &render_tex)); -#else - } -#endif // ENABLE_RAYCAST_PICKING } m_hover_volume_idxs.assign(idxs.begin(), idxs.end()); @@ -6280,11 +6127,7 @@ void GLCanvas3D::_render_overlays() #endif // !ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_RAYCAST_PICKING 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 GLShaderProgram* shader = wxGetApp().get_shader("flat_clip"); @@ -6300,11 +6143,7 @@ void GLCanvas3D::_render_volumes_for_picking() const glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); #endif // !ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING 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) { 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) @@ -6316,12 +6155,7 @@ void GLCanvas3D::_render_volumes_for_picking() const #if ENABLE_LEGACY_OPENGL_REMOVAL volume.first->model.set_color(picking_decode(id)); shader->start_using(); -#if ENABLE_RAYCAST_PICKING 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("volume_world_matrix", volume.first->world_matrix()); 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) return Vec3d(DBL_MAX, DBL_MAX, DBL_MAX); -#if ENABLE_RAYCAST_PICKING if (z == nullptr) { const SceneRaycaster::HitResult hit = m_scene_raycaster.hit(mouse_pos.cast(), wxGetApp().plater()->get_camera(), nullptr); return hit.is_valid() ? hit.position.cast() : _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); 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) diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index a519a26a19..b24a15bbef 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -16,9 +16,7 @@ #include "libslic3r/GCode/GCodeProcessor.hpp" #include "GCodeViewer.hpp" #include "Camera.hpp" -#if ENABLE_RAYCAST_PICKING #include "SceneRaycaster.hpp" -#endif // ENABLE_RAYCAST_PICKING #include "GUI_Utils.hpp" #include "libslic3r/Slicing.hpp" @@ -483,9 +481,7 @@ public: private: wxGLCanvas* m_canvas; wxGLContext* m_context; -#if ENABLE_RAYCAST_PICKING SceneRaycaster m_scene_raycaster; -#endif // ENABLE_RAYCAST_PICKING Bed3D &m_bed; #if ENABLE_RETINA_GL std::unique_ptr m_retina_helper; @@ -669,7 +665,6 @@ public: bool init(); void post_event(wxEvent &&event); -#if ENABLE_RAYCAST_PICKING std::shared_ptr add_raycaster_for_picking(SceneRaycaster::EType type, int id, const MeshRaycaster& raycaster, const Transform3d& trafo = Transform3d::Identity(), bool use_back_faces = false) { 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) { m_scene_raycaster.set_gizmos_on_top(value); } -#endif // ENABLE_RAYCAST_PICKING void set_as_dirty(); void requires_check_outside_state() { m_requires_check_outside_state = true; } @@ -1008,11 +1002,7 @@ private: #endif // ENABLE_RENDER_SELECTION_CENTER void _check_and_update_toolbar_icon_scale(); void _render_overlays(); -#if ENABLE_RAYCAST_PICKING void _render_volumes_for_picking(const Camera& camera) const; -#else - void _render_volumes_for_picking() const; -#endif // ENABLE_RAYCAST_PICKING void _render_current_gizmo() const; void _render_gizmos_overlay(); void _render_main_toolbar(); diff --git a/src/slic3r/GUI/GLSelectionRectangle.cpp b/src/slic3r/GUI/GLSelectionRectangle.cpp index a2c93184b8..d4b4741175 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.cpp +++ b/src/slic3r/GUI/GLSelectionRectangle.cpp @@ -30,21 +30,10 @@ namespace GUI { m_end_corner = mouse_position; } -#if ENABLE_RAYCAST_PICKING std::vector GLSelectionRectangle::contains(const std::vector& points) const -#else - std::vector GLSelectionRectangle::stop_dragging(const GLCanvas3D& canvas, const std::vector& points) -#endif // ENABLE_RAYCAST_PICKING { std::vector 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 const BoundingBox rectangle(Points{ Point(m_start_corner.cast()), Point(m_end_corner.cast()) }); diff --git a/src/slic3r/GUI/GLSelectionRectangle.hpp b/src/slic3r/GUI/GLSelectionRectangle.hpp index 16eab222ae..ac8abb6aae 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.hpp +++ b/src/slic3r/GUI/GLSelectionRectangle.hpp @@ -26,15 +26,9 @@ public: // To be called on mouse move. void dragging(const Vec2d& mouse_position); -#if ENABLE_RAYCAST_PICKING // Given a vector of points in world coordinates, the function returns indices of those // that are in the rectangle. std::vector contains(const std::vector& 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 stop_dragging(const GLCanvas3D& canvas, const std::vector& points); -#endif // ENABLE_RAYCAST_PICKING // Disables the rectangle. void stop_dragging(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp index f4200f8343..a3829fc219 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp @@ -18,29 +18,16 @@ const float GLGizmoBase::Grabber::SizeFactor = 0.05f; const float GLGizmoBase::Grabber::MinHalfSize = 1.5f; const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f; -#if ENABLE_RAYCAST_PICKING PickingModel GLGizmoBase::Grabber::s_cube; PickingModel GLGizmoBase::Grabber::s_cone; -#else -GLModel GLGizmoBase::Grabber::s_cube; -GLModel GLGizmoBase::Grabber::s_cone; -#endif // ENABLE_RAYCAST_PICKING GLGizmoBase::Grabber::~Grabber() { -#if ENABLE_RAYCAST_PICKING if (s_cube.model.is_initialized()) s_cube.model.reset(); if (s_cone.model.is_initialized()) 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 @@ -53,7 +40,6 @@ float GLGizmoBase::Grabber::get_dragging_half_size(float size) const return get_half_size(size) * DraggingScaleFactor; } -#if ENABLE_RAYCAST_PICKING void GLGizmoBase::Grabber::register_raycasters_for_picking(int id) { picking_id = id; @@ -66,13 +52,8 @@ void GLGizmoBase::Grabber::unregister_raycasters_for_picking() picking_id = -1; raycasters = { nullptr }; } -#endif // ENABLE_RAYCAST_PICKING -#if ENABLE_RAYCAST_PICKING void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color) -#else -void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, bool picking) -#endif // ENABLE_RAYCAST_PICKING { #if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_current_shader(); @@ -80,69 +61,41 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, boo return; #endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING 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 // initialized at that point (on Linux at least). indexed_triangle_set its = its_make_cube(1.0, 1.0, 1.0); its_translate(its, -0.5f * Vec3f::Ones()); #if ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING s_cube.model.init_from(its); s_cube.mesh_raycaster = std::make_unique(std::make_shared(std::move(its))); -#else - s_cube.init_from(its); -#endif // ENABLE_RAYCAST_PICKING #else s_cube.init_from(its, BoundingBoxf3{ { -0.5, -0.5, -0.5 }, { 0.5, 0.5, 0.5 } }); #endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_RAYCAST_PICKING if (!s_cone.model.is_initialized()) { indexed_triangle_set its = its_make_cone(0.375, 1.5, double(PI) / 18.0); s_cone.model.init_from(its); s_cone.mesh_raycaster = std::make_unique(std::make_shared(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); #if ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING s_cube.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(); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#if ENABLE_RAYCAST_PICKING const Transform3d& view_matrix = camera.get_view_matrix(); const Matrix3d view_matrix_no_offset = view_matrix.matrix().block(0, 0, 3, 3); std::vector 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); 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); -#if ENABLE_RAYCAST_PICKING 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); #else 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(::glScaled(2.0 * half_size, 2.0 * half_size, 2.0 * half_size)); #endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING s_cube.model.render(); 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); s_cone.model.render(); }; -#else - s_cube.render(); -#endif // ENABLE_RAYCAST_PICKING #if ENABLE_LEGACY_OPENGL_REMOVAL if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosX)) != 0) { -#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 }); 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 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 }); 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 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 }); 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 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 }); 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 ENABLE_RAYCAST_PICKING elements_matrices[5] = elements_matrices[0] * Geometry::translation_transform(Vec3d::UnitZ()); 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 ENABLE_RAYCAST_PICKING 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]); -#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 + render_extension(elements_matrices[6]); } #else 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()); #endif // !ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING if (raycasters[0] == nullptr) { GLCanvas3D& canvas = *wxGetApp().plater()->canvas3D(); 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]); } } -#endif // ENABLE_RAYCAST_PICKING } GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) @@ -327,7 +244,6 @@ bool GLGizmoBase::update_items_state() return res; } -#if ENABLE_RAYCAST_PICKING void GLGizmoBase::register_grabbers_for_picking() { 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(); } } -#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 { @@ -371,29 +277,6 @@ void GLGizmoBase::render_grabbers(float size) const 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 // call start_dragging, stop_dragging, on_dragging bool GLGizmoBase::use_grabbers(const wxMouseEvent &mouse_event) { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp index 1d134948d4..3c3f5c287e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp @@ -6,10 +6,8 @@ #include "slic3r/GUI/I18N.hpp" #include "slic3r/GUI/GLModel.hpp" -#if ENABLE_RAYCAST_PICKING #include "slic3r/GUI/MeshUtils.hpp" #include "slic3r/GUI/SceneRaycaster.hpp" -#endif // ENABLE_RAYCAST_PICKING #include @@ -73,44 +71,26 @@ protected: #endif // ENABLE_LEGACY_OPENGL_REMOVAL ColorRGBA color{ ColorRGBA::WHITE() }; EGrabberExtension extensions{ EGrabberExtension::None }; -#if ENABLE_RAYCAST_PICKING // the picking id shared by all the elements int picking_id{ -1 }; std::array, GRABBER_ELEMENTS_MAX_COUNT> raycasters = { nullptr }; -#endif // ENABLE_RAYCAST_PICKING Grabber() = default; ~Grabber(); -#if ENABLE_RAYCAST_PICKING void render(bool hover, float size) { render(size, hover ? complementary(color) : color); } -#else - void render(bool hover, float size) { render(size, hover ? complementary(color) : color, false); } - void render_for_picking(float size) { render(size, color, true); } -#endif // ENABLE_RAYCAST_PICKING float get_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 unregister_raycasters_for_picking(); -#endif // ENABLE_RAYCAST_PICKING private: -#if ENABLE_RAYCAST_PICKING void render(float size, const ColorRGBA& render_color); -#else - void render(float size, const ColorRGBA& render_color, bool picking); -#endif // ENABLE_RAYCAST_PICKING -#if ENABLE_RAYCAST_PICKING static PickingModel s_cube; static PickingModel s_cone; -#else - static GLModel s_cube; - static GLModel s_cone; -#endif // ENABLE_RAYCAST_PICKING }; public: @@ -186,9 +166,6 @@ public: bool update_items_state(); 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); /// @@ -210,10 +187,8 @@ public: /// Return True when use the information and don't want to propagate it otherwise 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 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_selection_rectangle_dragging() const { return false; } @@ -237,27 +212,15 @@ protected: virtual void on_dragging(const UpdateData& data) {} 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) {} -#if ENABLE_RAYCAST_PICKING void register_grabbers_for_picking(); void unregister_grabbers_for_picking(); virtual void on_register_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(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; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 7a853e7187..542aceead0 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -600,18 +600,12 @@ void GLGizmoEmboss::on_render() { } } -#if ENABLE_RAYCAST_PICKING void GLGizmoEmboss::on_register_raycasters_for_picking(){ m_rotate_gizmo.register_raycasters_for_picking(); } void GLGizmoEmboss::on_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 // draw suggested position of window diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp index 092041e96e..fe3ccf73bc 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp @@ -56,12 +56,8 @@ protected: bool on_init() override; std::string on_get_name() const override; void on_render() override; -#if ENABLE_RAYCAST_PICKING virtual void on_register_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; bool on_is_activable() const override { return true; } bool on_is_selectable() const override { return false; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp index ddabec7e61..463eb3182b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp @@ -131,14 +131,9 @@ void GLGizmoFlatten::on_render() update_planes(); for (int i = 0; i < (int)m_planes.size(); ++i) { #if ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING 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.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 glsafe(::glColor4fv(i == m_hover_id ? DEFAULT_HOVER_PLANE_COLOR.data() : DEFAULT_PLANE_COLOR.data())); if (m_planes[i].vbo.has_VBOs()) @@ -158,7 +153,6 @@ void GLGizmoFlatten::on_render() #endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_RAYCAST_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 @@ -183,66 +177,12 @@ void GLGizmoFlatten::on_unregister_raycasters_for_picking() m_parent.set_raycaster_gizmos_on_top(false); 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) { if (model_object != m_old_model_object) { m_planes.clear(); -#if ENABLE_RAYCAST_PICKING on_unregister_raycasters_for_picking(); -#endif // ENABLE_RAYCAST_PICKING } } @@ -259,9 +199,7 @@ void GLGizmoFlatten::update_planes() } ch = ch.convex_hull_3d(); m_planes.clear(); -#if ENABLE_RAYCAST_PICKING on_unregister_raycasters_for_picking(); -#endif // ENABLE_RAYCAST_PICKING #if ENABLE_WORLD_COORDINATE const Transform3d inst_matrix = mo->instances.front()->get_matrix_no_offset(); #else @@ -458,7 +396,6 @@ void GLGizmoFlatten::update_planes() // the vertices in order, so triangulation is trivial. for (auto& plane : m_planes) { #if ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING indexed_triangle_set its; its.vertices.reserve(plane.vertices.size()); its.indices.reserve(plane.vertices.size() / 3); @@ -470,18 +407,6 @@ void GLGizmoFlatten::update_planes() } plane.vbo.model.init_from(its); plane.vbo.mesh_raycaster = std::make_unique(std::make_shared(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(), (Vec3f)plane.normal.cast()); - init_data.add_index((unsigned int)i); - } - plane.vbo.init_from(std::move(init_data)); -#endif // ENABLE_RAYCAST_PICKING #else plane.vbo.reserve(plane.vertices.size()); for (const auto& vert : plane.vertices) @@ -496,12 +421,9 @@ void GLGizmoFlatten::update_planes() plane.vertices.shrink_to_fit(); } -#if ENABLE_RAYCAST_PICKING on_register_raycasters_for_picking(); -#endif // ENABLE_RAYCAST_PICKING } - bool GLGizmoFlatten::is_plane_update_necessary() const { const ModelObject* mo = m_c->selection_info()->model_object(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp index b4e47d3985..900a3361db 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp @@ -4,9 +4,7 @@ #include "GLGizmoBase.hpp" #if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/GLModel.hpp" -#if ENABLE_RAYCAST_PICKING #include "slic3r/GUI/MeshUtils.hpp" -#endif // ENABLE_RAYCAST_PICKING #else #include "slic3r/GUI/3DScene.hpp" #endif // ENABLE_LEGACY_OPENGL_REMOVAL @@ -30,19 +28,13 @@ private: struct PlaneData { std::vector vertices; // should be in fact local in update_planes() #if ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING PickingModel vbo; -#else - GLModel vbo; -#endif // ENABLE_RAYCAST_PICKING #else GLIndexedVertexArray vbo; #endif // ENABLE_LEGACY_OPENGL_REMOVAL Vec3d normal; float area; -#if ENABLE_RAYCAST_PICKING int picking_id{ -1 }; -#endif // ENABLE_RAYCAST_PICKING }; // This holds information to decide whether recalculation is necessary: @@ -52,9 +44,7 @@ private: Vec3d m_first_instance_mirror; std::vector m_planes; -#if ENABLE_RAYCAST_PICKING std::vector> m_planes_casters; -#endif // ENABLE_RAYCAST_PICKING bool m_mouse_left_down = false; // for detection left_up of this gizmo const ModelObject* m_old_model_object = nullptr; @@ -79,12 +69,8 @@ protected: std::string on_get_name() const override; bool on_is_activable() const override; void on_render() override; -#if ENABLE_RAYCAST_PICKING virtual void on_register_raycasters_for_picking() override; virtual void on_unregister_raycasters_for_picking() override; -#else - void on_render_for_picking() override; -#endif // ENABLE_RAYCAST_PICKING void on_set_state() override; CommonGizmosDataID on_get_requirements() const override; }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp index 51ea56c821..be04fb92c6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp @@ -55,12 +55,10 @@ void GLGizmoHollow::data_changed() } if (m_c->hollowed_mesh() && m_c->hollowed_mesh()->get_hollowed_mesh()) m_holes_in_drilled_mesh = mo->sla_drain_holes; -#if ENABLE_RAYCAST_PICKING if (m_raycasters.empty()) on_register_raycasters_for_picking(); else update_raycasters_for_picking_transform(); -#endif // ENABLE_RAYCAST_PICKING } } @@ -68,11 +66,6 @@ void GLGizmoHollow::data_changed() 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 CommonGizmosDataObjects::SelectionInfo* sel_info = m_c->selection_info(); @@ -88,11 +81,7 @@ void GLGizmoHollow::on_render() glsafe(::glEnable(GL_DEPTH_TEST)); if (selection.is_from_single_instance()) -#if ENABLE_RAYCAST_PICKING render_points(selection); -#else - render_points(selection, false); -#endif // ENABLE_RAYCAST_PICKING m_selection_rectangle.render(m_parent); m_c->object_clipper()->render_cut(); @@ -101,7 +90,6 @@ void GLGizmoHollow::on_render() glsafe(::glDisable(GL_BLEND)); } -#if ENABLE_RAYCAST_PICKING void GLGizmoHollow::on_register_raycasters_for_picking() { assert(m_raycasters.empty()); @@ -126,27 +114,11 @@ void GLGizmoHollow::on_unregister_raycasters_for_picking() m_raycasters.clear(); 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) -#else -void GLGizmoHollow::render_points(const Selection& selection, bool picking) -#endif // ENABLE_RAYCAST_PICKING { #if ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING 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) return; @@ -188,41 +160,24 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) const sla::DrainHole& drain_hole = drain_holes[i]; const bool point_selected = m_selected[i]; -#if ENABLE_RAYCAST_PICKING const bool clipped = is_mesh_point_clipped(drain_hole.pos.cast()); m_raycasters[i]->set_active(!clipped); if (clipped) continue; -#else - if (is_mesh_point_clipped(drain_hole.pos.cast())) - continue; -#endif // ENABLE_RAYCAST_PICKING // First decide about the color of the point. -#if !ENABLE_RAYCAST_PICKING - if (picking) - render_color = picking_color_component(i); - else { -#endif // !ENABLE_RAYCAST_PICKING - if (size_t(m_hover_id) == i) - render_color = ColorRGBA::CYAN(); - else if (m_c->hollowed_mesh() && - i < m_c->hollowed_mesh()->get_drainholes().size() && - 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 (size_t(m_hover_id) == i) + render_color = ColorRGBA::CYAN(); + else if (m_c->hollowed_mesh() && + i < m_c->hollowed_mesh()->get_drainholes().size() && + 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_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING 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. const Transform3d hole_matrix = Geometry::translation_transform(drain_hole.pos.cast()) * instance_scaling_matrix_inverse; #else @@ -251,11 +206,7 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) glsafe(::glTranslated(0., 0., -drain_hole.height)); glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); #endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING m_cylinder.model.render(); -#else - m_cylinder.render(); -#endif // ENABLE_RAYCAST_PICKING if (vol->is_left_handed()) 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()); m_parent.set_as_dirty(); m_wait_for_up_event = true; -#if ENABLE_RAYCAST_PICKING on_unregister_raycasters_for_picking(); on_register_raycasters_for_picking(); -#endif // ENABLE_RAYCAST_PICKING } else 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. std::vector points_inside; -#if ENABLE_RAYCAST_PICKING std::vector points_idxs = m_selection_rectangle.contains(points); m_selection_rectangle.stop_dragging(); -#else - std::vector points_idxs = m_selection_rectangle.stop_dragging(m_parent, points); -#endif // ENABLE_RAYCAST_PICKING for (size_t idx : points_idxs) points_inside.push_back(points[idx].cast()); @@ -509,10 +454,8 @@ void GLGizmoHollow::delete_selected_points() } } -#if ENABLE_RAYCAST_PICKING on_unregister_raycasters_for_picking(); on_register_raycasters_for_picking(); -#endif // ENABLE_RAYCAST_PICKING 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) { std::vector>* 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> GLGizmoHollow::get_config_options(const std::vector& keys) const @@ -900,11 +841,9 @@ RENDER_AGAIN: bool show_sups = m_c->instances_hider()->are_supports_shown(); if (m_imgui->checkbox(m_desc["show_supports"], show_sups)) { m_c->instances_hider()->show_supports(show_sups); -#if ENABLE_RAYCAST_PICKING if (show_sups) // ensure supports and pad are disabled from picking even when they are visible set_sla_auxiliary_volumes_picking_state(false); -#endif // ENABLE_RAYCAST_PICKING force_refresh = true; } @@ -1100,7 +1039,6 @@ void GLGizmoHollow::on_set_hover_id() m_hover_id = -1; } -#if ENABLE_RAYCAST_PICKING void GLGizmoHollow::init_cylinder_model() { if (!m_cylinder.model.is_initialized()) { @@ -1109,7 +1047,6 @@ void GLGizmoHollow::init_cylinder_model() m_cylinder.mesh_raycaster = std::make_unique(std::make_shared(std::move(its))); } } -#endif // ENABLE_RAYCAST_PICKING diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp index 0fdc3b2db7..ea88c4291a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp @@ -46,33 +46,19 @@ public: protected: bool on_init() override; void on_render() override; -#if ENABLE_RAYCAST_PICKING virtual void on_register_raycasters_for_picking() override; virtual void on_unregister_raycasters_for_picking() override; -#else - void on_render_for_picking() override; -#endif // ENABLE_RAYCAST_PICKING private: -#if ENABLE_RAYCAST_PICKING 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); -#if ENABLE_RAYCAST_PICKING void set_sla_auxiliary_volumes_picking_state(bool state); void update_raycasters_for_picking_transform(); -#endif // ENABLE_RAYCAST_PICKING ObjectID m_old_mo_id = -1; -#if ENABLE_RAYCAST_PICKING PickingModel m_cylinder; std::vector> 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_height = 6.f; @@ -128,9 +114,7 @@ protected: void on_load(cereal::BinaryInputArchive& ar) override; void on_save(cereal::BinaryOutputArchive& ar) const override; -#if ENABLE_RAYCAST_PICKING void init_cylinder_model(); -#endif // ENABLE_RAYCAST_PICKING }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp index 23edd6143f..bb5ebfd260 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp @@ -362,7 +362,6 @@ void GLGizmoMove3D::on_render() #endif // ENABLE_WORLD_COORDINATE } -#if ENABLE_RAYCAST_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 @@ -373,32 +372,6 @@ void GLGizmoMove3D::on_unregister_raycasters_for_picking() { 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 { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp index 7a4d82a41c..3a69e86efb 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp @@ -62,12 +62,8 @@ protected: void on_stop_dragging() override; void on_dragging(const UpdateData& data) override; void on_render() override; -#if ENABLE_RAYCAST_PICKING virtual void on_register_raycasters_for_picking() override; virtual void on_unregister_raycasters_for_picking() override; -#else - void on_render_for_picking() override; -#endif // ENABLE_RAYCAST_PICKING private: double calc_projection(const UpdateData& data) const; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp index 94aca4fdb7..d4261761f6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp @@ -138,9 +138,6 @@ private: ObjectID m_old_mo_id; size_t m_old_volumes_size = 0; void on_render() override {} -#if !ENABLE_RAYCAST_PICKING - void on_render_for_picking() override {} -#endif // !ENABLE_RAYCAST_PICKING public: GLGizmoPainterBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index 6c57df7e59..5b39c09291 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -256,33 +256,6 @@ void GLGizmoRotate::on_render() #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 void GLGizmoRotate::init_data_from_selection(const Selection& selection) { @@ -906,7 +879,6 @@ void GLGizmoRotate3D::on_render() m_gizmos[Z].render(); } -#if ENABLE_RAYCAST_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 @@ -923,7 +895,6 @@ void GLGizmoRotate3D::on_unregister_raycasters_for_picking() } m_parent.set_raycaster_gizmos_on_top(false); } -#endif // ENABLE_RAYCAST_PICKING GLGizmoRotate3D::RotoptimzeWindow::RotoptimzeWindow(ImGuiWrapper * imgui, State & state, diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp index cbc0f104b3..d117a12192 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp @@ -98,9 +98,6 @@ protected: void on_start_dragging() override; void on_dragging(const UpdateData &data) override; void on_render() override; -#if !ENABLE_RAYCAST_PICKING - void on_render_for_picking() override; -#endif // !ENABLE_RAYCAST_PICKING private: #if ENABLE_LEGACY_OPENGL_REMOVAL @@ -189,16 +186,8 @@ protected: void on_dragging(const UpdateData &data) override; void on_render() override; -#if ENABLE_RAYCAST_PICKING virtual void on_register_raycasters_for_picking() override; virtual void on_unregister_raycasters_for_picking() override; -#else - void on_render_for_picking() override { - for (GLGizmoRotate& g : m_gizmos) { - g.render_for_picking(); - } - } -#endif // ENABLE_RAYCAST_PICKING void on_render_input_window(float x, float y, float bottom_limit) override; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp index 03be5c2f4c..42c74594c7 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp @@ -650,7 +650,6 @@ void GLGizmoScale3D::on_render() #endif // ENABLE_WORLD_COORDINATE } -#if ENABLE_RAYCAST_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 @@ -661,29 +660,6 @@ void GLGizmoScale3D::on_unregister_raycasters_for_picking() { 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 void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2, const ColorRGBA& color) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp index d51cec8150..bf55115282 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp @@ -94,12 +94,8 @@ protected: virtual void on_stop_dragging() override; virtual void on_dragging(const UpdateData& data) override; virtual void on_render() override; -#if ENABLE_RAYCAST_PICKING virtual void on_register_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: #if ENABLE_LEGACY_OPENGL_REMOVAL diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp index 8317b45d71..f95aad4953 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp @@ -38,9 +38,6 @@ protected: // must implement virtual bool on_init() override { return true;}; 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; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 1646f31c7f..1520a2ef14 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -22,10 +22,8 @@ #include "libslic3r/PresetBundle.hpp" #include "libslic3r/SLAPrint.hpp" -#if ENABLE_RAYCAST_PICKING static const double CONE_RADIUS = 0.25; static const double CONE_HEIGHT = 0.75; -#endif // ENABLE_RAYCAST_PICKING namespace Slic3r { namespace GUI { @@ -51,12 +49,6 @@ bool GLGizmoSlaSupports::on_init() m_desc["clipping_of_view"] = _L("Clipping of view")+ ": "; 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; } @@ -79,12 +71,10 @@ void GLGizmoSlaSupports::data_changed() if (mo->sla_points_status == sla::PointsStatus::Generating) get_data_from_backend(); -#if ENABLE_RAYCAST_PICKING if (m_raycasters.empty()) on_register_raycasters_for_picking(); else update_raycasters_for_picking_transform(); -#endif // ENABLE_RAYCAST_PICKING } } @@ -92,7 +82,6 @@ void GLGizmoSlaSupports::data_changed() void GLGizmoSlaSupports::on_render() { -#if ENABLE_RAYCAST_PICKING if (!m_sphere.model.is_initialized()) { indexed_triangle_set its = its_make_sphere(1.0, double(PI) / 12.0); m_sphere.model.init_from(its); @@ -103,12 +92,6 @@ void GLGizmoSlaSupports::on_render() m_cone.model.init_from(its); m_cone.mesh_raycaster = std::make_unique(std::make_shared(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()) 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)); if (selection.is_from_single_instance()) -#if ENABLE_RAYCAST_PICKING render_points(selection); -#else - render_points(selection, false); -#endif // ENABLE_RAYCAST_PICKING m_selection_rectangle.render(m_parent); m_c->object_clipper()->render_cut(); @@ -140,7 +119,6 @@ void GLGizmoSlaSupports::on_render() glsafe(::glDisable(GL_BLEND)); } -#if ENABLE_RAYCAST_PICKING void GLGizmoSlaSupports::on_register_raycasters_for_picking() { assert(m_raycasters.empty()); @@ -161,20 +139,8 @@ void GLGizmoSlaSupports::on_unregister_raycasters_for_picking() m_raycasters.clear(); 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) -#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(); @@ -186,11 +152,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) return; #if ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); -#else - GLShaderProgram* shader = wxGetApp().get_shader(picking ? "flat" : "gouraud_light"); -#endif // ENABLE_RAYCAST_PICKING if (shader == nullptr) 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 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()); if (!m_raycasters.empty()) { m_raycasters[i].first->set_active(!clipped); @@ -238,48 +199,28 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) } if (clipped) continue; -#else - if (is_mesh_point_clipped(support_point.pos.cast())) - continue; -#endif // ENABLE_RAYCAST_PICKING // First decide about the color of the point. -#if !ENABLE_RAYCAST_PICKING - if (picking) - render_color = picking_color_component(i); - else { -#endif // !ENABLE_RAYCAST_PICKING - if (size_t(m_hover_id) == i && m_editing_mode) // ignore hover state unless editing mode is active - render_color = { 0.f, 1.f, 1.f, 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 }; - } + if (size_t(m_hover_id) == i && m_editing_mode) // ignore hover state unless editing mode is active + render_color = { 0.f, 1.f, 1.f, 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 - 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_RAYCAST_PICKING m_cone.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 m_cone.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; q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * m_editing_cache[i].normal.cast()); 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 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::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); 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(::glScaled(cone_radius, cone_radius, cone_height)); #endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING m_cone.model.render(); -#else - m_cone.render(); -#endif // ENABLE_RAYCAST_PICKING #if !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glPopMatrix()); #endif // !ENABLE_LEGACY_OPENGL_REMOVAL @@ -353,11 +281,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) glsafe(::glPushMatrix()); glsafe(::glScaled(radius, radius, radius)); #endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_RAYCAST_PICKING m_sphere.model.render(); -#else - m_sphere.render(); -#endif // ENABLE_RAYCAST_PICKING #if !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glPopMatrix()); #endif // !ENABLE_LEGACY_OPENGL_REMOVAL @@ -371,11 +295,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) } // Now render the drain holes: -#if ENABLE_RAYCAST_PICKING if (has_holes) { -#else - if (has_holes && ! picking) { -#endif // ENABLE_RAYCAST_PICKING render_color = { 0.7f, 0.7f, 0.7f, 0.7f }; #if ENABLE_LEGACY_OPENGL_REMOVAL 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_parent.set_as_dirty(); m_wait_for_up_event = true; -#if ENABLE_RAYCAST_PICKING on_unregister_raycasters_for_picking(); on_register_raycasters_for_picking(); -#endif // ENABLE_RAYCAST_PICKING } else 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. std::vector points_inside; -#if ENABLE_RAYCAST_PICKING std::vector points_idxs = m_selection_rectangle.contains(points); m_selection_rectangle.stop_dragging(); -#else - std::vector points_idxs = m_selection_rectangle.stop_dragging(m_parent, points); -#endif // ENABLE_RAYCAST_PICKING for (size_t idx : points_idxs) points_inside.push_back(points[idx].cast()); @@ -707,10 +621,8 @@ void GLGizmoSlaSupports::delete_selected_points(bool force) } } -#if ENABLE_RAYCAST_PICKING on_unregister_raycasters_for_picking(); on_register_raycasters_for_picking(); -#endif // ENABLE_RAYCAST_PICKING select_point(NoPoints); } @@ -1390,9 +1302,7 @@ void GLGizmoSlaSupports::switch_to_editing_mode() for (const sla::SupportPoint& sp : m_normal_cache) m_editing_cache.emplace_back(sp); select_point(NoPoints); -#if ENABLE_RAYCAST_PICKING on_register_raycasters_for_picking(); -#endif // ENABLE_RAYCAST_PICKING m_c->instances_hider()->show_supports(false); m_parent.set_as_dirty(); @@ -1406,9 +1316,7 @@ void GLGizmoSlaSupports::disable_editing_mode() wxGetApp().plater()->leave_gizmos_stack(); m_c->instances_hider()->show_supports(true); m_parent.set_as_dirty(); -#if ENABLE_RAYCAST_PICKING on_unregister_raycasters_for_picking(); -#endif // ENABLE_RAYCAST_PICKING } wxGetApp().plater()->get_notification_manager()->close_notification_of_type(NotificationType::QuitSLAManualMode); } @@ -1427,7 +1335,6 @@ bool GLGizmoSlaSupports::unsaved_changes() const return false; } -#if ENABLE_RAYCAST_PICKING void GLGizmoSlaSupports::set_sla_auxiliary_volumes_picking_state(bool state) { std::vector>* 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() : wxDialog(nullptr, wxID_ANY, _L("SLA gizmo keyboard shortcuts"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp index 136276803e..e8238c8884 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp @@ -81,23 +81,13 @@ public: private: bool on_init() override; void on_render() override; -#if ENABLE_RAYCAST_PICKING virtual void on_register_raycasters_for_picking() override; virtual void on_unregister_raycasters_for_picking() override; -#else - void on_render_for_picking() override; -#endif // ENABLE_RAYCAST_PICKING -#if ENABLE_RAYCAST_PICKING void render_points(const Selection& selection); -#else - void render_points(const Selection& selection, bool picking = false); -#endif // ENABLE_RAYCAST_PICKING bool unsaved_changes() const; -#if ENABLE_RAYCAST_PICKING void set_sla_auxiliary_volumes_picking_state(bool state); void update_raycasters_for_picking_transform(); -#endif // ENABLE_RAYCAST_PICKING bool m_lock_unique_islands = false; bool m_editing_mode = false; // Is editing mode active? @@ -110,14 +100,9 @@ private: std::vector m_normal_cache; // to restore after discarding changes or undo/redo ObjectID m_old_mo_id; -#if ENABLE_RAYCAST_PICKING PickingModel m_sphere; PickingModel m_cone; std::vector, std::shared_ptr>> m_raycasters; -#else - GLModel m_cone; - GLModel m_sphere; -#endif // ENABLE_RAYCAST_PICKING GLModel m_cylinder; // This map holds all translated description texts, so they can be easily referenced during layout calculations diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp index 11c44113bc..b044cc5c85 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp @@ -359,11 +359,7 @@ void Raycaster::on_update() if (meshes != m_old_meshes) { m_raycasters.clear(); for (const TriangleMesh* mesh : meshes) -#if ENABLE_RAYCAST_PICKING m_raycasters.emplace_back(new MeshRaycaster(std::make_shared(*mesh))); -#else - m_raycasters.emplace_back(new MeshRaycaster(*mesh)); -#endif // ENABLE_RAYCAST_PICKING m_old_meshes = meshes; } } diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index c68a510276..9c0f50c8f8 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -339,17 +339,6 @@ void GLGizmosManager::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() { if (!m_enabled) @@ -1132,9 +1121,7 @@ bool GLGizmosManager::activate_gizmo(EType type) if (old_gizmo.get_state() != GLGizmoBase::Off) return false; // gizmo refused to be turned off, do nothing. -#if ENABLE_RAYCAST_PICKING old_gizmo.unregister_raycasters_for_picking(); -#endif // ENABLE_RAYCAST_PICKING if (!m_serializing && old_gizmo.wants_enter_leave_snapshots()) Plater::TakeSnapshot @@ -1165,9 +1152,7 @@ bool GLGizmosManager::activate_gizmo(EType type) return false; // gizmo refused to be turned on. } -#if ENABLE_RAYCAST_PICKING new_gizmo.register_raycasters_for_picking(); -#endif // ENABLE_RAYCAST_PICKING // sucessful activation of gizmo return true; diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp index 1469c2ef75..b380c55c46 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp @@ -216,9 +216,6 @@ public: bool is_hiding_instances() 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_overlay(); diff --git a/src/slic3r/GUI/MeshUtils.cpp b/src/slic3r/GUI/MeshUtils.cpp index 68572c801e..8ac1af7dcd 100644 --- a/src/slic3r/GUI/MeshUtils.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -370,13 +370,8 @@ Vec3f MeshRaycaster::get_triangle_normal(size_t facet_idx) const return m_normals[facet_idx]; } -#if ENABLE_RAYCAST_PICKING void MeshRaycaster::line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera, Vec3d& point, Vec3d& direction) -#else -void MeshRaycaster::line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera, - Vec3d& point, Vec3d& direction) -#endif // ENABLE_RAYCAST_PICKING { Matrix4d modelview = camera.get_view_matrix().matrix(); Matrix4d projection= camera.get_projection_matrix().matrix(); @@ -540,7 +535,6 @@ std::vector MeshRaycaster::get_unobscured_idxs(const Geometry::Transfo return out; } -#if ENABLE_RAYCAST_PICKING 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 { @@ -573,7 +567,6 @@ bool MeshRaycaster::closest_hit(const Vec2d& mouse_pos, const Transform3d& trafo return true; } -#endif // ENABLE_RAYCAST_PICKING Vec3f MeshRaycaster::get_closest_point(const Vec3f& point, Vec3f* normal) const { diff --git a/src/slic3r/GUI/MeshUtils.hpp b/src/slic3r/GUI/MeshUtils.hpp index 9db2ed1b1f..f1225c4ff9 100644 --- a/src/slic3r/GUI/MeshUtils.hpp +++ b/src/slic3r/GUI/MeshUtils.hpp @@ -15,9 +15,7 @@ #include #include -#if ENABLE_RAYCAST_PICKING #include -#endif // ENABLE_RAYCAST_PICKING namespace Slic3r { @@ -61,10 +59,8 @@ public: void set_offset(double offset) { m_data[3] = offset; } double get_offset() const { return m_data[3]; } 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; } ClippingPlane inverted_normal() const { return ClippingPlane(-get_normal(), get_offset()); } -#endif // ENABLE_RAYCAST_PICKING bool is_active() const { return m_data[3] != DBL_MAX; } static ClippingPlane ClipsNothing() { return ClippingPlane(Vec3d(0., 0., 1.), DBL_MAX); } const std::array& get_data() const { return m_data; } @@ -155,7 +151,6 @@ private: // whether certain points are visible or obscured by the mesh etc. class MeshRaycaster { public: -#if ENABLE_RAYCAST_PICKING explicit MeshRaycaster(std::shared_ptr mesh) : m_mesh(mesh) , 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, 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. bool unproject_on_mesh( @@ -208,7 +189,6 @@ public: const ClippingPlane* clipping_plane = nullptr // clipping plane (if active) ) const; -#if ENABLE_RAYCAST_PICKING // 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, // 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) size_t* facet_idx = nullptr // index of the facet hit ) const; -#endif // ENABLE_RAYCAST_PICKING // Given a point in world coords, the method returns closest point on the mesh. // The output is in mesh coords. @@ -234,14 +213,11 @@ public: Vec3f get_triangle_normal(size_t facet_idx) const; private: -#if ENABLE_RAYCAST_PICKING std::shared_ptr m_mesh; -#endif // ENABLE_RAYCAST_PICKING AABBMesh m_emesh; std::vector m_normals; }; -#if ENABLE_RAYCAST_PICKING struct PickingModel { GLModel model; @@ -252,7 +228,6 @@ struct PickingModel mesh_raycaster.reset(); } }; -#endif // ENABLE_RAYCAST_PICKING } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/SceneRaycaster.cpp b/src/slic3r/GUI/SceneRaycaster.cpp index a92c622c1b..619e26042b 100644 --- a/src/slic3r/GUI/SceneRaycaster.cpp +++ b/src/slic3r/GUI/SceneRaycaster.cpp @@ -4,8 +4,6 @@ #include "Camera.hpp" #include "GUI_App.hpp" -#if ENABLE_RAYCAST_PICKING - namespace Slic3r { namespace GUI { @@ -233,5 +231,3 @@ int SceneRaycaster::decode_id(EType type, int id) { return id - base_id(type); } } // namespace GUI } // namespace Slic3r - -#endif // ENABLE_RAYCAST_PICKING diff --git a/src/slic3r/GUI/SceneRaycaster.hpp b/src/slic3r/GUI/SceneRaycaster.hpp index 2254a2022d..3119e6d1e7 100644 --- a/src/slic3r/GUI/SceneRaycaster.hpp +++ b/src/slic3r/GUI/SceneRaycaster.hpp @@ -1,8 +1,6 @@ #ifndef slic3r_SceneRaycaster_hpp_ #define slic3r_SceneRaycaster_hpp_ -#if ENABLE_RAYCAST_PICKING - #include "MeshUtils.hpp" #include "GLModel.hpp" #include @@ -115,6 +113,4 @@ private: } // namespace GUI } // namespace Slic3r -#endif // ENABLE_RAYCAST_PICKING - #endif // slic3r_SceneRaycaster_hpp_ diff --git a/src/slic3r/Utils/RaycastManager.cpp b/src/slic3r/Utils/RaycastManager.cpp index 14c76722d9..084cf83a63 100644 --- a/src/slic3r/Utils/RaycastManager.cpp +++ b/src/slic3r/Utils/RaycastManager.cpp @@ -26,11 +26,7 @@ void RaycastManager::actualize(const ModelObject *object, const ISkip *skip) }); if (item == m_raycasters.end()) { // add new raycaster -#if ENABLE_RAYCAST_PICKING auto raycaster = std::make_unique(volume->get_mesh_shared_ptr()); -#else // !ENABLE_RAYCAST_PICKING - auto raycaster = std::make_unique(volume->mesh()); -#endif // ENABLE_RAYCAST_PICKING m_raycasters.emplace_back(std::make_pair(oid, std::move(raycaster))); } else { size_t index = item - m_raycasters.begin(); diff --git a/tests/libslic3r/test_color.cpp b/tests/libslic3r/test_color.cpp index 632691669e..bb35f5e38e 100644 --- a/tests/libslic3r/test_color.cpp +++ b/tests/libslic3r/test_color.cpp @@ -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(255), static_cast(127), static_cast(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 - From 7b569c4eb71e77646bfe7dbe9447cfd8cd516486 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 5 Dec 2022 13:52:49 +0100 Subject: [PATCH 090/109] Gizmo measure - Do not show distance strict if distance infinite is already shown --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index a2d2518d6a..8c4b468260 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -2051,8 +2051,7 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit ++measure_row_count; ImGui::PopID(); } - if (measure.distance_strict.has_value() && - (!measure.distance_infinite.has_value() || std::abs(measure.distance_strict->dist - measure.distance_infinite->dist) > EPSILON)) { + if (measure.distance_strict.has_value() && !measure.distance_infinite.has_value()) { double distance = measure.distance_strict->dist; if (use_inches) distance = ObjectManipulation::mm_to_in * distance; From bed64cb7c7ceac5531762c06c715d92b15556ad6 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 5 Dec 2022 13:28:56 +0100 Subject: [PATCH 091/109] Measurement: optimize plane highlighting --- src/libslic3r/Measure.cpp | 29 ++++++++++++++++-------- src/libslic3r/Measure.hpp | 11 +++++---- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 14 ++++-------- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 6368f30f57..89af1cf826 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -68,7 +68,8 @@ public: std::vector get_all_features() const; std::optional get_feature(size_t face_idx, const Vec3d& point) const; - std::vector> get_planes_triangle_indices() const; + int get_num_of_planes() const; + const std::vector& get_plane_triangle_indices(int idx) const; const std::vector& get_plane_features(unsigned int plane_id) const; const TriangleMesh& get_mesh() const; @@ -554,12 +555,17 @@ std::optional MeasuringImpl::get_feature(size_t face_idx, const -std::vector> MeasuringImpl::get_planes_triangle_indices() const +int MeasuringImpl::get_num_of_planes() const { - std::vector> out; - for (const PlaneData& plane : m_planes) - out.emplace_back(plane.facets); - return out; + return (m_planes.size()); +} + + + +const std::vector& MeasuringImpl::get_plane_triangle_indices(int idx) const +{ + assert(idx >= 0 && idx < int(m_planes.size())); + return m_planes[idx].facets; } const std::vector& MeasuringImpl::get_plane_features(unsigned int plane_id) const @@ -602,10 +608,15 @@ std::optional Measuring::get_feature(size_t face_idx, const Vec3 } - -std::vector> Measuring::get_planes_triangle_indices() const +int Measuring::get_num_of_planes() const { - return priv->get_planes_triangle_indices(); + return priv->get_num_of_planes(); +} + + +const std::vector& Measuring::get_plane_triangle_indices(int idx) const +{ + return priv->get_plane_triangle_indices(idx); } const std::vector& Measuring::get_plane_features(unsigned int plane_id) const diff --git a/src/libslic3r/Measure.hpp b/src/libslic3r/Measure.hpp index 3a1a4b89d9..b1d2e611f2 100644 --- a/src/libslic3r/Measure.hpp +++ b/src/libslic3r/Measure.hpp @@ -102,11 +102,12 @@ public: // should be highlighted (if any). std::optional get_feature(size_t face_idx, const Vec3d& point) const; - // Returns a list of triangle indices for each identified plane. Each - // Plane object contains an index into this vector. Expensive, do not - // call too often. - std::vector> get_planes_triangle_indices() const; - + // Return total number of planes. + int get_num_of_planes() const; + + // Returns a list of triangle indices for given plane. + const std::vector& get_plane_triangle_indices(int idx) const; + // Returns the surface features of the plane with the given index const std::vector& get_plane_features(unsigned int plane_id) const; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 8c4b468260..0e3f480cc8 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -93,11 +93,8 @@ static std::string center_on_feature_type_as_string(Measure::SurfaceFeatureType return ret; } -static GLModel::Geometry init_plane_data(const indexed_triangle_set& its, const std::vector>& planes_triangles, int idx) +static GLModel::Geometry init_plane_data(const indexed_triangle_set& its, const std::vector& triangle_indices) { - assert(0 <= idx && idx < (int)planes_triangles.size()); - const std::vector& triangle_indices = planes_triangles[idx]; - GLModel::Geometry init_data; init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; unsigned int i = 0; @@ -653,8 +650,8 @@ void GLGizmoMeasure::on_render() if (m_last_plane_idx != idx) { m_last_plane_idx = idx; const indexed_triangle_set& its = m_measuring->get_mesh().its; - const std::vector> planes_triangles = m_measuring->get_planes_triangle_indices(); - GLModel::Geometry init_data = init_plane_data(its, planes_triangles, idx); + const std::vector& plane_triangles = m_measuring->get_plane_triangle_indices(idx); + GLModel::Geometry init_data = init_plane_data(its, plane_triangles); m_plane.reset(); m_plane.mesh_raycaster = std::make_unique(std::make_shared(init_data.get_as_indexed_triangle_set())); m_plane.model.init_from(std::move(init_data)); @@ -1041,10 +1038,9 @@ void GLGizmoMeasure::update_if_needed() { auto update_plane_models_cache = [this](const indexed_triangle_set& its) { m_plane_models_cache.clear(); - const std::vector> planes_triangles = m_measuring->get_planes_triangle_indices(); - for (int idx = 0; idx < (int)planes_triangles.size(); ++idx) { + for (int idx = 0; idx < m_measuring->get_num_of_planes(); ++idx) { m_plane_models_cache.emplace_back(GLModel()); - GLModel::Geometry init_data = init_plane_data(its, planes_triangles, idx); + GLModel::Geometry init_data = init_plane_data(its, m_measuring->get_plane_triangle_indices(idx)); m_plane_models_cache.back().init_from(std::move(init_data)); } }; From a37f09edaa6829736b62e5b2aa5c42fe669ed0fc Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 5 Dec 2022 14:50:25 +0100 Subject: [PATCH 092/109] Measurement: optimize feature extraction: - do not call ransac when not needed - decrease number of ransac iterations - precalculate inverse of transformation matrix - pass the min error from ransac algorithm, do not calculate it again --- src/libslic3r/Geometry/Circle.cpp | 4 +- src/libslic3r/Geometry/Circle.hpp | 2 +- src/libslic3r/Measure.cpp | 83 ++++++++++-------------- src/libslic3r/Measure.hpp | 5 +- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 1 - 5 files changed, 40 insertions(+), 55 deletions(-) diff --git a/src/libslic3r/Geometry/Circle.cpp b/src/libslic3r/Geometry/Circle.cpp index 4d7c38ccc2..6796671954 100644 --- a/src/libslic3r/Geometry/Circle.cpp +++ b/src/libslic3r/Geometry/Circle.cpp @@ -108,7 +108,7 @@ Circled circle_taubin_newton(const Vec2ds& input, size_t cycles) return out; } -Circled circle_ransac(const Vec2ds& input, size_t iterations) +Circled circle_ransac(const Vec2ds& input, size_t iterations, double* min_error) { if (input.size() < 3) return Circled::make_invalid(); @@ -132,6 +132,8 @@ Circled circle_ransac(const Vec2ds& input, size_t iterations) circle_best = c; } } + if (min_error) + *min_error = err_min; return circle_best; } diff --git a/src/libslic3r/Geometry/Circle.hpp b/src/libslic3r/Geometry/Circle.hpp index 39973d916d..653102e2ab 100644 --- a/src/libslic3r/Geometry/Circle.hpp +++ b/src/libslic3r/Geometry/Circle.hpp @@ -102,7 +102,7 @@ inline Vec2d circle_center_taubin_newton(const Vec2ds& input, size_t cycles = 20 Circled circle_taubin_newton(const Vec2ds& input, size_t cycles = 20); // Find circle using RANSAC randomized algorithm. -Circled circle_ransac(const Vec2ds& input, size_t iterations = 20); +Circled circle_ransac(const Vec2ds& input, size_t iterations = 20, double* min_error = nullptr); // Randomized algorithm by Emo Welzl, working with squared radii for efficiency. The returned circle radius is inflated by epsilon. template diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 89af1cf826..747da622c8 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -14,7 +14,7 @@ namespace Measure { constexpr double feature_hover_limit = 0.5; // how close to a feature the mouse must be to highlight it -static std::pair get_center_and_radius(const std::vector& points, const Transform3d& trafo) +static std::tuple get_center_and_radius(const std::vector& points, const Transform3d& trafo, const Transform3d& trafo_inv) { Vec2ds out; double z = 0.; @@ -24,18 +24,17 @@ static std::pair get_center_and_radius(const std::vector& out.emplace_back(pt_transformed.x(), pt_transformed.y()); } - auto circle = Geometry::circle_ransac(out, 20); // FIXME: iterations? + const int iter = points.size() < 10 ? 2 : + points.size() < 100 ? 4 : + 6; - return std::make_pair(trafo.inverse() * Vec3d(circle.center.x(), circle.center.y(), z), circle.radius); + double error = std::numeric_limits::max(); + auto circle = Geometry::circle_ransac(out, iter, &error); + + return std::make_tuple(trafo.inverse() * Vec3d(circle.center.x(), circle.center.y(), z), circle.radius, error); } -static bool circle_fit_is_ok(const std::vector& pts, const Vec3d& center, double radius) -{ - for (const Vec3d& pt : pts) - if (std::abs((pt - center).norm() - radius) > 0.05) - return false; - return true; -} + static std::array orthonormal_basis(const Vec3d& v) { @@ -66,7 +65,6 @@ public: float area; }; - std::vector get_all_features() const; std::optional get_feature(size_t face_idx, const Vec3d& point) const; int get_num_of_planes() const; const std::vector& get_plane_triangle_indices(int idx) const; @@ -267,7 +265,8 @@ void MeasuringImpl::extract_features() Eigen::Quaterniond q; q.setFromTwoVectors(plane.normal, Vec3d::UnitZ()); Transform3d trafo = Transform3d::Identity(); - trafo.rotate(q); + trafo.rotate(q); + const Transform3d trafo_inv = trafo.inverse(); for (const std::vector& border : plane.borders) { if (border.size() <= 1) @@ -275,28 +274,31 @@ void MeasuringImpl::extract_features() bool done = false; - if (const auto& [center, radius] = get_center_and_radius(border, trafo); - (border.size()>4) && circle_fit_is_ok(border, center, radius)) { - // The whole border is one circle. Just add it into the list of features - // and we are done. + if (border.size() > 4) { + const auto& [center, radius, err] = get_center_and_radius(border, trafo, trafo_inv); - bool is_polygon = border.size()>4 && border.size()<=8; - bool lengths_match = std::all_of(border.begin()+2, border.end(), [is_polygon](const Vec3d& pt) { - return Slic3r::is_approx((pt - *((&pt)-1)).squaredNorm(), (*((&pt)-1) - *((&pt)-2)).squaredNorm(), is_polygon ? 0.01 : 0.01); - }); + if (err < 0.05) { + // The whole border is one circle. Just add it into the list of features + // and we are done. - if (lengths_match && (is_polygon || border.size() > 8)) { - if (is_polygon) { - // This is a polygon, add the separate edges with the center. - for (int j=0; j4 && border.size()<=8; + bool lengths_match = std::all_of(border.begin()+2, border.end(), [is_polygon](const Vec3d& pt) { + return Slic3r::is_approx((pt - *((&pt)-1)).squaredNorm(), (*((&pt)-1) - *((&pt)-2)).squaredNorm(), is_polygon ? 0.01 : 0.01); + }); + + if (lengths_match && (is_polygon || border.size() > 8)) { + if (is_polygon) { + // This is a polygon, add the separate edges with the center. + for (int j=0; j 0.9*M_PI/2.; @@ -485,16 +487,6 @@ void MeasuringImpl::extract_features() -std::vector MeasuringImpl::get_all_features() const -{ - std::vector features; - //PlaneData& plane = m_planes[0]; - for (const PlaneData& plane : m_planes) - for (const SurfaceFeature& feature : plane.surface_features) - features.emplace_back(feature); - return features; -} - @@ -596,11 +588,6 @@ Measuring::Measuring(const indexed_triangle_set& its) Measuring::~Measuring() {} -std::vector Measuring::get_all_features() const -{ - return priv->get_all_features(); -} - std::optional Measuring::get_feature(size_t face_idx, const Vec3d& point) const { diff --git a/src/libslic3r/Measure.hpp b/src/libslic3r/Measure.hpp index b1d2e611f2..a273135ca8 100644 --- a/src/libslic3r/Measure.hpp +++ b/src/libslic3r/Measure.hpp @@ -93,10 +93,7 @@ public: // Construct the measurement object on a given its. explicit Measuring(const indexed_triangle_set& its); ~Measuring(); - - // Return a reference to a list of all features identified on the its. - // Use only for debugging. Expensive, do not call often. - std::vector get_all_features() const; + // Given a face_idx where the mouse cursor points, return a feature that // should be highlighted (if any). diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 0e3f480cc8..6994bfa329 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -654,7 +654,6 @@ void GLGizmoMeasure::on_render() GLModel::Geometry init_data = init_plane_data(its, plane_triangles); m_plane.reset(); m_plane.mesh_raycaster = std::make_unique(std::make_shared(init_data.get_as_indexed_triangle_set())); - m_plane.model.init_from(std::move(init_data)); } m_raycasters.insert({ PLANE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, PLANE_ID, *m_plane.mesh_raycaster) }); From a47bb5bf1b93e0fe711bd05bac7a9dba3815d282 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 5 Dec 2022 15:25:31 +0100 Subject: [PATCH 093/109] Measurement: extract features on the fly, not when the tool is opened --- src/libslic3r/Measure.cpp | 409 ++++++++++++++++++++------------------ 1 file changed, 212 insertions(+), 197 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 747da622c8..08c17df47b 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -8,6 +8,8 @@ #include +#define DEBUG_EXTRACT_ALL_FEATURES_AT_ONCE 0 + namespace Slic3r { namespace Measure { @@ -63,17 +65,18 @@ public: std::vector surface_features; Vec3d normal; float area; + bool features_extracted = false; }; - std::optional get_feature(size_t face_idx, const Vec3d& point) const; + std::optional get_feature(size_t face_idx, const Vec3d& point); int get_num_of_planes() const; const std::vector& get_plane_triangle_indices(int idx) const; - const std::vector& get_plane_features(unsigned int plane_id) const; + const std::vector& get_plane_features(unsigned int plane_id); const TriangleMesh& get_mesh() const; private: void update_planes(); - void extract_features(); + void extract_features(int plane_idx); std::vector m_planes; std::vector m_face_to_plane; @@ -89,7 +92,13 @@ MeasuringImpl::MeasuringImpl(const indexed_triangle_set& its) : m_mesh(its) { update_planes(); - extract_features(); + + // Extracting features will be done as needed. + // To extract all planes at once, run the following: +#if DEBUG_EXTRACT_ALL_FEATURES_AT_ONCE + for (int i=0; i angles; // placed in outer scope to prevent reallocations std::vector lengths; + for (const std::vector& border : plane.borders) { + if (border.size() <= 1) + continue; - for (int i=0; i<(int)m_planes.size(); ++i) { - PlaneData& plane = m_planes[i]; - plane.surface_features.clear(); - const Vec3d& normal = plane.normal; + bool done = false; - Eigen::Quaterniond q; - q.setFromTwoVectors(plane.normal, Vec3d::UnitZ()); - Transform3d trafo = Transform3d::Identity(); - trafo.rotate(q); - const Transform3d trafo_inv = trafo.inverse(); + if (border.size() > 4) { + const auto& [center, radius, err] = get_center_and_radius(border, trafo, trafo_inv); - for (const std::vector& border : plane.borders) { - if (border.size() <= 1) - continue; + if (err < 0.05) { + // The whole border is one circle. Just add it into the list of features + // and we are done. - bool done = false; + bool is_polygon = border.size()>4 && border.size()<=8; + bool lengths_match = std::all_of(border.begin()+2, border.end(), [is_polygon](const Vec3d& pt) { + return Slic3r::is_approx((pt - *((&pt)-1)).squaredNorm(), (*((&pt)-1) - *((&pt)-2)).squaredNorm(), is_polygon ? 0.01 : 0.01); + }); - if (border.size() > 4) { - const auto& [center, radius, err] = get_center_and_radius(border, trafo, trafo_inv); - - if (err < 0.05) { - // The whole border is one circle. Just add it into the list of features - // and we are done. - - bool is_polygon = border.size()>4 && border.size()<=8; - bool lengths_match = std::all_of(border.begin()+2, border.end(), [is_polygon](const Vec3d& pt) { - return Slic3r::is_approx((pt - *((&pt)-1)).squaredNorm(), (*((&pt)-1) - *((&pt)-2)).squaredNorm(), is_polygon ? 0.01 : 0.01); - }); - - if (lengths_match && (is_polygon || border.size() > 8)) { - if (is_polygon) { - // This is a polygon, add the separate edges with the center. - for (int j=0; j 8)) { + if (is_polygon) { + // This is a polygon, add the separate edges with the center. + for (int j=0; j int { - assert(std::abs(offset) < border_size); - int out = idx+offset; - if (out >= border_size) - out = out - border_size; - else if (out < 0) - out = border_size + out; + // Given an idx into border, return the index that is idx+offset position, + // while taking into account the need for wrap-around and the fact that + // the first and last point are the same. + auto offset_to_index = [border_size = int(border.size())](int idx, int offset) -> int { + assert(std::abs(offset) < border_size); + int out = idx+offset; + if (out >= border_size) + out = out - border_size; + else if (out < 0) + out = border_size + out; - return out; - }; + return out; + }; - // First calculate angles at all the vertices. - angles.clear(); - lengths.clear(); - int first_different_angle_idx = 0; - for (int i=0; i M_PI) - angle = 2*M_PI - angle; + // First calculate angles at all the vertices. + angles.clear(); + lengths.clear(); + int first_different_angle_idx = 0; + for (int i=0; i M_PI) + angle = 2*M_PI - angle; - angles.push_back(angle); - lengths.push_back(v2.norm()); - if (first_different_angle_idx == 0 && angles.size() > 1) { - if (! are_angles_same(angles.back(), angles[angles.size()-2])) - first_different_angle_idx = angles.size()-1; - } + angles.push_back(angle); + lengths.push_back(v2.norm()); + if (first_different_angle_idx == 0 && angles.size() > 1) { + if (! are_angles_same(angles.back(), angles[angles.size()-2])) + first_different_angle_idx = angles.size()-1; } - assert(border.size() == angles.size()); - assert(border.size() == lengths.size()); + } + assert(border.size() == angles.size()); + assert(border.size() == lengths.size()); - // First go around the border and pick what might be circular segments. - // Save pair of indices to where such potential segments start and end. - // Also remember the length of these segments. - int start_idx = -1; - bool circle = false; - bool first_iter = true; - std::vector circles; - std::vector edges; - std::vector> circles_idxs; - //std::vector circles_lengths; - std::vector single_circle; // could be in loop-scope, but reallocations - double single_circle_length = 0.; - int first_pt_idx = offset_to_index(first_different_angle_idx, 1); - int i = first_pt_idx; - while (i != first_pt_idx || first_iter) { - if (are_angles_same(angles[i], angles[offset_to_index(i,-1)]) - && i != offset_to_index(first_pt_idx, -1) // not the last point - && i != start_idx ) { - // circle - if (! circle) { - circle = true; - single_circle.clear(); - single_circle_length = 0.; - start_idx = offset_to_index(i, -2); - single_circle = { border[start_idx], border[offset_to_index(start_idx,1)] }; - single_circle_length += lengths[offset_to_index(i, -1)]; - } + // First go around the border and pick what might be circular segments. + // Save pair of indices to where such potential segments start and end. + // Also remember the length of these segments. + int start_idx = -1; + bool circle = false; + bool first_iter = true; + std::vector circles; + std::vector edges; + std::vector> circles_idxs; + //std::vector circles_lengths; + std::vector single_circle; // could be in loop-scope, but reallocations + double single_circle_length = 0.; + int first_pt_idx = offset_to_index(first_different_angle_idx, 1); + int i = first_pt_idx; + while (i != first_pt_idx || first_iter) { + if (are_angles_same(angles[i], angles[offset_to_index(i,-1)]) + && i != offset_to_index(first_pt_idx, -1) // not the last point + && i != start_idx ) { + // circle + if (! circle) { + circle = true; + single_circle.clear(); + single_circle_length = 0.; + start_idx = offset_to_index(i, -2); + single_circle = { border[start_idx], border[offset_to_index(start_idx,1)] }; + single_circle_length += lengths[offset_to_index(i, -1)]; + } + single_circle.emplace_back(border[i]); + single_circle_length += lengths[i]; + } else { + if (circle && single_circle.size() >= 5) { // Less than 5 vertices? Not a circle. single_circle.emplace_back(border[i]); single_circle_length += lengths[i]; - } else { - if (circle && single_circle.size() >= 5) { // Less than 5 vertices? Not a circle. - single_circle.emplace_back(border[i]); - single_circle_length += lengths[i]; - bool accept_circle = true; - { - // Check that lengths of internal (!!!) edges match. - int j = offset_to_index(start_idx, 3); - while (j != i) { - if (! are_lengths_same(lengths[offset_to_index(j,-1)], lengths[j])) { - accept_circle = false; - break; - } - j = offset_to_index(j, 1); + bool accept_circle = true; + { + // Check that lengths of internal (!!!) edges match. + int j = offset_to_index(start_idx, 3); + while (j != i) { + if (! are_lengths_same(lengths[offset_to_index(j,-1)], lengths[j])) { + accept_circle = false; + break; } + j = offset_to_index(j, 1); } + } + + if (accept_circle) { + const auto& [center, radius, err] = get_center_and_radius(single_circle, trafo, trafo_inv); + + // Check that the fit went well. The tolerance is high, only to + // reject complete failures. + accept_circle &= err < 0.05; + + // If the segment subtends less than 90 degrees, throw it away. + accept_circle &= single_circle_length / radius > 0.9*M_PI/2.; if (accept_circle) { - const auto& [center, radius, err] = get_center_and_radius(single_circle, trafo, trafo_inv); - - // Check that the fit went well. The tolerance is high, only to - // reject complete failures. - accept_circle &= err < 0.05; - - // If the segment subtends less than 90 degrees, throw it away. - accept_circle &= single_circle_length / radius > 0.9*M_PI/2.; - - if (accept_circle) { - // Add the circle and remember indices into borders. - circles_idxs.emplace_back(start_idx, i); - circles.emplace_back(SurfaceFeature(SurfaceFeatureType::Circle, center, plane.normal, std::nullopt, radius)); - } + // Add the circle and remember indices into borders. + circles_idxs.emplace_back(start_idx, i); + circles.emplace_back(SurfaceFeature(SurfaceFeatureType::Circle, center, plane.normal, std::nullopt, radius)); } } - circle = false; } - // Take care of the wrap around. - first_iter = false; + circle = false; + } + // Take care of the wrap around. + first_iter = false; + i = offset_to_index(i, 1); + } + + // We have the circles. Now go around again and pick edges, while jumping over circles. + if (circles_idxs.empty()) { + // Just add all edges. + for (int i=1; i 1 || circles_idxs.front().first != circles_idxs.front().second) { + // There is at least one circular segment. Start at its end and add edges until the start of the next one. + int i = circles_idxs.front().second; + int circle_idx = 1; + while (true) { i = offset_to_index(i, 1); - } - - // We have the circles. Now go around again and pick edges, while jumping over circles. - if (circles_idxs.empty()) { - // Just add all edges. - for (int i=1; i 1 || circles_idxs.front().first != circles_idxs.front().second) { - // There is at least one circular segment. Start at its end and add edges until the start of the next one. - int i = circles_idxs.front().second; - int circle_idx = 1; - while (true) { - i = offset_to_index(i, 1); - edges.emplace_back(SurfaceFeature(SurfaceFeatureType::Edge, border[offset_to_index(i,-1)], border[i])); - if (circle_idx < int(circles_idxs.size()) && i == circles_idxs[circle_idx].first) { - i = circles_idxs[circle_idx].second; - ++circle_idx; - } - if (i == circles_idxs.front().first) - break; + edges.emplace_back(SurfaceFeature(SurfaceFeatureType::Edge, border[offset_to_index(i,-1)], border[i])); + if (circle_idx < int(circles_idxs.size()) && i == circles_idxs[circle_idx].first) { + i = circles_idxs[circle_idx].second; + ++circle_idx; } + if (i == circles_idxs.front().first) + break; } + } - // Merge adjacent edges where needed. - assert(std::all_of(edges.begin(), edges.end(), - [](const SurfaceFeature& f) { return f.get_type() == SurfaceFeatureType::Edge; })); - for (int i=edges.size()-1; i>=0; --i) { - const auto& [first_start, first_end] = edges[i==0 ? edges.size()-1 : i-1].get_edge(); - const auto& [second_start, second_end] = edges[i].get_edge(); + // Merge adjacent edges where needed. + assert(std::all_of(edges.begin(), edges.end(), + [](const SurfaceFeature& f) { return f.get_type() == SurfaceFeatureType::Edge; })); + for (int i=edges.size()-1; i>=0; --i) { + const auto& [first_start, first_end] = edges[i==0 ? edges.size()-1 : i-1].get_edge(); + const auto& [second_start, second_end] = edges[i].get_edge(); - if (Slic3r::is_approx(first_end, second_start) - && Slic3r::is_approx((first_end-first_start).normalized().dot((second_end-second_start).normalized()), 1.)) { - // The edges have the same direction and share a point. Merge them. - edges[i==0 ? edges.size()-1 : i-1] = SurfaceFeature(SurfaceFeatureType::Edge, first_start, second_end); - edges.erase(edges.begin() + i); - } + if (Slic3r::is_approx(first_end, second_start) + && Slic3r::is_approx((first_end-first_start).normalized().dot((second_end-second_start).normalized()), 1.)) { + // The edges have the same direction and share a point. Merge them. + edges[i==0 ? edges.size()-1 : i-1] = SurfaceFeature(SurfaceFeatureType::Edge, first_start, second_end); + edges.erase(edges.begin() + i); } - - // Now move the circles and edges into the feature list for the plane. - assert(std::all_of(circles.begin(), circles.end(), [](const SurfaceFeature& f) { - return f.get_type() == SurfaceFeatureType::Circle; - })); - assert(std::all_of(edges.begin(), edges.end(), [](const SurfaceFeature& f) { - return f.get_type() == SurfaceFeatureType::Edge; - })); - plane.surface_features.insert(plane.surface_features.end(), std::make_move_iterator(circles.begin()), - std::make_move_iterator(circles.end())); - plane.surface_features.insert(plane.surface_features.end(), std::make_move_iterator(edges.begin()), - std::make_move_iterator(edges.end())); } - } - // The last surface feature is the plane itself. - Vec3d cog = Vec3d::Zero(); - size_t counter = 0; - for (const std::vector& b : plane.borders) { - for (size_t i = 1; i < b.size(); ++i) { - cog += b[i]; - ++counter; - } + // Now move the circles and edges into the feature list for the plane. + assert(std::all_of(circles.begin(), circles.end(), [](const SurfaceFeature& f) { + return f.get_type() == SurfaceFeatureType::Circle; + })); + assert(std::all_of(edges.begin(), edges.end(), [](const SurfaceFeature& f) { + return f.get_type() == SurfaceFeatureType::Edge; + })); + plane.surface_features.insert(plane.surface_features.end(), std::make_move_iterator(circles.begin()), + std::make_move_iterator(circles.end())); + plane.surface_features.insert(plane.surface_features.end(), std::make_move_iterator(edges.begin()), + std::make_move_iterator(edges.end())); } - cog /= double(counter); - plane.surface_features.emplace_back(SurfaceFeature(SurfaceFeatureType::Plane, - plane.normal, cog, std::optional(), i + 0.0001)); - - plane.borders.clear(); - plane.borders.shrink_to_fit(); } + + // The last surface feature is the plane itself. + Vec3d cog = Vec3d::Zero(); + size_t counter = 0; + for (const std::vector& b : plane.borders) { + for (size_t i = 1; i < b.size(); ++i) { + cog += b[i]; + ++counter; + } + } + cog /= double(counter); + plane.surface_features.emplace_back(SurfaceFeature(SurfaceFeatureType::Plane, + plane.normal, cog, std::optional(), plane_idx + 0.0001)); + + plane.borders.clear(); + plane.borders.shrink_to_fit(); + + plane.features_extracted = true; } @@ -492,12 +502,15 @@ void MeasuringImpl::extract_features() -std::optional MeasuringImpl::get_feature(size_t face_idx, const Vec3d& point) const +std::optional MeasuringImpl::get_feature(size_t face_idx, const Vec3d& point) { if (face_idx >= m_face_to_plane.size()) return std::optional(); const PlaneData& plane = m_planes[m_face_to_plane[face_idx]]; + + if (! plane.features_extracted) + extract_features(m_face_to_plane[face_idx]); size_t closest_feature_idx = size_t(-1); double min_dist = std::numeric_limits::max(); @@ -560,9 +573,11 @@ const std::vector& MeasuringImpl::get_plane_triangle_indices(int idx) const return m_planes[idx].facets; } -const std::vector& MeasuringImpl::get_plane_features(unsigned int plane_id) const +const std::vector& MeasuringImpl::get_plane_features(unsigned int plane_id) { assert(plane_id < m_planes.size()); + if (! m_planes[plane_id].features_extracted) + extract_features(plane_id); return m_planes[plane_id].surface_features; } From b1bfef44ba6bb72d925fc6c9f3133956be60e6ac Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 6 Dec 2022 10:00:51 +0100 Subject: [PATCH 094/109] Convert static data to compile time constants --- src/libslic3r/SLA/RasterBase.cpp | 5 ----- src/libslic3r/SLA/RasterBase.hpp | 8 ++++---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/SLA/RasterBase.cpp b/src/libslic3r/SLA/RasterBase.cpp index 0b6c45eff3..7240b198da 100644 --- a/src/libslic3r/SLA/RasterBase.cpp +++ b/src/libslic3r/SLA/RasterBase.cpp @@ -11,11 +11,6 @@ namespace Slic3r { namespace sla { -const RasterBase::TMirroring RasterBase::NoMirror = {false, false}; -const RasterBase::TMirroring RasterBase::MirrorX = {true, false}; -const RasterBase::TMirroring RasterBase::MirrorY = {false, true}; -const RasterBase::TMirroring RasterBase::MirrorXY = {true, true}; - EncodedRaster PNGRasterEncoder::operator()(const void *ptr, size_t w, size_t h, size_t num_components) { diff --git a/src/libslic3r/SLA/RasterBase.hpp b/src/libslic3r/SLA/RasterBase.hpp index ae8c0aefa5..33d39eafbd 100644 --- a/src/libslic3r/SLA/RasterBase.hpp +++ b/src/libslic3r/SLA/RasterBase.hpp @@ -60,10 +60,10 @@ public: enum Orientation { roLandscape, roPortrait }; using TMirroring = std::array; - static const TMirroring NoMirror; - static const TMirroring MirrorX; - static const TMirroring MirrorY; - static const TMirroring MirrorXY; + static const constexpr TMirroring NoMirror = {false, false}; + static const constexpr TMirroring MirrorX = {true, false}; + static const constexpr TMirroring MirrorY = {false, true}; + static const constexpr TMirroring MirrorXY = {true, true}; struct Trafo { bool mirror_x = false, mirror_y = false, flipXY = false; From 7309c729e03d3170bb09ebfc548e19c79a077cc1 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Mon, 5 Dec 2022 09:59:59 +0100 Subject: [PATCH 095/109] Reworked "only_retract_when_crossing_perimeters" feature, which was terribly slow: Introduced RetractWhenCrossingPerimeters.cpp,hpp AABBTreeIndirect traverse template was extended to support early exit. --- src/libslic3r/AABBTreeIndirect.hpp | 23 ++++--- src/libslic3r/CMakeLists.txt | 2 + src/libslic3r/ClipperUtils.cpp | 17 +++++ src/libslic3r/ClipperUtils.hpp | 2 + src/libslic3r/GCode.cpp | 2 +- src/libslic3r/GCode.hpp | 2 + .../GCode/RetractWhenCrossingPerimeters.cpp | 67 +++++++++++++++++++ .../GCode/RetractWhenCrossingPerimeters.hpp | 32 +++++++++ src/libslic3r/SLAPrintSteps.cpp | 2 + 9 files changed, 140 insertions(+), 9 deletions(-) create mode 100644 src/libslic3r/GCode/RetractWhenCrossingPerimeters.cpp create mode 100644 src/libslic3r/GCode/RetractWhenCrossingPerimeters.hpp diff --git a/src/libslic3r/AABBTreeIndirect.hpp b/src/libslic3r/AABBTreeIndirect.hpp index b4b74ef138..e70e8be39b 100644 --- a/src/libslic3r/AABBTreeIndirect.hpp +++ b/src/libslic3r/AABBTreeIndirect.hpp @@ -920,29 +920,35 @@ template auto within(const G &g) { return Within{g}; } namespace detail { +// Returns true in case traversal should continue, +// returns false if traversal should stop (for example if the first hit was found). template -void traverse_recurse(const Tree &tree, +bool traverse_recurse(const Tree &tree, size_t idx, Pred && pred, Fn && callback) { assert(tree.node(idx).is_valid()); - if (!pred(tree.node(idx))) return; + if (!pred(tree.node(idx))) + // Continue traversal. + return true; if (tree.node(idx).is_leaf()) { - callback(tree.node(idx)); + // Callback returns true to continue traversal, false to stop traversal. + return callback(tree.node(idx)); } else { // call this with left and right node idx: - auto trv = [&](size_t idx) { - traverse_recurse(tree, idx, std::forward(pred), - std::forward(callback)); + auto trv = [&](size_t idx) -> bool { + return traverse_recurse(tree, idx, std::forward(pred), + std::forward(callback)); }; // Left / right child node index. - trv(Tree::left_child_idx(idx)); - trv(Tree::right_child_idx(idx)); + // Returns true if both children allow the traversal to continue. + return trv(Tree::left_child_idx(idx)) && + trv(Tree::right_child_idx(idx)); } } @@ -952,6 +958,7 @@ void traverse_recurse(const Tree &tree, // traverse(tree, intersecting(QueryBox), [](size_t face_idx) { // /* ... */ // }); +// Callback shall return true to continue traversal, false if it wants to stop traversal, for example if it found the answer. template void traverse(const Tree &tree, Predicate &&pred, Fn &&callback) { diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index bee7ceb628..9afa00ccb7 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -130,6 +130,8 @@ set(SLIC3R_SOURCES GCode/PressureEqualizer.hpp GCode/PrintExtents.cpp GCode/PrintExtents.hpp + GCode/RetractWhenCrossingPerimeters.cpp + GCode/RetractWhenCrossingPerimeters.hpp GCode/SpiralVase.cpp GCode/SpiralVase.hpp GCode/SeamPlacer.cpp diff --git a/src/libslic3r/ClipperUtils.cpp b/src/libslic3r/ClipperUtils.cpp index ea50157986..4762c3e241 100644 --- a/src/libslic3r/ClipperUtils.cpp +++ b/src/libslic3r/ClipperUtils.cpp @@ -140,6 +140,21 @@ namespace ClipperUtils { out.reserve(src.size()); for (const Polygon &p : src) out.emplace_back(clip_clipper_polygon_with_subject_bbox(p, bbox)); + out.erase( + std::remove_if(out.begin(), out.end(), [](const Polygon &polygon) { return polygon.empty(); }), + out.end()); + return out; + } + [[nodiscard]] Polygons clip_clipper_polygons_with_subject_bbox(const ExPolygon &src, const BoundingBox &bbox) + { + Polygons out; + out.reserve(src.num_contours()); + out.emplace_back(clip_clipper_polygon_with_subject_bbox(src.contour, bbox)); + for (const Polygon &p : src.holes) + out.emplace_back(clip_clipper_polygon_with_subject_bbox(p, bbox)); + out.erase( + std::remove_if(out.begin(), out.end(), [](const Polygon &polygon) { return polygon.empty(); }), + out.end()); return out; } } @@ -794,6 +809,8 @@ Polylines _clipper_pl_closed(ClipperLib::ClipType clipType, PathProvider1 &&subj return retval; } +Slic3r::Polylines diff_pl(const Slic3r::Polyline &subject, const Slic3r::Polygons &clip) + { return _clipper_pl_open(ClipperLib::ctDifference, ClipperUtils::SinglePathProvider(subject.points), ClipperUtils::PolygonsProvider(clip)); } Slic3r::Polylines diff_pl(const Slic3r::Polylines &subject, const Slic3r::Polygons &clip) { return _clipper_pl_open(ClipperLib::ctDifference, ClipperUtils::PolylinesProvider(subject), ClipperUtils::PolygonsProvider(clip)); } Slic3r::Polylines diff_pl(const Slic3r::Polyline &subject, const Slic3r::ExPolygon &clip) diff --git a/src/libslic3r/ClipperUtils.hpp b/src/libslic3r/ClipperUtils.hpp index 4017a73f1a..65ecfb76a1 100644 --- a/src/libslic3r/ClipperUtils.hpp +++ b/src/libslic3r/ClipperUtils.hpp @@ -323,6 +323,7 @@ namespace ClipperUtils { void clip_clipper_polygon_with_subject_bbox(const Polygon &src, const BoundingBox &bbox, Polygon &out); [[nodiscard]] Polygon clip_clipper_polygon_with_subject_bbox(const Polygon &src, const BoundingBox &bbox); [[nodiscard]] Polygons clip_clipper_polygons_with_subject_bbox(const Polygons &src, const BoundingBox &bbox); + [[nodiscard]] Polygons clip_clipper_polygons_with_subject_bbox(const ExPolygon &src, const BoundingBox &bbox); } // offset Polygons @@ -427,6 +428,7 @@ Slic3r::ExPolygons diff_ex(const Slic3r::Surfaces &subject, const Slic3r::ExPoly Slic3r::ExPolygons diff_ex(const Slic3r::ExPolygons &subject, const Slic3r::Surfaces &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No); Slic3r::ExPolygons diff_ex(const Slic3r::Surfaces &subject, const Slic3r::Surfaces &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No); Slic3r::ExPolygons diff_ex(const Slic3r::SurfacesPtr &subject, const Slic3r::Polygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No); +Slic3r::Polylines diff_pl(const Slic3r::Polyline &subject, const Slic3r::Polygons &clip); Slic3r::Polylines diff_pl(const Slic3r::Polylines &subject, const Slic3r::Polygons &clip); Slic3r::Polylines diff_pl(const Slic3r::Polyline &subject, const Slic3r::ExPolygon &clip); Slic3r::Polylines diff_pl(const Slic3r::Polyline &subject, const Slic3r::ExPolygons &clip); diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 06801b0e48..dc587f3880 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -3090,7 +3090,7 @@ bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role) } if (m_config.only_retract_when_crossing_perimeters && m_layer != nullptr && - m_config.fill_density.value > 0 && m_layer->any_internal_region_slice_contains(travel)) + m_config.fill_density.value > 0 && m_retract_when_crossing_perimeters.travel_inside_internal_regions(*m_layer, travel)) // Skip retraction if travel is contained in an internal slice *and* // internal infill is enabled (so that stringing is entirely not visible). //FIXME any_internal_region_slice_contains() is potentionally very slow, it shall test for the bounding boxes first. diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 435941de5f..e37d11a2e9 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -12,6 +12,7 @@ #include "GCode/AvoidCrossingPerimeters.hpp" #include "GCode/CoolingBuffer.hpp" #include "GCode/FindReplace.hpp" +#include "GCode/RetractWhenCrossingPerimeters.hpp" #include "GCode/SpiralVase.hpp" #include "GCode/ToolOrdering.hpp" #include "GCode/WipeTower.hpp" @@ -349,6 +350,7 @@ private: Wipe m_wipe; AvoidCrossingPerimeters m_avoid_crossing_perimeters; JPSPathFinder m_avoid_curled_filaments; + RetractWhenCrossingPerimeters m_retract_when_crossing_perimeters; bool m_enable_loop_clipping; // If enabled, the G-code generator will put following comments at the ends // of the G-code lines: _EXTRUDE_SET_SPEED, _WIPE, _BRIDGE_FAN_START, _BRIDGE_FAN_END diff --git a/src/libslic3r/GCode/RetractWhenCrossingPerimeters.cpp b/src/libslic3r/GCode/RetractWhenCrossingPerimeters.cpp new file mode 100644 index 0000000000..4be42d763a --- /dev/null +++ b/src/libslic3r/GCode/RetractWhenCrossingPerimeters.cpp @@ -0,0 +1,67 @@ +#include "../ClipperUtils.hpp" +#include "../Layer.hpp" +#include "../Polyline.hpp" + +#include "RetractWhenCrossingPerimeters.hpp" + +namespace Slic3r { + +bool RetractWhenCrossingPerimeters::travel_inside_internal_regions(const Layer &layer, const Polyline &travel) +{ + if (m_layer != &layer) { + // Update cache. + m_layer = &layer; + m_internal_islands.clear(); + m_aabbtree_internal_islands.clear(); + // Collect expolygons of internal slices. + for (const LayerRegion *layerm : layer.regions()) + for (const Surface &surface : layerm->slices().surfaces) + if (surface.is_internal()) + m_internal_islands.emplace_back(&surface.expolygon); + // Calculate bounding boxes of internal slices. + class BBoxWrapper { + public: + BBoxWrapper(const size_t idx, const BoundingBox &bbox) : + m_idx(idx), + // Inflate the bounding box a bit to account for numerical issues. + m_bbox(bbox.min - Point(SCALED_EPSILON, SCALED_EPSILON), bbox.max + Point(SCALED_EPSILON, SCALED_EPSILON)) {} + size_t idx() const { return m_idx; } + const AABBTree::BoundingBox& bbox() const { return m_bbox; } + Point centroid() const { return ((m_bbox.min().cast() + m_bbox.max().cast()) / 2).cast(); } + private: + size_t m_idx; + AABBTree::BoundingBox m_bbox; + }; + std::vector bboxes; + bboxes.reserve(m_internal_islands.size()); + for (size_t i = 0; i < m_internal_islands.size(); ++ i) + bboxes.emplace_back(i, get_extents(*m_internal_islands[i])); + // Build AABB tree over bounding boxes of internal slices. + m_aabbtree_internal_islands.build_modify_input(bboxes); + } + + BoundingBox bbox_travel = get_extents(travel); + AABBTree::BoundingBox bbox_travel_eigen{ bbox_travel.min, bbox_travel.max }; + int result = -1; + bbox_travel.offset(SCALED_EPSILON); + AABBTreeIndirect::traverse(m_aabbtree_internal_islands, + [&bbox_travel_eigen](const AABBTree::Node &node) { + return bbox_travel_eigen.intersects(node.bbox); + }, + [&travel, &bbox_travel, &result, &islands = m_internal_islands](const AABBTree::Node &node) { + assert(node.is_leaf()); + assert(node.is_valid()); + Polygons clipped = ClipperUtils::clip_clipper_polygons_with_subject_bbox(*islands[node.idx], bbox_travel); + if (diff_pl(travel, clipped).empty()) { + // Travel path is completely inside an "internal" island. Don't retract. + result = int(node.idx); + // Stop traversal. + return false; + } + // Continue traversal. + return true; + }); + return result != -1; +} + +} // namespace Slic3r diff --git a/src/libslic3r/GCode/RetractWhenCrossingPerimeters.hpp b/src/libslic3r/GCode/RetractWhenCrossingPerimeters.hpp new file mode 100644 index 0000000000..fb624d7f90 --- /dev/null +++ b/src/libslic3r/GCode/RetractWhenCrossingPerimeters.hpp @@ -0,0 +1,32 @@ +#ifndef slic3r_RetractWhenCrossingPerimeters_hpp_ +#define slic3r_RetractWhenCrossingPerimeters_hpp_ + +#include + +#include "../AABBTreeIndirect.hpp" + +namespace Slic3r { + +// Forward declarations. +class ExPolygon; +class Layer; +class Polyline; + +class RetractWhenCrossingPerimeters +{ +public: + bool travel_inside_internal_regions(const Layer &layer, const Polyline &travel); + +private: + // Last object layer visited, for which a cache of internal islands was created. + const Layer *m_layer; + // Internal islands only, referencing data owned by m_layer->regions()->surfaces(). + std::vector m_internal_islands; + // Search structure over internal islands. + using AABBTree = AABBTreeIndirect::Tree<2, coord_t>; + AABBTree m_aabbtree_internal_islands; +}; + +} // namespace Slic3r + +#endif // slic3r_RetractWhenCrossingPerimeters_hpp_ diff --git a/src/libslic3r/SLAPrintSteps.cpp b/src/libslic3r/SLAPrintSteps.cpp index 4498cb6b01..bed4f02498 100644 --- a/src/libslic3r/SLAPrintSteps.cpp +++ b/src/libslic3r/SLAPrintSteps.cpp @@ -413,6 +413,8 @@ void SLAPrint::Steps::drill_holes(SLAPrintObject &po) [&part_to_drill, &hollowed_mesh](const auto& node) { part_to_drill.indices.emplace_back(hollowed_mesh.its.indices[node.idx]); + // continue traversal + return true; }); auto cgal_meshpart = MeshBoolean::cgal::triangle_mesh_to_cgal( From 96ab500a1303ee880ef2e64636328761ab82fddf Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Tue, 6 Dec 2022 11:44:56 +0100 Subject: [PATCH 096/109] Fixing Cut numerical issues on 45 degree rotated cube and on 90 degree rotated cylinder. --- src/libslic3r/TriangleMesh.cpp | 7 +++ src/libslic3r/TriangleMesh.hpp | 2 + src/libslic3r/TriangleMeshSlicer.cpp | 78 +++++++++++++++++++++++++--- src/libslic3r/TriangleMeshSlicer.hpp | 2 +- 4 files changed, 80 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/TriangleMesh.cpp b/src/libslic3r/TriangleMesh.cpp index 5610c9f780..6e17daa564 100644 --- a/src/libslic3r/TriangleMesh.cpp +++ b/src/libslic3r/TriangleMesh.cpp @@ -738,6 +738,13 @@ void its_flip_triangles(indexed_triangle_set &its) std::swap(face(1), face(2)); } +int its_num_degenerate_faces(const indexed_triangle_set &its) +{ + return std::count_if(its.indices.begin(), its.indices.end(), [](auto &face) { + return face(0) == face(1) || face(0) == face(2) || face(1) == face(2); + }); +} + int its_remove_degenerate_faces(indexed_triangle_set &its, bool shrink_to_fit) { auto it = std::remove_if(its.indices.begin(), its.indices.end(), [](auto &face) { diff --git a/src/libslic3r/TriangleMesh.hpp b/src/libslic3r/TriangleMesh.hpp index c288b6d3a6..d8096eae2d 100644 --- a/src/libslic3r/TriangleMesh.hpp +++ b/src/libslic3r/TriangleMesh.hpp @@ -204,6 +204,8 @@ void its_flip_triangles(indexed_triangle_set &its); // or more than two faces share the same edge position! int its_merge_vertices(indexed_triangle_set &its, bool shrink_to_fit = true); +// Calculate number of degenerate faces. There should be no degenerate faces in a nice mesh. +int its_num_degenerate_faces(const indexed_triangle_set &its); // Remove degenerate faces, return number of faces removed. int its_remove_degenerate_faces(indexed_triangle_set &its, bool shrink_to_fit = true); diff --git a/src/libslic3r/TriangleMeshSlicer.cpp b/src/libslic3r/TriangleMeshSlicer.cpp index ae917756b0..63802961b9 100644 --- a/src/libslic3r/TriangleMeshSlicer.cpp +++ b/src/libslic3r/TriangleMeshSlicer.cpp @@ -242,7 +242,12 @@ static FacetSliceType slice_facet( std::swap(a, b); } IntersectionPoint &point = points[num_points]; - double t = (double(slice_z) - double(b->z())) / (double(a->z()) - double(b->z())); + double t = (double(slice_z) - double(a->z())) / (double(b->z()) - double(a->z())); +#if 0 + // If the intersection point falls into one of the end points, mark it with the end point identifier. + // While this sounds like a good idea, it likely breaks the chaining by logical addresses of the intersection points + // and the branch for 0 < t < 1 does not guarantee uniqness of the interection point anyways. + // Thus this branch is only kept for reference and it is not used in production code. if (t <= 0.) { if (point_on_layer == size_t(-1) || points[point_on_layer].point_id != a_id) { point.x() = a->x(); @@ -258,11 +263,26 @@ static FacetSliceType slice_facet( point.point_id = b_id; } } else { - point.x() = coord_t(floor(double(b->x()) + (double(a->x()) - double(b->x())) * t + 0.5)); - point.y() = coord_t(floor(double(b->y()) + (double(a->y()) - double(b->y())) * t + 0.5)); + point.x() = coord_t(floor(double(a->x()) + (double(b->x()) - double(a->x())) * t + 0.5)); + point.y() = coord_t(floor(double(a->y()) + (double(b->y()) - double(a->y())) * t + 0.5)); point.edge_id = edge_id; ++ num_points; } +#else + // Just clamp the intersection point to source triangle edge. + if (t <= 0.) { + point.x() = a->x(); + point.y() = a->y(); + } else if (t >= 1.) { + point.x() = b->x(); + point.y() = b->y(); + } else { + point.x() = coord_t(floor(double(a->x()) + (double(b->x()) - double(a->x())) * t + 0.5)); + point.y() = coord_t(floor(double(a->y()) + (double(b->y()) - double(a->y())) * t + 0.5)); + } + point.edge_id = edge_id; + ++ num_points; +#endif } } @@ -284,6 +304,11 @@ static FacetSliceType slice_facet( assert(line_out.edge_a_id != -1 || line_out.edge_b_id != -1); // General slicing position, use the segment for both slicing and object cutting. #if 0 + // See the discussion on calculating the intersection point on a triangle edge. + // Even if the intersection point is clamped to one of the end points of the triangle edge, + // the intersection point is still marked as "on edge", not "on vertex". Such implementation + // may produce degenerate triangles, but is topologically correct. + // Therefore this block for solving snapping of an intersection edge to triangle vertices is not used. if (line_out.a_id != -1 && line_out.b_id != -1) { // Solving a degenerate case, where both the intersections snapped to an edge. // Correctly classify the face as below or above based on the position of the 3rd point. @@ -2009,6 +2034,7 @@ static void triangulate_slice( (l.first.y() == r.first.y() && l.second < r.second))); }); // 2) Discover duplicate points on the slice. Remap duplicate vertices to a vertex with a lowest index. + // Remove denegerate triangles, if they happen to be created by merging duplicate vertices. { std::vector map_duplicate_vertex(int(its.vertices.size()) - num_original_vertices, -1); int i = 0; @@ -2031,10 +2057,20 @@ static void triangulate_slice( i = j; } map_vertex_to_index.erase(map_vertex_to_index.begin() + k, map_vertex_to_index.end()); - for (stl_triangle_vertex_indices &f : its.indices) - for (i = 0; i < 3; ++ i) - if (f(i) >= num_original_vertices) - f(i) = map_duplicate_vertex[f(i) - num_original_vertices]; + for (i = 0; i < int(its.indices.size());) { + stl_triangle_vertex_indices &f = its.indices[i]; + // Remap the newly added face vertices. + for (k = 0; k < 3; ++ k) + if (f(k) >= num_original_vertices) + f(k) = map_duplicate_vertex[f(k) - num_original_vertices]; + if (f(0) == f(1) || f(0) == f(2) || f(1) == f(2)) { + // Remove degenerate face. + f = its.indices.back(); + its.indices.pop_back(); + } else + // Keep the face. + ++ i; + } } if (triangulate) { @@ -2108,6 +2144,10 @@ void cut_mesh(const indexed_triangle_set &mesh, float z, indexed_triangle_set *u if (upper == nullptr && lower == nullptr) return; +#ifndef NDEBUG + const size_t had_degenerate_faces = its_num_degenerate_faces(mesh); +#endif // NDEBUG + BOOST_LOG_TRIVIAL(trace) << "cut_mesh - slicing object"; if (upper) { @@ -2251,8 +2291,27 @@ void cut_mesh(const indexed_triangle_set &mesh, float z, indexed_triangle_set *u new_face(lower, iv0, iv0v1_lower, iv2v0_lower); } } + +/* + char buf[2048]; + static int irun = 0; + ++irun; + temp.indices.emplace_back(int(temp.vertices.size()), int(temp.vertices.size() + 1), int(temp.vertices.size() + 2)); + temp.vertices.emplace_back(vertices[0]); + temp.vertices.emplace_back(vertices[1]); + temp.vertices.emplace_back(vertices[2]); + sprintf(buf, "D:\\temp\\test\\temp-%d.obj", irun); + its_write_obj(temp, buf); + sprintf(buf, "D:\\temp\\test\\upper-%d.obj", irun); + its_write_obj(*upper, buf); + sprintf(buf, "D:\\temp\\test\\lower-%d.obj", irun); + its_write_obj(*lower, buf); +*/ } - + + assert(had_degenerate_faces || ! upper || its_num_degenerate_faces(*upper) == 0); + assert(had_degenerate_faces || ! lower || its_num_degenerate_faces(*lower) == 0); + if (upper != nullptr) { triangulate_slice(*upper, upper_lines, upper_slice_vertices, int(mesh.vertices.size()), z, triangulate_caps, NORMALS_DOWN); #ifndef NDEBUG @@ -2272,6 +2331,9 @@ void cut_mesh(const indexed_triangle_set &mesh, float z, indexed_triangle_set *u } #endif // NDEBUG } + + assert(had_degenerate_faces || ! upper || its_num_degenerate_faces(*upper) == 0); + assert(had_degenerate_faces || ! lower || its_num_degenerate_faces(*lower) == 0); } } // namespace Slic3r diff --git a/src/libslic3r/TriangleMeshSlicer.hpp b/src/libslic3r/TriangleMeshSlicer.hpp index fbe7244332..ea6a7262cc 100644 --- a/src/libslic3r/TriangleMeshSlicer.hpp +++ b/src/libslic3r/TriangleMeshSlicer.hpp @@ -130,6 +130,6 @@ void cut_mesh( indexed_triangle_set *lower, bool triangulate_caps = true); -} +} // namespace Slic3r #endif // slic3r_TriangleMeshSlicer_hpp_ From 028dfb5d9e48ae7764ebf4664b659e2947cffe26 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 6 Dec 2022 12:17:01 +0100 Subject: [PATCH 097/109] Tech ENABLE_LEGACY_OPENGL_REMOVAL set as default --- resources/shaders/background.fs | 11 - resources/shaders/background.vs | 9 - resources/shaders/flat.fs | 8 - resources/shaders/flat.vs | 6 - resources/shaders/flat_texture.fs | 10 - resources/shaders/flat_texture.vs | 9 - resources/shaders/gouraud.fs | 79 -- resources/shaders/gouraud.vs | 71 -- resources/shaders/gouraud_light.fs | 12 - resources/shaders/gouraud_light.vs | 38 - resources/shaders/gouraud_light_instanced.fs | 12 - resources/shaders/gouraud_light_instanced.vs | 46 - resources/shaders/mm_contour.fs | 6 - resources/shaders/mm_contour.vs | 11 - resources/shaders/mm_gouraud.fs | 60 - resources/shaders/mm_gouraud.vs | 23 - resources/shaders/printbed.fs | 36 - resources/shaders/printbed.vs | 9 - resources/shaders/toolpaths_cog.fs | 18 - resources/shaders/toolpaths_cog.vs | 40 - resources/shaders/toolpaths_lines.fs | 28 - resources/shaders/toolpaths_lines.vs | 9 - resources/shaders/variable_layer_height.fs | 41 - resources/shaders/variable_layer_height.vs | 52 - src/libslic3r/BuildVolume.hpp | 2 - src/libslic3r/Technologies.hpp | 10 +- src/slic3r/GUI/3DBed.cpp | 386 ------ src/slic3r/GUI/3DBed.hpp | 68 - src/slic3r/GUI/3DScene.cpp | 1127 +---------------- src/slic3r/GUI/3DScene.hpp | 297 +---- src/slic3r/GUI/Camera.cpp | 44 - src/slic3r/GUI/Camera.hpp | 3 - src/slic3r/GUI/CoordAxes.cpp | 29 - src/slic3r/GUI/CoordAxes.hpp | 4 - src/slic3r/GUI/GCodeViewer.cpp | 194 --- src/slic3r/GUI/GCodeViewer.hpp | 17 - src/slic3r/GUI/GLCanvas3D.cpp | 719 +---------- src/slic3r/GUI/GLCanvas3D.hpp | 29 +- src/slic3r/GUI/GLModel.cpp | 706 ----------- src/slic3r/GUI/GLModel.hpp | 75 -- src/slic3r/GUI/GLSelectionRectangle.cpp | 48 - src/slic3r/GUI/GLSelectionRectangle.hpp | 4 - src/slic3r/GUI/GLShadersManager.cpp | 38 - src/slic3r/GUI/GLTexture.cpp | 13 - src/slic3r/GUI/GLToolbar.cpp | 639 ---------- src/slic3r/GUI/GLToolbar.hpp | 16 - src/slic3r/GUI/GalleryDialog.cpp | 5 - src/slic3r/GUI/Gizmos/GLGizmoBase.cpp | 66 - src/slic3r/GUI/Gizmos/GLGizmoBase.hpp | 2 - src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 22 - src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp | 30 - src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp | 8 - src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp | 38 - .../GUI/Gizmos/GLGizmoMmuSegmentation.cpp | 66 - .../GUI/Gizmos/GLGizmoMmuSegmentation.hpp | 6 - src/slic3r/GUI/Gizmos/GLGizmoMove.cpp | 64 - src/slic3r/GUI/Gizmos/GLGizmoMove.hpp | 6 - src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp | 295 +---- src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp | 66 - src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp | 166 +-- src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp | 14 - src/slic3r/GUI/Gizmos/GLGizmoScale.cpp | 102 -- src/slic3r/GUI/Gizmos/GLGizmoScale.hpp | 10 - src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp | 29 - src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 80 +- src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp | 32 - src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 189 --- src/slic3r/GUI/Gizmos/GLGizmosManager.hpp | 14 - src/slic3r/GUI/ImGuiWrapper.cpp | 60 - src/slic3r/GUI/MeshUtils.cpp | 32 +- src/slic3r/GUI/MeshUtils.hpp | 14 - src/slic3r/GUI/Selection.cpp | 343 +---- src/slic3r/GUI/Selection.hpp | 11 - src/slic3r/Utils/UndoRedo.cpp | 2 - 74 files changed, 37 insertions(+), 6847 deletions(-) delete mode 100644 resources/shaders/background.fs delete mode 100644 resources/shaders/background.vs delete mode 100644 resources/shaders/flat.fs delete mode 100644 resources/shaders/flat.vs delete mode 100644 resources/shaders/flat_texture.fs delete mode 100644 resources/shaders/flat_texture.vs delete mode 100644 resources/shaders/gouraud.fs delete mode 100644 resources/shaders/gouraud.vs delete mode 100644 resources/shaders/gouraud_light.fs delete mode 100644 resources/shaders/gouraud_light.vs delete mode 100644 resources/shaders/gouraud_light_instanced.fs delete mode 100644 resources/shaders/gouraud_light_instanced.vs delete mode 100644 resources/shaders/mm_contour.fs delete mode 100644 resources/shaders/mm_contour.vs delete mode 100644 resources/shaders/mm_gouraud.fs delete mode 100644 resources/shaders/mm_gouraud.vs delete mode 100644 resources/shaders/printbed.fs delete mode 100644 resources/shaders/printbed.vs delete mode 100644 resources/shaders/toolpaths_cog.fs delete mode 100644 resources/shaders/toolpaths_cog.vs delete mode 100644 resources/shaders/toolpaths_lines.fs delete mode 100644 resources/shaders/toolpaths_lines.vs delete mode 100644 resources/shaders/variable_layer_height.fs delete mode 100644 resources/shaders/variable_layer_height.vs diff --git a/resources/shaders/background.fs b/resources/shaders/background.fs deleted file mode 100644 index b148440898..0000000000 --- a/resources/shaders/background.fs +++ /dev/null @@ -1,11 +0,0 @@ -#version 110 - -uniform vec4 top_color; -uniform vec4 bottom_color; - -varying vec2 tex_coord; - -void main() -{ - gl_FragColor = mix(bottom_color, top_color, tex_coord.y); -} diff --git a/resources/shaders/background.vs b/resources/shaders/background.vs deleted file mode 100644 index b7c1d92c0e..0000000000 --- a/resources/shaders/background.vs +++ /dev/null @@ -1,9 +0,0 @@ -#version 110 - -varying vec2 tex_coord; - -void main() -{ - gl_Position = gl_Vertex; - tex_coord = gl_MultiTexCoord0.xy; -} diff --git a/resources/shaders/flat.fs b/resources/shaders/flat.fs deleted file mode 100644 index ab656998df..0000000000 --- a/resources/shaders/flat.fs +++ /dev/null @@ -1,8 +0,0 @@ -#version 110 - -uniform vec4 uniform_color; - -void main() -{ - gl_FragColor = uniform_color; -} diff --git a/resources/shaders/flat.vs b/resources/shaders/flat.vs deleted file mode 100644 index d0d3ee42a9..0000000000 --- a/resources/shaders/flat.vs +++ /dev/null @@ -1,6 +0,0 @@ -#version 110 - -void main() -{ - gl_Position = ftransform(); -} diff --git a/resources/shaders/flat_texture.fs b/resources/shaders/flat_texture.fs deleted file mode 100644 index ffe193b1c0..0000000000 --- a/resources/shaders/flat_texture.fs +++ /dev/null @@ -1,10 +0,0 @@ -#version 110 - -uniform sampler2D uniform_texture; - -varying vec2 tex_coord; - -void main() -{ - gl_FragColor = texture2D(uniform_texture, tex_coord); -} diff --git a/resources/shaders/flat_texture.vs b/resources/shaders/flat_texture.vs deleted file mode 100644 index 27addc7526..0000000000 --- a/resources/shaders/flat_texture.vs +++ /dev/null @@ -1,9 +0,0 @@ -#version 110 - -varying vec2 tex_coord; - -void main() -{ - gl_Position = ftransform(); - tex_coord = gl_MultiTexCoord0.xy; -} diff --git a/resources/shaders/gouraud.fs b/resources/shaders/gouraud.fs deleted file mode 100644 index 1657fc0513..0000000000 --- a/resources/shaders/gouraud.fs +++ /dev/null @@ -1,79 +0,0 @@ -#version 110 - -const vec3 ZERO = vec3(0.0, 0.0, 0.0); -const float EPSILON = 0.0001; - -struct PrintVolumeDetection -{ - // 0 = rectangle, 1 = circle, 2 = custom, 3 = invalid - int type; - // type = 0 (rectangle): - // x = min.x, y = min.y, z = max.x, w = max.y - // type = 1 (circle): - // x = center.x, y = center.y, z = radius - vec4 xy_data; - // x = min z, y = max z - vec2 z_data; -}; - -struct SlopeDetection -{ - bool actived; - float normal_z; - mat3 volume_world_normal_matrix; -}; - -uniform vec4 uniform_color; -uniform SlopeDetection slope; - -#ifdef ENABLE_ENVIRONMENT_MAP - uniform sampler2D environment_tex; - uniform bool use_environment_tex; -#endif // ENABLE_ENVIRONMENT_MAP - -varying vec3 clipping_planes_dots; - -// x = diffuse, y = specular; -varying vec2 intensity; - -uniform PrintVolumeDetection print_volume; - -varying vec4 world_pos; -varying float world_normal_z; -varying vec3 eye_normal; - -void main() -{ - if (any(lessThan(clipping_planes_dots, ZERO))) - discard; - vec3 color = uniform_color.rgb; - float alpha = uniform_color.a; - - if (slope.actived && world_normal_z < slope.normal_z - EPSILON) { - color = vec3(0.7, 0.7, 1.0); - alpha = 1.0; - } - - // if the fragment is outside the print volume -> use darker color - vec3 pv_check_min = ZERO; - vec3 pv_check_max = ZERO; - if (print_volume.type == 0) { - // rectangle - pv_check_min = world_pos.xyz - vec3(print_volume.xy_data.x, print_volume.xy_data.y, print_volume.z_data.x); - pv_check_max = world_pos.xyz - vec3(print_volume.xy_data.z, print_volume.xy_data.w, print_volume.z_data.y); - } - else if (print_volume.type == 1) { - // circle - float delta_radius = print_volume.xy_data.z - distance(world_pos.xy, print_volume.xy_data.xy); - pv_check_min = vec3(delta_radius, 0.0, world_pos.z - print_volume.z_data.x); - pv_check_max = vec3(0.0, 0.0, world_pos.z - print_volume.z_data.y); - } - color = (any(lessThan(pv_check_min, ZERO)) || any(greaterThan(pv_check_max, ZERO))) ? mix(color, ZERO, 0.3333) : color; - -#ifdef ENABLE_ENVIRONMENT_MAP - if (use_environment_tex) - gl_FragColor = vec4(0.45 * texture2D(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color * intensity.x, alpha); - else -#endif - gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha); -} diff --git a/resources/shaders/gouraud.vs b/resources/shaders/gouraud.vs deleted file mode 100644 index c8b3d7b335..0000000000 --- a/resources/shaders/gouraud.vs +++ /dev/null @@ -1,71 +0,0 @@ -#version 110 - -#define INTENSITY_CORRECTION 0.6 - -// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) -const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); -#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SHININESS 20.0 - -// normalized values for (1./1.43, 0.2/1.43, 1./1.43) -const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); -#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) -//#define LIGHT_FRONT_SPECULAR (0.0 * INTENSITY_CORRECTION) -//#define LIGHT_FRONT_SHININESS 5.0 - -#define INTENSITY_AMBIENT 0.3 - -const vec3 ZERO = vec3(0.0, 0.0, 0.0); - -struct SlopeDetection -{ - bool actived; - float normal_z; - mat3 volume_world_normal_matrix; -}; - -uniform mat4 volume_world_matrix; -uniform SlopeDetection slope; - -// Clipping plane, x = min z, y = max z. Used by the FFF and SLA previews to clip with a top / bottom plane. -uniform vec2 z_range; -// Clipping plane - general orientation. Used by the SLA gizmo. -uniform vec4 clipping_plane; - -// x = diffuse, y = specular; -varying vec2 intensity; - -varying vec3 clipping_planes_dots; - -varying vec4 world_pos; -varying float world_normal_z; -varying vec3 eye_normal; - -void main() -{ - // First transform the normal into camera space and normalize the result. - eye_normal = normalize(gl_NormalMatrix * gl_Normal); - - // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. - // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. - float NdotL = max(dot(eye_normal, LIGHT_TOP_DIR), 0.0); - - intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; - vec3 position = (gl_ModelViewMatrix * gl_Vertex).xyz; - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_TOP_DIR, eye_normal)), 0.0), LIGHT_TOP_SHININESS); - - // Perform the same lighting calculation for the 2nd light source (no specular applied). - NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0); - intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; - - // Point in homogenous coordinates. - world_pos = volume_world_matrix * gl_Vertex; - - // z component of normal vector in world coordinate used for slope shading - world_normal_z = slope.actived ? (normalize(slope.volume_world_normal_matrix * gl_Normal)).z : 0.0; - - gl_Position = ftransform(); - // Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded. - clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z); -} diff --git a/resources/shaders/gouraud_light.fs b/resources/shaders/gouraud_light.fs deleted file mode 100644 index 970185a00e..0000000000 --- a/resources/shaders/gouraud_light.fs +++ /dev/null @@ -1,12 +0,0 @@ -#version 110 - -uniform vec4 uniform_color; -uniform float emission_factor; - -// x = tainted, y = specular; -varying vec2 intensity; - -void main() -{ - gl_FragColor = vec4(vec3(intensity.y) + uniform_color.rgb * (intensity.x + emission_factor), uniform_color.a); -} diff --git a/resources/shaders/gouraud_light.vs b/resources/shaders/gouraud_light.vs deleted file mode 100644 index d4f71938a9..0000000000 --- a/resources/shaders/gouraud_light.vs +++ /dev/null @@ -1,38 +0,0 @@ -#version 110 - -#define INTENSITY_CORRECTION 0.6 - -// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) -const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); -#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SHININESS 20.0 - -// normalized values for (1./1.43, 0.2/1.43, 1./1.43) -const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); -#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) - -#define INTENSITY_AMBIENT 0.3 - -// x = tainted, y = specular; -varying vec2 intensity; - -void main() -{ - // First transform the normal into camera space and normalize the result. - vec3 normal = normalize(gl_NormalMatrix * gl_Normal); - - // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. - // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. - float NdotL = max(dot(normal, LIGHT_TOP_DIR), 0.0); - - intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; - vec3 position = (gl_ModelViewMatrix * gl_Vertex).xyz; - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); - - // Perform the same lighting calculation for the 2nd light source (no specular applied). - NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0); - intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; - - gl_Position = ftransform(); -} diff --git a/resources/shaders/gouraud_light_instanced.fs b/resources/shaders/gouraud_light_instanced.fs deleted file mode 100644 index 970185a00e..0000000000 --- a/resources/shaders/gouraud_light_instanced.fs +++ /dev/null @@ -1,12 +0,0 @@ -#version 110 - -uniform vec4 uniform_color; -uniform float emission_factor; - -// x = tainted, y = specular; -varying vec2 intensity; - -void main() -{ - gl_FragColor = vec4(vec3(intensity.y) + uniform_color.rgb * (intensity.x + emission_factor), uniform_color.a); -} diff --git a/resources/shaders/gouraud_light_instanced.vs b/resources/shaders/gouraud_light_instanced.vs deleted file mode 100644 index a42f8e9a4e..0000000000 --- a/resources/shaders/gouraud_light_instanced.vs +++ /dev/null @@ -1,46 +0,0 @@ -#version 110 - -#define INTENSITY_CORRECTION 0.6 - -// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) -const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); -#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SHININESS 20.0 - -// normalized values for (1./1.43, 0.2/1.43, 1./1.43) -const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); -#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) - -#define INTENSITY_AMBIENT 0.3 - -// vertex attributes -attribute vec3 v_position; -attribute vec3 v_normal; -// instance attributes -attribute vec3 i_offset; -attribute vec2 i_scales; - -// x = tainted, y = specular; -varying vec2 intensity; - -void main() -{ - // First transform the normal into camera space and normalize the result. - vec3 eye_normal = normalize(gl_NormalMatrix * v_normal); - - // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. - // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. - float NdotL = max(dot(eye_normal, LIGHT_TOP_DIR), 0.0); - - intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; - vec4 world_position = vec4(v_position * vec3(vec2(1.5 * i_scales.x), 1.5 * i_scales.y) + i_offset - vec3(0.0, 0.0, 0.5 * i_scales.y), 1.0); - vec3 eye_position = (gl_ModelViewMatrix * world_position).xyz; - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(eye_position), reflect(-LIGHT_TOP_DIR, eye_normal)), 0.0), LIGHT_TOP_SHININESS); - - // Perform the same lighting calculation for the 2nd light source (no specular applied). - NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0); - intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; - - gl_Position = gl_ProjectionMatrix * vec4(eye_position, 1.0); -} diff --git a/resources/shaders/mm_contour.fs b/resources/shaders/mm_contour.fs deleted file mode 100644 index 14c18dcf16..0000000000 --- a/resources/shaders/mm_contour.fs +++ /dev/null @@ -1,6 +0,0 @@ -#version 110 - -void main() -{ - gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); -} diff --git a/resources/shaders/mm_contour.vs b/resources/shaders/mm_contour.vs deleted file mode 100644 index 8423362e46..0000000000 --- a/resources/shaders/mm_contour.vs +++ /dev/null @@ -1,11 +0,0 @@ -#version 110 - -uniform float offset; - -void main() -{ - // Add small epsilon to z to solve z-fighting between painted triangles and contour lines. - vec4 clip_position = gl_ModelViewProjectionMatrix * gl_Vertex; - clip_position.z -= offset * abs(clip_position.w); - gl_Position = clip_position; -} diff --git a/resources/shaders/mm_gouraud.fs b/resources/shaders/mm_gouraud.fs deleted file mode 100644 index 5932efe592..0000000000 --- a/resources/shaders/mm_gouraud.fs +++ /dev/null @@ -1,60 +0,0 @@ -#version 110 - -#define INTENSITY_CORRECTION 0.6 - -// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) -const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); -#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SHININESS 20.0 - -// normalized values for (1./1.43, 0.2/1.43, 1./1.43) -const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); -#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) - -#define INTENSITY_AMBIENT 0.3 - -const vec3 ZERO = vec3(0.0, 0.0, 0.0); -const float EPSILON = 0.0001; - -uniform vec4 uniform_color; - -varying vec3 clipping_planes_dots; -varying vec4 model_pos; - -uniform bool volume_mirrored; - -void main() -{ - if (any(lessThan(clipping_planes_dots, ZERO))) - discard; - vec3 color = uniform_color.rgb; - float alpha = uniform_color.a; - - vec3 triangle_normal = normalize(cross(dFdx(model_pos.xyz), dFdy(model_pos.xyz))); -#ifdef FLIP_TRIANGLE_NORMALS - triangle_normal = -triangle_normal; -#endif - - if (volume_mirrored) - triangle_normal = -triangle_normal; - - // First transform the normal into camera space and normalize the result. - vec3 eye_normal = normalize(gl_NormalMatrix * triangle_normal); - - // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. - // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. - float NdotL = max(dot(eye_normal, LIGHT_TOP_DIR), 0.0); - - // x = diffuse, y = specular; - vec2 intensity = vec2(0.0, 0.0); - intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; - vec3 position = (gl_ModelViewMatrix * model_pos).xyz; - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_TOP_DIR, eye_normal)), 0.0), LIGHT_TOP_SHININESS); - - // Perform the same lighting calculation for the 2nd light source (no specular applied). - NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0); - intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; - - gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha); -} diff --git a/resources/shaders/mm_gouraud.vs b/resources/shaders/mm_gouraud.vs deleted file mode 100644 index 2847c3136b..0000000000 --- a/resources/shaders/mm_gouraud.vs +++ /dev/null @@ -1,23 +0,0 @@ -#version 110 - -const vec3 ZERO = vec3(0.0, 0.0, 0.0); - -uniform mat4 volume_world_matrix; -// Clipping plane, x = min z, y = max z. Used by the FFF and SLA previews to clip with a top / bottom plane. -uniform vec2 z_range; -// Clipping plane - general orientation. Used by the SLA gizmo. -uniform vec4 clipping_plane; - -varying vec3 clipping_planes_dots; -varying vec4 model_pos; - -void main() -{ - model_pos = gl_Vertex; - // Point in homogenous coordinates. - vec4 world_pos = volume_world_matrix * gl_Vertex; - - gl_Position = ftransform(); - // Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded. - clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z); -} diff --git a/resources/shaders/printbed.fs b/resources/shaders/printbed.fs deleted file mode 100644 index e11b293e98..0000000000 --- a/resources/shaders/printbed.fs +++ /dev/null @@ -1,36 +0,0 @@ -#version 110 - -const vec3 back_color_dark = vec3(0.235, 0.235, 0.235); -const vec3 back_color_light = vec3(0.365, 0.365, 0.365); - -uniform sampler2D texture; -uniform bool transparent_background; -uniform bool svg_source; - -varying vec2 tex_coord; - -vec4 svg_color() -{ - // takes foreground from texture - vec4 fore_color = texture2D(texture, tex_coord); - - // calculates radial gradient - vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(tex_coord.xy) - vec2(0.5))))); - - // blends foreground with background - return vec4(mix(back_color, fore_color.rgb, fore_color.a), transparent_background ? fore_color.a : 1.0); -} - -vec4 non_svg_color() -{ - // takes foreground from texture - vec4 color = texture2D(texture, tex_coord); - return vec4(color.rgb, transparent_background ? color.a * 0.25 : color.a); -} - -void main() -{ - vec4 color = svg_source ? svg_color() : non_svg_color(); - color.a = transparent_background ? color.a * 0.5 : color.a; - gl_FragColor = color; -} \ No newline at end of file diff --git a/resources/shaders/printbed.vs b/resources/shaders/printbed.vs deleted file mode 100644 index 27addc7526..0000000000 --- a/resources/shaders/printbed.vs +++ /dev/null @@ -1,9 +0,0 @@ -#version 110 - -varying vec2 tex_coord; - -void main() -{ - gl_Position = ftransform(); - tex_coord = gl_MultiTexCoord0.xy; -} diff --git a/resources/shaders/toolpaths_cog.fs b/resources/shaders/toolpaths_cog.fs deleted file mode 100644 index f88d79b969..0000000000 --- a/resources/shaders/toolpaths_cog.fs +++ /dev/null @@ -1,18 +0,0 @@ -#version 110 - -const vec4 BLACK = vec4(vec3(0.1), 1.0); -const vec4 WHITE = vec4(vec3(1.0), 1.0); - -const float emission_factor = 0.25; - -// x = tainted, y = specular; -varying vec2 intensity; -varying vec3 world_position; -uniform vec3 world_center; - -void main() -{ - vec3 delta = world_position - world_center; - vec4 color = delta.x * delta.y * delta.z > 0.0 ? BLACK : WHITE; - gl_FragColor = vec4(vec3(intensity.y) + color.rgb * (intensity.x + emission_factor), 1.0); -} diff --git a/resources/shaders/toolpaths_cog.vs b/resources/shaders/toolpaths_cog.vs deleted file mode 100644 index c7b1abfdbd..0000000000 --- a/resources/shaders/toolpaths_cog.vs +++ /dev/null @@ -1,40 +0,0 @@ -#version 110 - -#define INTENSITY_CORRECTION 0.6 - -// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) -const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); -#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SHININESS 20.0 - -// normalized values for (1./1.43, 0.2/1.43, 1./1.43) -const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); -#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) - -#define INTENSITY_AMBIENT 0.3 - -// x = tainted, y = specular; -varying vec2 intensity; -varying vec3 world_position; - -void main() -{ - // First transform the normal into camera space and normalize the result. - vec3 normal = normalize(gl_NormalMatrix * gl_Normal); - - // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. - // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. - float NdotL = max(dot(normal, LIGHT_TOP_DIR), 0.0); - - intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; - vec3 position = (gl_ModelViewMatrix * gl_Vertex).xyz; - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); - - // Perform the same lighting calculation for the 2nd light source (no specular applied). - NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0); - intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; - - world_position = gl_Vertex.xyz; - gl_Position = ftransform(); -} diff --git a/resources/shaders/toolpaths_lines.fs b/resources/shaders/toolpaths_lines.fs deleted file mode 100644 index 31151cdc17..0000000000 --- a/resources/shaders/toolpaths_lines.fs +++ /dev/null @@ -1,28 +0,0 @@ -#version 110 - -// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) -const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); -const vec3 LIGHT_FRONT_DIR = vec3(0.0, 0.0, 1.0); - -// x = ambient, y = top diffuse, z = front diffuse, w = global -uniform vec4 light_intensity; -uniform vec4 uniform_color; - -varying vec3 eye_normal; - -void main() -{ - vec3 normal = normalize(eye_normal); - - // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. - // Since these two are normalized the cosine is the dot product. Take the abs value to light the lines no matter in which direction the normal points. - float NdotL = abs(dot(normal, LIGHT_TOP_DIR)); - - float intensity = light_intensity.x + NdotL * light_intensity.y; - - // Perform the same lighting calculation for the 2nd light source. - NdotL = abs(dot(normal, LIGHT_FRONT_DIR)); - intensity += NdotL * light_intensity.z; - - gl_FragColor = vec4(uniform_color.rgb * light_intensity.w * intensity, uniform_color.a); -} diff --git a/resources/shaders/toolpaths_lines.vs b/resources/shaders/toolpaths_lines.vs deleted file mode 100644 index c008aedc66..0000000000 --- a/resources/shaders/toolpaths_lines.vs +++ /dev/null @@ -1,9 +0,0 @@ -#version 110 - -varying vec3 eye_normal; - -void main() -{ - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; - eye_normal = gl_NormalMatrix * gl_Normal; -} diff --git a/resources/shaders/variable_layer_height.fs b/resources/shaders/variable_layer_height.fs deleted file mode 100644 index 693c1c6a0b..0000000000 --- a/resources/shaders/variable_layer_height.fs +++ /dev/null @@ -1,41 +0,0 @@ -#version 110 - -#define M_PI 3.1415926535897932384626433832795 - -// 2D texture (1D texture split by the rows) of color along the object Z axis. -uniform sampler2D z_texture; -// Scaling from the Z texture rows coordinate to the normalized texture row coordinate. -uniform float z_to_texture_row; -uniform float z_texture_row_to_normalized; -uniform float z_cursor; -uniform float z_cursor_band_width; - -// x = tainted, y = specular; -varying vec2 intensity; - -varying float object_z; - -void main() -{ - float object_z_row = z_to_texture_row * object_z; - // Index of the row in the texture. - float z_texture_row = floor(object_z_row); - // Normalized coordinate from 0. to 1. - float z_texture_col = object_z_row - z_texture_row; - float z_blend = 0.25 * cos(min(M_PI, abs(M_PI * (object_z - z_cursor) * 1.8 / z_cursor_band_width))) + 0.25; - // Calculate level of detail from the object Z coordinate. - // This makes the slowly sloping surfaces to be shown with high detail (with stripes), - // and the vertical surfaces to be shown with low detail (no stripes) - float z_in_cells = object_z_row * 190.; - // Gradient of Z projected on the screen. - float dx_vtc = dFdx(z_in_cells); - float dy_vtc = dFdy(z_in_cells); - float lod = clamp(0.5 * log2(max(dx_vtc * dx_vtc, dy_vtc * dy_vtc)), 0., 1.); - // Sample the Z texture. Texture coordinates are normalized to <0, 1>. - vec4 color = vec4(0.25, 0.25, 0.25, 1.0); - if (z_texture_row >= 0.0) - color = mix(texture2D(z_texture, vec2(z_texture_col, z_texture_row_to_normalized * (z_texture_row + 0.5 )), -10000.), - texture2D(z_texture, vec2(z_texture_col, z_texture_row_to_normalized * (z_texture_row * 2. + 1.)), 10000.), lod); - // Mix the final color. - gl_FragColor = vec4(vec3(intensity.y), 1.0) + intensity.x * mix(color, vec4(1.0, 1.0, 0.0, 1.0), z_blend); -} diff --git a/resources/shaders/variable_layer_height.vs b/resources/shaders/variable_layer_height.vs deleted file mode 100644 index 0e966b0814..0000000000 --- a/resources/shaders/variable_layer_height.vs +++ /dev/null @@ -1,52 +0,0 @@ -#version 110 - -#define INTENSITY_CORRECTION 0.6 - -const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); -#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SHININESS 20.0 - -const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); -#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) -//#define LIGHT_FRONT_SPECULAR (0.0 * INTENSITY_CORRECTION) -//#define LIGHT_FRONT_SHININESS 5.0 - -#define INTENSITY_AMBIENT 0.3 - -uniform mat4 volume_world_matrix; -uniform float object_max_z; - -// x = tainted, y = specular; -varying vec2 intensity; - -varying float object_z; - -void main() -{ - // First transform the normal into camera space and normalize the result. - vec3 normal = normalize(gl_NormalMatrix * gl_Normal); - - // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. - // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. - float NdotL = max(dot(normal, LIGHT_TOP_DIR), 0.0); - - intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; - vec3 position = (gl_ModelViewMatrix * gl_Vertex).xyz; - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); - - // Perform the same lighting calculation for the 2nd light source (no specular) - NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0); - - intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; - - // Scaled to widths of the Z texture. - if (object_max_z > 0.0) - // when rendering the overlay - object_z = object_max_z * gl_MultiTexCoord0.y; - else - // when rendering the volumes - object_z = (volume_world_matrix * gl_Vertex).z; - - gl_Position = ftransform(); -} diff --git a/src/libslic3r/BuildVolume.hpp b/src/libslic3r/BuildVolume.hpp index b4ac118eca..6537d27452 100644 --- a/src/libslic3r/BuildVolume.hpp +++ b/src/libslic3r/BuildVolume.hpp @@ -95,10 +95,8 @@ public: bool all_paths_inside_vertices_and_normals_interleaved(const std::vector& paths, const Eigen::AlignedBox& bbox, bool ignore_bottom = true) const; -#if ENABLE_LEGACY_OPENGL_REMOVAL const std::pair, std::vector>& top_bottom_convex_hull_decomposition_scene() const { return m_top_bottom_convex_hull_decomposition_scene; } const std::pair, std::vector>& top_bottom_convex_hull_decomposition_bed() const { return m_top_bottom_convex_hull_decomposition_bed; } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL private: // Source definition of the print bed geometry (PrintConfig::bed_shape) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 4e6d2106b1..996bc2fdfc 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -30,6 +30,8 @@ #define ENABLE_MEASURE_GIZMO_DEBUG 0 // Enable scene raycast picking debug window #define ENABLE_RAYCAST_PICKING_DEBUG 0 +// Shows an imgui dialog with GLModel statistics data +#define ENABLE_GLMODEL_STATISTICS 0 // Enable rendering of objects using environment map @@ -43,16 +45,12 @@ //==================== #define ENABLE_2_6_0_ALPHA1 1 -// Enable removal of legacy OpenGL calls -#define ENABLE_LEGACY_OPENGL_REMOVAL (1 && ENABLE_2_6_0_ALPHA1) // Enable OpenGL ES -#define ENABLE_OPENGL_ES (0 && ENABLE_LEGACY_OPENGL_REMOVAL) +#define ENABLE_OPENGL_ES 0 // Enable OpenGL core profile context (tested against Mesa 20.1.8 on Windows) -#define ENABLE_GL_CORE_PROFILE (1 && ENABLE_LEGACY_OPENGL_REMOVAL && !ENABLE_OPENGL_ES) +#define ENABLE_GL_CORE_PROFILE (1 && !ENABLE_OPENGL_ES) // Enable OpenGL debug messages using debug context #define ENABLE_OPENGL_DEBUG_OPTION (1 && ENABLE_GL_CORE_PROFILE) -// Shows an imgui dialog with GLModel statistics data -#define ENABLE_GLMODEL_STATISTICS (0 && ENABLE_LEGACY_OPENGL_REMOVAL) // Enable rework of Reload from disk command #define ENABLE_RELOAD_FROM_DISK_REWORK (1 && ENABLE_2_6_0_ALPHA1) // Enable editing volumes transformation in world coordinates and instances in local coordinates diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index a7e70bc430..d19e23ecde 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -11,10 +11,8 @@ #include "GUI_App.hpp" #include "GLCanvas3D.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "Plater.hpp" #include "Camera.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include @@ -31,77 +29,6 @@ static const Slic3r::ColorRGBA DEFAULT_TRANSPARENT_GRID_COLOR = { 0.9f, 0.9f, 0 namespace Slic3r { namespace GUI { -#if !ENABLE_LEGACY_OPENGL_REMOVAL -bool GeometryBuffer::set_from_triangles(const std::vector &triangles, float z) -{ - if (triangles.empty()) { - m_vertices.clear(); - return false; - } - - assert(triangles.size() % 3 == 0); - m_vertices = std::vector(triangles.size(), Vertex()); - - Vec2f min = triangles.front(); - Vec2f max = min; - - for (size_t v_count = 0; v_count < triangles.size(); ++ v_count) { - const Vec2f &p = triangles[v_count]; - Vertex &v = m_vertices[v_count]; - v.position = Vec3f(p.x(), p.y(), z); - v.tex_coords = p; - min = min.cwiseMin(p).eval(); - max = max.cwiseMax(p).eval(); - } - - Vec2f size = max - min; - if (size.x() != 0.f && size.y() != 0.f) { - Vec2f inv_size = size.cwiseInverse(); - inv_size.y() *= -1; - for (Vertex& v : m_vertices) { - v.tex_coords -= min; - v.tex_coords.x() *= inv_size.x(); - v.tex_coords.y() *= inv_size.y(); - } - } - - return true; -} - -bool GeometryBuffer::set_from_lines(const Lines& lines, float z) -{ - m_vertices.clear(); - - unsigned int v_size = 2 * (unsigned int)lines.size(); - if (v_size == 0) - return false; - - m_vertices = std::vector(v_size, Vertex()); - - unsigned int v_count = 0; - for (const Line& l : lines) { - Vertex& v1 = m_vertices[v_count]; - v1.position[0] = unscale(l.a(0)); - v1.position[1] = unscale(l.a(1)); - v1.position[2] = z; - ++v_count; - - Vertex& v2 = m_vertices[v_count]; - v2.position[0] = unscale(l.b(0)); - v2.position[1] = unscale(l.b(1)); - v2.position[2] = z; - ++v_count; - } - - return true; -} - -const float* GeometryBuffer::get_vertices_data() const -{ - return (m_vertices.size() > 0) ? (const float*)m_vertices.data() : nullptr; -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - #if !ENABLE_WORLD_COORDINATE const float Bed3D::Axes::DefaultStemRadius = 0.5f; const float Bed3D::Axes::DefaultStemLength = 25.0f; @@ -110,7 +37,6 @@ const float Bed3D::Axes::DefaultTipLength = 5.0f; void Bed3D::Axes::render() { -#if ENABLE_LEGACY_OPENGL_REMOVAL auto render_axis = [this](GLShaderProgram* shader, const Transform3d& transform) { const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); @@ -118,15 +44,7 @@ void Bed3D::Axes::render() shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * transform.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - auto render_axis = [this](const Transform3f& transform) { - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixf(transform.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL }; if (!m_arrow.is_initialized()) @@ -142,31 +60,16 @@ void Bed3D::Axes::render() shader->set_uniform("emission_factor", 0.0f); // x axis -#if ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.set_color(ColorRGBA::X()); render_axis(shader, Geometry::assemble_transform(m_origin, { 0.0, 0.5 * M_PI, 0.0 })); -#else - m_arrow.set_color(-1, ColorRGBA::X()); - render_axis(Geometry::assemble_transform(m_origin, { 0.0, 0.5 * M_PI, 0.0 }).cast()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // y axis -#if ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.set_color(ColorRGBA::Y()); render_axis(shader, Geometry::assemble_transform(m_origin, { -0.5 * M_PI, 0.0, 0.0 })); -#else - m_arrow.set_color(-1, ColorRGBA::Y()); - render_axis(Geometry::assemble_transform(m_origin, { -0.5 * M_PI, 0.0, 0.0 }).cast()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // z axis -#if ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.set_color(ColorRGBA::Z()); render_axis(shader, Geometry::assemble_transform(m_origin)); -#else - m_arrow.set_color(-1, ColorRGBA::Z()); - render_axis(Geometry::assemble_transform(m_origin).cast()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); @@ -221,7 +124,6 @@ bool Bed3D::set_shape(const Pointfs& bed_shape, const double max_print_height, c m_model_filename = model_filename; m_extended_bounding_box = this->calc_extended_bounding_box(); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_contour = ExPolygon(Polygon::new_scale(bed_shape)); const BoundingBox bbox = m_contour.contour.bounding_box(); if (!bbox.defined) @@ -231,20 +133,6 @@ bool Bed3D::set_shape(const Pointfs& bed_shape, const double max_print_height, c m_triangles.reset(); m_gridlines.reset(); m_contourlines.reset(); -#else - ExPolygon poly{ Polygon::new_scale(bed_shape) }; - - calc_triangles(poly); - - const BoundingBox& bed_bbox = poly.contour.bounding_box(); - calc_gridlines(poly, bed_bbox); - - calc_contourlines(poly); - - m_polygon = offset(poly.contour, (float)bed_bbox.radius() * 1.7f, jtRound, scale_(0.5)).front(); - - this->release_VBOs(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_texture.reset(); m_model.reset(); @@ -269,7 +157,6 @@ Point Bed3D::point_projection(const Point& point) const return m_polygon.point_projection(point); } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, bool show_axes, bool show_texture) { render_internal(canvas, view_matrix, projection_matrix, bottom, scale_factor, show_axes, show_texture, false); @@ -279,25 +166,9 @@ void Bed3D::render_for_picking(GLCanvas3D& canvas, const Transform3d& view_matri { render_internal(canvas, view_matrix, projection_matrix, bottom, scale_factor, false, false, true); } -#else -void Bed3D::render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture) -{ - render_internal(canvas, bottom, scale_factor, show_axes, show_texture, false); -} -void Bed3D::render_for_picking(GLCanvas3D& canvas, bool bottom, float scale_factor) -{ - render_internal(canvas, bottom, scale_factor, false, false, true); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render_internal(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, bool show_axes, bool show_texture, bool picking) -#else -void Bed3D::render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor, - bool show_axes, bool show_texture, bool picking) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { m_scale_factor = scale_factor; @@ -306,23 +177,13 @@ void Bed3D::render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor, glsafe(::glEnable(GL_DEPTH_TEST)); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_model.model.set_color(picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR); -#else - m_model.set_color(-1, picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL switch (m_type) { -#if ENABLE_LEGACY_OPENGL_REMOVAL case Type::System: { render_system(canvas, view_matrix, projection_matrix, bottom, show_texture); break; } default: case Type::Custom: { render_custom(canvas, view_matrix, projection_matrix, bottom, show_texture, picking); break; } -#else - case Type::System: { render_system(canvas, bottom, show_texture); break; } - default: - case Type::Custom: { render_custom(canvas, bottom, show_texture, picking); break; } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } glsafe(::glDisable(GL_DEPTH_TEST)); @@ -357,7 +218,6 @@ BoundingBoxf3 Bed3D::calc_extended_bounding_box() const return out; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::init_triangles() { if (m_triangles.is_initialized()) @@ -453,42 +313,7 @@ void Bed3D::init_gridlines() m_gridlines.init_from(std::move(init_data)); } -#else -void Bed3D::calc_triangles(const ExPolygon& poly) -{ - if (! m_triangles.set_from_triangles(triangulate_expolygon_2f(poly, NORMALS_UP), GROUND_Z)) - BOOST_LOG_TRIVIAL(error) << "Unable to create bed triangles"; -} -void Bed3D::calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox) -{ - Polylines axes_lines; - for (coord_t x = bed_bbox.min.x(); x <= bed_bbox.max.x(); x += scale_(10.0)) { - Polyline line; - line.append(Point(x, bed_bbox.min.y())); - line.append(Point(x, bed_bbox.max.y())); - axes_lines.push_back(line); - } - for (coord_t y = bed_bbox.min.y(); y <= bed_bbox.max.y(); y += scale_(10.0)) { - Polyline line; - line.append(Point(bed_bbox.min.x(), y)); - line.append(Point(bed_bbox.max.x(), y)); - axes_lines.push_back(line); - } - - // clip with a slightly grown expolygon because our lines lay on the contours and may get erroneously clipped - Lines gridlines = to_lines(intersection_pl(axes_lines, offset(poly, (float)SCALED_EPSILON))); - - // append bed contours - Lines contour_lines = to_lines(poly); - std::copy(contour_lines.begin(), contour_lines.end(), std::back_inserter(gridlines)); - - if (!m_gridlines.set_from_lines(gridlines, GROUND_Z)) - BOOST_LOG_TRIVIAL(error) << "Unable to create bed grid lines\n"; -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::init_contourlines() { if (m_contourlines.is_initialized()) @@ -514,14 +339,6 @@ void Bed3D::init_contourlines() m_contourlines.init_from(std::move(init_data)); m_contourlines.set_color({ 1.0f, 1.0f, 1.0f, 0.5f }); } -#else -void Bed3D::calc_contourlines(const ExPolygon& poly) -{ - const Lines contour_lines = to_lines(poly); - if (!m_contourlines.set_from_lines(contour_lines, GROUND_Z)) - BOOST_LOG_TRIVIAL(error) << "Unable to create bed contour lines\n"; -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Try to match the print bed shape with the shape of an active profile. If such a match exists, // return the print bed model. @@ -551,17 +368,12 @@ void Bed3D::render_axes() { if (m_build_volume.valid()) #if ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL m_axes.render(Transform3d::Identity(), 0.25f); -#else - m_axes.render(0.25f); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #else m_axes.render(); #endif // ENABLE_WORLD_COORDINATE } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render_system(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture) { if (!bottom) @@ -572,32 +384,12 @@ void Bed3D::render_system(GLCanvas3D& canvas, const Transform3d& view_matrix, co else if (bottom) render_contour(view_matrix, projection_matrix); } -#else -void Bed3D::render_system(GLCanvas3D& canvas, bool bottom, bool show_texture) -{ - if (!bottom) - render_model(); - if (show_texture) - render_texture(bottom, canvas); - else if (bottom) - render_contour(); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix) -#else -void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (m_texture_filename.empty()) { m_texture.reset(); -#if ENABLE_LEGACY_OPENGL_REMOVAL render_default(bottom, false, true, view_matrix, projection_matrix); -#else - render_default(bottom, false, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return; } @@ -610,11 +402,7 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) if (m_temp_texture.get_id() == 0 || m_temp_texture.get_source() != m_texture_filename) { // generate a temporary lower resolution texture to show while no main texture levels have been compressed if (!m_temp_texture.load_from_svg_file(m_texture_filename, false, false, false, max_tex_size / 8)) { -#if ENABLE_LEGACY_OPENGL_REMOVAL render_default(bottom, false, true, view_matrix, projection_matrix); -#else - render_default(bottom, false, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return; } canvas.request_extra_frame(); @@ -622,11 +410,7 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) // starts generating the main texture, compression will run asynchronously if (!m_texture.load_from_svg_file(m_texture_filename, true, true, true, max_tex_size)) { -#if ENABLE_LEGACY_OPENGL_REMOVAL render_default(bottom, false, true, view_matrix, projection_matrix); -#else - render_default(bottom, false, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return; } } @@ -634,11 +418,7 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) // generate a temporary lower resolution texture to show while no main texture levels have been compressed if (m_temp_texture.get_id() == 0 || m_temp_texture.get_source() != m_texture_filename) { if (!m_temp_texture.load_from_file(m_texture_filename, false, GLTexture::None, false)) { -#if ENABLE_LEGACY_OPENGL_REMOVAL render_default(bottom, false, true, view_matrix, projection_matrix); -#else - render_default(bottom, false, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return; } canvas.request_extra_frame(); @@ -646,20 +426,12 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) // starts generating the main texture, compression will run asynchronously if (!m_texture.load_from_file(m_texture_filename, true, GLTexture::MultiThreaded, true)) { -#if ENABLE_LEGACY_OPENGL_REMOVAL render_default(bottom, false, true, view_matrix, projection_matrix); -#else - render_default(bottom, false, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return; } } else { -#if ENABLE_LEGACY_OPENGL_REMOVAL render_default(bottom, false, true, view_matrix, projection_matrix); -#else - render_default(bottom, false, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return; } } @@ -674,7 +446,6 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) canvas.request_extra_frame(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL init_triangles(); GLShaderProgram* shader = wxGetApp().get_shader("printbed"); @@ -713,83 +484,15 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) shader->stop_using(); } -#else - if (m_triangles.get_vertices_count() > 0) { - GLShaderProgram* shader = wxGetApp().get_shader("printbed"); - if (shader != nullptr) { - shader->start_using(); - shader->set_uniform("transparent_background", bottom); - shader->set_uniform("svg_source", boost::algorithm::iends_with(m_texture.get_source(), ".svg")); - - if (m_vbo_id == 0) { - glsafe(::glGenBuffers(1, &m_vbo_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id)); - glsafe(::glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)m_triangles.get_vertices_data_size(), (const GLvoid*)m_triangles.get_vertices_data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - } - - glsafe(::glEnable(GL_DEPTH_TEST)); - if (bottom) - glsafe(::glDepthMask(GL_FALSE)); - - glsafe(::glEnable(GL_BLEND)); - glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - - if (bottom) - glsafe(::glFrontFace(GL_CW)); - - const unsigned int stride = m_triangles.get_vertex_data_size(); - - // show the temporary texture while no compressed data is available - GLuint tex_id = (GLuint)m_temp_texture.get_id(); - if (tex_id == 0) - tex_id = (GLuint)m_texture.get_id(); - - glsafe(::glBindTexture(GL_TEXTURE_2D, tex_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id)); - - glsafe(::glVertexPointer(3, GL_FLOAT, stride, (const void*)(intptr_t)m_triangles.get_position_offset())); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - - glsafe(::glTexCoordPointer(2, GL_FLOAT, stride, (const void*)(intptr_t)m_triangles.get_tex_coords_offset())); - glsafe(::glEnableClientState(GL_TEXTURE_COORD_ARRAY)); - - glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)m_triangles.get_vertices_count())); - - glsafe(::glDisableClientState(GL_TEXTURE_COORD_ARRAY)); - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); - - if (bottom) - glsafe(::glFrontFace(GL_CCW)); - - glsafe(::glDisable(GL_BLEND)); - if (bottom) - glsafe(::glDepthMask(GL_TRUE)); - - shader->stop_using(); - } - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render_model(const Transform3d& view_matrix, const Transform3d& projection_matrix) -#else -void Bed3D::render_model() -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (m_model_filename.empty()) return; if (m_model.model.get_filename() != m_model_filename && m_model.model.init_from_file(m_model_filename)) { -#if ENABLE_LEGACY_OPENGL_REMOVAL m_model.model.set_color(DEFAULT_MODEL_COLOR); -#else - m_model.set_color(-1, DEFAULT_MODEL_COLOR); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // 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); @@ -806,41 +509,24 @@ void Bed3D::render_model() if (shader != nullptr) { shader->start_using(); shader->set_uniform("emission_factor", 0.0f); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d model_matrix = Geometry::translation_transform(m_model_offset); shader->set_uniform("view_model_matrix", view_matrix * model_matrix); shader->set_uniform("projection_matrix", projection_matrix); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glPushMatrix()); - glsafe(::glTranslated(m_model_offset.x(), m_model_offset.y(), m_model_offset.z())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_model.model.render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); } } } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture, bool picking) -#else -void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (m_texture_filename.empty() && m_model_filename.empty()) { -#if ENABLE_LEGACY_OPENGL_REMOVAL render_default(bottom, picking, show_texture, view_matrix, projection_matrix); -#else - render_default(bottom, picking, show_texture); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return; } -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!bottom) render_model(view_matrix, projection_matrix); @@ -848,26 +534,12 @@ void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bo render_texture(bottom, canvas, view_matrix, projection_matrix); else if (bottom) render_contour(view_matrix, projection_matrix); -#else - if (!bottom) - render_model(); - - if (show_texture) - render_texture(bottom, canvas); - else if (bottom) - render_contour(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render_default(bool bottom, bool picking, bool show_texture, const Transform3d& view_matrix, const Transform3d& projection_matrix) -#else -void Bed3D::render_default(bool bottom, bool picking, bool show_texture) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { m_texture.reset(); -#if ENABLE_LEGACY_OPENGL_REMOVAL init_gridlines(); init_triangles(); @@ -906,45 +578,8 @@ void Bed3D::render_default(bool bottom, bool picking, bool show_texture) shader->stop_using(); } -#else - const unsigned int triangles_vcount = m_triangles.get_vertices_count(); - if (triangles_vcount > 0) { - const bool has_model = !m_model.get_filename().empty(); - - glsafe(::glEnable(GL_DEPTH_TEST)); - glsafe(::glEnable(GL_BLEND)); - glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - - if (!has_model && !bottom) { - // draw background - glsafe(::glDepthMask(GL_FALSE)); - glsafe(::glColor4fv(picking ? PICKING_MODEL_COLOR.data() : DEFAULT_MODEL_COLOR.data())); - glsafe(::glNormal3d(0.0f, 0.0f, 1.0f)); - glsafe(::glVertexPointer(3, GL_FLOAT, m_triangles.get_vertex_data_size(), (GLvoid*)m_triangles.get_vertices_data())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)triangles_vcount)); - glsafe(::glDepthMask(GL_TRUE)); - } - - if (!picking && show_texture) { - // draw grid - glsafe(::glLineWidth(1.5f * m_scale_factor)); - glsafe(::glColor4fv(has_model && !bottom ? DEFAULT_SOLID_GRID_COLOR.data() : DEFAULT_TRANSPARENT_GRID_COLOR.data())); - glsafe(::glVertexPointer(3, GL_FLOAT, m_gridlines.get_vertex_data_size(), (GLvoid*)m_gridlines.get_vertices_data())); - glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_gridlines.get_vertices_count())); - } - else if (!show_texture) - render_contour(); - - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - - glsafe(::glDisable(GL_BLEND)); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render_contour(const Transform3d& view_matrix, const Transform3d& projection_matrix) { init_contourlines(); @@ -971,27 +606,6 @@ void Bed3D::render_contour(const Transform3d& view_matrix, const Transform3d& pr shader->stop_using(); } } -#else -void Bed3D::render_contour() -{ - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glLineWidth(1.5f * m_scale_factor)); - glsafe(::glColor4f(1.0f, 1.0f, 1.0f, 0.5f)); - glsafe(::glVertexPointer(3, GL_FLOAT, m_contourlines.get_vertex_data_size(), (GLvoid*)m_contourlines.get_vertices_data())); - glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_contourlines.get_vertices_count())); - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if !ENABLE_LEGACY_OPENGL_REMOVAL -void Bed3D::release_VBOs() -{ - if (m_vbo_id > 0) { - glsafe(::glDeleteBuffers(1, &m_vbo_id)); - m_vbo_id = 0; - } -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::register_raycasters_for_picking(const GLModel::Geometry& geometry, const Transform3d& trafo) { diff --git a/src/slic3r/GUI/3DBed.hpp b/src/slic3r/GUI/3DBed.hpp index c12674b4a7..ebfc1123d6 100644 --- a/src/slic3r/GUI/3DBed.hpp +++ b/src/slic3r/GUI/3DBed.hpp @@ -11,9 +11,7 @@ #include "MeshUtils.hpp" #include "libslic3r/BuildVolume.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "libslic3r/ExPolygon.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include #include @@ -23,30 +21,6 @@ namespace GUI { class GLCanvas3D; -#if !ENABLE_LEGACY_OPENGL_REMOVAL -class GeometryBuffer -{ - struct Vertex - { - Vec3f position{ Vec3f::Zero() }; - Vec2f tex_coords{ Vec2f::Zero() }; - }; - - std::vector m_vertices; - -public: - bool set_from_triangles(const std::vector &triangles, float z); - bool set_from_lines(const Lines& lines, float z); - - const float* get_vertices_data() const; - unsigned int get_vertices_data_size() const { return (unsigned int)m_vertices.size() * get_vertex_data_size(); } - unsigned int get_vertex_data_size() const { return (unsigned int)(5 * sizeof(float)); } - size_t get_position_offset() const { return 0; } - size_t get_tex_coords_offset() const { return (size_t)(3 * sizeof(float)); } - unsigned int get_vertices_count() const { return (unsigned int)m_vertices.size(); } -}; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - class Bed3D { #if !ENABLE_WORLD_COORDINATE @@ -91,29 +65,18 @@ private: std::string m_model_filename; // Print volume bounding box exteded with axes and model. BoundingBoxf3 m_extended_bounding_box; -#if ENABLE_LEGACY_OPENGL_REMOVAL // Print bed polygon ExPolygon m_contour; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Slightly expanded print bed polygon, for collision detection. Polygon m_polygon; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel m_triangles; GLModel m_gridlines; GLModel m_contourlines; -#else - GeometryBuffer m_triangles; - GeometryBuffer m_gridlines; - GeometryBuffer m_contourlines; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLTexture m_texture; // temporary texture shown until the main texture has still no levels compressed GLTexture m_temp_texture; PickingModel m_model; Vec3d m_model_offset{ Vec3d::Zero() }; -#if !ENABLE_LEGACY_OPENGL_REMOVAL - unsigned int m_vbo_id{ 0 }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE CoordAxes m_axes; #else @@ -124,11 +87,7 @@ private: public: Bed3D() = default; -#if ENABLE_LEGACY_OPENGL_REMOVAL ~Bed3D() = default; -#else - ~Bed3D() { release_VBOs(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Update print bed model from configuration. // Return true if the bed shape changed, so the calee will update the UI. @@ -152,52 +111,25 @@ public: bool contains(const Point& point) const; Point point_projection(const Point& point) const; -#if ENABLE_LEGACY_OPENGL_REMOVAL void render(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, bool show_axes, bool show_texture); void render_for_picking(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor); -#else - void render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture); - void render_for_picking(GLCanvas3D& canvas, bool bottom, float scale_factor); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL private: // Calculate an extended bounding box from axes and current model for visualization purposes. BoundingBoxf3 calc_extended_bounding_box() const; -#if ENABLE_LEGACY_OPENGL_REMOVAL void init_triangles(); void init_gridlines(); void init_contourlines(); -#else - void calc_triangles(const ExPolygon& poly); - void calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox); - void calc_contourlines(const ExPolygon& poly); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL static std::tuple detect_type(const Pointfs& shape); -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_internal(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, bool show_axes, bool show_texture, bool picking); -#else - void render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor, - bool show_axes, bool show_texture, bool picking); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void render_axes(); -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_system(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture); void render_texture(bool bottom, GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix); void render_model(const Transform3d& view_matrix, const Transform3d& projection_matrix); void render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture, bool picking); void render_default(bool bottom, bool picking, bool show_texture, const Transform3d& view_matrix, const Transform3d& projection_matrix); void render_contour(const Transform3d& view_matrix, const Transform3d& projection_matrix); -#else - void render_system(GLCanvas3D& canvas, bool bottom, bool show_texture); - void render_texture(bool bottom, GLCanvas3D& canvas); - void render_model(); - void render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking); - void render_default(bool bottom, bool picking, bool show_texture); - void render_contour(); - - void release_VBOs(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void register_raycasters_for_picking(const GLModel::Geometry& geometry, const Transform3d& trafo); }; diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 4bf05555c8..27a67001ec 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -1,21 +1,11 @@ #include -#if !ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_SMOOTH_NORMALS -#include -#include -#include -#endif // ENABLE_SMOOTH_NORMALS -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - #include "3DScene.hpp" #include "GLShader.hpp" #include "GUI_App.hpp" #include "Plater.hpp" #include "BitmapCache.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "Camera.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include "libslic3r/BuildVolume.hpp" #include "libslic3r/ExtrusionEntity.hpp" @@ -74,234 +64,12 @@ void glAssertRecentCallImpl(const char* file_name, unsigned int line, const char namespace Slic3r { -#if !ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_SMOOTH_NORMALS -static void smooth_normals_corner(TriangleMesh& mesh, std::vector& normals) -{ - using MapMatrixXfUnaligned = Eigen::Map>; - using MapMatrixXiUnaligned = Eigen::Map>; - - std::vector face_normals = its_face_normals(mesh.its); - - Eigen::MatrixXd vertices = MapMatrixXfUnaligned(mesh.its.vertices.front().data(), - Eigen::Index(mesh.its.vertices.size()), 3).cast(); - Eigen::MatrixXi indices = MapMatrixXiUnaligned(mesh.its.indices.front().data(), - Eigen::Index(mesh.its.indices.size()), 3); - Eigen::MatrixXd in_normals = MapMatrixXfUnaligned(face_normals.front().data(), - Eigen::Index(face_normals.size()), 3).cast(); - Eigen::MatrixXd out_normals; - - igl::per_corner_normals(vertices, indices, in_normals, 1.0, out_normals); - - normals = std::vector(mesh.its.vertices.size()); - for (size_t i = 0; i < mesh.its.indices.size(); ++i) { - for (size_t j = 0; j < 3; ++j) { - normals[mesh.its.indices[i][j]] = out_normals.row(i * 3 + j).cast(); - } - } -} - -static void smooth_normals_vertex(TriangleMesh& mesh, std::vector& normals) -{ - using MapMatrixXfUnaligned = Eigen::Map>; - using MapMatrixXiUnaligned = Eigen::Map>; - - Eigen::MatrixXd vertices = MapMatrixXfUnaligned(mesh.its.vertices.front().data(), - Eigen::Index(mesh.its.vertices.size()), 3).cast(); - Eigen::MatrixXi indices = MapMatrixXiUnaligned(mesh.its.indices.front().data(), - Eigen::Index(mesh.its.indices.size()), 3); - Eigen::MatrixXd out_normals; - -// igl::per_vertex_normals(vertices, indices, igl::PER_VERTEX_NORMALS_WEIGHTING_TYPE_UNIFORM, out_normals); -// igl::per_vertex_normals(vertices, indices, igl::PER_VERTEX_NORMALS_WEIGHTING_TYPE_AREA, out_normals); - igl::per_vertex_normals(vertices, indices, igl::PER_VERTEX_NORMALS_WEIGHTING_TYPE_ANGLE, out_normals); -// igl::per_vertex_normals(vertices, indices, igl::PER_VERTEX_NORMALS_WEIGHTING_TYPE_DEFAULT, out_normals); - - normals = std::vector(mesh.its.vertices.size()); - for (size_t i = 0; i < static_cast(out_normals.rows()); ++i) { - normals[i] = out_normals.row(i).cast(); - } -} -#endif // ENABLE_SMOOTH_NORMALS - -#if ENABLE_SMOOTH_NORMALS -void GLIndexedVertexArray::load_mesh_full_shading(const TriangleMesh& mesh, bool smooth_normals) -#else -void GLIndexedVertexArray::load_mesh_full_shading(const TriangleMesh& mesh) -#endif // ENABLE_SMOOTH_NORMALS -{ - assert(triangle_indices.empty() && vertices_and_normals_interleaved_size == 0); - assert(quad_indices.empty() && triangle_indices_size == 0); - assert(vertices_and_normals_interleaved.size() % 6 == 0 && quad_indices_size == vertices_and_normals_interleaved.size()); - -#if ENABLE_SMOOTH_NORMALS - if (smooth_normals) { - TriangleMesh new_mesh(mesh); - std::vector normals; - smooth_normals_corner(new_mesh, normals); -// smooth_normals_vertex(new_mesh, normals); - - this->vertices_and_normals_interleaved.reserve(this->vertices_and_normals_interleaved.size() + 3 * 2 * new_mesh.its.vertices.size()); - for (size_t i = 0; i < new_mesh.its.vertices.size(); ++i) { - const stl_vertex& v = new_mesh.its.vertices[i]; - const stl_normal& n = normals[i]; - this->push_geometry(v(0), v(1), v(2), n(0), n(1), n(2)); - } - - for (size_t i = 0; i < new_mesh.its.indices.size(); ++i) { - const stl_triangle_vertex_indices& idx = new_mesh.its.indices[i]; - this->push_triangle(idx(0), idx(1), idx(2)); - } - } - else { -#endif // ENABLE_SMOOTH_NORMALS - this->load_its_flat_shading(mesh.its); -#if ENABLE_SMOOTH_NORMALS - } -#endif // ENABLE_SMOOTH_NORMALS -} - -void GLIndexedVertexArray::load_its_flat_shading(const indexed_triangle_set &its) -{ - this->vertices_and_normals_interleaved.reserve(this->vertices_and_normals_interleaved.size() + 3 * 3 * 2 * its.indices.size()); - unsigned int vertices_count = 0; - for (int i = 0; i < int(its.indices.size()); ++ i) { - stl_triangle_vertex_indices face = its.indices[i]; - stl_vertex vertex[3] = { its.vertices[face[0]], its.vertices[face[1]], its.vertices[face[2]] }; - stl_vertex n = face_normal_normalized(vertex); - for (int j = 0; j < 3; ++j) - this->push_geometry(vertex[j](0), vertex[j](1), vertex[j](2), n(0), n(1), n(2)); - this->push_triangle(vertices_count, vertices_count + 1, vertices_count + 2); - vertices_count += 3; - } -} - -void GLIndexedVertexArray::finalize_geometry(bool opengl_initialized) -{ - assert(this->vertices_and_normals_interleaved_VBO_id == 0); - assert(this->triangle_indices_VBO_id == 0); - assert(this->quad_indices_VBO_id == 0); - - if (! opengl_initialized) { - // Shrink the data vectors to conserve memory in case the data cannot be transfered to the OpenGL driver yet. - this->shrink_to_fit(); - return; - } - - if (! this->vertices_and_normals_interleaved.empty()) { - glsafe(::glGenBuffers(1, &this->vertices_and_normals_interleaved_VBO_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved_VBO_id)); - glsafe(::glBufferData(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved.size() * 4, this->vertices_and_normals_interleaved.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - this->vertices_and_normals_interleaved.clear(); - } - if (! this->triangle_indices.empty()) { - glsafe(::glGenBuffers(1, &this->triangle_indices_VBO_id)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_id)); - glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices.size() * 4, this->triangle_indices.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - this->triangle_indices.clear(); - } - if (! this->quad_indices.empty()) { - glsafe(::glGenBuffers(1, &this->quad_indices_VBO_id)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices_VBO_id)); - glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices.size() * 4, this->quad_indices.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - this->quad_indices.clear(); - } -} - -void GLIndexedVertexArray::release_geometry() -{ - if (this->vertices_and_normals_interleaved_VBO_id) { - glsafe(::glDeleteBuffers(1, &this->vertices_and_normals_interleaved_VBO_id)); - this->vertices_and_normals_interleaved_VBO_id = 0; - } - if (this->triangle_indices_VBO_id) { - glsafe(::glDeleteBuffers(1, &this->triangle_indices_VBO_id)); - this->triangle_indices_VBO_id = 0; - } - if (this->quad_indices_VBO_id) { - glsafe(::glDeleteBuffers(1, &this->quad_indices_VBO_id)); - this->quad_indices_VBO_id = 0; - } - this->clear(); -} - -void GLIndexedVertexArray::render() const -{ - assert(this->vertices_and_normals_interleaved_VBO_id != 0); - assert(this->triangle_indices_VBO_id != 0 || this->quad_indices_VBO_id != 0); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved_VBO_id)); - glsafe(::glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), (const void*)(3 * sizeof(float)))); - glsafe(::glNormalPointer(GL_FLOAT, 6 * sizeof(float), nullptr)); - - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); - - // Render using the Vertex Buffer Objects. - if (this->triangle_indices_size > 0) { - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_id)); - glsafe(::glDrawElements(GL_TRIANGLES, GLsizei(this->triangle_indices_size), GL_UNSIGNED_INT, nullptr)); - glsafe(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - } - if (this->quad_indices_size > 0) { - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices_VBO_id)); - glsafe(::glDrawElements(GL_QUADS, GLsizei(this->quad_indices_size), GL_UNSIGNED_INT, nullptr)); - glsafe(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - } - - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); -} - -void GLIndexedVertexArray::render( - const std::pair& tverts_range, - const std::pair& qverts_range) const -{ - // this method has been called before calling finalize() ? - if (this->vertices_and_normals_interleaved_VBO_id == 0 && !this->vertices_and_normals_interleaved.empty()) - return; - - assert(this->vertices_and_normals_interleaved_VBO_id != 0); - assert(this->triangle_indices_VBO_id != 0 || this->quad_indices_VBO_id != 0); - - // Render using the Vertex Buffer Objects. - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved_VBO_id)); - glsafe(::glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), (const void*)(3 * sizeof(float)))); - glsafe(::glNormalPointer(GL_FLOAT, 6 * sizeof(float), nullptr)); - - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); - - if (this->triangle_indices_size > 0) { - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_id)); - glsafe(::glDrawElements(GL_TRIANGLES, GLsizei(std::min(this->triangle_indices_size, tverts_range.second - tverts_range.first)), GL_UNSIGNED_INT, (const void*)(tverts_range.first * 4))); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - } - if (this->quad_indices_size > 0) { - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices_VBO_id)); - glsafe(::glDrawElements(GL_QUADS, GLsizei(std::min(this->quad_indices_size, qverts_range.second - qverts_range.first)), GL_UNSIGNED_INT, (const void*)(qverts_range.first * 4))); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - } - - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - const float GLVolume::SinkingContours::HalfWidth = 0.25f; void GLVolume::SinkingContours::render() { update(); -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = GUI::wxGetApp().get_current_shader(); if (shader == nullptr) return; @@ -309,14 +77,7 @@ void GLVolume::SinkingContours::render() const GUI::Camera& camera = GUI::wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * Geometry::translation_transform(m_shift)); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#else - glsafe(::glPushMatrix()); - glsafe(::glTranslated(m_shift.x(), m_shift.y(), m_shift.z())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_model.render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } void GLVolume::SinkingContours::update() @@ -347,18 +108,15 @@ void GLVolume::SinkingContours::update() m_model.reset(); GUI::GLModel::Geometry init_data; -#if ENABLE_LEGACY_OPENGL_REMOVAL init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Triangles, GUI::GLModel::Geometry::EVertexLayout::P3 }; init_data.color = ColorRGBA::WHITE(); unsigned int vertices_counter = 0; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL MeshSlicingParams slicing_params; slicing_params.trafo = m_parent.world_matrix(); const Polygons polygons = union_(slice_mesh(mesh.its, 0.0f, slicing_params)); if (polygons.empty()) return; for (const ExPolygon& expoly : diff_ex(expand(polygons, float(scale_(HalfWidth))), shrink(polygons, float(scale_(HalfWidth))))) { -#if ENABLE_LEGACY_OPENGL_REMOVAL const std::vector triangulation = triangulate_expolygon_3d(expoly); init_data.reserve_vertices(init_data.vertices_count() + triangulation.size()); init_data.reserve_indices(init_data.indices_count() + triangulation.size()); @@ -370,27 +128,6 @@ void GLVolume::SinkingContours::update() } } m_model.init_from(std::move(init_data)); -#else - GUI::GLModel::Geometry::Entity entity; - entity.type = GUI::GLModel::EPrimitiveType::Triangles; - const std::vector triangulation = triangulate_expolygon_3d(expoly); - entity.positions.reserve(entity.positions.size() + triangulation.size()); - entity.normals.reserve(entity.normals.size() + triangulation.size()); - entity.indices.reserve(entity.indices.size() + triangulation.size() / 3); - for (const Vec3d& v : triangulation) { - entity.positions.emplace_back(v.cast() + 0.015f * Vec3f::UnitZ()); // add a small positive z to avoid z-fighting - entity.normals.emplace_back(Vec3f::UnitZ()); - const size_t positions_count = entity.positions.size(); - if (positions_count % 3 == 0) { - entity.indices.emplace_back(positions_count - 3); - entity.indices.emplace_back(positions_count - 2); - entity.indices.emplace_back(positions_count - 1); - } - } - init_data.entities.emplace_back(entity); - } - m_model.init_from(init_data); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GLVolume::NonManifoldEdges::render() @@ -401,7 +138,7 @@ void GLVolume::NonManifoldEdges::render() if (!GUI::OpenGLManager::get_gl_info().is_core_profile()) #endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(2.0f)); -#if ENABLE_LEGACY_OPENGL_REMOVAL + GLShaderProgram* shader = GUI::wxGetApp().get_current_shader(); if (shader == nullptr) return; @@ -416,15 +153,7 @@ void GLVolume::NonManifoldEdges::render() shader->set_uniform("gap_size", 0.0f); #endif // ENABLE_GL_CORE_PROFILE m_model.set_color(complementary(m_parent.render_color)); -#else - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(m_parent.world_matrix().data())); - m_model.set_color(-1, complementary(m_parent.render_color)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_model.render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } void GLVolume::NonManifoldEdges::update() @@ -444,7 +173,6 @@ void GLVolume::NonManifoldEdges::update() const std::vector> edges = its_get_open_edges(mesh.its); if (!edges.empty()) { GUI::GLModel::Geometry init_data; -#if ENABLE_LEGACY_OPENGL_REMOVAL init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Lines, GUI::GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(2 * edges.size()); init_data.reserve_indices(2 * edges.size()); @@ -458,25 +186,6 @@ void GLVolume::NonManifoldEdges::update() init_data.add_line(vertices_count - 2, vertices_count - 1); } m_model.init_from(std::move(init_data)); -#else - GUI::GLModel::Geometry::Entity entity; - entity.type = GUI::GLModel::EPrimitiveType::Lines; - - entity.positions.reserve(2 * edges.size()); - entity.normals.reserve(2 * edges.size()); - entity.indices.reserve(2 * edges.size()); - for (const std::pair& edge : edges) { - entity.positions.emplace_back(mesh.its.vertices[edge.first].cast()); - entity.positions.emplace_back(mesh.its.vertices[edge.second].cast()); - entity.normals.emplace_back(Vec3f::UnitZ()); - entity.normals.emplace_back(Vec3f::UnitZ()); - entity.indices.emplace_back(entity.positions.size() - 2); - entity.indices.emplace_back(entity.positions.size() - 1); - } - - init_data.entities.emplace_back(entity); - m_model.init_from(init_data); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } } @@ -522,9 +231,6 @@ GLVolume::GLVolume(float r, float g, float b, float a) , force_neutral_color(false) , force_sinking_contours(false) , tverts_range(0, size_t(-1)) -#if !ENABLE_LEGACY_OPENGL_REMOVAL - , qverts_range(0, size_t(-1)) -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL { color = { r, g, b, a }; set_render_color(color); @@ -640,7 +346,6 @@ const BoundingBoxf3& GLVolume::transformed_non_sinking_bounding_box() const return *m_transformed_non_sinking_bounding_box; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLVolume::set_range(double min_z, double max_z) { this->tverts_range.first = 0; @@ -669,71 +374,24 @@ void GLVolume::set_range(double min_z, double max_z) } } } -#else -void GLVolume::set_range(double min_z, double max_z) -{ - this->qverts_range.first = 0; - this->qverts_range.second = this->indexed_vertex_array.quad_indices_size; - this->tverts_range.first = 0; - this->tverts_range.second = this->indexed_vertex_array.triangle_indices_size; - if (! this->print_zs.empty()) { - // The Z layer range is specified. - // First test whether the Z span of this object is not out of (min_z, max_z) completely. - if (this->print_zs.front() > max_z || this->print_zs.back() < min_z) { - this->qverts_range.second = 0; - this->tverts_range.second = 0; - } - else { - // Then find the lowest layer to be displayed. - size_t i = 0; - for (; i < this->print_zs.size() && this->print_zs[i] < min_z; ++ i); - if (i == this->print_zs.size()) { - // This shall not happen. - this->qverts_range.second = 0; - this->tverts_range.second = 0; - } - else { - // Remember start of the layer. - this->qverts_range.first = this->offsets[i * 2]; - this->tverts_range.first = this->offsets[i * 2 + 1]; - // Some layers are above $min_z. Which? - for (; i < this->print_zs.size() && this->print_zs[i] <= max_z; ++ i); - if (i < this->print_zs.size()) { - this->qverts_range.second = this->offsets[i * 2]; - this->tverts_range.second = this->offsets[i * 2 + 1]; - } - } - } - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void GLVolume::render() { if (!is_active) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = GUI::wxGetApp().get_current_shader(); if (shader == nullptr) return; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (this->is_left_handed()) glsafe(::glFrontFace(GL_CW)); glsafe(::glCullFace(GL_BACK)); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (tverts_range == std::make_pair(0, -1)) model.render(); else model.render(this->tverts_range); -#else - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(world_matrix().data())); - this->indexed_vertex_array.render(this->tverts_range, this->qverts_range); - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (this->is_left_handed()) glsafe(::glFrontFace(GL_CCW)); @@ -765,44 +423,23 @@ void GLVolume::render_non_manifold_edges() m_non_manifold_edges.render(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL std::vector GLVolumeCollection::load_object( const ModelObject* model_object, int obj_idx, const std::vector& instance_idxs) -#else -std::vector GLVolumeCollection::load_object( - const ModelObject *model_object, - int obj_idx, - const std::vector &instance_idxs, - bool opengl_initialized) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { std::vector volumes_idx; for (int volume_idx = 0; volume_idx < int(model_object->volumes.size()); ++volume_idx) for (int instance_idx : instance_idxs) -#if ENABLE_LEGACY_OPENGL_REMOVAL - volumes_idx.emplace_back(this->GLVolumeCollection::load_object_volume(model_object, obj_idx, volume_idx, instance_idx)); -#else - volumes_idx.emplace_back(this->GLVolumeCollection::load_object_volume(model_object, obj_idx, volume_idx, instance_idx, opengl_initialized)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL + volumes_idx.emplace_back(this->GLVolumeCollection::load_object_volume(model_object, obj_idx, volume_idx, instance_idx)); return volumes_idx; } -#if ENABLE_LEGACY_OPENGL_REMOVAL int GLVolumeCollection::load_object_volume( const ModelObject* model_object, int obj_idx, int volume_idx, int instance_idx) -#else -int GLVolumeCollection::load_object_volume( - const ModelObject *model_object, - int obj_idx, - int volume_idx, - int instance_idx, - bool opengl_initialized) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { const ModelVolume *model_volume = model_object->volumes[volume_idx]; const int extruder_id = model_volume->extruder_id(); @@ -811,7 +448,6 @@ int GLVolumeCollection::load_object_volume( this->volumes.emplace_back(new GLVolume()); GLVolume& v = *this->volumes.back(); v.set_color(color_from_model_volume(*model_volume)); -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_SMOOTH_NORMALS v.model.init_from(*mesh, true); v.mesh_raycaster = std::make_unique(mesh); @@ -819,14 +455,6 @@ int GLVolumeCollection::load_object_volume( v.model.init_from(*mesh); v.mesh_raycaster = std::make_unique(mesh); #endif // ENABLE_SMOOTH_NORMALS -#else -#if ENABLE_SMOOTH_NORMALS - v.indexed_vertex_array.load_mesh(mesh, true); -#else - v.indexed_vertex_array.load_mesh(mesh); -#endif // ENABLE_SMOOTH_NORMALS - v.indexed_vertex_array.finalize_geometry(opengl_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL v.composite_id = GLVolume::CompositeID(obj_idx, volume_idx, instance_idx); if (model_volume->is_model_part()) { // GLVolume will reference a convex hull from model_volume! @@ -845,7 +473,6 @@ int GLVolumeCollection::load_object_volume( // Load SLA auxiliary GLVolumes (for support trees or pad). // This function produces volumes for multiple instances in a single shot, // as some object specific mesh conversions may be expensive. -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLVolumeCollection::load_object_auxiliary( const SLAPrintObject* print_object, int obj_idx, @@ -854,17 +481,6 @@ void GLVolumeCollection::load_object_auxiliary( SLAPrintObjectStep milestone, // Timestamp of the last change of the milestone size_t timestamp) -#else -void GLVolumeCollection::load_object_auxiliary( - const SLAPrintObject *print_object, - int obj_idx, - // pairs of - const std::vector>& instances, - SLAPrintObjectStep milestone, - // Timestamp of the last change of the milestone - size_t timestamp, - bool opengl_initialized) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { assert(print_object->is_step_done(milestone)); Transform3d mesh_trafo_inv = print_object->trafo().inverse(); @@ -877,7 +493,6 @@ void GLVolumeCollection::load_object_auxiliary( const ModelInstance& model_instance = *print_object->model_object()->instances[instance_idx.first]; this->volumes.emplace_back(new GLVolume((milestone == slaposPad) ? GLVolume::SLA_PAD_COLOR : GLVolume::SLA_SUPPORT_COLOR)); GLVolume& v = *this->volumes.back(); -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_SMOOTH_NORMALS v.model.init_from(mesh, true); #else @@ -885,14 +500,6 @@ void GLVolumeCollection::load_object_auxiliary( v.model.set_color((milestone == slaposPad) ? GLVolume::SLA_PAD_COLOR : GLVolume::SLA_SUPPORT_COLOR); v.mesh_raycaster = std::make_unique(std::make_shared(mesh)); #endif // ENABLE_SMOOTH_NORMALS -#else -#if ENABLE_SMOOTH_NORMALS - v.indexed_vertex_array.load_mesh(mesh, true); -#else - v.indexed_vertex_array.load_mesh(mesh); -#endif // ENABLE_SMOOTH_NORMALS - v.indexed_vertex_array.finalize_geometry(opengl_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL v.composite_id = GLVolume::CompositeID(obj_idx, -int(milestone), (int)instance_idx.first); v.geometry_id = std::pair(timestamp, model_instance.id().id); // Create a copy of the convex hull mesh for each instance. Use a move operator on the last instance. @@ -908,7 +515,6 @@ void GLVolumeCollection::load_object_auxiliary( } } -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_OPENGL_ES int GLVolumeCollection::load_wipe_tower_preview( float pos_x, float pos_y, float width, float depth, float height, @@ -918,11 +524,6 @@ int GLVolumeCollection::load_wipe_tower_preview( float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool size_unknown, float brim_width) #endif // ENABLE_OPENGL_ES -#else -int GLVolumeCollection::load_wipe_tower_preview( - float pos_x, float pos_y, float width, float depth, float height, - float rotation_angle, bool size_unknown, float brim_width, bool opengl_initialized) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (depth < 0.01f) return int(this->volumes.size() - 1); @@ -1136,7 +737,6 @@ int GLVolumeCollection::load_wipe_tower_preview( volumes.emplace_back(new GLVolume(color)); GLVolume& v = *volumes.back(); -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_OPENGL_ES if (out_mesh != nullptr) *out_mesh = mesh; @@ -1144,13 +744,7 @@ int GLVolumeCollection::load_wipe_tower_preview( v.model.init_from(mesh); v.model.set_color(color); v.mesh_raycaster = std::make_unique(std::make_shared(mesh)); -#else - v.indexed_vertex_array.load_mesh(mesh); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL v.set_convex_hull(mesh.convex_hull_3d()); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - v.indexed_vertex_array.finalize_geometry(opengl_initialized); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL v.set_volume_offset(Vec3d(pos_x, pos_y, 0.0)); v.set_volume_rotation(Vec3d(0., 0., (M_PI / 180.) * rotation_angle)); v.composite_id = GLVolume::CompositeID(INT_MAX, 0, 0); @@ -1161,7 +755,6 @@ int GLVolumeCollection::load_wipe_tower_preview( return int(volumes.size() - 1); } -#if ENABLE_LEGACY_OPENGL_REMOVAL GLVolume* GLVolumeCollection::new_toolpath_volume(const ColorRGBA& rgba) { GLVolume* out = new_nontoolpath_volume(rgba); @@ -1176,24 +769,6 @@ GLVolume* GLVolumeCollection::new_nontoolpath_volume(const ColorRGBA& rgba) this->volumes.emplace_back(out); return out; } -#else -GLVolume* GLVolumeCollection::new_toolpath_volume(const ColorRGBA& rgba, size_t reserve_vbo_floats) -{ - GLVolume *out = new_nontoolpath_volume(rgba, reserve_vbo_floats); - out->is_extrusion_path = true; - return out; -} - -GLVolume* GLVolumeCollection::new_nontoolpath_volume(const ColorRGBA& rgba, size_t reserve_vbo_floats) -{ - GLVolume *out = new GLVolume(rgba); - out->is_extrusion_path = false; - // Reserving number of vertices (3x position + 3x color) - out->indexed_vertex_array.reserve(reserve_vbo_floats / 6); - this->volumes.emplace_back(out); - return out; -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCollection::ERenderType type, const Transform3d& view_matrix, std::function filter_func) { @@ -1228,12 +803,8 @@ GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCo return list; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disable_cullface, const Transform3d& view_matrix, const Transform3d& projection_matrix, std::function filter_func) const -#else -void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function filter_func) const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { GLVolumeWithIdAndZList to_render = volumes_to_render(volumes, type, view_matrix, filter_func); if (to_render.empty()) @@ -1243,14 +814,12 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab if (shader == nullptr) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* sink_shader = GUI::wxGetApp().get_shader("flat"); #if ENABLE_GL_CORE_PROFILE GLShaderProgram* edges_shader = GUI::OpenGLManager::get_gl_info().is_core_profile() ? GUI::wxGetApp().get_shader("dashed_thick_lines") : GUI::wxGetApp().get_shader("flat"); #else GLShaderProgram* edges_shader = GUI::wxGetApp().get_shader("flat"); #endif // ENABLE_GL_CORE_PROFILE -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (type == ERenderType::Transparent) { glsafe(::glEnable(GL_BLEND)); @@ -1266,31 +835,18 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab volume.first->set_render_color(true); // render sinking contours of non-hovered volumes -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); if (sink_shader != nullptr) { sink_shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (m_show_sinking_contours) { if (volume.first->is_sinking() && !volume.first->is_below_printbed() && volume.first->hover == GLVolume::HS_None && !volume.first->force_sinking_contours) { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - shader->stop_using(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL volume.first->render_sinking_contours(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - shader->start_using(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } -#if ENABLE_LEGACY_OPENGL_REMOVAL sink_shader->stop_using(); } shader->start_using(); -#else - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("z_range", m_z_range); shader->set_uniform("clipping_plane", m_clipping_plane); @@ -1311,16 +867,12 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab #endif // ENABLE_ENVIRONMENT_MAP glcheck(); -#if ENABLE_LEGACY_OPENGL_REMOVAL volume.first->model.set_color(volume.first->render_color); const Transform3d model_matrix = volume.first->world_matrix(); shader->set_uniform("view_model_matrix", view_matrix * model_matrix); shader->set_uniform("projection_matrix", projection_matrix); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - shader->set_uniform("uniform_color", volume.first->render_color); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL volume.first->render(); #if ENABLE_ENVIRONMENT_MAP @@ -1330,56 +882,37 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } if (m_show_sinking_contours) { -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); if (sink_shader != nullptr) { sink_shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (GLVolumeWithIdAndZ& volume : to_render) { // render sinking contours of hovered/displaced volumes if (volume.first->is_sinking() && !volume.first->is_below_printbed() && (volume.first->hover != GLVolume::HS_None || volume.first->force_sinking_contours)) { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - shader->stop_using(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glDepthFunc(GL_ALWAYS)); volume.first->render_sinking_contours(); glsafe(::glDepthFunc(GL_LESS)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - shader->start_using(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } -#if ENABLE_LEGACY_OPENGL_REMOVAL sink_shader->start_using(); } shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); if (edges_shader != nullptr) { edges_shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (m_show_non_manifold_edges && GUI::wxGetApp().app_config->get("non_manifold_edges") == "1") { for (GLVolumeWithIdAndZ& volume : to_render) { volume.first->render_non_manifold_edges(); } } -#if ENABLE_LEGACY_OPENGL_REMOVAL edges_shader->stop_using(); } shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (disable_cullface) glsafe(::glEnable(GL_CULL_FACE)); @@ -1558,7 +1091,6 @@ std::string GLVolumeCollection::log_memory_info() const return " (GLVolumeCollection RAM: " + format_memsize_MB(this->cpu_memory_used()) + " GPU: " + format_memsize_MB(this->gpu_memory_used()) + " Both: " + format_memsize_MB(this->gpu_memory_used()) + ")"; } -#if ENABLE_LEGACY_OPENGL_REMOVAL static void thick_lines_to_geometry( const Lines& lines, const std::vector& widths, @@ -2024,519 +1556,7 @@ static void thick_lines_to_geometry( geometry.add_triangle(idx_a[Left], idx_b[Bottom], idx_a[Bottom]); } } -#else -// caller is responsible for supplying NO lines with zero length -static void thick_lines_to_indexed_vertex_array( - const Lines &lines, - const std::vector &widths, - const std::vector &heights, - bool closed, - double top_z, - GLIndexedVertexArray &volume) -{ - assert(! lines.empty()); - if (lines.empty()) - return; -#define LEFT 0 -#define RIGHT 1 -#define TOP 2 -#define BOTTOM 3 - - // right, left, top, bottom - int idx_prev[4] = { -1, -1, -1, -1 }; - double bottom_z_prev = 0.; - Vec2d b1_prev(Vec2d::Zero()); - Vec2d v_prev(Vec2d::Zero()); - int idx_initial[4] = { -1, -1, -1, -1 }; - double width_initial = 0.; - double bottom_z_initial = 0.0; - double len_prev = 0.0; - - // loop once more in case of closed loops - size_t lines_end = closed ? (lines.size() + 1) : lines.size(); - for (size_t ii = 0; ii < lines_end; ++ ii) { - size_t i = (ii == lines.size()) ? 0 : ii; - const Line &line = lines[i]; - double bottom_z = top_z - heights[i]; - double middle_z = 0.5 * (top_z + bottom_z); - double width = widths[i]; - - bool is_first = (ii == 0); - bool is_last = (ii == lines_end - 1); - bool is_closing = closed && is_last; - - Vec2d v = unscale(line.vector()).normalized(); - double len = unscale(line.length()); - - Vec2d a = unscale(line.a); - Vec2d b = unscale(line.b); - Vec2d a1 = a; - Vec2d a2 = a; - Vec2d b1 = b; - Vec2d b2 = b; - { - double dist = 0.5 * width; // scaled - double dx = dist * v(0); - double dy = dist * v(1); - a1 += Vec2d(+dy, -dx); - a2 += Vec2d(-dy, +dx); - b1 += Vec2d(+dy, -dx); - b2 += Vec2d(-dy, +dx); - } - - // calculate new XY normals - Vec2d xy_right_normal = unscale(line.normal()).normalized(); - - int idx_a[4] = { 0, 0, 0, 0 }; // initialized to avoid warnings - int idx_b[4] = { 0, 0, 0, 0 }; // initialized to avoid warnings - int idx_last = int(volume.vertices_and_normals_interleaved.size() / 6); - - bool bottom_z_different = bottom_z_prev != bottom_z; - bottom_z_prev = bottom_z; - - if (!is_first && bottom_z_different) - { - // Found a change of the layer thickness -> Add a cap at the end of the previous segment. - volume.push_quad(idx_b[BOTTOM], idx_b[LEFT], idx_b[TOP], idx_b[RIGHT]); - } - - // Share top / bottom vertices if possible. - if (is_first) { - idx_a[TOP] = idx_last++; - volume.push_geometry(a(0), a(1), top_z , 0., 0., 1.); - } else { - idx_a[TOP] = idx_prev[TOP]; - } - - if (is_first || bottom_z_different) { - // Start of the 1st line segment or a change of the layer thickness while maintaining the print_z. - idx_a[BOTTOM] = idx_last ++; - volume.push_geometry(a(0), a(1), bottom_z, 0., 0., -1.); - idx_a[LEFT ] = idx_last ++; - volume.push_geometry(a2(0), a2(1), middle_z, -xy_right_normal(0), -xy_right_normal(1), 0.0); - idx_a[RIGHT] = idx_last ++; - volume.push_geometry(a1(0), a1(1), middle_z, xy_right_normal(0), xy_right_normal(1), 0.0); - } - else { - idx_a[BOTTOM] = idx_prev[BOTTOM]; - } - - if (is_first) { - // Start of the 1st line segment. - width_initial = width; - bottom_z_initial = bottom_z; - memcpy(idx_initial, idx_a, sizeof(int) * 4); - } else { - // Continuing a previous segment. - // Share left / right vertices if possible. - double v_dot = v_prev.dot(v); - // To reduce gpu memory usage, we try to reuse vertices - // To reduce the visual artifacts, due to averaged normals, we allow to reuse vertices only when any of two adjacent edges - // is longer than a fixed threshold. - // The following value is arbitrary, it comes from tests made on a bunch of models showing the visual artifacts - double len_threshold = 2.5; - - // Generate new vertices if the angle between adjacent edges is greater than 45 degrees or thresholds conditions are met - bool sharp = (v_dot < 0.707) || (len_prev > len_threshold) || (len > len_threshold); - if (sharp) { - if (!bottom_z_different) - { - // Allocate new left / right points for the start of this segment as these points will receive their own normals to indicate a sharp turn. - idx_a[RIGHT] = idx_last++; - volume.push_geometry(a1(0), a1(1), middle_z, xy_right_normal(0), xy_right_normal(1), 0.0); - idx_a[LEFT] = idx_last++; - volume.push_geometry(a2(0), a2(1), middle_z, -xy_right_normal(0), -xy_right_normal(1), 0.0); - if (cross2(v_prev, v) > 0.) { - // Right turn. Fill in the right turn wedge. - volume.push_triangle(idx_prev[RIGHT], idx_a[RIGHT], idx_prev[TOP]); - volume.push_triangle(idx_prev[RIGHT], idx_prev[BOTTOM], idx_a[RIGHT]); - } - else { - // Left turn. Fill in the left turn wedge. - volume.push_triangle(idx_prev[LEFT], idx_prev[TOP], idx_a[LEFT]); - volume.push_triangle(idx_prev[LEFT], idx_a[LEFT], idx_prev[BOTTOM]); - } - } - } - else - { - if (!bottom_z_different) - { - // The two successive segments are nearly collinear. - idx_a[LEFT ] = idx_prev[LEFT]; - idx_a[RIGHT] = idx_prev[RIGHT]; - } - } - if (is_closing) { - if (!sharp) { - if (!bottom_z_different) - { - // Closing a loop with smooth transition. Unify the closing left / right vertices. - memcpy(volume.vertices_and_normals_interleaved.data() + idx_initial[LEFT ] * 6, volume.vertices_and_normals_interleaved.data() + idx_prev[LEFT ] * 6, sizeof(float) * 6); - memcpy(volume.vertices_and_normals_interleaved.data() + idx_initial[RIGHT] * 6, volume.vertices_and_normals_interleaved.data() + idx_prev[RIGHT] * 6, sizeof(float) * 6); - volume.vertices_and_normals_interleaved.erase(volume.vertices_and_normals_interleaved.end() - 12, volume.vertices_and_normals_interleaved.end()); - // Replace the left / right vertex indices to point to the start of the loop. - for (size_t u = volume.quad_indices.size() - 16; u < volume.quad_indices.size(); ++ u) { - if (volume.quad_indices[u] == idx_prev[LEFT]) - volume.quad_indices[u] = idx_initial[LEFT]; - else if (volume.quad_indices[u] == idx_prev[RIGHT]) - volume.quad_indices[u] = idx_initial[RIGHT]; - } - } - } - // This is the last iteration, only required to solve the transition. - break; - } - } - - // Only new allocate top / bottom vertices, if not closing a loop. - if (is_closing) { - idx_b[TOP] = idx_initial[TOP]; - } else { - idx_b[TOP] = idx_last ++; - volume.push_geometry(b(0), b(1), top_z , 0., 0., 1.); - } - - if (is_closing && (width == width_initial) && (bottom_z == bottom_z_initial)) { - idx_b[BOTTOM] = idx_initial[BOTTOM]; - } else { - idx_b[BOTTOM] = idx_last ++; - volume.push_geometry(b(0), b(1), bottom_z, 0., 0., -1.); - } - // Generate new vertices for the end of this line segment. - idx_b[LEFT ] = idx_last ++; - volume.push_geometry(b2(0), b2(1), middle_z, -xy_right_normal(0), -xy_right_normal(1), 0.0); - idx_b[RIGHT ] = idx_last ++; - volume.push_geometry(b1(0), b1(1), middle_z, xy_right_normal(0), xy_right_normal(1), 0.0); - - memcpy(idx_prev, idx_b, 4 * sizeof(int)); - bottom_z_prev = bottom_z; - b1_prev = b1; - v_prev = v; - len_prev = len; - - if (bottom_z_different && (closed || (!is_first && !is_last))) - { - // Found a change of the layer thickness -> Add a cap at the beginning of this segment. - volume.push_quad(idx_a[BOTTOM], idx_a[RIGHT], idx_a[TOP], idx_a[LEFT]); - } - - if (! closed) { - // Terminate open paths with caps. - if (is_first) - volume.push_quad(idx_a[BOTTOM], idx_a[RIGHT], idx_a[TOP], idx_a[LEFT]); - // We don't use 'else' because both cases are true if we have only one line. - if (is_last) - volume.push_quad(idx_b[BOTTOM], idx_b[LEFT], idx_b[TOP], idx_b[RIGHT]); - } - - // Add quads for a straight hollow tube-like segment. - // bottom-right face - volume.push_quad(idx_a[BOTTOM], idx_b[BOTTOM], idx_b[RIGHT], idx_a[RIGHT]); - // top-right face - volume.push_quad(idx_a[RIGHT], idx_b[RIGHT], idx_b[TOP], idx_a[TOP]); - // top-left face - volume.push_quad(idx_a[TOP], idx_b[TOP], idx_b[LEFT], idx_a[LEFT]); - // bottom-left face - volume.push_quad(idx_a[LEFT], idx_b[LEFT], idx_b[BOTTOM], idx_a[BOTTOM]); - } - -#undef LEFT -#undef RIGHT -#undef TOP -#undef BOTTOM -} - -// caller is responsible for supplying NO lines with zero length -static void thick_lines_to_indexed_vertex_array(const Lines3& lines, - const std::vector& widths, - const std::vector& heights, - bool closed, - GLIndexedVertexArray& volume) -{ - assert(!lines.empty()); - if (lines.empty()) - return; - -#define LEFT 0 -#define RIGHT 1 -#define TOP 2 -#define BOTTOM 3 - - // left, right, top, bottom - int idx_initial[4] = { -1, -1, -1, -1 }; - int idx_prev[4] = { -1, -1, -1, -1 }; - double z_prev = 0.0; - double len_prev = 0.0; - Vec3d n_right_prev = Vec3d::Zero(); - Vec3d n_top_prev = Vec3d::Zero(); - Vec3d unit_v_prev = Vec3d::Zero(); - double width_initial = 0.0; - - // new vertices around the line endpoints - // left, right, top, bottom - Vec3d a[4] = { Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero() }; - Vec3d b[4] = { Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero() }; - - // loop once more in case of closed loops - size_t lines_end = closed ? (lines.size() + 1) : lines.size(); - for (size_t ii = 0; ii < lines_end; ++ii) - { - size_t i = (ii == lines.size()) ? 0 : ii; - - const Line3& line = lines[i]; - double height = heights[i]; - double width = widths[i]; - - Vec3d unit_v = unscale(line.vector()).normalized(); - double len = unscale(line.length()); - - Vec3d n_top = Vec3d::Zero(); - Vec3d n_right = Vec3d::Zero(); - - if ((line.a(0) == line.b(0)) && (line.a(1) == line.b(1))) - { - // vertical segment - n_top = Vec3d::UnitY(); - n_right = Vec3d::UnitX(); - if (line.a(2) < line.b(2)) - n_right = -n_right; - } - else - { - // horizontal segment - n_right = unit_v.cross(Vec3d::UnitZ()).normalized(); - n_top = n_right.cross(unit_v).normalized(); - } - - Vec3d rl_displacement = 0.5 * width * n_right; - Vec3d tb_displacement = 0.5 * height * n_top; - Vec3d l_a = unscale(line.a); - Vec3d l_b = unscale(line.b); - - a[RIGHT] = l_a + rl_displacement; - a[LEFT] = l_a - rl_displacement; - a[TOP] = l_a + tb_displacement; - a[BOTTOM] = l_a - tb_displacement; - b[RIGHT] = l_b + rl_displacement; - b[LEFT] = l_b - rl_displacement; - b[TOP] = l_b + tb_displacement; - b[BOTTOM] = l_b - tb_displacement; - - Vec3d n_bottom = -n_top; - Vec3d n_left = -n_right; - - int idx_a[4]; - int idx_b[4]; - int idx_last = int(volume.vertices_and_normals_interleaved.size() / 6); - - bool z_different = (z_prev != l_a(2)); - z_prev = l_b(2); - - // Share top / bottom vertices if possible. - if (ii == 0) - { - idx_a[TOP] = idx_last++; - volume.push_geometry(a[TOP], n_top); - } - else - idx_a[TOP] = idx_prev[TOP]; - - if ((ii == 0) || z_different) - { - // Start of the 1st line segment or a change of the layer thickness while maintaining the print_z. - idx_a[BOTTOM] = idx_last++; - volume.push_geometry(a[BOTTOM], n_bottom); - idx_a[LEFT] = idx_last++; - volume.push_geometry(a[LEFT], n_left); - idx_a[RIGHT] = idx_last++; - volume.push_geometry(a[RIGHT], n_right); - } - else - idx_a[BOTTOM] = idx_prev[BOTTOM]; - - if (ii == 0) - { - // Start of the 1st line segment. - width_initial = width; - ::memcpy(idx_initial, idx_a, sizeof(int) * 4); - } - else - { - // Continuing a previous segment. - // Share left / right vertices if possible. - double v_dot = unit_v_prev.dot(unit_v); - bool is_right_turn = n_top_prev.dot(unit_v_prev.cross(unit_v)) > 0.0; - - // To reduce gpu memory usage, we try to reuse vertices - // To reduce the visual artifacts, due to averaged normals, we allow to reuse vertices only when any of two adjacent edges - // is longer than a fixed threshold. - // The following value is arbitrary, it comes from tests made on a bunch of models showing the visual artifacts - double len_threshold = 2.5; - - // Generate new vertices if the angle between adjacent edges is greater than 45 degrees or thresholds conditions are met - bool is_sharp = (v_dot < 0.707) || (len_prev > len_threshold) || (len > len_threshold); - if (is_sharp) - { - // Allocate new left / right points for the start of this segment as these points will receive their own normals to indicate a sharp turn. - idx_a[RIGHT] = idx_last++; - volume.push_geometry(a[RIGHT], n_right); - idx_a[LEFT] = idx_last++; - volume.push_geometry(a[LEFT], n_left); - - if (is_right_turn) - { - // Right turn. Fill in the right turn wedge. - volume.push_triangle(idx_prev[RIGHT], idx_a[RIGHT], idx_prev[TOP]); - volume.push_triangle(idx_prev[RIGHT], idx_prev[BOTTOM], idx_a[RIGHT]); - } - else - { - // Left turn. Fill in the left turn wedge. - volume.push_triangle(idx_prev[LEFT], idx_prev[TOP], idx_a[LEFT]); - volume.push_triangle(idx_prev[LEFT], idx_a[LEFT], idx_prev[BOTTOM]); - } - } - else - { - // The two successive segments are nearly collinear. - idx_a[LEFT] = idx_prev[LEFT]; - idx_a[RIGHT] = idx_prev[RIGHT]; - } - - if (ii == lines.size()) - { - if (!is_sharp) - { - // Closing a loop with smooth transition. Unify the closing left / right vertices. - ::memcpy(volume.vertices_and_normals_interleaved.data() + idx_initial[LEFT] * 6, volume.vertices_and_normals_interleaved.data() + idx_prev[LEFT] * 6, sizeof(float) * 6); - ::memcpy(volume.vertices_and_normals_interleaved.data() + idx_initial[RIGHT] * 6, volume.vertices_and_normals_interleaved.data() + idx_prev[RIGHT] * 6, sizeof(float) * 6); - volume.vertices_and_normals_interleaved.erase(volume.vertices_and_normals_interleaved.end() - 12, volume.vertices_and_normals_interleaved.end()); - // Replace the left / right vertex indices to point to the start of the loop. - for (size_t u = volume.quad_indices.size() - 16; u < volume.quad_indices.size(); ++u) - { - if (volume.quad_indices[u] == idx_prev[LEFT]) - volume.quad_indices[u] = idx_initial[LEFT]; - else if (volume.quad_indices[u] == idx_prev[RIGHT]) - volume.quad_indices[u] = idx_initial[RIGHT]; - } - } - - // This is the last iteration, only required to solve the transition. - break; - } - } - - // Only new allocate top / bottom vertices, if not closing a loop. - if (closed && (ii + 1 == lines.size())) - idx_b[TOP] = idx_initial[TOP]; - else - { - idx_b[TOP] = idx_last++; - volume.push_geometry(b[TOP], n_top); - } - - if (closed && (ii + 1 == lines.size()) && (width == width_initial)) - idx_b[BOTTOM] = idx_initial[BOTTOM]; - else - { - idx_b[BOTTOM] = idx_last++; - volume.push_geometry(b[BOTTOM], n_bottom); - } - - // Generate new vertices for the end of this line segment. - idx_b[LEFT] = idx_last++; - volume.push_geometry(b[LEFT], n_left); - idx_b[RIGHT] = idx_last++; - volume.push_geometry(b[RIGHT], n_right); - - ::memcpy(idx_prev, idx_b, 4 * sizeof(int)); - n_right_prev = n_right; - n_top_prev = n_top; - unit_v_prev = unit_v; - len_prev = len; - - if (!closed) - { - // Terminate open paths with caps. - if (i == 0) - volume.push_quad(idx_a[BOTTOM], idx_a[RIGHT], idx_a[TOP], idx_a[LEFT]); - - // We don't use 'else' because both cases are true if we have only one line. - if (i + 1 == lines.size()) - volume.push_quad(idx_b[BOTTOM], idx_b[LEFT], idx_b[TOP], idx_b[RIGHT]); - } - - // Add quads for a straight hollow tube-like segment. - // bottom-right face - volume.push_quad(idx_a[BOTTOM], idx_b[BOTTOM], idx_b[RIGHT], idx_a[RIGHT]); - // top-right face - volume.push_quad(idx_a[RIGHT], idx_b[RIGHT], idx_b[TOP], idx_a[TOP]); - // top-left face - volume.push_quad(idx_a[TOP], idx_b[TOP], idx_b[LEFT], idx_a[LEFT]); - // bottom-left face - volume.push_quad(idx_a[LEFT], idx_b[LEFT], idx_b[BOTTOM], idx_a[BOTTOM]); - } - -#undef LEFT -#undef RIGHT -#undef TOP -#undef BOTTOM -} - -static void point_to_indexed_vertex_array(const Vec3crd& point, - double width, - double height, - GLIndexedVertexArray& volume) -{ - // builds a double piramid, with vertices on the local axes, around the point - - Vec3d center = unscale(point); - - double scale_factor = 1.0; - double w = scale_factor * width; - double h = scale_factor * height; - - // new vertices ids - int idx_last = int(volume.vertices_and_normals_interleaved.size() / 6); - int idxs[6]; - for (int i = 0; i < 6; ++i) - { - idxs[i] = idx_last + i; - } - - Vec3d displacement_x(w, 0.0, 0.0); - Vec3d displacement_y(0.0, w, 0.0); - Vec3d displacement_z(0.0, 0.0, h); - - Vec3d unit_x(1.0, 0.0, 0.0); - Vec3d unit_y(0.0, 1.0, 0.0); - Vec3d unit_z(0.0, 0.0, 1.0); - - // vertices - volume.push_geometry(center - displacement_x, -unit_x); // idxs[0] - volume.push_geometry(center + displacement_x, unit_x); // idxs[1] - volume.push_geometry(center - displacement_y, -unit_y); // idxs[2] - volume.push_geometry(center + displacement_y, unit_y); // idxs[3] - volume.push_geometry(center - displacement_z, -unit_z); // idxs[4] - volume.push_geometry(center + displacement_z, unit_z); // idxs[5] - - // top piramid faces - volume.push_triangle(idxs[0], idxs[2], idxs[5]); - volume.push_triangle(idxs[2], idxs[1], idxs[5]); - volume.push_triangle(idxs[1], idxs[3], idxs[5]); - volume.push_triangle(idxs[3], idxs[0], idxs[5]); - - // bottom piramid faces - volume.push_triangle(idxs[2], idxs[0], idxs[4]); - volume.push_triangle(idxs[1], idxs[2], idxs[4]); - volume.push_triangle(idxs[3], idxs[1], idxs[4]); - volume.push_triangle(idxs[0], idxs[3], idxs[4]); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void _3DScene::thick_lines_to_verts( const Lines& lines, const std::vector& widths, @@ -2557,52 +1577,8 @@ void _3DScene::thick_lines_to_verts( { thick_lines_to_geometry(lines, widths, heights, closed, geometry); } -#else -void _3DScene::thick_lines_to_verts( - const Lines &lines, - const std::vector &widths, - const std::vector &heights, - bool closed, - double top_z, - GLVolume &volume) -{ - thick_lines_to_indexed_vertex_array(lines, widths, heights, closed, top_z, volume.indexed_vertex_array); -} - -void _3DScene::thick_lines_to_verts(const Lines3& lines, - const std::vector& widths, - const std::vector& heights, - bool closed, - GLVolume& volume) -{ - thick_lines_to_indexed_vertex_array(lines, widths, heights, closed, volume.indexed_vertex_array); -} - -static void thick_point_to_verts(const Vec3crd& point, - double width, - double height, - GLVolume& volume) -{ - point_to_indexed_vertex_array(point, width, height, volume.indexed_vertex_array); -} - -void _3DScene::extrusionentity_to_verts(const Polyline &polyline, float width, float height, float print_z, GLVolume& volume) -{ - if (polyline.size() >= 2) { - size_t num_segments = polyline.size() - 1; - thick_lines_to_verts(polyline.lines(), std::vector(num_segments, width), std::vector(num_segments, height), false, print_z, volume); - } -} // Fill in the qverts and tverts with quads and triangles for the extrusion_path. -void _3DScene::extrusionentity_to_verts(const ExtrusionPath &extrusion_path, float print_z, GLVolume &volume) -{ - extrusionentity_to_verts(extrusion_path.polyline, extrusion_path.width, extrusion_path.height, print_z, volume); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -// Fill in the qverts and tverts with quads and triangles for the extrusion_path. -#if ENABLE_LEGACY_OPENGL_REMOVAL void _3DScene::extrusionentity_to_verts(const ExtrusionPath& extrusion_path, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry) { Polyline polyline = extrusion_path.polyline; @@ -2613,21 +1589,8 @@ void _3DScene::extrusionentity_to_verts(const ExtrusionPath& extrusion_path, flo std::vector heights(lines.size(), extrusion_path.height); thick_lines_to_verts(lines, widths, heights, false, print_z, geometry); } -#else -void _3DScene::extrusionentity_to_verts(const ExtrusionPath &extrusion_path, float print_z, const Point ©, GLVolume &volume) -{ - Polyline polyline = extrusion_path.polyline; - polyline.remove_duplicate_points(); - polyline.translate(copy); - Lines lines = polyline.lines(); - std::vector widths(lines.size(), extrusion_path.width); - std::vector heights(lines.size(), extrusion_path.height); - thick_lines_to_verts(lines, widths, heights, false, print_z, volume); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Fill in the qverts and tverts with quads and triangles for the extrusion_loop. -#if ENABLE_LEGACY_OPENGL_REMOVAL void _3DScene::extrusionentity_to_verts(const ExtrusionLoop& extrusion_loop, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry) { Lines lines; @@ -2644,27 +1607,8 @@ void _3DScene::extrusionentity_to_verts(const ExtrusionLoop& extrusion_loop, flo } thick_lines_to_verts(lines, widths, heights, true, print_z, geometry); } -#else -void _3DScene::extrusionentity_to_verts(const ExtrusionLoop &extrusion_loop, float print_z, const Point ©, GLVolume &volume) -{ - Lines lines; - std::vector widths; - std::vector heights; - for (const ExtrusionPath &extrusion_path : extrusion_loop.paths) { - Polyline polyline = extrusion_path.polyline; - polyline.remove_duplicate_points(); - polyline.translate(copy); - Lines lines_this = polyline.lines(); - append(lines, lines_this); - widths.insert(widths.end(), lines_this.size(), extrusion_path.width); - heights.insert(heights.end(), lines_this.size(), extrusion_path.height); - } - thick_lines_to_verts(lines, widths, heights, true, print_z, volume); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Fill in the qverts and tverts with quads and triangles for the extrusion_multi_path. -#if ENABLE_LEGACY_OPENGL_REMOVAL void _3DScene::extrusionentity_to_verts(const ExtrusionMultiPath& extrusion_multi_path, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry) { Lines lines; @@ -2681,40 +1625,13 @@ void _3DScene::extrusionentity_to_verts(const ExtrusionMultiPath& extrusion_mult } thick_lines_to_verts(lines, widths, heights, false, print_z, geometry); } -#else -void _3DScene::extrusionentity_to_verts(const ExtrusionMultiPath &extrusion_multi_path, float print_z, const Point ©, GLVolume &volume) -{ - Lines lines; - std::vector widths; - std::vector heights; - for (const ExtrusionPath &extrusion_path : extrusion_multi_path.paths) { - Polyline polyline = extrusion_path.polyline; - polyline.remove_duplicate_points(); - polyline.translate(copy); - Lines lines_this = polyline.lines(); - append(lines, lines_this); - widths.insert(widths.end(), lines_this.size(), extrusion_path.width); - heights.insert(heights.end(), lines_this.size(), extrusion_path.height); - } - thick_lines_to_verts(lines, widths, heights, false, print_z, volume); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL void _3DScene::extrusionentity_to_verts(const ExtrusionEntityCollection& extrusion_entity_collection, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry) { for (const ExtrusionEntity* extrusion_entity : extrusion_entity_collection.entities) extrusionentity_to_verts(extrusion_entity, print_z, copy, geometry); } -#else -void _3DScene::extrusionentity_to_verts(const ExtrusionEntityCollection &extrusion_entity_collection, float print_z, const Point ©, GLVolume &volume) -{ - for (const ExtrusionEntity *extrusion_entity : extrusion_entity_collection.entities) - extrusionentity_to_verts(extrusion_entity, print_z, copy, volume); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL void _3DScene::extrusionentity_to_verts(const ExtrusionEntity* extrusion_entity, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry) { if (extrusion_entity != nullptr) { @@ -2740,45 +1657,5 @@ void _3DScene::extrusionentity_to_verts(const ExtrusionEntity* extrusion_entity, } } } -#else -void _3DScene::extrusionentity_to_verts(const ExtrusionEntity *extrusion_entity, float print_z, const Point ©, GLVolume &volume) -{ - if (extrusion_entity != nullptr) { - auto *extrusion_path = dynamic_cast(extrusion_entity); - if (extrusion_path != nullptr) - extrusionentity_to_verts(*extrusion_path, print_z, copy, volume); - else { - auto *extrusion_loop = dynamic_cast(extrusion_entity); - if (extrusion_loop != nullptr) - extrusionentity_to_verts(*extrusion_loop, print_z, copy, volume); - else { - auto *extrusion_multi_path = dynamic_cast(extrusion_entity); - if (extrusion_multi_path != nullptr) - extrusionentity_to_verts(*extrusion_multi_path, print_z, copy, volume); - else { - auto *extrusion_entity_collection = dynamic_cast(extrusion_entity); - if (extrusion_entity_collection != nullptr) - extrusionentity_to_verts(*extrusion_entity_collection, print_z, copy, volume); - else - throw Slic3r::RuntimeError("Unexpected extrusion_entity type in to_verts()"); - } - } - } - } -} - -void _3DScene::polyline3_to_verts(const Polyline3& polyline, double width, double height, GLVolume& volume) -{ - Lines3 lines = polyline.lines(); - std::vector widths(lines.size(), width); - std::vector heights(lines.size(), height); - thick_lines_to_verts(lines, widths, heights, false, volume); -} - -void _3DScene::point3_to_verts(const Vec3crd& point, double width, double height, GLVolume& volume) -{ - thick_point_to_verts(point, width, height, volume); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } // namespace Slic3r diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index a7146d61cf..2eb161480b 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -47,209 +47,6 @@ enum ModelInstanceEPrintVolumeState : unsigned char; // Return appropriate color based on the ModelVolume. extern ColorRGBA color_from_model_volume(const ModelVolume& model_volume); -#if !ENABLE_LEGACY_OPENGL_REMOVAL -// A container for interleaved arrays of 3D vertices and normals, -// possibly indexed by triangles and / or quads. -class GLIndexedVertexArray { -public: - // Only Eigen types of Nx16 size are vectorized. This bounding box will not be vectorized. - static_assert(sizeof(Eigen::AlignedBox) == 24, "Eigen::AlignedBox is not being vectorized, thus it does not need to be aligned"); - using BoundingBox = Eigen::AlignedBox; - - GLIndexedVertexArray() { m_bounding_box.setEmpty(); } - GLIndexedVertexArray(const GLIndexedVertexArray &rhs) : - vertices_and_normals_interleaved(rhs.vertices_and_normals_interleaved), - triangle_indices(rhs.triangle_indices), - quad_indices(rhs.quad_indices), - m_bounding_box(rhs.m_bounding_box) - { assert(! rhs.has_VBOs()); m_bounding_box.setEmpty(); } - GLIndexedVertexArray(GLIndexedVertexArray &&rhs) : - vertices_and_normals_interleaved(std::move(rhs.vertices_and_normals_interleaved)), - triangle_indices(std::move(rhs.triangle_indices)), - quad_indices(std::move(rhs.quad_indices)), - m_bounding_box(rhs.m_bounding_box) - { assert(! rhs.has_VBOs()); } - - ~GLIndexedVertexArray() { release_geometry(); } - - GLIndexedVertexArray& operator=(const GLIndexedVertexArray &rhs) - { - assert(vertices_and_normals_interleaved_VBO_id == 0); - assert(triangle_indices_VBO_id == 0); - assert(quad_indices_VBO_id == 0); - assert(rhs.vertices_and_normals_interleaved_VBO_id == 0); - assert(rhs.triangle_indices_VBO_id == 0); - assert(rhs.quad_indices_VBO_id == 0); - this->vertices_and_normals_interleaved = rhs.vertices_and_normals_interleaved; - this->triangle_indices = rhs.triangle_indices; - this->quad_indices = rhs.quad_indices; - this->m_bounding_box = rhs.m_bounding_box; - this->vertices_and_normals_interleaved_size = rhs.vertices_and_normals_interleaved_size; - this->triangle_indices_size = rhs.triangle_indices_size; - this->quad_indices_size = rhs.quad_indices_size; - return *this; - } - - GLIndexedVertexArray& operator=(GLIndexedVertexArray &&rhs) - { - assert(vertices_and_normals_interleaved_VBO_id == 0); - assert(triangle_indices_VBO_id == 0); - assert(quad_indices_VBO_id == 0); - assert(rhs.vertices_and_normals_interleaved_VBO_id == 0); - assert(rhs.triangle_indices_VBO_id == 0); - assert(rhs.quad_indices_VBO_id == 0); - this->vertices_and_normals_interleaved = std::move(rhs.vertices_and_normals_interleaved); - this->triangle_indices = std::move(rhs.triangle_indices); - this->quad_indices = std::move(rhs.quad_indices); - this->m_bounding_box = rhs.m_bounding_box; - this->vertices_and_normals_interleaved_size = rhs.vertices_and_normals_interleaved_size; - this->triangle_indices_size = rhs.triangle_indices_size; - this->quad_indices_size = rhs.quad_indices_size; - return *this; - } - - // Vertices and their normals, interleaved to be used by void glInterleavedArrays(GL_N3F_V3F, 0, x) - std::vector vertices_and_normals_interleaved; - std::vector triangle_indices; - std::vector quad_indices; - - // When the geometry data is loaded into the graphics card as Vertex Buffer Objects, - // the above mentioned std::vectors are cleared and the following variables keep their original length. - size_t vertices_and_normals_interleaved_size{ 0 }; - size_t triangle_indices_size{ 0 }; - size_t quad_indices_size{ 0 }; - - // IDs of the Vertex Array Objects, into which the geometry has been loaded. - // Zero if the VBOs are not sent to GPU yet. - unsigned int vertices_and_normals_interleaved_VBO_id{ 0 }; - unsigned int triangle_indices_VBO_id{ 0 }; - unsigned int quad_indices_VBO_id{ 0 }; - -#if ENABLE_SMOOTH_NORMALS - void load_mesh_full_shading(const TriangleMesh& mesh, bool smooth_normals = false); - void load_mesh(const TriangleMesh& mesh, bool smooth_normals = false) { this->load_mesh_full_shading(mesh, smooth_normals); } -#else - void load_mesh_full_shading(const TriangleMesh& mesh); - void load_mesh(const TriangleMesh& mesh) { this->load_mesh_full_shading(mesh); } -#endif // ENABLE_SMOOTH_NORMALS - - void load_its_flat_shading(const indexed_triangle_set &its); - - inline bool has_VBOs() const { return vertices_and_normals_interleaved_VBO_id != 0; } - - inline void reserve(size_t sz) { - this->vertices_and_normals_interleaved.reserve(sz * 6); - this->triangle_indices.reserve(sz * 3); - this->quad_indices.reserve(sz * 4); - } - - inline void push_geometry(float x, float y, float z, float nx, float ny, float nz) { - assert(this->vertices_and_normals_interleaved_VBO_id == 0); - if (this->vertices_and_normals_interleaved_VBO_id != 0) - return; - - if (this->vertices_and_normals_interleaved.size() + 6 > this->vertices_and_normals_interleaved.capacity()) - this->vertices_and_normals_interleaved.reserve(next_highest_power_of_2(this->vertices_and_normals_interleaved.size() + 6)); - this->vertices_and_normals_interleaved.emplace_back(nx); - this->vertices_and_normals_interleaved.emplace_back(ny); - this->vertices_and_normals_interleaved.emplace_back(nz); - this->vertices_and_normals_interleaved.emplace_back(x); - this->vertices_and_normals_interleaved.emplace_back(y); - this->vertices_and_normals_interleaved.emplace_back(z); - - this->vertices_and_normals_interleaved_size = this->vertices_and_normals_interleaved.size(); - m_bounding_box.extend(Vec3f(x, y, z)); - }; - - inline void push_geometry(double x, double y, double z, double nx, double ny, double nz) { - push_geometry(float(x), float(y), float(z), float(nx), float(ny), float(nz)); - } - - template - inline void push_geometry(const Eigen::MatrixBase& p, const Eigen::MatrixBase& n) { - push_geometry(float(p(0)), float(p(1)), float(p(2)), float(n(0)), float(n(1)), float(n(2))); - } - - inline void push_triangle(int idx1, int idx2, int idx3) { - assert(this->vertices_and_normals_interleaved_VBO_id == 0); - if (this->vertices_and_normals_interleaved_VBO_id != 0) - return; - - if (this->triangle_indices.size() + 3 > this->vertices_and_normals_interleaved.capacity()) - this->triangle_indices.reserve(next_highest_power_of_2(this->triangle_indices.size() + 3)); - this->triangle_indices.emplace_back(idx1); - this->triangle_indices.emplace_back(idx2); - this->triangle_indices.emplace_back(idx3); - this->triangle_indices_size = this->triangle_indices.size(); - }; - - inline void push_quad(int idx1, int idx2, int idx3, int idx4) { - assert(this->vertices_and_normals_interleaved_VBO_id == 0); - if (this->vertices_and_normals_interleaved_VBO_id != 0) - return; - - if (this->quad_indices.size() + 4 > this->vertices_and_normals_interleaved.capacity()) - this->quad_indices.reserve(next_highest_power_of_2(this->quad_indices.size() + 4)); - this->quad_indices.emplace_back(idx1); - this->quad_indices.emplace_back(idx2); - this->quad_indices.emplace_back(idx3); - this->quad_indices.emplace_back(idx4); - this->quad_indices_size = this->quad_indices.size(); - }; - - // Finalize the initialization of the geometry & indices, - // upload the geometry and indices to OpenGL VBO objects - // and shrink the allocated data, possibly relasing it if it has been loaded into the VBOs. - void finalize_geometry(bool opengl_initialized); - // Release the geometry data, release OpenGL VBOs. - void release_geometry(); - - void render() const; - void render(const std::pair& tverts_range, const std::pair& qverts_range) const; - - // Is there any geometry data stored? - bool empty() const { return vertices_and_normals_interleaved_size == 0; } - - void clear() { - this->vertices_and_normals_interleaved.clear(); - this->triangle_indices.clear(); - this->quad_indices.clear(); - vertices_and_normals_interleaved_size = 0; - triangle_indices_size = 0; - quad_indices_size = 0; - m_bounding_box.setEmpty(); - } - - // Shrink the internal storage to tighly fit the data stored. - void shrink_to_fit() { - this->vertices_and_normals_interleaved.shrink_to_fit(); - this->triangle_indices.shrink_to_fit(); - this->quad_indices.shrink_to_fit(); - } - - const BoundingBox& bounding_box() const { return m_bounding_box; } - - // Return an estimate of the memory consumed by this class. - size_t cpu_memory_used() const { return sizeof(*this) + vertices_and_normals_interleaved.capacity() * sizeof(float) + triangle_indices.capacity() * sizeof(int) + quad_indices.capacity() * sizeof(int); } - // Return an estimate of the memory held by GPU vertex buffers. - size_t gpu_memory_used() const - { - size_t memsize = 0; - if (this->vertices_and_normals_interleaved_VBO_id != 0) - memsize += this->vertices_and_normals_interleaved_size * 4; - if (this->triangle_indices_VBO_id != 0) - memsize += this->triangle_indices_size * 4; - if (this->quad_indices_VBO_id != 0) - memsize += this->quad_indices_size * 4; - return memsize; - } - size_t total_memory_used() const { return this->cpu_memory_used() + this->gpu_memory_used(); } - -private: - BoundingBox m_bounding_box; -}; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - class GLVolume { public: static const ColorRGBA SELECTED_COLOR; @@ -389,19 +186,11 @@ public: // Is mouse or rectangle selection over this object to select/deselect it ? EHoverState hover; -#if ENABLE_LEGACY_OPENGL_REMOVAL GUI::GLModel model; // raycaster used for picking std::unique_ptr mesh_raycaster; -#else - // Interleaved triangles & normals with indexed triangles & quads. - GLIndexedVertexArray indexed_vertex_array; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Ranges of triangle and quad indices to be rendered. std::pair tverts_range; -#if !ENABLE_LEGACY_OPENGL_REMOVAL - std::pair qverts_range; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL // If the qverts or tverts contain thick extrusions, then offsets keeps pointers of the starts // of the extrusions per layer. @@ -411,17 +200,7 @@ public: // Bounding box of this volume, in unscaled coordinates. BoundingBoxf3 bounding_box() const { -#if ENABLE_LEGACY_OPENGL_REMOVAL return this->model.get_bounding_box(); -#else - BoundingBoxf3 out; - if (!this->indexed_vertex_array.bounding_box().isEmpty()) { - out.min = this->indexed_vertex_array.bounding_box().min().cast(); - out.max = this->indexed_vertex_array.bounding_box().max().cast(); - out.defined = true; - } - return out; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void set_color(const ColorRGBA& rgba) { color = rgba; } @@ -541,21 +320,12 @@ public: // convex hull const TriangleMesh* convex_hull() const { return m_convex_hull.get(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL bool empty() const { return this->model.is_empty(); } -#else - bool empty() const { return this->indexed_vertex_array.empty(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void set_range(double low, double high); void render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - void finalize_geometry(bool opengl_initialized) { this->indexed_vertex_array.finalize_geometry(opengl_initialized); } - void release_geometry() { this->indexed_vertex_array.release_geometry(); } -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - void set_bounding_boxes_as_dirty() { m_transformed_bounding_box.reset(); m_transformed_convex_hull_bounding_box.reset(); @@ -572,19 +342,11 @@ public: // Return an estimate of the memory consumed by this class. size_t cpu_memory_used() const { -#if ENABLE_LEGACY_OPENGL_REMOVAL - return sizeof(*this) + this->model.cpu_memory_used() + this->print_zs.capacity() * sizeof(coordf_t) + + return sizeof(*this) + this->model.cpu_memory_used() + this->print_zs.capacity() * sizeof(coordf_t) + this->offsets.capacity() * sizeof(size_t); } // Return an estimate of the memory held by GPU vertex buffers. size_t gpu_memory_used() const { return this->model.gpu_memory_used(); } -#else - //FIXME what to do wih m_convex_hull? - return sizeof(*this) - sizeof(this->indexed_vertex_array) + this->indexed_vertex_array.cpu_memory_used() + this->print_zs.capacity() * sizeof(coordf_t) + this->offsets.capacity() * sizeof(size_t); - } - // Return an estimate of the memory held by GPU vertex buffers. - size_t gpu_memory_used() const { return this->indexed_vertex_array.gpu_memory_used(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL size_t total_memory_used() const { return this->cpu_memory_used() + this->gpu_memory_used(); } }; @@ -642,7 +404,6 @@ public: GLVolumeCollection() { set_default_slope_normal_z(); } ~GLVolumeCollection() { clear(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL std::vector load_object( const ModelObject* model_object, int obj_idx, @@ -671,54 +432,12 @@ public: int load_wipe_tower_preview( float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool size_unknown, float brim_width); #endif // ENABLE_OPENGL_ES -#else - std::vector load_object( - const ModelObject *model_object, - int obj_idx, - const std::vector &instance_idxs, - bool opengl_initialized); - int load_object_volume( - const ModelObject *model_object, - int obj_idx, - int volume_idx, - int instance_idx, - bool opengl_initialized); - - // Load SLA auxiliary GLVolumes (for support trees or pad). - void load_object_auxiliary( - const SLAPrintObject *print_object, - int obj_idx, - // pairs of - const std::vector>& instances, - SLAPrintObjectStep milestone, - // Timestamp of the last change of the milestone - size_t timestamp, - bool opengl_initialized); - - int load_wipe_tower_preview( - float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool size_unknown, float brim_width, bool opengl_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL GLVolume* new_toolpath_volume(const ColorRGBA& rgba); GLVolume* new_nontoolpath_volume(const ColorRGBA& rgba); // Render the volumes by OpenGL. void render(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, const Transform3d& projection_matrix, std::function filter_func = std::function()) const; -#else - GLVolume* new_toolpath_volume(const ColorRGBA& rgba, size_t reserve_vbo_floats = 0); - GLVolume* new_nontoolpath_volume(const ColorRGBA& rgba, size_t reserve_vbo_floats = 0); - // Render the volumes by OpenGL. - void render(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function filter_func = std::function()) const; - // Finalize the initialization of the geometry & indices, - // upload the geometry and indices to OpenGL VBO objects - // and shrink the allocated data, possibly relasing it if it has been loaded into the VBOs. - void finalize_geometry(bool opengl_initialized) { for (auto* v : volumes) v->finalize_geometry(opengl_initialized); } - // Release the geometry data assigned to the volumes. - // If OpenGL VBOs were allocated, an OpenGL context has to be active to release them. - void release_geometry() { for (auto* v : volumes) v->release_geometry(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Clear the geometry void clear() { for (auto *v : volumes) delete v; volumes.clear(); } @@ -770,7 +489,6 @@ GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCo struct _3DScene { -#if ENABLE_LEGACY_OPENGL_REMOVAL static void thick_lines_to_verts(const Lines& lines, const std::vector& widths, const std::vector& heights, bool closed, double top_z, GUI::GLModel::Geometry& geometry); static void thick_lines_to_verts(const Lines3& lines, const std::vector& widths, const std::vector& heights, bool closed, GUI::GLModel::Geometry& geometry); static void extrusionentity_to_verts(const ExtrusionPath& extrusion_path, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry); @@ -778,19 +496,6 @@ struct _3DScene static void extrusionentity_to_verts(const ExtrusionMultiPath& extrusion_multi_path, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry); static void extrusionentity_to_verts(const ExtrusionEntityCollection& extrusion_entity_collection, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry); static void extrusionentity_to_verts(const ExtrusionEntity* extrusion_entity, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry); -#else - static void thick_lines_to_verts(const Lines& lines, const std::vector& widths, const std::vector& heights, bool closed, double top_z, GLVolume& volume); - static void thick_lines_to_verts(const Lines3& lines, const std::vector& widths, const std::vector& heights, bool closed, GLVolume& volume); - static void extrusionentity_to_verts(const Polyline& polyline, float width, float height, float print_z, GLVolume& volume); - static void extrusionentity_to_verts(const ExtrusionPath& extrusion_path, float print_z, GLVolume& volume); - static void extrusionentity_to_verts(const ExtrusionPath& extrusion_path, float print_z, const Point& copy, GLVolume& volume); - static void extrusionentity_to_verts(const ExtrusionLoop& extrusion_loop, float print_z, const Point& copy, GLVolume& volume); - static void extrusionentity_to_verts(const ExtrusionMultiPath& extrusion_multi_path, float print_z, const Point& copy, GLVolume& volume); - static void extrusionentity_to_verts(const ExtrusionEntityCollection& extrusion_entity_collection, float print_z, const Point& copy, GLVolume& volume); - static void extrusionentity_to_verts(const ExtrusionEntity* extrusion_entity, float print_z, const Point& copy, GLVolume& volume); - static void polyline3_to_verts(const Polyline3& polyline, double width, double height, GLVolume& volume); - static void point3_to_verts(const Vec3crd& point, double width, double height, GLVolume& volume); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; } diff --git a/src/slic3r/GUI/Camera.cpp b/src/slic3r/GUI/Camera.cpp index a549d87da8..7a79b8cbf1 100644 --- a/src/slic3r/GUI/Camera.cpp +++ b/src/slic3r/GUI/Camera.cpp @@ -177,11 +177,7 @@ double Camera::get_fov() const void Camera::set_viewport(int x, int y, unsigned int w, unsigned int 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 } void Camera::apply_viewport() const @@ -189,29 +185,12 @@ void Camera::apply_viewport() const glsafe(::glViewport(m_viewport[0], m_viewport[1], m_viewport[2], m_viewport[3])); } -#if !ENABLE_LEGACY_OPENGL_REMOVAL -void Camera::apply_view_matrix() -{ - glsafe(::glMatrixMode(GL_MODELVIEW)); - glsafe(::glLoadIdentity()); - glsafe(::glMultMatrixd(m_view_matrix.data())); -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double far_z) { double w = 0.0; double h = 0.0; -#if !ENABLE_LEGACY_OPENGL_REMOVAL - const double old_distance = m_distance; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL m_frustrum_zs = calc_tight_frustrum_zs_around(box); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - if (m_distance != old_distance) - // the camera has been moved re-apply view matrix - apply_view_matrix(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL if (near_z > 0.0) m_frustrum_zs.first = std::max(std::min(m_frustrum_zs.first, near_z), FrustrumMinNearZ); @@ -245,30 +224,7 @@ void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double fa } } -#if ENABLE_LEGACY_OPENGL_REMOVAL apply_projection(-w, w, -h, h, m_frustrum_zs.first, m_frustrum_zs.second); -#else - glsafe(::glMatrixMode(GL_PROJECTION)); - glsafe(::glLoadIdentity()); - - switch (m_type) - { - default: - case EType::Ortho: - { - glsafe(::glOrtho(-w, w, -h, h, m_frustrum_zs.first, m_frustrum_zs.second)); - break; - } - case EType::Perspective: - { - glsafe(::glFrustum(-w, w, -h, h, m_frustrum_zs.first, m_frustrum_zs.second)); - break; - } - } - - glsafe(::glGetDoublev(GL_PROJECTION_MATRIX, m_projection_matrix.data())); - glsafe(::glMatrixMode(GL_MODELVIEW)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void Camera::apply_projection(double left, double right, double bottom, double top, double near_z, double far_z) diff --git a/src/slic3r/GUI/Camera.hpp b/src/slic3r/GUI/Camera.hpp index dca7ba642e..abca87b9d2 100644 --- a/src/slic3r/GUI/Camera.hpp +++ b/src/slic3r/GUI/Camera.hpp @@ -100,9 +100,6 @@ public: void set_viewport(int x, int y, unsigned int w, unsigned int h); void apply_viewport() const; -#if !ENABLE_LEGACY_OPENGL_REMOVAL - void apply_view_matrix(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL // 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) void apply_projection(const BoundingBoxf3& box, double near_z = -1.0, double far_z = -1.0); diff --git a/src/slic3r/GUI/CoordAxes.cpp b/src/slic3r/GUI/CoordAxes.cpp index 7370f6f783..277c8ad300 100644 --- a/src/slic3r/GUI/CoordAxes.cpp +++ b/src/slic3r/GUI/CoordAxes.cpp @@ -3,10 +3,8 @@ #include "CoordAxes.hpp" #include "GUI_App.hpp" #include "3DScene.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "Plater.hpp" #include "Camera.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include @@ -20,13 +18,8 @@ const float CoordAxes::DefaultStemLength = 25.0f; const float CoordAxes::DefaultTipRadius = 2.5f * CoordAxes::DefaultStemRadius; const float CoordAxes::DefaultTipLength = 5.0f; -#if ENABLE_LEGACY_OPENGL_REMOVAL void CoordAxes::render(const Transform3d& trafo, float emission_factor) -#else -void CoordAxes::render(float emission_factor) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { -#if ENABLE_LEGACY_OPENGL_REMOVAL auto render_axis = [this](GLShaderProgram& shader, const Transform3d& transform) { const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); @@ -35,13 +28,6 @@ void CoordAxes::render(float emission_factor) shader.set_uniform("projection_matrix", camera.get_projection_matrix()); shader.set_uniform("view_normal_matrix", (Matrix3d)(view_matrix.matrix().block(0, 0, 3, 3) * transform.matrix().block(0, 0, 3, 3).inverse().transpose())); m_arrow.render(); -#else - auto render_axis = [this](const Transform3f& transform) { - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixf(transform.data())); - m_arrow.render(); - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; if (!m_arrow.is_initialized()) @@ -59,31 +45,16 @@ void CoordAxes::render(float emission_factor) shader->set_uniform("emission_factor", emission_factor); // x axis -#if ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.set_color(ColorRGBA::X()); render_axis(*shader, trafo * Geometry::translation_transform(m_origin) * Geometry::rotation_transform({ 0.0, 0.5 * M_PI, 0.0 })); -#else - m_arrow.set_color(-1, ColorRGBA::X()); - render_axis(Geometry::translation_transform(m_origin) * Geometry::rotation_transform({ 0.0, 0.5 * M_PI, 0.0 }).cast()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // y axis -#if ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.set_color(ColorRGBA::Y()); render_axis(*shader, trafo * Geometry::translation_transform(m_origin) * Geometry::rotation_transform({ -0.5 * M_PI, 0.0, 0.0 })); -#else - m_arrow.set_color(-1, ColorRGBA::Y()); - render_axis(Geometry::translation_transform(m_origin) * Geometry::rotation_transform({ -0.5 * M_PI, 0.0, 0.0 }).cast()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // z axis -#if ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.set_color(ColorRGBA::Z()); render_axis(*shader, trafo * Geometry::translation_transform(m_origin)); -#else - m_arrow.set_color(-1, ColorRGBA::Z()); - render_axis(Geometry::translation_transform(m_origin).cast()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); if (curr_shader != nullptr) diff --git a/src/slic3r/GUI/CoordAxes.hpp b/src/slic3r/GUI/CoordAxes.hpp index d2e830a658..2679608a3f 100644 --- a/src/slic3r/GUI/CoordAxes.hpp +++ b/src/slic3r/GUI/CoordAxes.hpp @@ -49,11 +49,7 @@ public: float get_tip_length() const { return m_tip_length; } float get_total_length() const { return m_stem_length + m_tip_length; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void render(const Transform3d& trafo, float emission_factor = 0.0f); -#else - void render(float emission_factor = 0.0f); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; } // GUI diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index ecdf60ca39..bfd4379b41 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -193,7 +193,6 @@ void GCodeViewer::COG::render() glsafe(::glDisable(GL_DEPTH_TEST)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); Transform3d model_matrix = Geometry::translation_transform(cog()); if (m_fixed_size) { @@ -206,17 +205,6 @@ void GCodeViewer::COG::render() const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); m_model.render(); -#else - glsafe(::glPushMatrix()); - const Vec3d position = cog(); - glsafe(::glTranslated(position.x(), position.y(), position.z())); - if (m_fixed_size) { - const double inv_zoom = wxGetApp().plater()->get_camera().get_inv_zoom(); - glsafe(::glScaled(inv_zoom, inv_zoom, inv_zoom)); - } - m_model.render(); - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); @@ -305,11 +293,7 @@ void GCodeViewer::SequentialRangeCap::reset() { void GCodeViewer::SequentialView::Marker::init() { m_model.init_from(stilized_arrow(16, 2.0f, 4.0f, 1.0f, 8.0f)); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_model.set_color({ 1.0f, 1.0f, 1.0f, 0.5f }); -#else - m_model.set_color(-1, { 1.0f, 1.0f, 1.0f, 0.5f }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GCodeViewer::SequentialView::Marker::set_world_position(const Vec3f& position) @@ -333,7 +317,6 @@ void GCodeViewer::SequentialView::Marker::render() shader->start_using(); shader->set_uniform("emission_factor", 0.0f); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); const Transform3d model_matrix = m_world_transform.cast(); @@ -341,17 +324,9 @@ void GCodeViewer::SequentialView::Marker::render() shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixf(m_world_transform.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_model.render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - shader->stop_using(); glsafe(::glDisable(GL_BLEND)); @@ -721,17 +696,12 @@ void GCodeViewer::init() } case EMoveType::Travel: { buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line; -#if ENABLE_LEGACY_OPENGL_REMOVAL buffer.vertices.format = VBuffer::EFormat::Position; #if ENABLE_GL_CORE_PROFILE buffer.shader = OpenGLManager::get_gl_info().is_core_profile() ? "dashed_thick_lines" : "flat"; #else buffer.shader = "flat"; #endif // ENABLE_GL_CORE_PROFILE -#else - buffer.vertices.format = VBuffer::EFormat::PositionNormal3; - buffer.shader = "toolpaths_lines"; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL break; } } @@ -745,11 +715,7 @@ void GCodeViewer::init() m_gl_data_initialized = true; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& print) -#else -void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& print, bool initialized) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { // avoid processing if called with the same gcode_result if (m_last_result_id == gcode_result.id && @@ -779,11 +745,7 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr m_filament_densities = gcode_result.filament_densities; if (wxGetApp().is_editor()) -#if ENABLE_LEGACY_OPENGL_REMOVAL load_shells(print); -#else - load_shells(print, initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL else { Pointfs bed_shape; std::string texture; @@ -1281,30 +1243,12 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) // format data into the buffers to be rendered as lines auto add_vertices_as_line = [](const GCodeProcessorResult::MoveVertex& prev, const GCodeProcessorResult::MoveVertex& curr, VertexBuffer& vertices) { -#if ENABLE_LEGACY_OPENGL_REMOVAL auto add_vertex = [&vertices](const GCodeProcessorResult::MoveVertex& vertex) { // add position vertices.push_back(vertex.position.x()); vertices.push_back(vertex.position.y()); vertices.push_back(vertex.position.z()); }; -#else - // x component of the normal to the current segment (the normal is parallel to the XY plane) - const Vec3f dir = (curr.position - prev.position).normalized(); - Vec3f normal(dir.y(), -dir.x(), 0.0); - normal.normalize(); - - auto add_vertex = [&vertices, &normal](const GCodeProcessorResult::MoveVertex& vertex) { - // add position - vertices.push_back(vertex.position.x()); - vertices.push_back(vertex.position.y()); - vertices.push_back(vertex.position.z()); - // add normal - vertices.push_back(normal.x()); - vertices.push_back(normal.y()); - vertices.push_back(normal.z()); - }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // add previous vertex add_vertex(prev); @@ -1555,7 +1499,6 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) Geometry::scale_transform({ width, width, height }); const Eigen::Matrix normal_matrix = trafo.matrix().template block<3, 3>(0, 0).inverse().transpose(); -#if ENABLE_LEGACY_OPENGL_REMOVAL // append vertices const size_t vertices_count = data.vertices_count(); for (size_t i = 0; i < vertices_count; ++i) { @@ -1571,24 +1514,6 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) vertices.push_back(float(normal.y())); vertices.push_back(float(normal.z())); } -#else - for (const auto& entity : data.entities) { - // append vertices - for (size_t i = 0; i < entity.positions.size(); ++i) { - // append position - const Vec3d position = trafo * entity.positions[i].cast(); - vertices.push_back(static_cast(position.x())); - vertices.push_back(static_cast(position.y())); - vertices.push_back(static_cast(position.z())); - - // append normal - const Vec3d normal = normal_matrix * entity.normals[i].cast(); - vertices.push_back(static_cast(normal.x())); - vertices.push_back(static_cast(normal.y())); - vertices.push_back(static_cast(normal.z())); - } - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // append instance position instances.push_back(curr.position.x()); @@ -1599,18 +1524,10 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) }; auto add_indices_as_model_batch = [](const GLModel::Geometry& data, IndexBuffer& indices, IBufferType base_index) { -#if ENABLE_LEGACY_OPENGL_REMOVAL const size_t indices_count = data.indices_count(); for (size_t i = 0; i < indices_count; ++i) { indices.push_back(static_cast(data.extract_index(i) + base_index)); } -#else - for (const auto& entity : data.entities) { - for (size_t i = 0; i < entity.indices.size(); ++i) { - indices.push_back(static_cast(entity.indices[i] + base_index)); - } - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; #if ENABLE_GCODE_VIEWER_STATISTICS @@ -2301,11 +2218,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) progress_dialog->Destroy(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GCodeViewer::load_shells(const Print& print) -#else -void GCodeViewer::load_shells(const Print& print, bool initialized) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (print.objects().empty()) // no shells, return @@ -2322,11 +2235,7 @@ void GCodeViewer::load_shells(const Print& print, bool initialized) } size_t current_volumes_count = m_shells.volumes.volumes.size(); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_shells.volumes.load_object(model_obj, object_id, instance_ids); -#else - m_shells.volumes.load_object(model_obj, object_id, instance_ids, initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // adjust shells' z if raft is present const SlicingParameters& slicing_parameters = obj->slicing_parameters(); @@ -2350,13 +2259,8 @@ void GCodeViewer::load_shells(const Print& print, bool initialized) const float depth = print.wipe_tower_data(extruders_count).depth; const float brim_width = print.wipe_tower_data(extruders_count).brim_width; -#if ENABLE_LEGACY_OPENGL_REMOVAL m_shells.volumes.load_wipe_tower_preview(config.wipe_tower_x, config.wipe_tower_y, config.wipe_tower_width, depth, max_z, config.wipe_tower_rotation_angle, !print.is_step_done(psWipeTower), brim_width); -#else - m_shells.volumes.load_wipe_tower_preview(config.wipe_tower_x, config.wipe_tower_y, config.wipe_tower_width, depth, max_z, config.wipe_tower_rotation_angle, - !print.is_step_done(psWipeTower), brim_width, initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } @@ -2947,19 +2851,11 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool void GCodeViewer::render_toolpaths() { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - const std::array light_intensity = { 0.25f, 0.70f, 0.75f, 0.75f }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); #if !ENABLE_GL_CORE_PROFILE const double zoom = camera.get_zoom(); #endif // !ENABLE_GL_CORE_PROFILE -#if !ENABLE_LEGACY_OPENGL_REMOVAL - auto shader_init_as_lines = [light_intensity](GLShaderProgram &shader) { - shader.set_uniform("light_intensity", light_intensity); - }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL auto render_as_lines = [ #if ENABLE_GCODE_VIEWER_STATISTICS this @@ -3031,11 +2927,7 @@ void GCodeViewer::render_toolpaths() } if (range.vbo > 0) { -#if ENABLE_LEGACY_OPENGL_REMOVAL buffer.model.model.set_color(range.color); -#else - buffer.model.model.set_color(-1, range.color); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL buffer.model.model.render_instanced(range.vbo, range.count); #if ENABLE_GCODE_VIEWER_STATISTICS ++m_statistics.gl_instanced_models_calls_count; @@ -3045,19 +2937,11 @@ void GCodeViewer::render_toolpaths() } }; -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GCODE_VIEWER_STATISTICS auto render_as_batched_model = [this](TBuffer& buffer, GLShaderProgram& shader, int position_id, int normal_id) { #else auto render_as_batched_model = [](TBuffer& buffer, GLShaderProgram& shader, int position_id, int normal_id) { #endif // ENABLE_GCODE_VIEWER_STATISTICS -#else -#if ENABLE_GCODE_VIEWER_STATISTICS - auto render_as_batched_model = [this](TBuffer& buffer, GLShaderProgram& shader) { -#else - auto render_as_batched_model = [](TBuffer& buffer, GLShaderProgram& shader) { -#endif // ENABLE_GCODE_VIEWER_STATISTICS -#endif // ENABLE_LEGACY_OPENGL_REMOVAL struct Range { @@ -3076,26 +2960,16 @@ void GCodeViewer::render_toolpaths() glsafe(::glBindVertexArray(i_buffer.vao)); #endif // ENABLE_GL_CORE_PROFILE glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo)); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (position_id != -1) { glsafe(::glVertexAttribPointer(position_id, buffer.vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); glsafe(::glEnableVertexAttribArray(position_id)); } -#else - glsafe(::glVertexPointer(buffer.vertices.position_size_floats(), GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const bool has_normals = buffer.vertices.normal_size_floats() > 0; if (has_normals) { -#if ENABLE_LEGACY_OPENGL_REMOVAL if (normal_id != -1) { glsafe(::glVertexAttribPointer(normal_id, buffer.vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); glsafe(::glEnableVertexAttribArray(normal_id)); } -#else - glsafe(::glNormalPointer(GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_buffer.ibo)); @@ -3119,17 +2993,10 @@ void GCodeViewer::render_toolpaths() glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (normal_id != -1) glsafe(::glDisableVertexAttribArray(normal_id)); if (position_id != -1) glsafe(::glDisableVertexAttribArray(position_id)); -#else - if (has_normals) - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); #if ENABLE_GL_CORE_PROFILE if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) @@ -3158,11 +3025,9 @@ void GCodeViewer::render_toolpaths() shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("view_model_matrix", camera.get_view_matrix()); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader->set_uniform("view_normal_matrix", (Matrix3d)Matrix3d::Identity()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::InstancedModel) { shader->set_uniform("emission_factor", 0.25f); @@ -3171,24 +3036,15 @@ void GCodeViewer::render_toolpaths() } else if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::BatchedModel) { shader->set_uniform("emission_factor", 0.25f); -#if ENABLE_LEGACY_OPENGL_REMOVAL const int position_id = shader->get_attrib_location("v_position"); const int normal_id = shader->get_attrib_location("v_normal"); render_as_batched_model(buffer, *shader, position_id, normal_id); -#else - render_as_batched_model(buffer, *shader); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("emission_factor", 0.0f); } else { shader->set_uniform("emission_factor", 0.15f); -#if ENABLE_LEGACY_OPENGL_REMOVAL const int position_id = shader->get_attrib_location("v_position"); const int normal_id = shader->get_attrib_location("v_normal"); -#else - if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::Line) - shader_init_as_lines(*shader); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const int uniform_color = shader->get_uniform_location("uniform_color"); auto it_path = buffer.render_paths.begin(); @@ -3205,26 +3061,16 @@ void GCodeViewer::render_toolpaths() glsafe(::glBindVertexArray(i_buffer.vao)); #endif // ENABLE_GL_CORE_PROFILE glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo)); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (position_id != -1) { glsafe(::glVertexAttribPointer(position_id, buffer.vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); glsafe(::glEnableVertexAttribArray(position_id)); } -#else - glsafe(::glVertexPointer(buffer.vertices.position_size_floats(), GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const bool has_normals = buffer.vertices.normal_size_floats() > 0; if (has_normals) { -#if ENABLE_LEGACY_OPENGL_REMOVAL if (normal_id != -1) { glsafe(::glVertexAttribPointer(normal_id, buffer.vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); glsafe(::glEnableVertexAttribArray(normal_id)); } -#else - glsafe(::glNormalPointer(GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_buffer.ibo)); @@ -3251,17 +3097,10 @@ void GCodeViewer::render_toolpaths() glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (normal_id != -1) glsafe(::glDisableVertexAttribArray(normal_id)); if (position_id != -1) glsafe(::glDisableVertexAttribArray(position_id)); -#else - if (has_normals) - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); #if ENABLE_GL_CORE_PROFILE if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) @@ -3286,40 +3125,28 @@ void GCodeViewer::render_toolpaths() shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("view_model_matrix", camera.get_view_matrix()); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader->set_uniform("view_normal_matrix", (Matrix3d)Matrix3d::Identity()); const int position_id = shader->get_attrib_location("v_position"); const int normal_id = shader->get_attrib_location("v_normal"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) glsafe(::glBindVertexArray(cap.vao)); #endif // ENABLE_GL_CORE_PROFILE glsafe(::glBindBuffer(GL_ARRAY_BUFFER, cap.vbo)); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (position_id != -1) { glsafe(::glVertexAttribPointer(position_id, buffer->vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.position_offset_bytes())); glsafe(::glEnableVertexAttribArray(position_id)); } -#else - glsafe(::glVertexPointer(buffer->vertices.position_size_floats(), GL_FLOAT, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.position_offset_bytes())); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const bool has_normals = buffer->vertices.normal_size_floats() > 0; if (has_normals) { -#if ENABLE_LEGACY_OPENGL_REMOVAL if (normal_id != -1) { glsafe(::glVertexAttribPointer(normal_id, buffer->vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.normal_offset_bytes())); glsafe(::glEnableVertexAttribArray(normal_id)); } -#else - glsafe(::glNormalPointer(GL_FLOAT, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.normal_offset_bytes())); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } shader->set_uniform("uniform_color", cap.color); @@ -3332,17 +3159,10 @@ void GCodeViewer::render_toolpaths() ++m_statistics.gl_triangles_calls_count; #endif // ENABLE_GCODE_VIEWER_STATISTICS -#if ENABLE_LEGACY_OPENGL_REMOVAL if (normal_id != -1) glsafe(::glDisableVertexAttribArray(normal_id)); if (position_id != -1) glsafe(::glDisableVertexAttribArray(position_id)); -#else - if (has_normals) - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); #if ENABLE_GL_CORE_PROFILE @@ -3368,25 +3188,11 @@ void GCodeViewer::render_shells() if (shader == nullptr) return; -#if !ENABLE_LEGACY_OPENGL_REMOVAL - // when the background processing is enabled, it may happen that the shells data have been loaded - // before opengl has been initialized for the preview canvas. - // when this happens, the volumes' data have not been sent to gpu yet. - for (GLVolume* v : m_shells.volumes.volumes) { - if (!v->indexed_vertex_array.has_VBOs()) - v->finalize_geometry(true); - } -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - // glsafe(::glDepthMask(GL_FALSE)); shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); m_shells.volumes.render(GLVolumeCollection::ERenderType::Transparent, true, camera.get_view_matrix(), camera.get_projection_matrix()); -#else - m_shells.volumes.render(GLVolumeCollection::ERenderType::Transparent, true, wxGetApp().plater()->get_camera().get_view_matrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); // glsafe(::glDepthMask(GL_TRUE)); diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 0785f6a048..b077de98a5 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -364,11 +364,7 @@ class GCodeViewer } case ERenderPrimitiveType::InstancedModel: { return model.model.is_initialized() && !model.instances.buffer.empty(); } case ERenderPrimitiveType::BatchedModel: { -#if ENABLE_LEGACY_OPENGL_REMOVAL return !model.data.vertices.empty() && !model.data.indices.empty() && -#else - return model.data.vertices_count() > 0 && model.data.indices_count() && -#endif // ENABLE_LEGACY_OPENGL_REMOVAL !vertices.vbos.empty() && vertices.vbos.front() != 0 && !indices.empty() && indices.front().ibo != 0; } default: { return false; } @@ -418,12 +414,7 @@ class GCodeViewer return; const float radius = m_fixed_size ? 10.0f : 1.0f; - -#if ENABLE_LEGACY_OPENGL_REMOVAL m_model.init_from(smooth_sphere(32, radius)); -#else - m_model.init_from(its_make_sphere(radius, PI / 32.0)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } }; @@ -799,11 +790,7 @@ public: void init(); // extract rendering data from the given parameters -#if ENABLE_LEGACY_OPENGL_REMOVAL void load(const GCodeProcessorResult& gcode_result, const Print& print); -#else - void load(const GCodeProcessorResult& gcode_result, const Print& print, bool initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // recalculate ranges in dependence of what is visible and sets tool/print colors void refresh(const GCodeProcessorResult& gcode_result, const std::vector& str_tool_colors); void refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const; @@ -855,11 +842,7 @@ public: private: void load_toolpaths(const GCodeProcessorResult& gcode_result); -#if ENABLE_LEGACY_OPENGL_REMOVAL void load_shells(const Print& print); -#else - void load_shells(const Print& print, bool initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void render_toolpaths(); void render_shells(); void render_legend(float& legend_height); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 0c505bc0b2..9fa54b9a02 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -73,26 +73,13 @@ static constexpr const float TRACKBALLSIZE = 0.8f; -#if ENABLE_LEGACY_OPENGL_REMOVAL static const Slic3r::ColorRGBA DEFAULT_BG_DARK_COLOR = { 0.478f, 0.478f, 0.478f, 1.0f }; static const Slic3r::ColorRGBA DEFAULT_BG_LIGHT_COLOR = { 0.753f, 0.753f, 0.753f, 1.0f }; static const Slic3r::ColorRGBA ERROR_BG_DARK_COLOR = { 0.478f, 0.192f, 0.039f, 1.0f }; static const Slic3r::ColorRGBA ERROR_BG_LIGHT_COLOR = { 0.753f, 0.192f, 0.039f, 1.0f }; -#else -static const Slic3r::ColorRGB DEFAULT_BG_DARK_COLOR = { 0.478f, 0.478f, 0.478f }; -static const Slic3r::ColorRGB DEFAULT_BG_LIGHT_COLOR = { 0.753f, 0.753f, 0.753f }; -static const Slic3r::ColorRGB ERROR_BG_DARK_COLOR = { 0.478f, 0.192f, 0.039f }; -static const Slic3r::ColorRGB ERROR_BG_LIGHT_COLOR = { 0.753f, 0.192f, 0.039f }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Number of floats static constexpr const size_t MAX_VERTEX_BUFFER_SIZE = 131072 * 6; // 3.15MB -// Reserve size in number of floats. -#if !ENABLE_LEGACY_OPENGL_REMOVAL -static constexpr const size_t VERTEX_BUFFER_RESERVE_SIZE = 131072 * 2; // 1.05MB -// Reserve size in number of floats, maximum sum of all preallocated buffers. -//static constexpr const size_t VERTEX_BUFFER_RESERVE_SIZE_SUM_MAX = 1024 * 1024 * 128 / 4; // 128MB -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL namespace Slic3r { namespace GUI { @@ -266,14 +253,8 @@ void GLCanvas3D::LayersEditing::render_overlay(const GLCanvas3D& canvas) GLCanvas3D::LayersEditing::s_overlay_window_width = ImGui::GetWindowSize().x /*+ (float)m_layers_texture.width/4*/; imgui.end(); -#if ENABLE_LEGACY_OPENGL_REMOVAL render_active_object_annotations(canvas); render_profile(canvas); -#else - const Rect& bar_rect = get_bar_rect_viewport(canvas); - render_active_object_annotations(canvas, bar_rect); - render_profile(bar_rect); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } float GLCanvas3D::LayersEditing::get_cursor_z_relative(const GLCanvas3D& canvas) @@ -307,17 +288,6 @@ Rect GLCanvas3D::LayersEditing::get_bar_rect_screen(const GLCanvas3D& canvas) return { w - thickness_bar_width(canvas), 0.0f, w, h }; } -#if !ENABLE_LEGACY_OPENGL_REMOVAL -Rect GLCanvas3D::LayersEditing::get_bar_rect_viewport(const GLCanvas3D& canvas) -{ - const Size& cnv_size = canvas.get_canvas_size(); - float half_w = 0.5f * (float)cnv_size.get_width(); - float half_h = 0.5f * (float)cnv_size.get_height(); - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - return { (half_w - thickness_bar_width(canvas)) * inv_zoom, half_h * inv_zoom, half_w * inv_zoom, -half_h * inv_zoom }; -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - bool GLCanvas3D::LayersEditing::is_initialized() const { return wxGetApp().get_shader("variable_layer_height") != nullptr; @@ -349,7 +319,6 @@ std::string GLCanvas3D::LayersEditing::get_tooltip(const GLCanvas3D& canvas) con return ret; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3D& canvas) { const Size cnv_size = canvas.get_canvas_size(); @@ -359,10 +328,6 @@ void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3 return; const float cnv_inv_width = 1.0f / cnv_width; -#else -void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3D& canvas, const Rect& bar_rect) -{ -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("variable_layer_height"); if (shader == nullptr) return; @@ -374,17 +339,14 @@ void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3 shader->set_uniform("z_cursor", m_object_max_z * this->get_cursor_z_relative(canvas)); shader->set_uniform("z_cursor_band_width", band_width); shader->set_uniform("object_max_z", m_object_max_z); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("view_model_matrix", Transform3d::Identity()); shader->set_uniform("projection_matrix", Transform3d::Identity()); shader->set_uniform("view_normal_matrix", (Matrix3d)Matrix3d::Identity()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); glsafe(::glBindTexture(GL_TEXTURE_2D, m_z_texture_id)); // Render the color bar -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_profile.background.is_initialized() || m_profile.old_canvas_width != cnv_width) { m_profile.old_canvas_width = cnv_width; m_profile.background.reset(); @@ -412,38 +374,19 @@ void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3 } m_profile.background.render(); -#else - const float l = bar_rect.get_left(); - const float r = bar_rect.get_right(); - const float t = bar_rect.get_top(); - const float b = bar_rect.get_bottom(); - - ::glBegin(GL_QUADS); - ::glNormal3f(0.0f, 0.0f, 1.0f); - ::glTexCoord2f(0.0f, 0.0f); ::glVertex2f(l, b); - ::glTexCoord2f(1.0f, 0.0f); ::glVertex2f(r, b); - ::glTexCoord2f(1.0f, 1.0f); ::glVertex2f(r, t); - ::glTexCoord2f(0.0f, 1.0f); ::glVertex2f(l, t); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); shader->stop_using(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLCanvas3D::LayersEditing::render_profile(const GLCanvas3D& canvas) -#else -void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { //FIXME show some kind of legend. if (!m_slicing_parameters) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL const Size cnv_size = canvas.get_canvas_size(); const float cnv_width = (float)cnv_size.get_width(); const float cnv_height = (float)cnv_size.get_height(); @@ -456,13 +399,7 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect) const float cnv_inv_width = 1.0f / cnv_width; const float cnv_inv_height = 1.0f / cnv_height; -#else - // Make the vertical bar a bit wider so the layer height curve does not touch the edge of the bar region. - const float scale_x = bar_rect.get_width() / float(1.12 * m_slicing_parameters->max_layer_height); - const float scale_y = bar_rect.get_height() / m_object_max_z; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL // Baseline if (!m_profile.baseline.is_initialized() || m_profile.old_layer_height_profile != m_layer_height_profile) { m_profile.baseline.reset(); @@ -523,23 +460,6 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect) m_profile.profile.render(); shader->stop_using(); } -#else - const float x = bar_rect.get_left() + float(m_slicing_parameters->layer_height) * scale_x; - - // Baseline - glsafe(::glColor3f(0.0f, 0.0f, 0.0f)); - ::glBegin(GL_LINE_STRIP); - ::glVertex2f(x, bar_rect.get_bottom()); - ::glVertex2f(x, bar_rect.get_top()); - glsafe(::glEnd()); - - // Curve - glsafe(::glColor3f(0.0f, 0.0f, 1.0f)); - ::glBegin(GL_LINE_STRIP); - for (unsigned int i = 0; i < m_layer_height_profile.size(); i += 2) - ::glVertex2f(bar_rect.get_left() + (float)m_layer_height_profile[i + 1] * scale_x, bar_rect.get_bottom() + (float)m_layer_height_profile[i] * scale_y); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GLCanvas3D::LayersEditing::render_volumes(const GLCanvas3D& canvas, const GLVolumeCollection& volumes) @@ -566,10 +486,8 @@ void GLCanvas3D::LayersEditing::render_volumes(const GLCanvas3D& canvas, const G shader->set_uniform("z_cursor", float(m_object_max_z) * float(this->get_cursor_z_relative(canvas))); shader->set_uniform("z_cursor_band_width", float(this->band_width)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Initialize the layer height texture mapping. const GLsizei w = (GLsizei)m_layers_texture.width; @@ -589,13 +507,11 @@ void GLCanvas3D::LayersEditing::render_volumes(const GLCanvas3D& canvas, const G shader->set_uniform("volume_world_matrix", glvolume->world_matrix()); shader->set_uniform("object_max_z", 0.0f); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d& view_matrix = camera.get_view_matrix(); const Transform3d model_matrix = glvolume->world_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(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glvolume->render(); } @@ -944,17 +860,8 @@ void GLCanvas3D::SequentialPrintClearance::set_polygons(const Polygons& polygons if (polygons.empty()) return; -#if !ENABLE_LEGACY_OPENGL_REMOVAL - size_t triangles_count = 0; - for (const Polygon& poly : polygons) { - triangles_count += poly.points.size() - 2; - } - const size_t vertices_count = 3 * triangles_count; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - if (m_render_fill) { GLModel::Geometry fill_data; -#if ENABLE_LEGACY_OPENGL_REMOVAL fill_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 }; fill_data.color = { 0.3333f, 0.0f, 0.0f, 0.5f }; @@ -974,55 +881,9 @@ void GLCanvas3D::SequentialPrintClearance::set_polygons(const Polygons& polygons } m_fill.init_from(std::move(fill_data)); -#else - GLModel::Geometry::Entity entity; - entity.type = GLModel::EPrimitiveType::Triangles; - entity.color = { 0.3333f, 0.0f, 0.0f, 0.5f }; - entity.positions.reserve(vertices_count); - entity.normals.reserve(vertices_count); - entity.indices.reserve(vertices_count); - - const ExPolygons polygons_union = union_ex(polygons); - for (const ExPolygon& poly : polygons_union) { - const std::vector triangulation = triangulate_expolygon_3d(poly); - for (const Vec3d& v : triangulation) { - entity.positions.emplace_back(v.cast() + Vec3f(0.0f, 0.0f, 0.0125f)); // add a small positive z to avoid z-fighting - entity.normals.emplace_back(Vec3f::UnitZ()); - const size_t positions_count = entity.positions.size(); - if (positions_count % 3 == 0) { - entity.indices.emplace_back(positions_count - 3); - entity.indices.emplace_back(positions_count - 2); - entity.indices.emplace_back(positions_count - 1); - } - } - } - - fill_data.entities.emplace_back(entity); - m_fill.init_from(fill_data); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL m_perimeter.init_from(polygons, 0.025f); // add a small positive z to avoid z-fighting -#else - GLModel::Geometry perimeter_data; - for (const Polygon& poly : polygons) { - GLModel::Geometry::Entity ent; - ent.type = GLModel::EPrimitiveType::LineLoop; - ent.positions.reserve(poly.points.size()); - ent.indices.reserve(poly.points.size()); - unsigned int id_count = 0; - for (const Point& p : poly.points) { - ent.positions.emplace_back(unscale(p.x()), unscale(p.y()), 0.025f); // add a small positive z to avoid z-fighting - ent.normals.emplace_back(Vec3f::UnitZ()); - ent.indices.emplace_back(id_count++); - } - - perimeter_data.entities.emplace_back(ent); - } - - m_perimeter.init_from(perimeter_data); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GLCanvas3D::SequentialPrintClearance::render() @@ -1030,32 +891,22 @@ void GLCanvas3D::SequentialPrintClearance::render() const ColorRGBA FILL_COLOR = { 1.0f, 0.0f, 0.0f, 0.5f }; const ColorRGBA NO_FILL_COLOR = { 1.0f, 1.0f, 1.0f, 0.75f }; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("flat"); -#else - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (shader == nullptr) return; shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix()); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_CULL_FACE)); glsafe(::glEnable(GL_BLEND)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_perimeter.set_color(m_render_fill ? FILL_COLOR : NO_FILL_COLOR); -#else - m_perimeter.set_color(-1, m_render_fill ? FILL_COLOR : NO_FILL_COLOR); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_perimeter.render(); m_fill.render(); @@ -1246,50 +1097,12 @@ bool GLCanvas3D::init() glsafe(::glEnable(GL_BLEND)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - // Set antialiasing / multisampling - glsafe(::glDisable(GL_LINE_SMOOTH)); - glsafe(::glDisable(GL_POLYGON_SMOOTH)); - - // ambient lighting - GLfloat ambient[4] = { 0.3f, 0.3f, 0.3f, 1.0f }; - glsafe(::glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient)); - - glsafe(::glEnable(GL_LIGHT0)); - glsafe(::glEnable(GL_LIGHT1)); - - // light from camera - GLfloat specular_cam[4] = { 0.3f, 0.3f, 0.3f, 1.0f }; - glsafe(::glLightfv(GL_LIGHT1, GL_SPECULAR, specular_cam)); - GLfloat diffuse_cam[4] = { 0.2f, 0.2f, 0.2f, 1.0f }; - glsafe(::glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_cam)); - - // light from above - GLfloat specular_top[4] = { 0.2f, 0.2f, 0.2f, 1.0f }; - glsafe(::glLightfv(GL_LIGHT0, GL_SPECULAR, specular_top)); - GLfloat diffuse_top[4] = { 0.5f, 0.5f, 0.5f, 1.0f }; - glsafe(::glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_top)); - - // Enables Smooth Color Shading; try GL_FLAT for (lack of) fun. - glsafe(::glShadeModel(GL_SMOOTH)); - - // A handy trick -- have surface material mirror the color. - glsafe(::glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)); - glsafe(::glEnable(GL_COLOR_MATERIAL)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - if (m_multisample_allowed) glsafe(::glEnable(GL_MULTISAMPLE)); if (m_main_toolbar.is_enabled()) m_layers_editing.init(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - // on linux the gl context is not valid until the canvas is not shown on screen - // we defer the geometry finalization of volumes until the first call to render() - m_volumes.finalize_geometry(true); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - if (m_gizmos.is_enabled() && !m_gizmos.init()) std::cout << "Unable to initialize gizmos: please, check that all the required textures are available" << std::endl; @@ -1663,18 +1476,8 @@ void GLCanvas3D::render() camera.requires_zoom_to_bed = false; } -#if !ENABLE_LEGACY_OPENGL_REMOVAL - camera.apply_view_matrix(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL camera.apply_projection(_max_bounding_box(true, true)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - GLfloat position_cam[4] = { 1.0f, 0.0f, 1.0f, 0.0f }; - glsafe(::glLightfv(GL_LIGHT1, GL_POSITION, position_cam)); - GLfloat position_top[4] = { -0.5f, -0.5f, 1.0f, 0.0f }; - glsafe(::glLightfv(GL_LIGHT0, GL_POSITION, position_top)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - wxGetApp().imgui()->new_frame(); if (m_picking_enabled) { @@ -1706,11 +1509,7 @@ void GLCanvas3D::render() _render_sla_slices(); _render_selection(); if (is_looking_downward) -#if ENABLE_LEGACY_OPENGL_REMOVAL _render_bed(camera.get_view_matrix(), camera.get_projection_matrix(), false, true); -#else - _render_bed(false, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL _render_objects(GLVolumeCollection::ERenderType::Transparent); _render_sequential_clearance(); @@ -1731,11 +1530,7 @@ void GLCanvas3D::render() _render_selection_sidebar_hints(); _render_current_gizmo(); if (!is_looking_downward) -#if ENABLE_LEGACY_OPENGL_REMOVAL _render_bed(camera.get_view_matrix(), camera.get_projection_matrix(), true, true); -#else - _render_bed(true, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_RAYCAST_PICKING_DEBUG if (m_picking_enabled && !m_mouse.dragging && !m_gizmos.is_dragging() && !m_rectangle_selection.is_dragging()) @@ -1933,11 +1728,7 @@ std::vector GLCanvas3D::load_object(const ModelObject& model_object, int ob instance_idxs.emplace_back(i); } } -#if ENABLE_LEGACY_OPENGL_REMOVAL return m_volumes.load_object(&model_object, obj_idx, instance_idxs); -#else - return m_volumes.load_object(&model_object, obj_idx, instance_idxs, m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } std::vector GLCanvas3D::load_object(const Model& model, int obj_idx) @@ -2165,11 +1956,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re // Note the index of the loaded volume, so that we can reload the main model GLVolume with the hollowed mesh // later in this function. it->volume_idx = m_volumes.volumes.size(); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_volumes.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx); -#else - m_volumes.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_volumes.volumes.back()->geometry_id = key.geometry_id; update_object_list = true; } else { @@ -2226,11 +2013,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re GLVolume &volume = *m_volumes.volumes[it->volume_idx]; if (! volume.offsets.empty() && state.step[istep].timestamp != volume.offsets.front()) { // The backend either produced a new hollowed mesh, or it invalidated the one that the front end has seen. -#if ENABLE_LEGACY_OPENGL_REMOVAL volume.model.reset(); -#else - volume.indexed_vertex_array.release_geometry(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (state.step[istep].state == PrintStateBase::DONE) { TriangleMesh mesh = print_object->get_mesh(slaposDrillHoles); assert(! mesh.empty()); @@ -2242,46 +2025,27 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re * mo.volumes.front()->get_transformation().get_matrix(); mesh.transform(trafo.inverse()); #if ENABLE_SMOOTH_NORMALS -#if ENABLE_LEGACY_OPENGL_REMOVAL volume.model.init_from(mesh, true); #else - volume.indexed_vertex_array.load_mesh(mesh, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#else -#if ENABLE_LEGACY_OPENGL_REMOVAL volume.model.init_from(mesh); volume.mesh_raycaster = std::make_unique(std::make_shared(mesh)); -#else - volume.indexed_vertex_array.load_mesh(mesh); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_SMOOTH_NORMALS } else { // Reload the original volume. #if ENABLE_SMOOTH_NORMALS -#if ENABLE_LEGACY_OPENGL_REMOVAL - volume.model.init_from(m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh(), true); + volume.model.init_from(m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh(), true); #else - volume.indexed_vertex_array.load_mesh(m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh(), true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#else -#if ENABLE_LEGACY_OPENGL_REMOVAL const TriangleMesh& new_mesh = m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh(); volume.model.init_from(new_mesh); volume.mesh_raycaster = std::make_unique(std::make_shared(new_mesh)); -#else - volume.indexed_vertex_array.load_mesh(m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_SMOOTH_NORMALS } -#if !ENABLE_LEGACY_OPENGL_REMOVAL - volume.finalize_geometry(true); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } - //FIXME it is an ugly hack to write the timestamp into the "offsets" field to not have to add another member variable - // to the GLVolume. We should refactor GLVolume significantly, so that the GLVolume will not contain member variables - // of various concenrs (model vs. 3D print path). - volume.offsets = { state.step[istep].timestamp }; + //FIXME it is an ugly hack to write the timestamp into the "offsets" field to not have to add another member variable + // to the GLVolume. We should refactor GLVolume significantly, so that the GLVolume will not contain member variables + // of various concenrs (model vs. 3D print path). + volume.offsets = { state.step[istep].timestamp }; } else if (state.step[istep].state == PrintStateBase::DONE) { // Check whether there is an existing auxiliary volume to be updated, or a new auxiliary volume to be created. @@ -2306,11 +2070,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re for (size_t istep = 0; istep < sla_steps.size(); ++istep) if (!instances[istep].empty()) -#if ENABLE_LEGACY_OPENGL_REMOVAL m_volumes.load_object_auxiliary(print_object, object_idx, instances[istep], sla_steps[istep], state.step[istep].timestamp); -#else - m_volumes.load_object_auxiliary(print_object, object_idx, instances[istep], sla_steps[istep], state.step[istep].timestamp, m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } // Shift-up all volumes of the object so that it has the right elevation with respect to the print bed @@ -2340,7 +2100,6 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re float depth = print->wipe_tower_data(extruders_count).depth; float brim_width = print->wipe_tower_data(extruders_count).brim_width; -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_OPENGL_ES int volume_idx_wipe_tower_new = m_volumes.load_wipe_tower_preview( x, y, w, depth, (float)height, a, !print->is_step_done(psWipeTower), @@ -2350,11 +2109,6 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re x, y, w, depth, (float)height, a, !print->is_step_done(psWipeTower), brim_width); #endif // ENABLE_OPENGL_ES -#else - int volume_idx_wipe_tower_new = m_volumes.load_wipe_tower_preview( - x, y, w, depth, (float)height, a, !print->is_step_done(psWipeTower), - brim_width, m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (volume_idx_wipe_tower_old != -1) map_glvolume_old_to_new[volume_idx_wipe_tower_old] = volume_idx_wipe_tower_new; } @@ -2446,30 +2200,9 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re m_dirty = true; } -#if !ENABLE_LEGACY_OPENGL_REMOVAL -static void reserve_new_volume_finalize_old_volume(GLVolume& vol_new, GLVolume& vol_old, bool gl_initialized, size_t prealloc_size = VERTEX_BUFFER_RESERVE_SIZE) -{ - // Assign the large pre-allocated buffers to the new GLVolume. - vol_new.indexed_vertex_array = std::move(vol_old.indexed_vertex_array); - // Copy the content back to the old GLVolume. - vol_old.indexed_vertex_array = vol_new.indexed_vertex_array; - // Clear the buffers, but keep them pre-allocated. - vol_new.indexed_vertex_array.clear(); - // Just make sure that clear did not clear the reserved memory. - // Reserving number of vertices (3x position + 3x color) - vol_new.indexed_vertex_array.reserve(prealloc_size / 6); - // Finalize the old geometry, possibly move data to the graphics card. - vol_old.finalize_geometry(gl_initialized); -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - void GLCanvas3D::load_gcode_preview(const GCodeProcessorResult& gcode_result, const std::vector& str_tool_colors) { -#if ENABLE_LEGACY_OPENGL_REMOVAL m_gcode_viewer.load(gcode_result, *this->fff_print()); -#else - m_gcode_viewer.load(gcode_result, *this->fff_print(), m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (wxGetApp().is_editor()) { m_gcode_viewer.update_shells_color_by_extruder(m_config); @@ -4396,12 +4129,7 @@ bool GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x) ImGuiWrapper* imgui = wxGetApp().imgui(); -#if ENABLE_LEGACY_OPENGL_REMOVAL imgui->set_next_window_pos(pos_x, m_undoredo_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); -#else - const float x = pos_x * (float)wxGetApp().plater()->get_camera().get_zoom() + 0.5f * (float)get_canvas_size().get_width(); - imgui->set_next_window_pos(x, m_undoredo_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL std::string title = is_undo ? L("Undo History") : L("Redo History"); imgui->begin(_(title), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); @@ -4440,12 +4168,7 @@ bool GLCanvas3D::_render_search_list(float pos_x) bool action_taken = false; ImGuiWrapper* imgui = wxGetApp().imgui(); -#if ENABLE_LEGACY_OPENGL_REMOVAL imgui->set_next_window_pos(pos_x, m_main_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); -#else - const float x = /*pos_x * (float)wxGetApp().plater()->get_camera().get_zoom() + */0.5f * (float)get_canvas_size().get_width(); - imgui->set_next_window_pos(x, m_main_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL std::string title = L("Search"); imgui->begin(_(title), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); @@ -4498,13 +4221,7 @@ bool GLCanvas3D::_render_arrange_menu(float pos_x) { ImGuiWrapper *imgui = wxGetApp().imgui(); -#if ENABLE_LEGACY_OPENGL_REMOVAL imgui->set_next_window_pos(pos_x, m_main_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); -#else - auto canvas_w = float(get_canvas_size().get_width()); - const float x = pos_x * float(wxGetApp().plater()->get_camera().get_zoom()) + 0.5f * canvas_w; - imgui->set_next_window_pos(x, m_main_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL imgui->begin(_L("Arrange options"), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse); @@ -4640,11 +4357,7 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const camera.apply_viewport(); camera.zoom_to_box(volumes_box); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d& view_matrix = camera.get_view_matrix(); -#else - camera.apply_view_matrix(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL double near_z = -1.0; double far_z = -1.0; @@ -4653,11 +4366,7 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const // extends the near and far z of the frustrum to avoid the bed being clipped // box in eye space -#if ENABLE_LEGACY_OPENGL_REMOVAL const BoundingBoxf3 t_bed_box = m_bed.extended_bounding_box().transformed(view_matrix); -#else - const BoundingBoxf3 t_bed_box = m_bed.extended_bounding_box().transformed(camera.get_view_matrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL near_z = -t_bed_box.max.z(); far_z = -t_bed_box.min.z(); } @@ -4677,26 +4386,18 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const shader->start_using(); shader->set_uniform("emission_factor", 0.0f); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d& projection_matrix = camera.get_projection_matrix(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (GLVolume* vol : visible_volumes) { -#if ENABLE_LEGACY_OPENGL_REMOVAL vol->model.set_color((vol->printable && !vol->is_outside) ? (current_printer_technology() == ptSLA ? vol->color : ColorRGBA::ORANGE()) : ColorRGBA::GRAY()); -#else - shader->set_uniform("uniform_color", (vol->printable && !vol->is_outside) ? (current_printer_technology() == ptSLA ? vol->color : ColorRGBA::ORANGE()) : ColorRGBA::GRAY()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // the volume may have been deactivated by an active gizmo const bool is_active = vol->is_active; vol->is_active = true; -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d model_matrix = vol->world_matrix(); shader->set_uniform("view_model_matrix", view_matrix * model_matrix); shader->set_uniform("projection_matrix", projection_matrix); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL vol->render(); vol->is_active = is_active; } @@ -4706,11 +4407,7 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const glsafe(::glDisable(GL_DEPTH_TEST)); if (thumbnail_params.show_bed) -#if ENABLE_LEGACY_OPENGL_REMOVAL _render_bed(view_matrix, projection_matrix, !camera.is_looking_downward(), false); -#else - _render_bed(!camera.is_looking_downward(), false); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // restore background color if (thumbnail_params.transparent_background) @@ -4977,25 +4674,11 @@ bool GLCanvas3D::_init_main_toolbar() return true; } // init arrow -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_main_toolbar.init_arrow("toolbar_arrow_2.svg")) -#else - BackgroundTexture::Metadata arrow_data; - arrow_data.filename = "toolbar_arrow.svg"; - arrow_data.left = 0; - arrow_data.top = 0; - arrow_data.right = 0; - arrow_data.bottom = 0; - if (!m_main_toolbar.init_arrow(arrow_data)) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL BOOST_LOG_TRIVIAL(error) << "Main toolbar failed to load arrow texture."; // m_gizmos is created at constructor, thus we can init arrow here. -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_gizmos.init_arrow("toolbar_arrow_2.svg")) -#else - if (!m_gizmos.init_arrow(arrow_data)) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL BOOST_LOG_TRIVIAL(error) << "Gizmos manager failed to load arrow texture."; // m_main_toolbar.set_layout_type(GLToolbar::Layout::Vertical); @@ -5202,17 +4885,7 @@ bool GLCanvas3D::_init_undoredo_toolbar() } // init arrow -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_undoredo_toolbar.init_arrow("toolbar_arrow_2.svg")) -#else - BackgroundTexture::Metadata arrow_data; - arrow_data.filename = "toolbar_arrow.svg"; - arrow_data.left = 0; - arrow_data.top = 0; - arrow_data.right = 0; - arrow_data.bottom = 0; - if (!m_undoredo_toolbar.init_arrow(arrow_data)) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL BOOST_LOG_TRIVIAL(error) << "Undo/Redo toolbar failed to load arrow texture."; // m_undoredo_toolbar.set_layout_type(GLToolbar::Layout::Vertical); @@ -5652,11 +5325,7 @@ void GLCanvas3D::_rectangular_selection_picking_pass() } _render_volumes_for_picking(*camera); -#if ENABLE_LEGACY_OPENGL_REMOVAL _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 if (m_multisample_allowed) glsafe(::glEnable(GL_MULTISAMPLE)); @@ -5744,18 +5413,9 @@ void GLCanvas3D::_render_background() use_error_color &= m_gcode_viewer.has_data() && !m_gcode_viewer.is_contained_in_bed(); } -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); - glsafe(::glMatrixMode(GL_PROJECTION)); - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - // Draws a bottom to top gradient over the complete screen. glsafe(::glDisable(GL_DEPTH_TEST)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const ColorRGBA bottom_color = use_error_color ? ERROR_BG_DARK_COLOR : DEFAULT_BG_DARK_COLOR; if (!m_background.is_initialized()) { @@ -5787,32 +5447,11 @@ void GLCanvas3D::_render_background() m_background.render(); shader->stop_using(); } -#else - ::glBegin(GL_QUADS); - ::glColor3fv(use_error_color ? ERROR_BG_DARK_COLOR.data(): DEFAULT_BG_DARK_COLOR.data()); - ::glVertex2f(-1.0f, -1.0f); - ::glVertex2f(1.0f, -1.0f); - - ::glColor3fv(use_error_color ? ERROR_BG_LIGHT_COLOR.data() : DEFAULT_BG_LIGHT_COLOR.data()); - ::glVertex2f(1.0f, 1.0f); - ::glVertex2f(-1.0f, 1.0f); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_DEPTH_TEST)); - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); - glsafe(::glMatrixMode(GL_MODELVIEW)); - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLCanvas3D::_render_bed(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_axes) -#else -void GLCanvas3D::_render_bed(bool bottom, bool show_axes) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { float scale_factor = 1.0; #if ENABLE_RETINA_GL @@ -5826,29 +5465,17 @@ void GLCanvas3D::_render_bed(bool bottom, bool show_axes) && m_gizmos.get_current_type() != GLGizmosManager::Seam && m_gizmos.get_current_type() != GLGizmosManager::MmuSegmentation); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_bed.render(*this, view_matrix, projection_matrix, bottom, scale_factor, show_axes, show_texture); -#else - m_bed.render(*this, bottom, scale_factor, show_axes, show_texture); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLCanvas3D::_render_bed_for_picking(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom) -#else -void GLCanvas3D::_render_bed_for_picking(bool bottom) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { float scale_factor = 1.0; #if ENABLE_RETINA_GL scale_factor = m_retina_helper->get_scale_factor(); #endif // ENABLE_RETINA_GL -#if ENABLE_LEGACY_OPENGL_REMOVAL m_bed.render_for_picking(*this, view_matrix, projection_matrix, bottom, scale_factor); -#else - m_bed.render_for_picking(*this, bottom, scale_factor); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type) @@ -5914,33 +5541,20 @@ void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type) { if (m_picking_enabled && !m_gizmos.is_dragging() && m_layers_editing.is_enabled() && (m_layers_editing.last_object_id != -1) && (m_layers_editing.object_max_z() > 0.0f)) { int object_id = m_layers_editing.last_object_id; -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); m_volumes.render(type, false, camera.get_view_matrix(), camera.get_projection_matrix(), [object_id](const GLVolume& volume) { // Which volume to paint without the layer height profile shader? return volume.is_active && (volume.is_modifier || volume.composite_id.object_id != object_id); }); -#else - m_volumes.render(type, false, wxGetApp().plater()->get_camera().get_view_matrix(), [object_id](const GLVolume& volume) { - // Which volume to paint without the layer height profile shader? - return volume.is_active && (volume.is_modifier || volume.composite_id.object_id != object_id); - }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Let LayersEditing handle rendering of the active object using the layer height profile shader. m_layers_editing.render_volumes(*this, m_volumes); } else { // do not cull backfaces to show broken geometry, if any -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); m_volumes.render(type, m_picking_enabled, camera.get_view_matrix(), camera.get_projection_matrix(), [this](const GLVolume& volume) { return (m_render_sla_auxiliaries || volume.composite_id.volume_id >= 0); }); -#else - m_volumes.render(type, m_picking_enabled, wxGetApp().plater()->get_camera().get_view_matrix(), [this](const GLVolume& volume) { - return (m_render_sla_auxiliaries || volume.composite_id.volume_id >= 0); - }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } // In case a painting gizmo is open, it should render the painted triangles @@ -5959,12 +5573,8 @@ void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type) } case GLVolumeCollection::ERenderType::Transparent: { -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); m_volumes.render(type, false, camera.get_view_matrix(), camera.get_projection_matrix()); -#else - m_volumes.render(type, false, wxGetApp().plater()->get_camera().get_view_matrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL break; } } @@ -6074,16 +5684,6 @@ void GLCanvas3D::_check_and_update_toolbar_icon_scale() void GLCanvas3D::_render_overlays() { glsafe(::glDisable(GL_DEPTH_TEST)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); - // ensure that the textures are renderered inside the frustrum - const Camera& camera = wxGetApp().plater()->get_camera(); - glsafe(::glTranslated(0.0, 0.0, -(camera.get_near_z() + 0.005))); - // ensure that the overlay fits the frustrum near z plane - double gui_scale = camera.get_gui_scale(); - glsafe(::glScaled(gui_scale, gui_scale, 1.0)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL _check_and_update_toolbar_icon_scale(); @@ -6121,28 +5721,17 @@ void GLCanvas3D::_render_overlays() } } m_labels.render(sorted_instances); - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } void GLCanvas3D::_render_volumes_for_picking(const Camera& camera) const { -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("flat_clip"); if (shader == nullptr) return; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // do not cull backfaces to show broken geometry, if any glsafe(::glDisable(GL_CULL_FACE)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - const Transform3d& view_matrix = camera.get_view_matrix(); 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); @@ -6152,7 +5741,6 @@ void GLCanvas3D::_render_volumes_for_picking(const Camera& camera) const // we reserve color = (0,0,0) for occluders (as the printbed) // so we shift volumes' id by 1 to get the proper color const unsigned int id = 1 + volume.second.first; -#if ENABLE_LEGACY_OPENGL_REMOVAL volume.first->model.set_color(picking_decode(id)); shader->start_using(); shader->set_uniform("view_model_matrix", view_matrix * volume.first->world_matrix()); @@ -6160,20 +5748,10 @@ void GLCanvas3D::_render_volumes_for_picking(const Camera& camera) const shader->set_uniform("volume_world_matrix", volume.first->world_matrix()); shader->set_uniform("z_range", m_volumes.get_z_range()); shader->set_uniform("clipping_plane", m_volumes.get_clipping_plane()); -#else - glsafe(::glColor4fv(picking_decode(id).data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL volume.first->render(); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - } - } - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL + } + } glsafe(::glEnable(GL_CULL_FACE)); } @@ -6208,20 +5786,11 @@ void GLCanvas3D::_render_main_toolbar() return; const Size cnv_size = get_canvas_size(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const float top = 0.5f * (float)cnv_size.get_height(); -#else - const float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - const float top = 0.5f * (float)cnv_size.get_height() * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLToolbar& collapse_toolbar = wxGetApp().plater()->get_collapse_toolbar(); const float collapse_toolbar_width = collapse_toolbar.is_enabled() ? collapse_toolbar.get_width() : 0.0f; -#if ENABLE_LEGACY_OPENGL_REMOVAL const float left = -0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar_width); -#else - const float left = -0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar_width) * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_main_toolbar.set_position(top, left); m_main_toolbar.render(*this); @@ -6235,20 +5804,10 @@ void GLCanvas3D::_render_undoredo_toolbar() return; const Size cnv_size = get_canvas_size(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const float top = 0.5f * (float)cnv_size.get_height(); -#else - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - - const float top = 0.5f * (float)cnv_size.get_height() * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLToolbar& collapse_toolbar = wxGetApp().plater()->get_collapse_toolbar(); const float collapse_toolbar_width = collapse_toolbar.is_enabled() ? collapse_toolbar.get_width() : 0.0f; -#if ENABLE_LEGACY_OPENGL_REMOVAL const float left = m_main_toolbar.get_width() - 0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar_width); -#else - const float left = (m_main_toolbar.get_width() - 0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar_width)) * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_undoredo_toolbar.set_position(top, left); m_undoredo_toolbar.render(*this); @@ -6262,15 +5821,8 @@ void GLCanvas3D::_render_collapse_toolbar() const const Size cnv_size = get_canvas_size(); const float band = m_layers_editing.is_enabled() ? (wxGetApp().imgui()->get_style_scaling() * LayersEditing::THICKNESS_BAR_WIDTH) : 0.0; -#if ENABLE_LEGACY_OPENGL_REMOVAL const float top = 0.5f * (float)cnv_size.get_height(); const float left = 0.5f * (float)cnv_size.get_width() - collapse_toolbar.get_width() - band; -#else - const float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - - const float top = 0.5f * (float)cnv_size.get_height() * inv_zoom; - const float left = (0.5f * (float)cnv_size.get_width() - (float)collapse_toolbar.get_width() - band) * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL collapse_toolbar.set_position(top, left); collapse_toolbar.render(*this); @@ -6294,17 +5846,9 @@ void GLCanvas3D::_render_view_toolbar() const #endif // ENABLE_RETINA_GL const Size cnv_size = get_canvas_size(); -#if ENABLE_LEGACY_OPENGL_REMOVAL // places the toolbar on the bottom-left corner of the 3d scene const float top = -0.5f * (float)cnv_size.get_height() + view_toolbar.get_height(); const float left = -0.5f * (float)cnv_size.get_width(); -#else - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - - // places the toolbar on the bottom-left corner of the 3d scene - float top = (-0.5f * (float)cnv_size.get_height() + view_toolbar.get_height()) * inv_zoom; - float left = -0.5f * (float)cnv_size.get_width() * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL view_toolbar.set_position(top, left); view_toolbar.render(*this); } @@ -6320,7 +5864,6 @@ void GLCanvas3D::_render_camera_target() #endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(2.0f)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Vec3f& target = wxGetApp().plater()->get_camera().get_target().cast(); m_camera_target.target = target.cast(); @@ -6362,7 +5905,6 @@ void GLCanvas3D::_render_camera_target() #endif // ENABLE_GL_CORE_PROFILE if (shader != nullptr) { shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * Geometry::translation_transform(m_camera_target.target)); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); @@ -6372,29 +5914,11 @@ void GLCanvas3D::_render_camera_target() shader->set_uniform("width", 0.5f); shader->set_uniform("gap_size", 0.0f); #endif // ENABLE_GL_CORE_PROFILE -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (int i = 0; i < 3; ++i) { m_camera_target.axis[i].render(); } shader->stop_using(); } -#else - ::glBegin(GL_LINES); - const Vec3d& target = wxGetApp().plater()->get_camera().get_target(); - // draw line for x axis - ::glColor3f(1.0f, 0.0f, 0.0f); - ::glVertex3d(target.x() - half_length, target.y(), target.z()); - ::glVertex3d(target.x() + half_length, target.y(), target.z()); - // draw line for y axis - ::glColor3f(0.0f, 1.0f, 0.0f); - ::glVertex3d(target.x(), target.y() - half_length, target.z()); - ::glVertex3d(target.x(), target.y() + half_length, target.z()); - // draw line for z axis - ::glColor3f(0.0f, 0.0f, 1.0f); - ::glVertex3d(target.x(), target.y(), target.z() - half_length); - ::glVertex3d(target.x(), target.y(), target.z() + half_length); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } #endif // ENABLE_SHOW_CAMERA_TARGET @@ -6417,52 +5941,29 @@ void GLCanvas3D::_render_sla_slices() if (!obj->is_step_done(slaposSliceSupports)) continue; -#if ENABLE_LEGACY_OPENGL_REMOVAL SlaCap::ObjectIdToModelsMap::iterator it_caps_bottom = m_sla_caps[0].triangles.find(i); SlaCap::ObjectIdToModelsMap::iterator it_caps_top = m_sla_caps[1].triangles.find(i); -#else - SlaCap::ObjectIdToTrianglesMap::iterator it_caps_bottom = m_sla_caps[0].triangles.find(i); - SlaCap::ObjectIdToTrianglesMap::iterator it_caps_top = m_sla_caps[1].triangles.find(i); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (it_caps_bottom == m_sla_caps[0].triangles.end()) it_caps_bottom = m_sla_caps[0].triangles.emplace(i, SlaCap::Triangles()).first; if (!m_sla_caps[0].matches(clip_min_z)) { m_sla_caps[0].z = clip_min_z; -#if ENABLE_LEGACY_OPENGL_REMOVAL it_caps_bottom->second.object.reset(); it_caps_bottom->second.supports.reset(); -#else - it_caps_bottom->second.object.clear(); - it_caps_bottom->second.supports.clear(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } if (it_caps_top == m_sla_caps[1].triangles.end()) it_caps_top = m_sla_caps[1].triangles.emplace(i, SlaCap::Triangles()).first; if (!m_sla_caps[1].matches(clip_max_z)) { m_sla_caps[1].z = clip_max_z; -#if ENABLE_LEGACY_OPENGL_REMOVAL it_caps_top->second.object.reset(); it_caps_top->second.supports.reset(); -#else - it_caps_top->second.object.clear(); - it_caps_top->second.supports.clear(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel& bottom_obj_triangles = it_caps_bottom->second.object; GLModel& bottom_sup_triangles = it_caps_bottom->second.supports; GLModel& top_obj_triangles = it_caps_top->second.object; GLModel& top_sup_triangles = it_caps_top->second.supports; -#else - Pointf3s &bottom_obj_triangles = it_caps_bottom->second.object; - Pointf3s &bottom_sup_triangles = it_caps_bottom->second.supports; - Pointf3s &top_obj_triangles = it_caps_top->second.object; - Pointf3s &top_sup_triangles = it_caps_top->second.supports; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL auto init_model = [](GLModel& model, const Pointf3s& triangles, const ColorRGBA& color) { GLModel::Geometry init_data; init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 }; @@ -6484,10 +5985,6 @@ void GLCanvas3D::_render_sla_slices() if ((!bottom_obj_triangles.is_initialized() || !bottom_sup_triangles.is_initialized() || !top_obj_triangles.is_initialized() || !top_sup_triangles.is_initialized()) && !obj->get_slice_index().empty()) { -#else - if ((bottom_obj_triangles.empty() || bottom_sup_triangles.empty() || top_obj_triangles.empty() || top_sup_triangles.empty()) && - !obj->get_slice_index().empty()) { -#endif // ENABLE_LEGACY_OPENGL_REMOVAL double layer_height = print->default_object_config().layer_height.value; double initial_layer_height = print->material_config().initial_layer_height.value; bool left_handed = obj->is_left_handed(); @@ -6507,45 +6004,26 @@ void GLCanvas3D::_render_sla_slices() if (slice_low.is_valid()) { const ExPolygons& obj_bottom = slice_low.get_slice(soModel); const ExPolygons& sup_bottom = slice_low.get_slice(soSupport); -#if ENABLE_LEGACY_OPENGL_REMOVAL // calculate model bottom cap if (!bottom_obj_triangles.is_initialized() && !obj_bottom.empty()) init_model(bottom_obj_triangles, triangulate_expolygons_3d(obj_bottom, clip_min_z - plane_shift_z, !left_handed), { 1.0f, 0.37f, 0.0f, 1.0f }); // calculate support bottom cap if (!bottom_sup_triangles.is_initialized() && !sup_bottom.empty()) init_model(bottom_sup_triangles, triangulate_expolygons_3d(sup_bottom, clip_min_z - plane_shift_z, !left_handed), { 1.0f, 0.0f, 0.37f, 1.0f }); -#else - // calculate model bottom cap - if (bottom_obj_triangles.empty() && !obj_bottom.empty()) - bottom_obj_triangles = triangulate_expolygons_3d(obj_bottom, clip_min_z - plane_shift_z, ! left_handed); - // calculate support bottom cap - if (bottom_sup_triangles.empty() && !sup_bottom.empty()) - bottom_sup_triangles = triangulate_expolygons_3d(sup_bottom, clip_min_z - plane_shift_z, !left_handed); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } if (slice_high.is_valid()) { const ExPolygons& obj_top = slice_high.get_slice(soModel); const ExPolygons& sup_top = slice_high.get_slice(soSupport); -#if ENABLE_LEGACY_OPENGL_REMOVAL // calculate model top cap if (!top_obj_triangles.is_initialized() && !obj_top.empty()) init_model(top_obj_triangles, triangulate_expolygons_3d(obj_top, clip_max_z + plane_shift_z, left_handed), { 1.0f, 0.37f, 0.0f, 1.0f }); // calculate support top cap if (!top_sup_triangles.is_initialized() && !sup_top.empty()) init_model(top_sup_triangles, triangulate_expolygons_3d(sup_top, clip_max_z + plane_shift_z, left_handed), { 1.0f, 0.0f, 0.37f, 1.0f }); -#else - // calculate model top cap - if (top_obj_triangles.empty() && !obj_top.empty()) - top_obj_triangles = triangulate_expolygons_3d(obj_top, clip_max_z + plane_shift_z, left_handed); - // calculate support top cap - if (top_sup_triangles.empty() && !sup_top.empty()) - top_sup_triangles = triangulate_expolygons_3d(sup_top, clip_max_z + plane_shift_z, left_handed); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("flat"); if (shader != nullptr) { shader->start_using(); @@ -6576,39 +6054,6 @@ void GLCanvas3D::_render_sla_slices() shader->stop_using(); } -#else - if (!bottom_obj_triangles.empty() || !top_obj_triangles.empty() || !bottom_sup_triangles.empty() || !top_sup_triangles.empty()) { - for (const SLAPrintObject::Instance& inst : obj->instances()) { - glsafe(::glPushMatrix()); - glsafe(::glTranslated(unscale(inst.shift.x()), unscale(inst.shift.y()), 0.0)); - glsafe(::glRotatef(Geometry::rad2deg(inst.rotation), 0.0f, 0.0f, 1.0f)); - if (obj->is_left_handed()) - // The polygons are mirrored by X. - glsafe(::glScalef(-1.0f, 1.0f, 1.0f)); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glColor3f(1.0f, 0.37f, 0.0f)); - if (!bottom_obj_triangles.empty()) { - glsafe(::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)bottom_obj_triangles.front().data())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, bottom_obj_triangles.size())); - } - if (! top_obj_triangles.empty()) { - glsafe(::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)top_obj_triangles.front().data())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, top_obj_triangles.size())); - } - glsafe(::glColor3f(1.0f, 0.0f, 0.37f)); - if (! bottom_sup_triangles.empty()) { - glsafe(::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)bottom_sup_triangles.front().data())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, bottom_sup_triangles.size())); - } - if (! top_sup_triangles.empty()) { - glsafe(::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)top_sup_triangles.front().data())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, top_sup_triangles.size())); - } - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - glsafe(::glPopMatrix()); - } - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } @@ -6789,48 +6234,24 @@ void GLCanvas3D::_load_print_toolpaths(const BuildVolume &build_volume) skirt_height = std::min(skirt_height, print_zs.size()); print_zs.erase(print_zs.begin() + skirt_height, print_zs.end()); -#if ENABLE_LEGACY_OPENGL_REMOVAL GLVolume* volume = m_volumes.new_toolpath_volume(color); GLModel::Geometry init_data; init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; -#else - GLVolume *volume = m_volumes.new_toolpath_volume(color, VERTEX_BUFFER_RESERVE_SIZE); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (size_t i = 0; i < skirt_height; ++ i) { volume->print_zs.emplace_back(print_zs[i]); -#if ENABLE_LEGACY_OPENGL_REMOVAL volume->offsets.emplace_back(init_data.indices_count()); if (i == 0) _3DScene::extrusionentity_to_verts(print->brim(), print_zs[i], Point(0, 0), init_data); _3DScene::extrusionentity_to_verts(print->skirt(), print_zs[i], Point(0, 0), init_data); -#else - volume->offsets.emplace_back(volume->indexed_vertex_array.quad_indices.size()); - volume->offsets.emplace_back(volume->indexed_vertex_array.triangle_indices.size()); - if (i == 0) - _3DScene::extrusionentity_to_verts(print->brim(), print_zs[i], Point(0, 0), *volume); - _3DScene::extrusionentity_to_verts(print->skirt(), print_zs[i], Point(0, 0), *volume); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Ensure that no volume grows over the limits. If the volume is too large, allocate a new one. -#if ENABLE_LEGACY_OPENGL_REMOVAL if (init_data.vertices_size_bytes() > MAX_VERTEX_BUFFER_SIZE) { volume->model.init_from(std::move(init_data)); -#else - if (volume->indexed_vertex_array.vertices_and_normals_interleaved.size() > MAX_VERTEX_BUFFER_SIZE) { -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLVolume &vol = *volume; volume = m_volumes.new_toolpath_volume(vol.color); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - reserve_new_volume_finalize_old_volume(*volume, vol, m_initialized); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } -#if ENABLE_LEGACY_OPENGL_REMOVAL volume->model.init_from(std::move(init_data)); volume->is_outside = !contains(build_volume, volume->model); -#else - volume->is_outside = ! build_volume.all_paths_inside_vertices_and_normals_interleaved(volume->indexed_vertex_array.vertices_and_normals_interleaved, volume->indexed_vertex_array.bounding_box()); - volume->indexed_vertex_array.finalize_geometry(m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, const BuildVolume& build_volume, const std::vector& str_tool_colors, const std::vector& color_print_values) @@ -7002,11 +6423,9 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c // Allocate the volume before locking. GLVolume *volume = new GLVolume(color); volume->is_extrusion_path = true; -#if ENABLE_LEGACY_OPENGL_REMOVAL // to prevent sending data to gpu (in the main thread) while // editing the model geometry volume->model.disable_render(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL tbb::spin_mutex::scoped_lock lock; // Lock by ROII, so if the emplace_back() fails, the lock will be released. lock.acquire(new_volume_mutex); @@ -7024,7 +6443,6 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c tbb::blocked_range(0, ctxt.layers.size(), grain_size), [&ctxt, &new_volume, is_selected_separate_extruder, this](const tbb::blocked_range& range) { GLVolumePtrs vols; -#if ENABLE_LEGACY_OPENGL_REMOVAL std::vector geometries; auto select_geometry = [&ctxt, &geometries](size_t layer_idx, int extruder, int feature) -> GLModel::Geometry& { return geometries[ctxt.color_by_color_print() ? @@ -7034,41 +6452,21 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c feature ]; }; -#else - auto volume = [&ctxt, &vols](size_t layer_idx, int extruder, int feature) -> GLVolume& { - return *vols[ctxt.color_by_color_print() ? - ctxt.color_print_color_idx_by_layer_idx_and_extruder(layer_idx, extruder) : - ctxt.color_by_tool() ? - std::min(ctxt.number_tools() - 1, std::max(extruder - 1, 0)) : - feature - ]; - }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (ctxt.color_by_color_print() || ctxt.color_by_tool()) { for (size_t i = 0; i < ctxt.number_tools(); ++i) { vols.emplace_back(new_volume(ctxt.color_tool(i))); -#if ENABLE_LEGACY_OPENGL_REMOVAL geometries.emplace_back(GLModel::Geometry()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } else { vols = { new_volume(ctxt.color_perimeters()), new_volume(ctxt.color_infill()), new_volume(ctxt.color_support()) }; -#if ENABLE_LEGACY_OPENGL_REMOVAL geometries = { GLModel::Geometry(), GLModel::Geometry(), GLModel::Geometry() }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL assert(vols.size() == geometries.size()); for (GLModel::Geometry& g : geometries) { g.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; } -#else - for (GLVolume *vol : vols) - // Reserving number of vertices (3x position + 3x color) - vol->indexed_vertex_array.reserve(VERTEX_BUFFER_RESERVE_SIZE / 6); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (size_t idx_layer = range.begin(); idx_layer < range.end(); ++ idx_layer) { const Layer *layer = ctxt.layers[idx_layer]; @@ -7089,7 +6487,6 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c continue; } -#if ENABLE_LEGACY_OPENGL_REMOVAL for (size_t i = 0; i < vols.size(); ++i) { GLVolume* vol = vols[i]; if (vol->print_zs.empty() || vol->print_zs.back() != layer->print_z) { @@ -7097,14 +6494,6 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c vol->offsets.emplace_back(geometries[i].indices_count()); } } -#else - for (GLVolume* vol : vols) - if (vol->print_zs.empty() || vol->print_zs.back() != layer->print_z) { - vol->print_zs.emplace_back(layer->print_z); - vol->offsets.emplace_back(vol->indexed_vertex_array.quad_indices.size()); - vol->offsets.emplace_back(vol->indexed_vertex_array.triangle_indices.size()); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (const PrintInstance &instance : *ctxt.shifted_copies) { const Point © = instance.shift; @@ -7117,31 +6506,17 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c continue; } if (ctxt.has_perimeters) -#if ENABLE_LEGACY_OPENGL_REMOVAL _3DScene::extrusionentity_to_verts(layerm->perimeters(), float(layer->print_z), copy, select_geometry(idx_layer, layerm->region().config().perimeter_extruder.value, 0)); -#else - _3DScene::extrusionentity_to_verts(layerm->perimeters(), float(layer->print_z), copy, - volume(idx_layer, layerm->region().config().perimeter_extruder.value, 0)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (ctxt.has_infill) { for (const ExtrusionEntity *ee : layerm->fills()) { // fill represents infill extrusions of a single island. const auto *fill = dynamic_cast(ee); if (! fill->entities.empty()) -#if ENABLE_LEGACY_OPENGL_REMOVAL _3DScene::extrusionentity_to_verts(*fill, float(layer->print_z), copy, select_geometry(idx_layer, is_solid_infill(fill->entities.front()->role()) ? layerm->region().config().solid_infill_extruder : layerm->region().config().infill_extruder, 1)); -#else - _3DScene::extrusionentity_to_verts(*fill, float(layer->print_z), copy, - volume(idx_layer, - is_solid_infill(fill->entities.front()->role()) ? - layerm->region().config().solid_infill_extruder : - layerm->region().config().infill_extruder, - 1)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } } @@ -7149,50 +6524,27 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c const SupportLayer *support_layer = dynamic_cast(layer); if (support_layer) { for (const ExtrusionEntity *extrusion_entity : support_layer->support_fills.entities) -#if ENABLE_LEGACY_OPENGL_REMOVAL _3DScene::extrusionentity_to_verts(extrusion_entity, float(layer->print_z), copy, select_geometry(idx_layer, (extrusion_entity->role() == erSupportMaterial) ? support_layer->object()->config().support_material_extruder : support_layer->object()->config().support_material_interface_extruder, 2)); -#else - _3DScene::extrusionentity_to_verts(extrusion_entity, float(layer->print_z), copy, - volume(idx_layer, - (extrusion_entity->role() == erSupportMaterial) ? - support_layer->object()->config().support_material_extruder : - support_layer->object()->config().support_material_interface_extruder, - 2)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } } // Ensure that no volume grows over the limits. If the volume is too large, allocate a new one. for (size_t i = 0; i < vols.size(); ++i) { GLVolume &vol = *vols[i]; -#if ENABLE_LEGACY_OPENGL_REMOVAL if (geometries[i].vertices_size_bytes() > MAX_VERTEX_BUFFER_SIZE) { vol.model.init_from(std::move(geometries[i])); -#else - if (vol.indexed_vertex_array.vertices_and_normals_interleaved.size() > MAX_VERTEX_BUFFER_SIZE) { -#endif // ENABLE_LEGACY_OPENGL_REMOVAL vols[i] = new_volume(vol.color); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - reserve_new_volume_finalize_old_volume(*vols[i], vol, false); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } } -#if ENABLE_LEGACY_OPENGL_REMOVAL for (size_t i = 0; i < vols.size(); ++i) { if (!geometries[i].is_empty()) vols[i]->model.init_from(std::move(geometries[i])); } -#else - for (GLVolume *vol : vols) - // Ideally one would call vol->indexed_vertex_array.finalize() here to move the buffers to the OpenGL driver, - // but this code runs in parallel and the OpenGL driver is not thread safe. - vol->indexed_vertex_array.shrink_to_fit(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }); }); // task arena @@ -7208,14 +6560,9 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c } for (size_t i = volumes_cnt_initial; i < m_volumes.volumes.size(); ++i) { GLVolume* v = m_volumes.volumes[i]; -#if ENABLE_LEGACY_OPENGL_REMOVAL v->is_outside = !contains(build_volume, v->model); // We are done editinig the model, now it can be sent to gpu v->model.enable_render(); -#else - v->is_outside = ! build_volume.all_paths_inside_vertices_and_normals_interleaved(v->indexed_vertex_array.vertices_and_normals_interleaved, v->indexed_vertex_array.bounding_box()); - v->indexed_vertex_array.finalize_geometry(m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } BOOST_LOG_TRIVIAL(debug) << "Loading print object toolpaths in parallel - end" << m_volumes.log_memory_info() << log_memory_info(); @@ -7280,11 +6627,9 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const BuildVolume& build_volume, con auto new_volume = [this, &new_volume_mutex](const ColorRGBA& color) { auto *volume = new GLVolume(color); volume->is_extrusion_path = true; -#if ENABLE_LEGACY_OPENGL_REMOVAL // to prevent sending data to gpu (in the main thread) while // editing the model geometry volume->model.disable_render(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL tbb::spin_mutex::scoped_lock lock; lock.acquire(new_volume_mutex); m_volumes.volumes.emplace_back(volume); @@ -7298,46 +6643,29 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const BuildVolume& build_volume, con [&ctxt, &new_volume](const tbb::blocked_range& range) { // Bounding box of this slab of a wipe tower. GLVolumePtrs vols; -#if ENABLE_LEGACY_OPENGL_REMOVAL std::vector geometries; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (ctxt.color_by_tool()) { for (size_t i = 0; i < ctxt.number_tools(); ++i) { vols.emplace_back(new_volume(ctxt.color_tool(i))); -#if ENABLE_LEGACY_OPENGL_REMOVAL geometries.emplace_back(GLModel::Geometry()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } else { vols = { new_volume(ctxt.color_support()) }; -#if ENABLE_LEGACY_OPENGL_REMOVAL geometries = { GLModel::Geometry() }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL assert(vols.size() == geometries.size()); for (GLModel::Geometry& g : geometries) { g.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; } -#else - for (GLVolume *volume : vols) - // Reserving number of vertices (3x position + 3x color) - volume->indexed_vertex_array.reserve(VERTEX_BUFFER_RESERVE_SIZE / 6); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (size_t idx_layer = range.begin(); idx_layer < range.end(); ++idx_layer) { const std::vector &layer = ctxt.tool_change(idx_layer); for (size_t i = 0; i < vols.size(); ++i) { GLVolume &vol = *vols[i]; if (vol.print_zs.empty() || vol.print_zs.back() != layer.front().print_z) { vol.print_zs.emplace_back(layer.front().print_z); -#if ENABLE_LEGACY_OPENGL_REMOVAL vol.offsets.emplace_back(geometries[i].indices_count()); -#else - vol.offsets.emplace_back(vol.indexed_vertex_array.quad_indices.size()); - vol.offsets.emplace_back(vol.indexed_vertex_array.triangle_indices.size()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } for (const WipeTower::ToolChangeResult &extrusions : layer) { @@ -7380,40 +6708,23 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const BuildVolume& build_volume, con e_prev = e; } -#if ENABLE_LEGACY_OPENGL_REMOVAL _3DScene::thick_lines_to_verts(lines, widths, heights, lines.front().a == lines.back().b, extrusions.print_z, geometries[ctxt.volume_idx(e.tool, 0)]); -#else - _3DScene::thick_lines_to_verts(lines, widths, heights, lines.front().a == lines.back().b, extrusions.print_z, - *vols[ctxt.volume_idx(e.tool, 0)]); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } } for (size_t i = 0; i < vols.size(); ++i) { GLVolume &vol = *vols[i]; -#if ENABLE_LEGACY_OPENGL_REMOVAL if (geometries[i].vertices_size_bytes() > MAX_VERTEX_BUFFER_SIZE) { vol.model.init_from(std::move(geometries[i])); -#else - if (vol.indexed_vertex_array.vertices_and_normals_interleaved.size() > MAX_VERTEX_BUFFER_SIZE) { -#endif // ENABLE_LEGACY_OPENGL_REMOVAL vols[i] = new_volume(vol.color); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - reserve_new_volume_finalize_old_volume(*vols[i], vol, false); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } -#if ENABLE_LEGACY_OPENGL_REMOVAL for (size_t i = 0; i < vols.size(); ++i) { if (!geometries[i].is_empty()) vols[i]->model.init_from(std::move(geometries[i])); } -#else - for (GLVolume *vol : vols) - vol->indexed_vertex_array.shrink_to_fit(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }); BOOST_LOG_TRIVIAL(debug) << "Loading wipe tower toolpaths in parallel - finalizing results" << m_volumes.log_memory_info() << log_memory_info(); @@ -7428,14 +6739,9 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const BuildVolume& build_volume, con } for (size_t i = volumes_cnt_initial; i < m_volumes.volumes.size(); ++i) { GLVolume* v = m_volumes.volumes[i]; -#if ENABLE_LEGACY_OPENGL_REMOVAL v->is_outside = !contains(build_volume, v->model); // We are done editinig the model, now it can be sent to gpu v->model.enable_render(); -#else - v->is_outside = ! build_volume.all_paths_inside_vertices_and_normals_interleaved(v->indexed_vertex_array.vertices_and_normals_interleaved, v->indexed_vertex_array.bounding_box()); - v->indexed_vertex_array.finalize_geometry(m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } BOOST_LOG_TRIVIAL(debug) << "Loading wipe tower toolpaths in parallel - end" << m_volumes.log_memory_info() << log_memory_info(); @@ -7459,21 +6765,10 @@ void GLCanvas3D::_load_sla_shells() m_volumes.volumes.emplace_back(new GLVolume(color)); GLVolume& v = *m_volumes.volumes.back(); #if ENABLE_SMOOTH_NORMALS -#if ENABLE_LEGACY_OPENGL_REMOVAL v.model.init_from(mesh, true); #else - v.indexed_vertex_array.load_mesh(mesh, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#else -#if ENABLE_LEGACY_OPENGL_REMOVAL v.model.init_from(mesh); -#else - v.indexed_vertex_array.load_mesh(mesh); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_SMOOTH_NORMALS -#if !ENABLE_LEGACY_OPENGL_REMOVAL - v.indexed_vertex_array.finalize_geometry(m_initialized); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL v.shader_outside_printer_detection_enabled = outside_printer_detection_enabled; v.composite_id.volume_id = volume_id; v.set_instance_offset(unscale(instance.shift.x(), instance.shift.y(), 0.0)); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index b24a15bbef..41880d2b27 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -243,7 +243,7 @@ class GLCanvas3D int last_object_id{ -1 }; float last_z{ 0.0f }; LayerHeightEditActionType last_action{ LAYER_HEIGHT_EDIT_ACTION_INCREASE }; -#if ENABLE_LEGACY_OPENGL_REMOVAL + struct Profile { GLModel baseline; @@ -253,7 +253,6 @@ class GLCanvas3D std::vector old_layer_height_profile; }; Profile m_profile; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL LayersEditing() = default; ~LayersEditing(); @@ -280,9 +279,6 @@ class GLCanvas3D static float get_cursor_z_relative(const GLCanvas3D& canvas); static bool bar_rect_contains(const GLCanvas3D& canvas, float x, float y); static Rect get_bar_rect_screen(const GLCanvas3D& canvas); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - static Rect get_bar_rect_viewport(const GLCanvas3D& canvas); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL static float get_overlay_window_width() { return LayersEditing::s_overlay_window_width; } float object_max_z() const { return m_object_max_z; } @@ -292,13 +288,8 @@ class GLCanvas3D private: bool is_initialized() const; void generate_layer_height_texture(); -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_active_object_annotations(const GLCanvas3D& canvas); void render_profile(const GLCanvas3D& canvas); -#else - void render_active_object_annotations(const GLCanvas3D& canvas, const Rect& bar_rect); - void render_profile(const Rect& bar_rect); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void update_slicing_parameters(); static float thickness_bar_width(const GLCanvas3D &canvas); @@ -345,7 +336,6 @@ class GLCanvas3D struct SlaCap { -#if ENABLE_LEGACY_OPENGL_REMOVAL struct Triangles { GLModel object; @@ -354,16 +344,6 @@ class GLCanvas3D typedef std::map ObjectIdToModelsMap; double z; ObjectIdToModelsMap triangles; -#else - struct Triangles - { - Pointf3s object; - Pointf3s supports; - }; - typedef std::map ObjectIdToTrianglesMap; - double z; - ObjectIdToTrianglesMap triangles; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL SlaCap() { reset(); } void reset() { z = DBL_MAX; triangles.clear(); } @@ -638,7 +618,6 @@ private: } m_gizmo_highlighter; -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_SHOW_CAMERA_TARGET struct CameraTarget { @@ -649,7 +628,6 @@ private: CameraTarget m_camera_target; #endif // ENABLE_SHOW_CAMERA_TARGET GLModel m_background; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL public: explicit GLCanvas3D(wxGLCanvas* canvas, Bed3D &bed); @@ -985,13 +963,8 @@ private: void _picking_pass(); void _rectangular_selection_picking_pass(); void _render_background(); -#if ENABLE_LEGACY_OPENGL_REMOVAL void _render_bed(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_axes); void _render_bed_for_picking(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom); -#else - void _render_bed(bool bottom, bool show_axes); - void _render_bed_for_picking(bool bottom); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void _render_objects(GLVolumeCollection::ERenderType type); void _render_gcode(); void _render_gcode_cog(); diff --git a/src/slic3r/GUI/GLModel.cpp b/src/slic3r/GUI/GLModel.cpp index 2d4d25f8c8..61736f9ac9 100644 --- a/src/slic3r/GUI/GLModel.cpp +++ b/src/slic3r/GUI/GLModel.cpp @@ -12,10 +12,8 @@ #include "libslic3r/TriangleMesh.hpp" #include "libslic3r/Model.hpp" #include "libslic3r/Polygon.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "libslic3r/BuildVolume.hpp" #include "libslic3r/Geometry/ConvexHull.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GLMODEL_STATISTICS #include @@ -24,20 +22,17 @@ #include #include -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_SMOOTH_NORMALS #include #include #include #endif // ENABLE_SMOOTH_NORMALS -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include namespace Slic3r { namespace GUI { -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_SMOOTH_NORMALS static void smooth_normals_corner(const TriangleMesh& mesh, std::vector& normals) { @@ -64,9 +59,7 @@ static void smooth_normals_corner(const TriangleMesh& mesh, std::vector()); } } -#else - if (!m_render_data.empty()) // call reset() if you want to reuse this model - return; - - for (const Geometry::Entity& entity : data.entities) { - if (entity.positions.empty() || entity.indices.empty()) - continue; - - assert(entity.normals.empty() || entity.normals.size() == entity.positions.size()); - - RenderData rdata; - rdata.type = entity.type; - rdata.color = entity.color; - - // vertices/normals data - std::vector vertices(6 * entity.positions.size()); - for (size_t i = 0; i < entity.positions.size(); ++i) { - const size_t offset = i * 6; - ::memcpy(static_cast(&vertices[offset]), static_cast(entity.positions[i].data()), 3 * sizeof(float)); - if (!entity.normals.empty()) - ::memcpy(static_cast(&vertices[3 + offset]), static_cast(entity.normals[i].data()), 3 * sizeof(float)); - } - - // indices data - std::vector indices = entity.indices; - - rdata.indices_count = static_cast(indices.size()); - - // update bounding box - for (size_t i = 0; i < entity.positions.size(); ++i) { - m_bounding_box.merge(entity.positions[i].cast()); - } - - send_to_gpu(rdata, vertices, indices); - m_render_data.emplace_back(rdata); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_SMOOTH_NORMALS void GLModel::init_from(const TriangleMesh& mesh, bool smooth_normals) { @@ -629,11 +560,7 @@ void GLModel::init_from(const TriangleMesh& mesh) #endif // ENABLE_SMOOTH_NORMALS void GLModel::init_from(const indexed_triangle_set& its) -#else -void GLModel::init_from(const indexed_triangle_set& its, const BoundingBoxf3 &bbox) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { -#if ENABLE_LEGACY_OPENGL_REMOVAL if (is_initialized()) { // call reset() if you want to reuse this model assert(false); @@ -667,49 +594,10 @@ void GLModel::init_from(const indexed_triangle_set& its, const BoundingBoxf3 &bb for (size_t i = 0; i < vertices_count(); ++i) { m_bounding_box.merge(data.extract_position_3(i).cast()); } -#else - if (!m_render_data.empty()) // call reset() if you want to reuse this model - return; - - RenderData data; - data.type = EPrimitiveType::Triangles; - - std::vector vertices = std::vector(18 * its.indices.size()); - std::vector indices = std::vector(3 * its.indices.size()); - - unsigned int vertices_count = 0; - for (uint32_t i = 0; i < its.indices.size(); ++i) { - stl_triangle_vertex_indices face = its.indices[i]; - stl_vertex vertex[3] = { its.vertices[face[0]], its.vertices[face[1]], its.vertices[face[2]] }; - stl_vertex n = face_normal_normalized(vertex); - for (size_t j = 0; j < 3; ++ j) { - size_t offset = i * 18 + j * 6; - ::memcpy(static_cast(&vertices[offset]), static_cast(vertex[j].data()), 3 * sizeof(float)); - ::memcpy(static_cast(&vertices[3 + offset]), static_cast(n.data()), 3 * sizeof(float)); - } - for (size_t j = 0; j < 3; ++j) - indices[i * 3 + j] = vertices_count + j; - vertices_count += 3; - } - - data.indices_count = static_cast(indices.size()); - m_bounding_box = bbox; - - send_to_gpu(data, vertices, indices); - m_render_data.emplace_back(data); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if !ENABLE_LEGACY_OPENGL_REMOVAL -void GLModel::init_from(const indexed_triangle_set& its) -{ - init_from(its, bounding_box(its)); -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - void GLModel::init_from(const Polygons& polygons, float z) { -#if ENABLE_LEGACY_OPENGL_REMOVAL if (is_initialized()) { // call reset() if you want to reuse this model assert(false); @@ -749,31 +637,6 @@ void GLModel::init_from(const Polygons& polygons, float z) for (size_t i = 0; i < vertices_count(); ++i) { m_bounding_box.merge(data.extract_position_3(i).cast()); } -#else - auto append_polygon = [](const Polygon& polygon, float z, GUI::GLModel::Geometry& data) { - if (!polygon.empty()) { - GUI::GLModel::Geometry::Entity entity; - entity.type = GUI::GLModel::EPrimitiveType::LineLoop; - // contour - entity.positions.reserve(polygon.size() + 1); - entity.indices.reserve(polygon.size() + 1); - unsigned int id = 0; - for (const Point& p : polygon) { - Vec3f position = unscale(p.x(), p.y(), 0.0).cast(); - position.z() = z; - entity.positions.emplace_back(position); - entity.indices.emplace_back(id++); - } - data.entities.emplace_back(entity); - } - }; - - Geometry init_data; - for (const Polygon& polygon : polygons) { - append_polygon(polygon, z, init_data); - } - init_from(init_data); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } bool GLModel::init_from_file(const std::string& filename) @@ -792,37 +655,15 @@ bool GLModel::init_from_file(const std::string& filename) return false; } -#if ENABLE_LEGACY_OPENGL_REMOVAL init_from(model.mesh()); -#else - const TriangleMesh& mesh = model.mesh(); - init_from(mesh.its, mesh.bounding_box()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_filename = filename; return true; } -#if !ENABLE_LEGACY_OPENGL_REMOVAL -void GLModel::set_color(int entity_id, const ColorRGBA& color) -{ - for (size_t i = 0; i < m_render_data.size(); ++i) { - if (entity_id == -1 || static_cast(i) == entity_id) - m_render_data[i].color = color; - } -} - -ColorRGBA GLModel::get_color(size_t entity_id) const -{ - if (entity_id < 0 || entity_id >= m_render_data.size()) return ColorRGBA{}; - return m_render_data[entity_id].color; -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - void GLModel::reset() { -#if ENABLE_LEGACY_OPENGL_REMOVAL // release gpu memory if (m_render_data.ibo_id > 0) { glsafe(::glDeleteBuffers(1, &m_render_data.ibo_id)); @@ -849,22 +690,10 @@ void GLModel::reset() m_render_data.indices_count = 0; m_render_data.geometry.vertices = std::vector(); m_render_data.geometry.indices = std::vector(); -#else - for (RenderData& data : m_render_data) { - // release gpu memory - if (data.ibo_id > 0) - glsafe(::glDeleteBuffers(1, &data.ibo_id)); - if (data.vbo_id > 0) - glsafe(::glDeleteBuffers(1, &data.vbo_id)); - } - - m_render_data.clear(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_bounding_box = BoundingBoxf3(); m_filename = std::string(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL static GLenum get_primitive_mode(const GLModel::Geometry::Format& format) { switch (format.type) @@ -892,54 +721,10 @@ static GLenum get_index_type(const GLModel::Geometry& data) } void GLModel::render() -#else -void GLModel::render() const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { -#if ENABLE_LEGACY_OPENGL_REMOVAL render(std::make_pair(0, indices_count())); -#else - GLShaderProgram* shader = wxGetApp().get_current_shader(); - - for (const RenderData& data : m_render_data) { - if (data.vbo_id == 0 || data.ibo_id == 0) - continue; - - GLenum mode; - switch (data.type) - { - default: - case EPrimitiveType::Triangles: { mode = GL_TRIANGLES; break; } - case EPrimitiveType::Lines: { mode = GL_LINES; break; } - case EPrimitiveType::LineStrip: { mode = GL_LINE_STRIP; break; } - case EPrimitiveType::LineLoop: { mode = GL_LINE_LOOP; break; } - } - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, data.vbo_id)); - glsafe(::glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), (const void*)0)); - glsafe(::glNormalPointer(GL_FLOAT, 6 * sizeof(float), (const void*)(3 * sizeof(float)))); - - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); - - if (shader != nullptr) - shader->set_uniform("uniform_color", data.color); - else - glsafe(::glColor4fv(data.color.data())); - - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.ibo_id)); - glsafe(::glDrawElements(mode, static_cast(data.indices_count), GL_UNSIGNED_INT, (const void*)0)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLModel::render(const std::pair& range) { if (m_render_disabled) @@ -1048,19 +833,13 @@ void GLModel::render(const std::pair& range) ++s_statistics.render_calls; #endif // ENABLE_GLMODEL_STATISTICS } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instances_count) -#else -void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instances_count) const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (instances_vbo == 0 || instances_count == 0) return; GLShaderProgram* shader = wxGetApp().get_current_shader(); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (shader == nullptr || !boost::algorithm::iends_with(shader->get_name(), "_instanced")) return; @@ -1080,19 +859,6 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance if (!send_to_gpu()) return; } -#else - assert(shader == nullptr || boost::algorithm::iends_with(shader->get_name(), "_instanced")); - - // vertex attributes - GLint position_id = (shader != nullptr) ? shader->get_attrib_location("v_position") : -1; - GLint normal_id = (shader != nullptr) ? shader->get_attrib_location("v_normal") : -1; - assert(position_id != -1 && normal_id != -1); - - // instance attributes - GLint offset_id = (shader != nullptr) ? shader->get_attrib_location("i_offset") : -1; - GLint scales_id = (shader != nullptr) ? shader->get_attrib_location("i_scales") : -1; - assert(offset_id != -1 && scales_id != -1); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) @@ -1100,7 +866,6 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance #endif // ENABLE_GL_CORE_PROFILE glsafe(::glBindBuffer(GL_ARRAY_BUFFER, instances_vbo)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const size_t instance_stride = 5 * sizeof(float); glsafe(::glVertexAttribPointer(offset_id, 3, GL_FLOAT, GL_FALSE, instance_stride, (const void*)0)); glsafe(::glEnableVertexAttribArray(offset_id)); @@ -1109,20 +874,7 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance glsafe(::glVertexAttribPointer(scales_id, 2, GL_FLOAT, GL_FALSE, instance_stride, (const void*)(3 * sizeof(float)))); glsafe(::glEnableVertexAttribArray(scales_id)); glsafe(::glVertexAttribDivisor(scales_id, 1)); -#else - if (offset_id != -1) { - glsafe(::glVertexAttribPointer(offset_id, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (GLvoid*)0)); - glsafe(::glEnableVertexAttribArray(offset_id)); - glsafe(::glVertexAttribDivisor(offset_id, 1)); - } - if (scales_id != -1) { - glsafe(::glVertexAttribPointer(scales_id, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (GLvoid*)(3 * sizeof(float)))); - glsafe(::glEnableVertexAttribArray(scales_id)); - glsafe(::glVertexAttribDivisor(scales_id, 1)); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL const Geometry& data = m_render_data.geometry; const GLenum mode = get_primitive_mode(data.format); @@ -1164,51 +916,6 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance glsafe(::glDisableVertexAttribArray(scales_id)); glsafe(::glDisableVertexAttribArray(offset_id)); -#else - for (const RenderData& data : m_render_data) { - if (data.vbo_id == 0 || data.ibo_id == 0) - continue; - - GLenum mode; - switch (data.type) - { - default: - case EPrimitiveType::Triangles: { mode = GL_TRIANGLES; break; } - case EPrimitiveType::Lines: { mode = GL_LINES; break; } - case EPrimitiveType::LineStrip: { mode = GL_LINE_STRIP; break; } - case EPrimitiveType::LineLoop: { mode = GL_LINE_LOOP; break; } - } - - if (shader != nullptr) - shader->set_uniform("uniform_color", data.color); - else - glsafe(::glColor4fv(data.color.data())); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, data.vbo_id)); - if (position_id != -1) { - glsafe(::glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (GLvoid*)0)); - glsafe(::glEnableVertexAttribArray(position_id)); - } - if (normal_id != -1) { - glsafe(::glVertexAttribPointer(normal_id, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (GLvoid*)(3 * sizeof(float)))); - glsafe(::glEnableVertexAttribArray(normal_id)); - } - - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.ibo_id)); - glsafe(::glDrawElementsInstanced(mode, static_cast(data.indices_count), GL_UNSIGNED_INT, (const void*)0, instances_count)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - - if (normal_id != -1) - glsafe(::glDisableVertexAttribArray(normal_id)); - if (position_id != -1) - glsafe(::glDisableVertexAttribArray(position_id)); - } - - if (scales_id != -1) - glsafe(::glDisableVertexAttribArray(scales_id)); - if (offset_id != -1) - glsafe(::glDisableVertexAttribArray(offset_id)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); #if ENABLE_GL_CORE_PROFILE @@ -1221,7 +928,6 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance #endif // ENABLE_GLMODEL_STATISTICS } -#if ENABLE_LEGACY_OPENGL_REMOVAL bool GLModel::send_to_gpu() { if (m_render_data.vbo_id > 0 || m_render_data.ibo_id > 0) { @@ -1361,27 +1067,6 @@ void GLModel::render_statistics() } #endif // ENABLE_GLMODEL_STATISTICS -#else -void GLModel::send_to_gpu(RenderData& data, const std::vector& vertices, const std::vector& indices) -{ - assert(data.vbo_id == 0); - assert(data.ibo_id == 0); - - // vertex data -> send to gpu - glsafe(::glGenBuffers(1, &data.vbo_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, data.vbo_id)); - glsafe(::glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), vertices.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - - // indices data -> send to gpu - glsafe(::glGenBuffers(1, &data.ibo_id)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.ibo_id)); - glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), indices.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL template inline bool all_vertices_inside(const GLModel::Geometry& geometry, Fn fn) { @@ -1435,33 +1120,15 @@ bool contains(const BuildVolume& volume, const GLModel& model, bool ignore_botto return true; } } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLModel::Geometry stilized_arrow(unsigned int resolution, float tip_radius, float tip_height, float stem_radius, float stem_height) { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - auto append_vertex = [](GLModel::Geometry::Entity& entity, const Vec3f& position, const Vec3f& normal) { - entity.positions.emplace_back(position); - entity.normals.emplace_back(normal); - }; - auto append_indices = [](GLModel::Geometry::Entity& entity, unsigned int v1, unsigned int v2, unsigned int v3) { - entity.indices.emplace_back(v1); - entity.indices.emplace_back(v2); - entity.indices.emplace_back(v3); - }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - resolution = std::max(4, resolution); GLModel::Geometry data; -#if ENABLE_LEGACY_OPENGL_REMOVAL data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; data.reserve_vertices(6 * resolution + 2); data.reserve_indices(6 * resolution * 3); -#else - GLModel::Geometry::Entity entity; - entity.type = GLModel::EPrimitiveType::Triangles; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const float angle_step = 2.0f * float(PI) / float(resolution); std::vector cosines(resolution); @@ -1476,7 +1143,6 @@ GLModel::Geometry stilized_arrow(unsigned int resolution, float tip_radius, floa const float total_height = tip_height + stem_height; // tip vertices/normals -#if ENABLE_LEGACY_OPENGL_REMOVAL data.add_vertex(Vec3f(0.0f, 0.0f, total_height), (Vec3f)Vec3f::UnitZ()); for (unsigned int i = 0; i < resolution; ++i) { data.add_vertex(Vec3f(tip_radius * sines[i], tip_radius * cosines[i], stem_height), Vec3f(sines[i], cosines[i], 0.0f)); @@ -1535,97 +1201,18 @@ GLModel::Geometry stilized_arrow(unsigned int resolution, float tip_radius, floa const unsigned int v3 = (i < resolution - 1) ? i + 5 * resolution + 3 : 5 * resolution + 2; data.add_triangle(5 * resolution + 1, v3, i + 5 * resolution + 2); } -#else - append_vertex(entity, { 0.0f, 0.0f, total_height }, Vec3f::UnitZ()); - for (unsigned int i = 0; i < resolution; ++i) { - append_vertex(entity, { tip_radius * sines[i], tip_radius * cosines[i], stem_height }, { sines[i], cosines[i], 0.0f }); - } - - // tip triangles - for (unsigned int i = 0; i < resolution; ++i) { - const int v3 = (i < resolution - 1) ? i + 2 : 1; - append_indices(entity, 0, i + 1, v3); - } - - // tip cap outer perimeter vertices - for (unsigned int i = 0; i < resolution; ++i) { - append_vertex(entity, { tip_radius * sines[i], tip_radius * cosines[i], stem_height }, -Vec3f::UnitZ()); - } - - // tip cap inner perimeter vertices - for (unsigned int i = 0; i < resolution; ++i) { - append_vertex(entity, { stem_radius * sines[i], stem_radius * cosines[i], stem_height }, -Vec3f::UnitZ()); - } - - // tip cap triangles - for (unsigned int i = 0; i < resolution; ++i) { - const unsigned int v2 = (i < resolution - 1) ? i + resolution + 2 : resolution + 1; - const unsigned int v3 = (i < resolution - 1) ? i + 2 * resolution + 2 : 2 * resolution + 1; - append_indices(entity, i + resolution + 1, v3, v2); - append_indices(entity, i + resolution + 1, i + 2 * resolution + 1, v3); - } - - // stem bottom vertices - for (unsigned int i = 0; i < resolution; ++i) { - append_vertex(entity, { stem_radius * sines[i], stem_radius * cosines[i], stem_height }, { sines[i], cosines[i], 0.0f }); - } - - // stem top vertices - for (unsigned int i = 0; i < resolution; ++i) { - append_vertex(entity, { stem_radius * sines[i], stem_radius * cosines[i], 0.0f }, { sines[i], cosines[i], 0.0f }); - } - - // stem triangles - for (unsigned int i = 0; i < resolution; ++i) { - const int unsigned v2 = (i < resolution - 1) ? i + 3 * resolution + 2 : 3 * resolution + 1; - const int unsigned v3 = (i < resolution - 1) ? i + 4 * resolution + 2 : 4 * resolution + 1; - append_indices(entity, i + 3 * resolution + 1, v3, v2); - append_indices(entity, i + 3 * resolution + 1, i + 4 * resolution + 1, v3); - } - - // stem cap vertices - append_vertex(entity, Vec3f::Zero(), -Vec3f::UnitZ()); - for (unsigned int i = 0; i < resolution; ++i) { - append_vertex(entity, { stem_radius * sines[i], stem_radius * cosines[i], 0.0f }, -Vec3f::UnitZ()); - } - - // stem cap triangles - for (unsigned int i = 0; i < resolution; ++i) { - const unsigned int v3 = (i < resolution - 1) ? i + 5 * resolution + 3 : 5 * resolution + 2; - append_indices(entity, 5 * resolution + 1, v3, i + 5 * resolution + 2); - } - - data.entities.emplace_back(entity); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return data; } GLModel::Geometry circular_arrow(unsigned int resolution, float radius, float tip_height, float tip_width, float stem_width, float thickness) { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - auto append_vertex = [](GLModel::Geometry::Entity& entity, const Vec3f& position, const Vec3f& normal) { - entity.positions.emplace_back(position); - entity.normals.emplace_back(normal); - }; - auto append_indices = [](GLModel::Geometry::Entity& entity, unsigned int v1, unsigned int v2, unsigned int v3) { - entity.indices.emplace_back(v1); - entity.indices.emplace_back(v2); - entity.indices.emplace_back(v3); - }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - resolution = std::max(2, resolution); GLModel::Geometry data; -#if ENABLE_LEGACY_OPENGL_REMOVAL data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; data.reserve_vertices(8 * (resolution + 1) + 30); data.reserve_indices((8 * resolution + 16) * 3); -#else - GLModel::Geometry::Entity entity; - entity.type = GLModel::EPrimitiveType::Triangles; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const float half_thickness = 0.5f * thickness; const float half_stem_width = 0.5f * stem_width; @@ -1635,7 +1222,6 @@ GLModel::Geometry circular_arrow(unsigned int resolution, float radius, float ti const float inner_radius = radius - half_stem_width; const float step_angle = 0.5f * float(PI) / float(resolution); -#if ENABLE_LEGACY_OPENGL_REMOVAL // tip // top face vertices data.add_vertex(Vec3f(0.0f, outer_radius, half_thickness), (Vec3f)Vec3f::UnitZ()); @@ -1779,187 +1365,22 @@ GLModel::Geometry circular_arrow(unsigned int resolution, float radius, float ti data.add_triangle(ii, ii + 1, ii + resolution + 2); data.add_triangle(ii, ii + resolution + 2, ii + resolution + 1); } -#else - // tip - // top face vertices - append_vertex(entity, { 0.0f, outer_radius, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { 0.0f, radius + half_tip_width, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { -tip_height, radius, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { 0.0f, radius - half_tip_width, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { 0.0f, inner_radius, half_thickness }, Vec3f::UnitZ()); - - // top face triangles - append_indices(entity, 0, 1, 2); - append_indices(entity, 0, 2, 4); - append_indices(entity, 4, 2, 3); - - // bottom face vertices - append_vertex(entity, { 0.0f, outer_radius, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { 0.0f, radius + half_tip_width, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { -tip_height, radius, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { 0.0f, radius - half_tip_width, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { 0.0f, inner_radius, -half_thickness }, -Vec3f::UnitZ()); - - // bottom face triangles - append_indices(entity, 5, 7, 6); - append_indices(entity, 5, 9, 7); - append_indices(entity, 9, 8, 7); - - // side faces vertices - append_vertex(entity, { 0.0f, outer_radius, -half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { 0.0f, radius + half_tip_width, -half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { 0.0f, outer_radius, half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { 0.0f, radius + half_tip_width, half_thickness }, Vec3f::UnitX()); - - Vec3f normal(-half_tip_width, tip_height, 0.0f); - normal.normalize(); - append_vertex(entity, { 0.0f, radius + half_tip_width, -half_thickness }, normal); - append_vertex(entity, { -tip_height, radius, -half_thickness }, normal); - append_vertex(entity, { 0.0f, radius + half_tip_width, half_thickness }, normal); - append_vertex(entity, { -tip_height, radius, half_thickness }, normal); - - normal = Vec3f(-half_tip_width, -tip_height, 0.0f); - normal.normalize(); - append_vertex(entity, { -tip_height, radius, -half_thickness }, normal); - append_vertex(entity, { 0.0f, radius - half_tip_width, -half_thickness }, normal); - append_vertex(entity, { -tip_height, radius, half_thickness }, normal); - append_vertex(entity, { 0.0f, radius - half_tip_width, half_thickness }, normal); - - append_vertex(entity, { 0.0f, radius - half_tip_width, -half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { 0.0f, inner_radius, -half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { 0.0f, radius - half_tip_width, half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { 0.0f, inner_radius, half_thickness }, Vec3f::UnitX()); - - // side face triangles - for (int i = 0; i < 4; ++i) { - const int ii = i * 4; - append_indices(entity, 10 + ii, 11 + ii, 13 + ii); - append_indices(entity, 10 + ii, 13 + ii, 12 + ii); - } - - // stem - // top face vertices - for (unsigned int i = 0; i <= resolution; ++i) { - const float angle = static_cast(i) * step_angle; - append_vertex(entity, { inner_radius * ::sin(angle), inner_radius * ::cos(angle), half_thickness }, Vec3f::UnitZ()); - } - - for (unsigned int i = 0; i <= resolution; ++i) { - const float angle = static_cast(i) * step_angle; - append_vertex(entity, { outer_radius * ::sin(angle), outer_radius * ::cos(angle), half_thickness }, Vec3f::UnitZ()); - } - - // top face triangles - for (unsigned int i = 0; i < resolution; ++i) { - append_indices(entity, 26 + i, 27 + i, 27 + resolution + i); - append_indices(entity, 27 + i, 28 + resolution + i, 27 + resolution + i); - } - - // bottom face vertices - for (unsigned int i = 0; i <= resolution; ++i) { - const float angle = static_cast(i) * step_angle; - append_vertex(entity, { inner_radius * ::sin(angle), inner_radius * ::cos(angle), -half_thickness }, -Vec3f::UnitZ()); - } - - for (unsigned int i = 0; i <= resolution; ++i) { - const float angle = static_cast(i) * step_angle; - append_vertex(entity, { outer_radius * ::sin(angle), outer_radius * ::cos(angle), -half_thickness }, -Vec3f::UnitZ()); - } - - // bottom face triangles - for (unsigned int i = 0; i < resolution; ++i) { - append_indices(entity, 28 + 2 * resolution + i, 29 + 3 * resolution + i, 29 + 2 * resolution + i); - append_indices(entity, 29 + 2 * resolution + i, 29 + 3 * resolution + i, 30 + 3 * resolution + i); - } - - // side faces vertices and triangles - for (unsigned int i = 0; i <= resolution; ++i) { - const float angle = static_cast(i) * step_angle; - const float c = ::cos(angle); - const float s = ::sin(angle); - append_vertex(entity, { inner_radius * s, inner_radius * c, -half_thickness }, { -s, -c, 0.0f }); - } - - for (unsigned int i = 0; i <= resolution; ++i) { - const float angle = static_cast(i) * step_angle; - const float c = ::cos(angle); - const float s = ::sin(angle); - append_vertex(entity, { inner_radius * s, inner_radius * c, half_thickness }, { -s, -c, 0.0f }); - } - - unsigned int first_id = 26 + 4 * (resolution + 1); - for (unsigned int i = 0; i < resolution; ++i) { - const unsigned int ii = first_id + i; - append_indices(entity, ii, ii + 1, ii + resolution + 2); - append_indices(entity, ii, ii + resolution + 2, ii + resolution + 1); - } - - append_vertex(entity, { inner_radius, 0.0f, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { outer_radius, 0.0f, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { inner_radius, 0.0f, half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { outer_radius, 0.0f, half_thickness }, -Vec3f::UnitY()); - - first_id = 26 + 6 * (resolution + 1); - append_indices(entity, first_id, first_id + 1, first_id + 3); - append_indices(entity, first_id, first_id + 3, first_id + 2); - - for (int i = int(resolution); i >= 0; --i) { - const float angle = static_cast(i) * step_angle; - const float c = ::cos(angle); - const float s = ::sin(angle); - append_vertex(entity, { outer_radius * s, outer_radius * c, -half_thickness }, { s, c, 0.0f }); - } - - for (int i = int(resolution); i >= 0; --i) { - const float angle = static_cast(i) * step_angle; - const float c = ::cos(angle); - const float s = ::sin(angle); - append_vertex(entity, { outer_radius * s, outer_radius * c, +half_thickness }, { s, c, 0.0f }); - } - - first_id = 30 + 6 * (resolution + 1); - for (unsigned int i = 0; i < resolution; ++i) { - const unsigned int ii = first_id + i; - append_indices(entity, ii, ii + 1, ii + resolution + 2); - append_indices(entity, ii, ii + resolution + 2, ii + resolution + 1); - } - - data.entities.emplace_back(entity); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return data; } GLModel::Geometry straight_arrow(float tip_width, float tip_height, float stem_width, float stem_height, float thickness) { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - auto append_vertex = [](GLModel::Geometry::Entity& entity, const Vec3f& position, const Vec3f& normal) { - entity.positions.emplace_back(position); - entity.normals.emplace_back(normal); - }; - auto append_indices = [](GLModel::Geometry::Entity& entity, unsigned int v1, unsigned int v2, unsigned int v3) { - entity.indices.emplace_back(v1); - entity.indices.emplace_back(v2); - entity.indices.emplace_back(v3); - }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - GLModel::Geometry data; -#if ENABLE_LEGACY_OPENGL_REMOVAL data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; data.reserve_vertices(42); data.reserve_indices(72); -#else - GLModel::Geometry::Entity entity; - entity.type = GLModel::EPrimitiveType::Triangles; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const float half_thickness = 0.5f * thickness; const float half_stem_width = 0.5f * stem_width; const float half_tip_width = 0.5f * tip_width; const float total_height = tip_height + stem_height; -#if ENABLE_LEGACY_OPENGL_REMOVAL // top face vertices data.add_vertex(Vec3f(half_stem_width, 0.0f, half_thickness), (Vec3f)Vec3f::UnitZ()); data.add_vertex(Vec3f(half_stem_width, stem_height, half_thickness), (Vec3f)Vec3f::UnitZ()); @@ -2038,88 +1459,6 @@ GLModel::Geometry straight_arrow(float tip_width, float tip_height, float stem_w data.add_triangle(14 + ii, 15 + ii, 17 + ii); data.add_triangle(14 + ii, 17 + ii, 16 + ii); } -#else - // top face vertices - append_vertex(entity, { half_stem_width, 0.0, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { half_stem_width, stem_height, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { half_tip_width, stem_height, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { 0.0, total_height, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { -half_tip_width, stem_height, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { -half_stem_width, stem_height, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { -half_stem_width, 0.0, half_thickness }, Vec3f::UnitZ()); - - // top face triangles - append_indices(entity, 0, 1, 6); - append_indices(entity, 6, 1, 5); - append_indices(entity, 4, 5, 3); - append_indices(entity, 5, 1, 3); - append_indices(entity, 1, 2, 3); - - // bottom face vertices - append_vertex(entity, { half_stem_width, 0.0, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { half_stem_width, stem_height, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { half_tip_width, stem_height, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { 0.0, total_height, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { -half_tip_width, stem_height, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { -half_stem_width, stem_height, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { -half_stem_width, 0.0, -half_thickness }, -Vec3f::UnitZ()); - - // bottom face triangles - append_indices(entity, 7, 13, 8); - append_indices(entity, 13, 12, 8); - append_indices(entity, 12, 11, 10); - append_indices(entity, 8, 12, 10); - append_indices(entity, 9, 8, 10); - - // side faces vertices - append_vertex(entity, { half_stem_width, 0.0, -half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { half_stem_width, stem_height, -half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { half_stem_width, 0.0, half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { half_stem_width, stem_height, half_thickness }, Vec3f::UnitX()); - - append_vertex(entity, { half_stem_width, stem_height, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { half_tip_width, stem_height, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { half_stem_width, stem_height, half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { half_tip_width, stem_height, half_thickness }, -Vec3f::UnitY()); - - Vec3f normal(tip_height, half_tip_width, 0.0f); - normal.normalize(); - append_vertex(entity, { half_tip_width, stem_height, -half_thickness }, normal); - append_vertex(entity, { 0.0, total_height, -half_thickness }, normal); - append_vertex(entity, { half_tip_width, stem_height, half_thickness }, normal); - append_vertex(entity, { 0.0, total_height, half_thickness }, normal); - - normal = Vec3f(-tip_height, half_tip_width, 0.0f); - normal.normalize(); - append_vertex(entity, { 0.0, total_height, -half_thickness }, normal); - append_vertex(entity, { -half_tip_width, stem_height, -half_thickness }, normal); - append_vertex(entity, { 0.0, total_height, half_thickness }, normal); - append_vertex(entity, { -half_tip_width, stem_height, half_thickness }, normal); - - append_vertex(entity, { -half_tip_width, stem_height, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { -half_stem_width, stem_height, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { -half_tip_width, stem_height, half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { -half_stem_width, stem_height, half_thickness }, -Vec3f::UnitY()); - - append_vertex(entity, { -half_stem_width, stem_height, -half_thickness }, -Vec3f::UnitX()); - append_vertex(entity, { -half_stem_width, 0.0, -half_thickness }, -Vec3f::UnitX()); - append_vertex(entity, { -half_stem_width, stem_height, half_thickness }, -Vec3f::UnitX()); - append_vertex(entity, { -half_stem_width, 0.0, half_thickness }, -Vec3f::UnitX()); - - append_vertex(entity, { -half_stem_width, 0.0, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { half_stem_width, 0.0, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { -half_stem_width, 0.0, half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { half_stem_width, 0.0, half_thickness }, -Vec3f::UnitY()); - - // side face triangles - for (int i = 0; i < 7; ++i) { - const int ii = i * 4; - append_indices(entity, 14 + ii, 15 + ii, 17 + ii); - append_indices(entity, 14 + ii, 17 + ii, 16 + ii); - } - - data.entities.emplace_back(entity); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return data; } @@ -2129,18 +1468,12 @@ GLModel::Geometry diamond(unsigned int resolution) resolution = std::max(4, resolution); GLModel::Geometry data; -#if ENABLE_LEGACY_OPENGL_REMOVAL data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; data.reserve_vertices(resolution + 2); data.reserve_indices((2 * (resolution + 1)) * 3); -#else - GLModel::Geometry::Entity entity; - entity.type = GLModel::EPrimitiveType::Triangles; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const float step = 2.0f * float(PI) / float(resolution); -#if ENABLE_LEGACY_OPENGL_REMOVAL // vertices for (unsigned int i = 0; i < resolution; ++i) { const float ii = float(i) * step; @@ -2164,48 +1497,10 @@ GLModel::Geometry diamond(unsigned int resolution) data.add_triangle(i + 0, resolution + 1, i + 1); } data.add_triangle(resolution - 1, resolution + 1, 0); -#else - // positions - for (unsigned int i = 0; i < resolution; ++i) { - const float ii = float(i) * step; - entity.positions.emplace_back(0.5f * ::cos(ii), 0.5f * ::sin(ii), 0.0f); - } - entity.positions.emplace_back(0.0f, 0.0f, 0.5f); - entity.positions.emplace_back(0.0f, 0.0f, -0.5f); - - // normals - for (const Vec3f& v : entity.positions) { - entity.normals.emplace_back(v.normalized()); - } - - // triangles - // top - for (unsigned int i = 0; i < resolution; ++i) { - entity.indices.push_back(i + 0); - entity.indices.push_back(i + 1); - entity.indices.push_back(resolution); - } - entity.indices.push_back(resolution - 1); - entity.indices.push_back(0); - entity.indices.push_back(resolution); - - // bottom - for (unsigned int i = 0; i < resolution; ++i) { - entity.indices.push_back(i + 0); - entity.indices.push_back(resolution + 1); - entity.indices.push_back(i + 1); - } - entity.indices.push_back(resolution - 1); - entity.indices.push_back(resolution + 1); - entity.indices.push_back(0); - - data.entities.emplace_back(entity); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return data; } -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel::Geometry smooth_sphere(unsigned int resolution, float radius) { resolution = std::max(4, resolution); @@ -2390,7 +1685,6 @@ GLModel::Geometry smooth_torus(unsigned int primary_resolution, unsigned int sec return data; } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/GLModel.hpp b/src/slic3r/GUI/GLModel.hpp index 2d1e352c48..ef4ab6d474 100644 --- a/src/slic3r/GUI/GLModel.hpp +++ b/src/slic3r/GUI/GLModel.hpp @@ -15,37 +15,15 @@ namespace Slic3r { class TriangleMesh; class Polygon; using Polygons = std::vector; -#if ENABLE_LEGACY_OPENGL_REMOVAL class BuildVolume; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL namespace GUI { class GLModel { public: -#if !ENABLE_LEGACY_OPENGL_REMOVAL - enum class EPrimitiveType : unsigned char - { - Triangles, - Lines, - LineStrip, - LineLoop - }; - - struct RenderData - { - EPrimitiveType type; - unsigned int vbo_id{ 0 }; - unsigned int ibo_id{ 0 }; - size_t indices_count{ 0 }; - ColorRGBA color; - }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - struct Geometry { -#if ENABLE_LEGACY_OPENGL_REMOVAL enum class EPrimitiveType : unsigned char { Points, @@ -175,28 +153,8 @@ namespace GUI { #if ENABLE_OPENGL_ES static bool has_extra(const Format& format); #endif // ENABLE_OPENGL_ES -#else - struct Entity - { - EPrimitiveType type; - std::vector positions; - std::vector normals; - std::vector indices; - ColorRGBA color; - }; - - std::vector entities; - - size_t vertices_count() const; - size_t vertices_size_floats() const { return vertices_count() * 6; } - size_t vertices_size_bytes() const { return vertices_size_floats() * sizeof(float); } - - size_t indices_count() const; - size_t indices_size_bytes() const { return indices_count() * sizeof(unsigned int); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; -#if ENABLE_LEGACY_OPENGL_REMOVAL struct RenderData { Geometry geometry; @@ -208,10 +166,8 @@ namespace GUI { size_t vertices_count{ 0 }; size_t indices_count{ 0 }; }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL private: -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GLMODEL_STATISTICS struct Statistics { @@ -245,9 +201,6 @@ namespace GUI { // enable_render() // to keep the data on cpu side until needed. bool m_render_disabled{ false }; -#else - std::vector m_render_data; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL BoundingBoxf3 m_bounding_box; std::string m_filename; @@ -255,7 +208,6 @@ namespace GUI { GLModel() = default; virtual ~GLModel() { reset(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL size_t vertices_count() const { return m_render_data.vertices_count > 0 ? m_render_data.vertices_count : m_render_data.geometry.vertices_count(); } size_t indices_count() const { return m_render_data.indices_count > 0 ? @@ -274,42 +226,24 @@ namespace GUI { #else void init_from(const TriangleMesh& mesh); #endif // ENABLE_SMOOTH_NORMALS -#else - void init_from(const Geometry& data); - void init_from(const indexed_triangle_set& its, const BoundingBoxf3& bbox); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void init_from(const indexed_triangle_set& its); void init_from(const Polygons& polygons, float z); bool init_from_file(const std::string& filename); -#if ENABLE_LEGACY_OPENGL_REMOVAL void set_color(const ColorRGBA& color) { m_render_data.geometry.color = color; } const ColorRGBA& get_color() const { return m_render_data.geometry.color; } -#else - // if entity_id == -1 set the color of all entities - void set_color(int entity_id, const ColorRGBA& color); - ColorRGBA get_color(size_t entity_id = 0U) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void reset(); -#if ENABLE_LEGACY_OPENGL_REMOVAL void render(); void render(const std::pair& range); void render_instanced(unsigned int instances_vbo, unsigned int instances_count); bool is_initialized() const { return vertices_count() > 0 && indices_count() > 0; } bool is_empty() const { return m_render_data.geometry.is_empty(); } -#else - void render() const; - void render_instanced(unsigned int instances_vbo, unsigned int instances_count) const; - - bool is_initialized() const { return !m_render_data.empty(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const BoundingBoxf3& get_bounding_box() const { return m_bounding_box; } const std::string& get_filename() const { return m_filename; } -#if ENABLE_LEGACY_OPENGL_REMOVAL bool is_render_disabled() const { return m_render_disabled; } void enable_render() { m_render_disabled = false; } void disable_render() { m_render_disabled = true; } @@ -338,19 +272,12 @@ namespace GUI { s_statistics.render_instanced_calls = 0; } #endif // ENABLE_GLMODEL_STATISTICS -#endif // ENABLE_LEGACY_OPENGL_REMOVAL private: -#if ENABLE_LEGACY_OPENGL_REMOVAL bool send_to_gpu(); -#else - void send_to_gpu(RenderData& data, const std::vector& vertices, const std::vector& indices); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; -#if ENABLE_LEGACY_OPENGL_REMOVAL bool contains(const BuildVolume& volume, const GLModel& model, bool ignore_bottom = true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // create an arrow with cylindrical stem and conical tip, with the given dimensions and resolution // the origin of the arrow is in the center of the stem cap @@ -375,7 +302,6 @@ namespace GUI { // the diamond is contained into a box with size [1, 1, 1] GLModel::Geometry diamond(unsigned int resolution); -#if ENABLE_LEGACY_OPENGL_REMOVAL // create a sphere with smooth normals // the origin of the sphere is in its center GLModel::Geometry smooth_sphere(unsigned int resolution, float radius); @@ -387,7 +313,6 @@ namespace GUI { // the axis of the torus is the Z axis // the origin of the torus is in its center GLModel::Geometry smooth_torus(unsigned int primary_resolution, unsigned int secondary_resolution, float radius, float thickness); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/GLSelectionRectangle.cpp b/src/slic3r/GUI/GLSelectionRectangle.cpp index d4b4741175..12f286ddb6 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.cpp +++ b/src/slic3r/GUI/GLSelectionRectangle.cpp @@ -60,7 +60,6 @@ namespace GUI { return; const Size cnv_size = canvas.get_canvas_size(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const float cnv_width = (float)cnv_size.get_width(); const float cnv_height = (float)cnv_size.get_height(); if (cnv_width == 0.0f || cnv_height == 0.0f) @@ -72,49 +71,15 @@ namespace GUI { const float right = 2.0f * (get_right() * cnv_inv_width - 0.5f); const float top = -2.0f * (get_top() * cnv_inv_height - 0.5f); const float bottom = -2.0f * (get_bottom() * cnv_inv_height - 0.5f); -#else - const Camera& camera = wxGetApp().plater()->get_camera(); - const float inv_zoom = (float)camera.get_inv_zoom(); - - const float cnv_half_width = 0.5f * (float)cnv_size.get_width(); - const float cnv_half_height = 0.5f * (float)cnv_size.get_height(); - if (cnv_half_width == 0.0f || cnv_half_height == 0.0f) - return; - - const Vec2d start(m_start_corner.x() - cnv_half_width, cnv_half_height - m_start_corner.y()); - const Vec2d end(m_end_corner.x() - cnv_half_width, cnv_half_height - m_end_corner.y()); - - const float left = (float)std::min(start.x(), end.x()) * inv_zoom; - const float top = (float)std::max(start.y(), end.y()) * inv_zoom; - const float right = (float)std::max(start.x(), end.x()) * inv_zoom; - const float bottom = (float)std::min(start.y(), end.y()) * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE const bool core_profile = OpenGLManager::get_gl_info().is_core_profile(); if (!core_profile) #endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(1.5f)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - float color[3]; - color[0] = (m_state == EState::Select) ? 0.3f : 1.0f; - color[1] = (m_state == EState::Select) ? 1.0f : 0.3f; - color[2] = 0.3f; - glsafe(::glColor3fv(color)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glDisable(GL_DEPTH_TEST)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); - // ensure that the rectangle is renderered inside the frustrum - glsafe(::glTranslated(0.0, 0.0, -(camera.get_near_z() + 0.5))); - // ensure that the overlay fits the frustrum near z plane - const double gui_scale = camera.get_gui_scale(); - glsafe(::glScaled(gui_scale, gui_scale, 1.0)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - #if !ENABLE_OPENGL_ES #if ENABLE_GL_CORE_PROFILE if (!core_profile) { @@ -127,7 +92,6 @@ namespace GUI { #endif // ENABLE_GL_CORE_PROFILE #endif // !ENABLE_OPENGL_ES -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_OPENGL_ES GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines"); #elif ENABLE_GL_CORE_PROFILE @@ -210,14 +174,6 @@ namespace GUI { m_rectangle.render(); shader->stop_using(); } -#else - ::glBegin(GL_LINE_LOOP); - ::glVertex2f((GLfloat)left, (GLfloat)bottom); - ::glVertex2f((GLfloat)right, (GLfloat)bottom); - ::glVertex2f((GLfloat)right, (GLfloat)top); - ::glVertex2f((GLfloat)left, (GLfloat)top); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if !ENABLE_OPENGL_ES #if ENABLE_GL_CORE_PROFILE @@ -225,10 +181,6 @@ namespace GUI { #endif // ENABLE_GL_CORE_PROFILE glsafe(::glPopAttrib()); #endif // !ENABLE_OPENGL_ES - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } // namespace GUI diff --git a/src/slic3r/GUI/GLSelectionRectangle.hpp b/src/slic3r/GUI/GLSelectionRectangle.hpp index ac8abb6aae..e57e02e724 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.hpp +++ b/src/slic3r/GUI/GLSelectionRectangle.hpp @@ -2,9 +2,7 @@ #define slic3r_GLSelectionRectangle_hpp_ #include "libslic3r/Point.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "GLModel.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL namespace Slic3r { namespace GUI { @@ -51,11 +49,9 @@ private: EState m_state{ EState::Off }; Vec2d m_start_corner{ Vec2d::Zero() }; Vec2d m_end_corner{ Vec2d::Zero() }; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel m_rectangle; Vec2d m_old_start_corner{ Vec2d::Zero() }; Vec2d m_old_end_corner{ Vec2d::Zero() }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; diff --git a/src/slic3r/GUI/GLShadersManager.cpp b/src/slic3r/GUI/GLShadersManager.cpp index f0b91faf32..804d489718 100644 --- a/src/slic3r/GUI/GLShadersManager.cpp +++ b/src/slic3r/GUI/GLShadersManager.cpp @@ -36,7 +36,6 @@ std::pair GLShadersManager::init() bool valid = true; -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_OPENGL_ES const std::string prefix = "ES/"; // used to render wireframed triangles @@ -62,73 +61,36 @@ std::pair GLShadersManager::init() // used to render thick and/or dashed lines valid &= append_shader("dashed_thick_lines", { prefix + "dashed_thick_lines.vs", prefix + "dashed_thick_lines.fs", prefix + "dashed_thick_lines.gs" }); #endif // ENABLE_OPENGL_ES -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // used to render toolpaths center of gravity -#if ENABLE_LEGACY_OPENGL_REMOVAL valid &= append_shader("toolpaths_cog", { prefix + "toolpaths_cog.vs", prefix + "toolpaths_cog.fs" }); -#else - valid &= append_shader("toolpaths_cog", { "toolpaths_cog.vs", "toolpaths_cog.fs" }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL // used to render bed axes and model, selection hints, gcode sequential view marker model, preview shells, options in gcode preview valid &= append_shader("gouraud_light", { prefix + "gouraud_light.vs", prefix + "gouraud_light.fs" }); // used to render printbed valid &= append_shader("printbed", { prefix + "printbed.vs", prefix + "printbed.fs" }); -#else - // used to render bed axes and model, selection hints, gcode sequential view marker model, preview shells, options in gcode preview - valid &= append_shader("gouraud_light", { "gouraud_light.vs", "gouraud_light.fs" }); - // used to render printbed - valid &= append_shader("printbed", { "printbed.vs", "printbed.fs" }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // used to render options in gcode preview if (GUI::wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) { -#if ENABLE_LEGACY_OPENGL_REMOVAL valid &= append_shader("gouraud_light_instanced", { prefix + "gouraud_light_instanced.vs", prefix + "gouraud_light_instanced.fs" }); -#else - valid &= append_shader("gouraud_light_instanced", { "gouraud_light_instanced.vs", "gouraud_light_instanced.fs" }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL // used to render objects in 3d editor valid &= append_shader("gouraud", { prefix + "gouraud.vs", prefix + "gouraud.fs" } -#else - // used to render extrusion and travel paths as lines in gcode preview - valid &= append_shader("toolpaths_lines", { "toolpaths_lines.vs", "toolpaths_lines.fs" }); - // used to render objects in 3d editor - valid &= append_shader("gouraud", { "gouraud.vs", "gouraud.fs" } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_ENVIRONMENT_MAP , { "ENABLE_ENVIRONMENT_MAP"sv } #endif // ENABLE_ENVIRONMENT_MAP ); -#if ENABLE_LEGACY_OPENGL_REMOVAL // used to render variable layers heights in 3d editor valid &= append_shader("variable_layer_height", { prefix + "variable_layer_height.vs", prefix + "variable_layer_height.fs" }); // used to render highlight contour around selected triangles inside the multi-material gizmo valid &= append_shader("mm_contour", { prefix + "mm_contour.vs", prefix + "mm_contour.fs" }); -#else - // used to render variable layers heights in 3d editor - valid &= append_shader("variable_layer_height", { "variable_layer_height.vs", "variable_layer_height.fs" }); - // used to render highlight contour around selected triangles inside the multi-material gizmo - valid &= append_shader("mm_contour", { "mm_contour.vs", "mm_contour.fs" }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Used to render painted triangles inside the multi-material gizmo. Triangle normals are computed inside fragment shader. // For Apple's on Arm CPU computed triangle normals inside fragment shader using dFdx and dFdy has the opposite direction. // Because of this, objects had darker colors inside the multi-material gizmo. // Based on https://stackoverflow.com/a/66206648, the similar behavior was also spotted on some other devices with Arm CPU. // Since macOS 12 (Monterey), this issue with the opposite direction on Apple's Arm CPU seems to be fixed, and computed // triangle normals inside fragment shader have the right direction. -#if ENABLE_LEGACY_OPENGL_REMOVAL if (platform_flavor() == PlatformFlavor::OSXOnArm && wxPlatformInfo::Get().GetOSMajorVersion() < 12) valid &= append_shader("mm_gouraud", { prefix + "mm_gouraud.vs", prefix + "mm_gouraud.fs" }, { "FLIP_TRIANGLE_NORMALS"sv }); else valid &= append_shader("mm_gouraud", { prefix + "mm_gouraud.vs", prefix + "mm_gouraud.fs" }); -#else - if (platform_flavor() == PlatformFlavor::OSXOnArm && wxPlatformInfo::Get().GetOSMajorVersion() < 12) - valid &= append_shader("mm_gouraud", {"mm_gouraud.vs", "mm_gouraud.fs"}, {"FLIP_TRIANGLE_NORMALS"sv}); - else - valid &= append_shader("mm_gouraud", {"mm_gouraud.vs", "mm_gouraud.fs"}); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return { valid, error }; } diff --git a/src/slic3r/GUI/GLTexture.cpp b/src/slic3r/GUI/GLTexture.cpp index 2374b088be..07a2edbe24 100644 --- a/src/slic3r/GUI/GLTexture.cpp +++ b/src/slic3r/GUI/GLTexture.cpp @@ -3,10 +3,8 @@ #include "3DScene.hpp" #include "OpenGLManager.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "GUI_App.hpp" #include "GLModel.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include "BitmapCache.hpp" #include @@ -342,7 +340,6 @@ void GLTexture::render_sub_texture(unsigned int tex_id, float left, float right, glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)tex_id)); -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel::Geometry init_data; init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P2T2 }; init_data.reserve_vertices(4); @@ -364,21 +361,11 @@ void GLTexture::render_sub_texture(unsigned int tex_id, float left, float right, GLShaderProgram* shader = wxGetApp().get_shader("flat_texture"); if (shader != nullptr) { shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("view_model_matrix", Transform3d::Identity()); shader->set_uniform("projection_matrix", Transform3d::Identity()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL model.render(); shader->stop_using(); } -#else - ::glBegin(GL_QUADS); - ::glTexCoord2f(uvs.left_bottom.u, uvs.left_bottom.v); ::glVertex2f(left, bottom); - ::glTexCoord2f(uvs.right_bottom.u, uvs.right_bottom.v); ::glVertex2f(right, bottom); - ::glTexCoord2f(uvs.right_top.u, uvs.right_top.v); ::glVertex2f(right, top); - ::glTexCoord2f(uvs.left_top.u, uvs.left_top.v); ::glVertex2f(left, top); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); diff --git a/src/slic3r/GUI/GLToolbar.cpp b/src/slic3r/GUI/GLToolbar.cpp index 9d7f621ba6..76075e1af0 100644 --- a/src/slic3r/GUI/GLToolbar.cpp +++ b/src/slic3r/GUI/GLToolbar.cpp @@ -85,11 +85,7 @@ bool GLToolbarItem::update_enabled_state() return ret; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLToolbarItem::render(const GLCanvas3D& parent, unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const -#else -void GLToolbarItem::render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { auto uvs = [this](unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) -> GLTexture::Quad_UVs { assert(tex_width != 0 && tex_height != 0); @@ -118,7 +114,6 @@ void GLToolbarItem::render(unsigned int tex_id, float left, float right, float b GLTexture::render_sub_texture(tex_id, left, right, bottom, top, uvs(tex_width, tex_height, icon_size)); if (is_pressed()) { -#if ENABLE_LEGACY_OPENGL_REMOVAL const Size cnv_size = parent.get_canvas_size(); const float cnv_w = (float)cnv_size.get_width(); const float cnv_h = (float)cnv_size.get_height(); @@ -131,12 +126,6 @@ void GLToolbarItem::render(unsigned int tex_id, float left, float right, float b m_data.left.render_callback(out_left, out_right, out_bottom, out_top); else if (m_last_action_type == Right && m_data.right.can_render()) m_data.right.render_callback(out_left, out_right, out_bottom, out_top); -#else - if (m_last_action_type == Left && m_data.left.can_render()) - m_data.left.render_callback(left, right, bottom, top); - else if (m_last_action_type == Right && m_data.right.can_render()) - m_data.right.render_callback(left, right, bottom, top); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } @@ -202,7 +191,6 @@ bool GLToolbar::init(const BackgroundTexture::Metadata& background_texture) return res; } -#if ENABLE_LEGACY_OPENGL_REMOVAL bool GLToolbar::init_arrow(const std::string& filename) { if (m_arrow_texture.get_id() != 0) @@ -211,24 +199,6 @@ bool GLToolbar::init_arrow(const std::string& filename) const std::string path = resources_dir() + "/icons/"; return (!filename.empty()) ? m_arrow_texture.load_from_svg_file(path + filename, false, false, false, 512) : false; } -#else -bool GLToolbar::init_arrow(const BackgroundTexture::Metadata& arrow_texture) -{ - if (m_arrow_texture.texture.get_id() != 0) - return true; - - std::string path = resources_dir() + "/icons/"; - bool res = false; - - if (!arrow_texture.filename.empty()) - res = m_arrow_texture.texture.load_from_svg_file(path + arrow_texture.filename, false, false, false, 1000); - - if (res) - m_arrow_texture.metadata = arrow_texture; - - return res; -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLToolbar::Layout::EType GLToolbar::get_layout_type() const { @@ -693,7 +663,6 @@ void GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent) } } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent) { const Size cnv_size = parent.get_canvas_size(); @@ -891,224 +860,6 @@ void GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& } } } -#else -void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent) -{ - // NB: mouse_pos is already scaled appropriately - - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float factor = m_layout.scale * inv_zoom; - - Size cnv_size = parent.get_canvas_size(); - Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom); - - float scaled_icons_size = m_layout.icons_size * factor; - float scaled_separator_size = m_layout.separator_size * factor; - float scaled_gap_size = m_layout.gap_size * factor; - float scaled_border = m_layout.border * factor; - - float separator_stride = scaled_separator_size + scaled_gap_size; - float icon_stride = scaled_icons_size + scaled_gap_size; - - float left = m_layout.left + scaled_border; - float top = m_layout.top - scaled_border; - - for (GLToolbarItem* item : m_items) - { - if (!item->is_visible()) - continue; - - if (item->is_separator()) - left += separator_stride; - else - { - float right = left + scaled_icons_size; - float bottom = top - scaled_icons_size; - - GLToolbarItem::EState state = item->get_state(); - bool inside = (left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top); - - switch (state) - { - case GLToolbarItem::Normal: - { - if (inside) - { - item->set_state(GLToolbarItem::Hover); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::Hover: - { - if (!inside) - { - item->set_state(GLToolbarItem::Normal); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::Pressed: - { - if (inside) - { - item->set_state(GLToolbarItem::HoverPressed); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::HoverPressed: - { - if (!inside) - { - item->set_state(GLToolbarItem::Pressed); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::Disabled: - { - if (inside) - { - item->set_state(GLToolbarItem::HoverDisabled); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::HoverDisabled: - { - if (!inside) - { - item->set_state(GLToolbarItem::Disabled); - parent.set_as_dirty(); - } - - break; - } - default: - { - break; - } - } - - left += icon_stride; - } - } -} - -void GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent) -{ - // NB: mouse_pos is already scaled appropriately - - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float factor = m_layout.scale * inv_zoom; - - Size cnv_size = parent.get_canvas_size(); - Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom); - - float scaled_icons_size = m_layout.icons_size * factor; - float scaled_separator_size = m_layout.separator_size * factor; - float scaled_gap_size = m_layout.gap_size * factor; - float scaled_border = m_layout.border * factor; - float separator_stride = scaled_separator_size + scaled_gap_size; - float icon_stride = scaled_icons_size + scaled_gap_size; - - float left = m_layout.left + scaled_border; - float top = m_layout.top - scaled_border; - - for (GLToolbarItem* item : m_items) - { - if (!item->is_visible()) - continue; - - if (item->is_separator()) - top -= separator_stride; - else - { - float right = left + scaled_icons_size; - float bottom = top - scaled_icons_size; - - GLToolbarItem::EState state = item->get_state(); - bool inside = (left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top); - - switch (state) - { - case GLToolbarItem::Normal: - { - if (inside) - { - item->set_state(GLToolbarItem::Hover); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::Hover: - { - if (!inside) - { - item->set_state(GLToolbarItem::Normal); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::Pressed: - { - if (inside) - { - item->set_state(GLToolbarItem::HoverPressed); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::HoverPressed: - { - if (!inside) - { - item->set_state(GLToolbarItem::Pressed); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::Disabled: - { - if (inside) - { - item->set_state(GLToolbarItem::HoverDisabled); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::HoverDisabled: - { - if (!inside) - { - item->set_state(GLToolbarItem::Disabled); - parent.set_as_dirty(); - } - - break; - } - default: - { - break; - } - } - - top -= icon_stride; - } - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLToolbarItem* GLToolbar::get_item(const std::string& item_name) { @@ -1135,7 +886,6 @@ int GLToolbar::contains_mouse(const Vec2d& mouse_pos, const GLCanvas3D& parent) } } -#if ENABLE_LEGACY_OPENGL_REMOVAL int GLToolbar::contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const { const Size cnv_size = parent.get_canvas_size(); @@ -1283,154 +1033,7 @@ int GLToolbar::contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D& return -1; } -#else -int GLToolbar::contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const -{ - // NB: mouse_pos is already scaled appropriately - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float factor = m_layout.scale * inv_zoom; - - Size cnv_size = parent.get_canvas_size(); - Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom); - - float scaled_icons_size = m_layout.icons_size * factor; - float scaled_separator_size = m_layout.separator_size * factor; - float scaled_gap_size = m_layout.gap_size * factor; - float scaled_border = m_layout.border * factor; - - float left = m_layout.left + scaled_border; - float top = m_layout.top - scaled_border; - - - for (size_t id=0; idis_visible()) - continue; - - if (item->is_separator()) - { - float right = left + scaled_separator_size; - float bottom = top - scaled_icons_size; - - // mouse inside the separator - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return id; - - left = right; - right += scaled_gap_size; - - if (id < m_items.size() - 1) - { - // mouse inside the gap - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return -2; - } - - left = right; - } - else - { - float right = left + scaled_icons_size; - float bottom = top - scaled_icons_size; - - // mouse inside the icon - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return id; - - left = right; - right += scaled_gap_size; - - if (id < m_items.size() - 1) - { - // mouse inside the gap - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return -2; - } - - left = right; - } - } - - return -1; -} - -int GLToolbar::contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D& parent) const -{ - // NB: mouse_pos is already scaled appropriately - - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float factor = m_layout.scale * inv_zoom; - - Size cnv_size = parent.get_canvas_size(); - Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom); - - float scaled_icons_size = m_layout.icons_size * factor; - float scaled_separator_size = m_layout.separator_size * factor; - float scaled_gap_size = m_layout.gap_size * factor; - float scaled_border = m_layout.border * factor; - - float left = m_layout.left + scaled_border; - float top = m_layout.top - scaled_border; - - for (size_t id=0; idis_visible()) - continue; - - if (item->is_separator()) - { - float right = left + scaled_icons_size; - float bottom = top - scaled_separator_size; - - // mouse inside the separator - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return id; - - top = bottom; - bottom -= scaled_gap_size; - - if (id < m_items.size() - 1) - { - // mouse inside the gap - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return -2; - } - - top = bottom; - } - else - { - float right = left + scaled_icons_size; - float bottom = top - scaled_icons_size; - - // mouse inside the icon - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return id; - - top = bottom; - bottom -= scaled_gap_size; - - if (id < m_items.size() - 1) - { - // mouse inside the gap - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return -2; - } - - top = bottom; - } - } - - return -1; -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLToolbar::render_background(float left, float top, float right, float bottom, float border_w, float border_h) const { const unsigned int tex_id = m_background_texture.texture.get_id(); @@ -1507,86 +1110,7 @@ void GLToolbar::render_background(float left, float top, float right, float bott GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_right_uv, bottom_uv }, { right_uv, bottom_uv }, { right_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv } }); } } -#else -void GLToolbar::render_background(float left, float top, float right, float bottom, float border) const -{ - unsigned int tex_id = m_background_texture.texture.get_id(); - float tex_width = (float)m_background_texture.texture.get_width(); - float tex_height = (float)m_background_texture.texture.get_height(); - if (tex_id != 0 && tex_width > 0 && tex_height > 0) { - float inv_tex_width = (tex_width != 0.0f) ? 1.0f / tex_width : 0.0f; - float inv_tex_height = (tex_height != 0.0f) ? 1.0f / tex_height : 0.0f; - float internal_left = left + border; - float internal_right = right - border; - float internal_top = top - border; - float internal_bottom = bottom + border; - - float left_uv = 0.0f; - float right_uv = 1.0f; - float top_uv = 1.0f; - float bottom_uv = 0.0f; - - float internal_left_uv = (float)m_background_texture.metadata.left * inv_tex_width; - float internal_right_uv = 1.0f - (float)m_background_texture.metadata.right * inv_tex_width; - float internal_top_uv = 1.0f - (float)m_background_texture.metadata.top * inv_tex_height; - float internal_bottom_uv = (float)m_background_texture.metadata.bottom * inv_tex_height; - - // top-left corner - if ((m_layout.horizontal_orientation == Layout::HO_Left) || (m_layout.vertical_orientation == Layout::VO_Top)) - GLTexture::render_sub_texture(tex_id, left, internal_left, internal_top, top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, left, internal_left, internal_top, top, { { left_uv, internal_top_uv }, { internal_left_uv, internal_top_uv }, { internal_left_uv, top_uv }, { left_uv, top_uv } }); - - // top edge - if (m_layout.vertical_orientation == Layout::VO_Top) - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_top, top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_top, top, { { internal_left_uv, internal_top_uv }, { internal_right_uv, internal_top_uv }, { internal_right_uv, top_uv }, { internal_left_uv, top_uv } }); - - // top-right corner - if ((m_layout.horizontal_orientation == Layout::HO_Right) || (m_layout.vertical_orientation == Layout::VO_Top)) - GLTexture::render_sub_texture(tex_id, internal_right, right, internal_top, top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, internal_right, right, internal_top, top, { { internal_right_uv, internal_top_uv }, { right_uv, internal_top_uv }, { right_uv, top_uv }, { internal_right_uv, top_uv } }); - - // center-left edge - if (m_layout.horizontal_orientation == Layout::HO_Left) - GLTexture::render_sub_texture(tex_id, left, internal_left, internal_bottom, internal_top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, left, internal_left, internal_bottom, internal_top, { { left_uv, internal_bottom_uv }, { internal_left_uv, internal_bottom_uv }, { internal_left_uv, internal_top_uv }, { left_uv, internal_top_uv } }); - - // center - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_bottom, internal_top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - - // center-right edge - if (m_layout.horizontal_orientation == Layout::HO_Right) - GLTexture::render_sub_texture(tex_id, internal_right, right, internal_bottom, internal_top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, internal_right, right, internal_bottom, internal_top, { { internal_right_uv, internal_bottom_uv }, { right_uv, internal_bottom_uv }, { right_uv, internal_top_uv }, { internal_right_uv, internal_top_uv } }); - - // bottom-left corner - if ((m_layout.horizontal_orientation == Layout::HO_Left) || (m_layout.vertical_orientation == Layout::VO_Bottom)) - GLTexture::render_sub_texture(tex_id, left, internal_left, bottom, internal_bottom, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, left, internal_left, bottom, internal_bottom, { { left_uv, bottom_uv }, { internal_left_uv, bottom_uv }, { internal_left_uv, internal_bottom_uv }, { left_uv, internal_bottom_uv } }); - - // bottom edge - if (m_layout.vertical_orientation == Layout::VO_Bottom) - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, bottom, internal_bottom, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, bottom, internal_bottom, { { internal_left_uv, bottom_uv }, { internal_right_uv, bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_left_uv, internal_bottom_uv } }); - - // bottom-right corner - if ((m_layout.horizontal_orientation == Layout::HO_Right) || (m_layout.vertical_orientation == Layout::VO_Bottom)) - GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_right_uv, bottom_uv }, { right_uv, bottom_uv }, { right_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv } }); - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLToolbar::render_arrow(const GLCanvas3D& parent, GLToolbarItem* highlighted_item) { // arrow texture not initialized @@ -1655,75 +1179,7 @@ void GLToolbar::render_arrow(const GLCanvas3D& parent, GLToolbarItem* highlighte GLTexture::render_sub_texture(tex_id, left, right, bottom, top, { { left_uv, top_uv }, { right_uv, top_uv }, { right_uv, bottom_uv }, { left_uv, bottom_uv } }); } } -#else -void GLToolbar::render_arrow(const GLCanvas3D& parent, GLToolbarItem* highlighted_item) -{ - // arrow texture not initialized - if (m_arrow_texture.texture.get_id() == 0) - return; - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float factor = inv_zoom * m_layout.scale; - - float scaled_icons_size = m_layout.icons_size * factor; - float scaled_separator_size = m_layout.separator_size * factor; - float scaled_gap_size = m_layout.gap_size * factor; - float border = m_layout.border * factor; - - float separator_stride = scaled_separator_size + scaled_gap_size; - float icon_stride = scaled_icons_size + scaled_gap_size; - - float left = m_layout.left; - float top = m_layout.top - icon_stride; - - bool found = false; - for (const GLToolbarItem* item : m_items) { - if (!item->is_visible()) - continue; - - if (item->is_separator()) - left += separator_stride; - else { - if (item->get_name() == highlighted_item->get_name()) { - found = true; - break; - } - left += icon_stride; - } - } - if (!found) - return; - - left += border; - top -= separator_stride; - float right = left + scaled_icons_size; - - unsigned int tex_id = m_arrow_texture.texture.get_id(); - // arrow width and height - float arr_tex_width = (float)m_arrow_texture.texture.get_width(); - float arr_tex_height = (float)m_arrow_texture.texture.get_height(); - if ((tex_id != 0) && (arr_tex_width > 0) && (arr_tex_height > 0)) { - float inv_tex_width = (arr_tex_width != 0.0f) ? 1.0f / arr_tex_width : 0.0f; - float inv_tex_height = (arr_tex_height != 0.0f) ? 1.0f / arr_tex_height : 0.0f; - - float internal_left = left + border - scaled_icons_size * 1.5f; // add scaled_icons_size for huge arrow - float internal_right = right - border + scaled_icons_size * 1.5f; - float internal_top = top - border; - // bottom is not moving and should be calculated from arrow texture sides ratio - float arrow_sides_ratio = (float)m_arrow_texture.texture.get_height() / (float)m_arrow_texture.texture.get_width(); - float internal_bottom = internal_top - (internal_right - internal_left) * arrow_sides_ratio ; - - float internal_left_uv = (float)m_arrow_texture.metadata.left * inv_tex_width; - float internal_right_uv = 1.0f - (float)m_arrow_texture.metadata.right * inv_tex_width; - float internal_top_uv = 1.0f - (float)m_arrow_texture.metadata.top * inv_tex_height; - float internal_bottom_uv = (float)m_arrow_texture.metadata.bottom * inv_tex_height; - - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_bottom, internal_top, { { internal_left_uv, internal_top_uv }, { internal_right_uv, internal_top_uv }, { internal_right_uv, internal_bottom_uv }, { internal_left_uv, internal_bottom_uv } }); - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLToolbar::render_horizontal(const GLCanvas3D& parent) { const Size cnv_size = parent.get_canvas_size(); @@ -1833,101 +1289,6 @@ void GLToolbar::render_vertical(const GLCanvas3D& parent) } } } -#else -void GLToolbar::render_horizontal(const GLCanvas3D& parent) -{ - unsigned int tex_id = m_icons_texture.get_id(); - int tex_width = m_icons_texture.get_width(); - int tex_height = m_icons_texture.get_height(); - - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float factor = inv_zoom * m_layout.scale; - - float scaled_icons_size = m_layout.icons_size * factor; - float scaled_separator_size = m_layout.separator_size * factor; - float scaled_gap_size = m_layout.gap_size * factor; - float scaled_border = m_layout.border * factor; - float scaled_width = get_width() * inv_zoom; - float scaled_height = get_height() * inv_zoom; - - float separator_stride = scaled_separator_size + scaled_gap_size; - float icon_stride = scaled_icons_size + scaled_gap_size; - - float left = m_layout.left; - float top = m_layout.top; - float right = left + scaled_width; - float bottom = top - scaled_height; - - render_background(left, top, right, bottom, scaled_border); - - left += scaled_border; - top -= scaled_border; - - if ((tex_id == 0) || (tex_width <= 0) || (tex_height <= 0)) - return; - - // renders icons - for (const GLToolbarItem* item : m_items) - { - if (!item->is_visible()) - continue; - - if (item->is_separator()) - left += separator_stride; - else - { - item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_width, (unsigned int)tex_height, (unsigned int)(m_layout.icons_size * m_layout.scale)); - left += icon_stride; - } - } -} - -void GLToolbar::render_vertical(const GLCanvas3D& parent) -{ - unsigned int tex_id = m_icons_texture.get_id(); - int tex_width = m_icons_texture.get_width(); - int tex_height = m_icons_texture.get_height(); - - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float factor = inv_zoom * m_layout.scale; - - float scaled_icons_size = m_layout.icons_size * factor; - float scaled_separator_size = m_layout.separator_size * factor; - float scaled_gap_size = m_layout.gap_size * factor; - float scaled_border = m_layout.border * factor; - float scaled_width = get_width() * inv_zoom; - float scaled_height = get_height() * inv_zoom; - - float separator_stride = scaled_separator_size + scaled_gap_size; - float icon_stride = scaled_icons_size + scaled_gap_size; - - float left = m_layout.left; - float top = m_layout.top; - float right = left + scaled_width; - float bottom = top - scaled_height; - - render_background(left, top, right, bottom, scaled_border); - - left += scaled_border; - top -= scaled_border; - - if (tex_id == 0 || tex_width <= 0 || tex_height <= 0) - return; - - // renders icons - for (const GLToolbarItem* item : m_items) { - if (!item->is_visible()) - continue; - - if (item->is_separator()) - top -= separator_stride; - else { - item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_width, (unsigned int)tex_height, (unsigned int)(m_layout.icons_size * m_layout.scale)); - top -= icon_stride; - } - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL bool GLToolbar::generate_icons_texture() { diff --git a/src/slic3r/GUI/GLToolbar.hpp b/src/slic3r/GUI/GLToolbar.hpp index 1a836164c4..6961827ce8 100644 --- a/src/slic3r/GUI/GLToolbar.hpp +++ b/src/slic3r/GUI/GLToolbar.hpp @@ -153,11 +153,7 @@ public: // returns true if the state changes bool update_enabled_state(); -#if ENABLE_LEGACY_OPENGL_REMOVAL void render(const GLCanvas3D& parent, unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const; -#else - void render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL private: void set_visible(bool visible) { m_data.visible = visible; } @@ -251,11 +247,7 @@ private: GLTexture m_icons_texture; bool m_icons_texture_dirty; BackgroundTexture m_background_texture; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLTexture m_arrow_texture; -#else - BackgroundTexture m_arrow_texture; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL Layout m_layout; ItemsList m_items; @@ -282,11 +274,7 @@ public: bool init(const BackgroundTexture::Metadata& background_texture); -#if ENABLE_LEGACY_OPENGL_REMOVAL bool init_arrow(const std::string& filename); -#else - bool init_arrow(const BackgroundTexture::Metadata& arrow_texture); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL Layout::EType get_layout_type() const; void set_layout_type(Layout::EType type); @@ -357,11 +345,7 @@ private: int contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const; int contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D& parent) const; -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_background(float left, float top, float right, float bottom, float border_w, float border_h) const; -#else - void render_background(float left, float top, float right, float bottom, float border) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void render_horizontal(const GLCanvas3D& parent); void render_vertical(const GLCanvas3D& parent); diff --git a/src/slic3r/GUI/GalleryDialog.cpp b/src/slic3r/GUI/GalleryDialog.cpp index 8265cb75ef..a08673e235 100644 --- a/src/slic3r/GUI/GalleryDialog.cpp +++ b/src/slic3r/GUI/GalleryDialog.cpp @@ -289,12 +289,7 @@ static void generate_thumbnail_from_model(const std::string& filename) GLVolumeCollection volumes; volumes.volumes.push_back(new GLVolume()); GLVolume* volume = volumes.volumes.back(); -#if ENABLE_LEGACY_OPENGL_REMOVAL volume->model.init_from(model.mesh()); -#else - volume->indexed_vertex_array.load_mesh(model.mesh()); - volume->indexed_vertex_array.finalize_geometry(true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL volume->set_instance_transformation(model.objects[0]->instances[0]->get_transformation()); volume->set_volume_transformation(model.objects[0]->volumes[0]->get_transformation()); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp index a3829fc219..322c631514 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp @@ -5,9 +5,7 @@ #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_ObjectManipulation.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/Plater.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // TODO: Display tooltips quicker on Linux @@ -55,23 +53,17 @@ void GLGizmoBase::Grabber::unregister_raycasters_for_picking() void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color) { -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_current_shader(); if (shader == nullptr) return; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (!s_cube.model.is_initialized()) { // This cannot be done in constructor, OpenGL is not yet // initialized at that point (on Linux at least). indexed_triangle_set its = its_make_cube(1.0, 1.0, 1.0); its_translate(its, -0.5f * Vec3f::Ones()); -#if ENABLE_LEGACY_OPENGL_REMOVAL s_cube.model.init_from(its); s_cube.mesh_raycaster = std::make_unique(std::make_shared(std::move(its))); -#else - s_cube.init_from(its, BoundingBoxf3{ { -0.5, -0.5, -0.5 }, { 0.5, 0.5, 0.5 } }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } if (!s_cone.model.is_initialized()) { @@ -82,7 +74,6 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color) const float half_size = dragging ? get_dragging_half_size(size) : get_half_size(size); -#if ENABLE_LEGACY_OPENGL_REMOVAL s_cube.model.set_color(render_color); s_cone.model.set_color(render_color); @@ -97,16 +88,6 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color) shader->set_uniform("view_model_matrix", view_model_matrix); Matrix3d view_normal_matrix = view_matrix_no_offset * elements_matrices[0].matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - s_cube.set_color(-1, render_color); - s_cone.set_color(-1, render_color); - glsafe(::glPushMatrix()); - glsafe(::glTranslated(center.x(), center.y(), center.z())); - glsafe(::glRotated(Geometry::rad2deg(angles.z()), 0.0, 0.0, 1.0)); - glsafe(::glRotated(Geometry::rad2deg(angles.y()), 0.0, 1.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)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL s_cube.model.render(); auto render_extension = [&view_matrix, &view_matrix_no_offset, shader](const Transform3d& matrix) { @@ -117,7 +98,6 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color) s_cone.model.render(); }; -#if ENABLE_LEGACY_OPENGL_REMOVAL if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosX)) != 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]); @@ -142,52 +122,6 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color) 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]); } -#else - if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosX)) != 0) { - glsafe(::glPushMatrix()); - glsafe(::glTranslated(1.0, 0.0, 0.0)); - glsafe(::glRotated(0.5 * Geometry::rad2deg(double(PI)), 0.0, 1.0, 0.0)); - s_cone.render(); - glsafe(::glPopMatrix()); - } - if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegX)) != 0) { - glsafe(::glPushMatrix()); - glsafe(::glTranslated(-1.0, 0.0, 0.0)); - glsafe(::glRotated(-0.5 * Geometry::rad2deg(double(PI)), 0.0, 1.0, 0.0)); - s_cone.render(); - glsafe(::glPopMatrix()); - } - if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosY)) != 0) { - glsafe(::glPushMatrix()); - glsafe(::glTranslated(0.0, 1.0, 0.0)); - glsafe(::glRotated(-0.5 * Geometry::rad2deg(double(PI)), 1.0, 0.0, 0.0)); - s_cone.render(); - glsafe(::glPopMatrix()); - } - if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegY)) != 0) { - glsafe(::glPushMatrix()); - glsafe(::glTranslated(0.0, -1.0, 0.0)); - glsafe(::glRotated(0.5 * Geometry::rad2deg(double(PI)), 1.0, 0.0, 0.0)); - s_cone.render(); - glsafe(::glPopMatrix()); - } - if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosZ)) != 0) { - glsafe(::glPushMatrix()); - glsafe(::glTranslated(0.0, 0.0, 1.0)); - s_cone.render(); - glsafe(::glPopMatrix()); - } - if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegZ)) != 0) { - glsafe(::glPushMatrix()); - glsafe(::glTranslated(0.0, 0.0, -1.0)); - glsafe(::glRotated(Geometry::rad2deg(double(PI)), 1.0, 0.0, 0.0)); - s_cone.render(); - glsafe(::glPopMatrix()); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL if (raycasters[0] == nullptr) { GLCanvas3D& canvas = *wxGetApp().plater()->canvas3D(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp index 3c3f5c287e..38d8c26617 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp @@ -66,9 +66,7 @@ protected: bool dragging{ false }; Vec3d center{ Vec3d::Zero() }; Vec3d angles{ Vec3d::Zero() }; -#if ENABLE_LEGACY_OPENGL_REMOVAL Transform3d matrix{ Transform3d::Identity() }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL ColorRGBA color{ ColorRGBA::WHITE() }; EGrabberExtension extensions{ EGrabberExtension::None }; // the picking id shared by all the elements diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 542aceead0..be04d804d7 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -535,28 +535,16 @@ void GLGizmoEmboss::on_render() { if (m_temp_transformation.has_value()) { // draw text volume on temporary position -#if ENABLE_LEGACY_OPENGL_REMOVAL GLVolume& gl_volume = *selection.get_volume(*selection.get_volume_idxs().begin()); -#else - const GLVolume& gl_volume = *selection.get_volume(*selection.get_volume_idxs().begin()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); -#else - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(m_temp_transformation->data())); - GLShaderProgram *shader = wxGetApp().get_shader("gouraud_light"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d matrix = camera.get_view_matrix() * (*m_temp_transformation); shader->set_uniform("view_model_matrix", matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader->set_uniform("view_normal_matrix", (Matrix3d) (matrix).matrix().block(0, 0, 3, 3).inverse().transpose()); shader->set_uniform("emission_factor", 0.0f); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // dragging object must be selected so draw it with correct color //auto color = gl_volume.color; @@ -569,25 +557,15 @@ void GLGizmoEmboss::on_render() { glsafe(::glEnable(GL_BLEND)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); } -#if !ENABLE_LEGACY_OPENGL_REMOVAL - shader->set_uniform("uniform_color", color); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_DEPTH_TEST)); -#if ENABLE_LEGACY_OPENGL_REMOVAL gl_volume.model.set_color(color); gl_volume.model.render(); -#else - gl_volume.indexed_vertex_array.render(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glDisable(GL_DEPTH_TEST)); if (is_transparent) glsafe(::glDisable(GL_BLEND)); shader->stop_using(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } bool is_surface_dragging = m_temp_transformation.has_value(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp index 463eb3182b..a1bbe84e90 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp @@ -1,10 +1,8 @@ // Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro. #include "GLGizmoFlatten.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/Plater.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" @@ -100,13 +98,11 @@ void GLGizmoFlatten::on_render() { 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(::glClear(GL_DEPTH_BUFFER_BIT)); @@ -115,42 +111,25 @@ void GLGizmoFlatten::on_render() if (selection.is_single_full_instance()) { const Transform3d& inst_matrix = selection.get_first_volume()->get_instance_transformation().get_matrix(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d model_matrix = Geometry::translation_transform(selection.get_first_volume()->get_sla_shift_z() * Vec3d::UnitZ()) * inst_matrix; const Transform3d view_model_matrix = camera.get_view_matrix() * model_matrix; 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(inst_matrix.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_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.render(); -#else - glsafe(::glColor4fv(i == m_hover_id ? DEFAULT_HOVER_PLANE_COLOR.data() : DEFAULT_PLANE_COLOR.data())); - if (m_planes[i].vbo.has_VBOs()) - m_planes[i].vbo.render(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } glsafe(::glEnable(GL_CULL_FACE)); glsafe(::glDisable(GL_BLEND)); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GLGizmoFlatten::on_register_raycasters_for_picking() @@ -395,7 +374,6 @@ void GLGizmoFlatten::update_planes() // And finally create respective VBOs. The polygon is convex with // the vertices in order, so triangulation is trivial. for (auto& plane : m_planes) { -#if ENABLE_LEGACY_OPENGL_REMOVAL indexed_triangle_set its; its.vertices.reserve(plane.vertices.size()); its.indices.reserve(plane.vertices.size() / 3); @@ -407,14 +385,6 @@ void GLGizmoFlatten::update_planes() } plane.vbo.model.init_from(its); plane.vbo.mesh_raycaster = std::make_unique(std::make_shared(std::move(its))); -#else - plane.vbo.reserve(plane.vertices.size()); - for (const auto& vert : plane.vertices) - plane.vbo.push_geometry(vert, plane.normal); - for (size_t i=1; i vertices; // should be in fact local in update_planes() -#if ENABLE_LEGACY_OPENGL_REMOVAL PickingModel vbo; -#else - GLIndexedVertexArray vbo; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL Vec3d normal; float area; int picking_id{ -1 }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp index be04fb92c6..99994f7b6f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp @@ -117,24 +117,16 @@ void GLGizmoHollow::on_unregister_raycasters_for_picking() void GLGizmoHollow::render_points(const Selection& selection) { -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); if (shader == nullptr) return; shader->start_using(); ScopeGuard guard([shader]() { shader->stop_using(); }); -#else - GLShaderProgram* shader = picking ? nullptr : wxGetApp().get_shader("gouraud_light"); - if (shader) - shader->start_using(); - ScopeGuard guard([shader]() { if (shader) shader->stop_using(); }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const GLVolume* vol = selection.get_first_volume(); const Transform3d trafo = vol->world_matrix(); -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE const Transform3d instance_scaling_matrix_inverse = vol->get_instance_transformation().get_scaling_factor_matrix().inverse(); #else @@ -143,14 +135,6 @@ void GLGizmoHollow::render_points(const Selection& selection) const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#else - const Transform3d& instance_scaling_matrix_inverse = trafo.get_matrix(true, true, false, true).inverse(); - const Transform3d& instance_matrix = trafo.get_matrix(); - - glsafe(::glPushMatrix()); - glsafe(::glTranslated(0.0, 0.0, m_c->selection_info()->get_sla_shift())); - glsafe(::glMultMatrixd(instance_matrix.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL ColorRGBA render_color; const sla::DrainHoles& drain_holes = m_c->selection_info()->model_object()->sla_drain_holes; @@ -176,17 +160,9 @@ void GLGizmoHollow::render_points(const Selection& selection) 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_LEGACY_OPENGL_REMOVAL m_cylinder.model.set_color(render_color); // 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()) * instance_scaling_matrix_inverse; -#else - const_cast(&m_cylinder)->set_color(-1, render_color); - // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. - glsafe(::glPushMatrix()); - glsafe(::glTranslatef(drain_hole.pos.x(), drain_hole.pos.y(), drain_hole.pos.z())); - glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (vol->is_left_handed()) glsafe(::glFrontFace(GL_CW)); @@ -195,30 +171,16 @@ void GLGizmoHollow::render_points(const Selection& selection) Eigen::Quaterniond q; q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * (-drain_hole.normal).cast()); const Eigen::AngleAxisd aa(q); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d model_matrix = trafo * hole_matrix * Transform3d(aa.toRotationMatrix()) * Geometry::translation_transform(-drain_hole.height * Vec3d::UnitZ()) * Geometry::scale_transform(Vec3d(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); 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(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z())); - glsafe(::glTranslated(0., 0., -drain_hole.height)); - glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_cylinder.model.render(); if (vol->is_left_handed()) glsafe(::glFrontFace(GL_CCW)); - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } bool GLGizmoHollow::is_mesh_point_clipped(const Vec3d& point) const diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp index 8c67014b6e..fd7963050f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp @@ -193,26 +193,16 @@ void GLGizmoMmuSegmentation::render_triangles(const Selection &selection) const if (is_left_handed) glsafe(::glFrontFace(GL_CW)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader->set_uniform("view_model_matrix", view_matrix * trafo_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * trafo_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(trafo_matrix.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("volume_world_matrix", trafo_matrix); shader->set_uniform("volume_mirrored", is_left_handed); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_triangle_selectors[mesh_id]->render(m_imgui, trafo_matrix); -#else - m_triangle_selectors[mesh_id]->render(m_imgui); - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (is_left_handed) glsafe(::glFrontFace(GL_CCW)); @@ -582,11 +572,7 @@ ColorRGBA GLGizmoMmuSegmentation::get_cursor_sphere_right_button_color() const return color; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void TriangleSelectorMmGui::render(ImGuiWrapper* imgui, const Transform3d& matrix) -#else -void TriangleSelectorMmGui::render(ImGuiWrapper *imgui) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (m_update_render_data) update_render_data(); @@ -595,14 +581,12 @@ void TriangleSelectorMmGui::render(ImGuiWrapper *imgui) if (!shader) return; assert(shader->get_name() == "mm_gouraud"); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader->set_uniform("view_model_matrix", view_matrix * matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (size_t color_idx = 0; color_idx < m_gizmo_scene.triangle_indices.size(); ++color_idx) { if (m_gizmo_scene.has_VBOs(color_idx)) { @@ -615,21 +599,7 @@ void TriangleSelectorMmGui::render(ImGuiWrapper *imgui) } } -#if ENABLE_LEGACY_OPENGL_REMOVAL render_paint_contour(matrix); -#else - if (m_paint_contour.has_VBO()) { - ScopeGuard guard_mm_gouraud([shader]() { shader->start_using(); }); - shader->stop_using(); - - auto *contour_shader = wxGetApp().get_shader("mm_contour"); - contour_shader->start_using(); - contour_shader->set_uniform("offset", OpenGLManager::get_gl_info().is_mesa() ? 0.0005 : 0.00001); - m_paint_contour.render(); - contour_shader->stop_using(); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - m_update_render_data = false; } @@ -662,29 +632,7 @@ void TriangleSelectorMmGui::update_render_data() m_gizmo_scene.triangle_indices_sizes[color_idx] = m_gizmo_scene.triangle_indices[color_idx].size(); m_gizmo_scene.finalize_triangle_indices(); - -#if ENABLE_LEGACY_OPENGL_REMOVAL update_paint_contour(); -#else - m_paint_contour.release_geometry(); - std::vector contour_edges = this->get_seed_fill_contour(); - m_paint_contour.contour_vertices.reserve(contour_edges.size() * 6); - for (const Vec2i &edge : contour_edges) { - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(0)].v.x()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(0)].v.y()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(0)].v.z()); - - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(1)].v.x()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(1)].v.y()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(1)].v.z()); - } - - m_paint_contour.contour_indices.assign(m_paint_contour.contour_vertices.size() / 3, 0); - std::iota(m_paint_contour.contour_indices.begin(), m_paint_contour.contour_indices.end(), 0); - m_paint_contour.contour_indices_size = m_paint_contour.contour_indices.size(); - - m_paint_contour.finalize_geometry(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } wxString GLGizmoMmuSegmentation::handle_snapshot_action_name(bool shift_down, GLGizmoPainterBase::Button button_down) const @@ -729,11 +677,9 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const assert(this->vertices_VBO_id != 0); assert(this->triangle_indices_VBO_ids[triangle_indices_idx] != 0); -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_current_shader(); if (shader == nullptr) return; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) @@ -741,7 +687,6 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const // the following binding is needed to set the vertex attributes #endif // ENABLE_GL_CORE_PROFILE glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_VBO_id)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const GLint position_id = shader->get_attrib_location("v_position"); if (position_id != -1) { glsafe(::glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (GLvoid*)0)); @@ -751,24 +696,13 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const // Render using the Vertex Buffer Objects. if (this->triangle_indices_VBO_ids[triangle_indices_idx] != 0 && this->triangle_indices_sizes[triangle_indices_idx] > 0) { -#else - glsafe(::glVertexPointer(3, GL_FLOAT, 3 * sizeof(float), (const void*)(0 * sizeof(float)))); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - - // Render using the Vertex Buffer Objects. - if (this->triangle_indices_sizes[triangle_indices_idx] > 0) { -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_ids[triangle_indices_idx])); glsafe(::glDrawElements(GL_TRIANGLES, GLsizei(this->triangle_indices_sizes[triangle_indices_idx]), GL_UNSIGNED_INT, nullptr)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); } -#if ENABLE_LEGACY_OPENGL_REMOVAL if (position_id != -1) glsafe(::glDisableVertexAttribArray(position_id)); -#else - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); #if ENABLE_GL_CORE_PROFILE diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp index 502db6ebc8..67eccd8e8e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp @@ -69,13 +69,7 @@ public: : TriangleSelectorGUI(mesh), m_colors(colors), m_default_volume_color(default_volume_color), m_gizmo_scene(2 * (colors.size() + 1)) {} ~TriangleSelectorMmGui() override = default; -#if ENABLE_LEGACY_OPENGL_REMOVAL void render(ImGuiWrapper* imgui, const Transform3d& matrix) override; -#else - // Render current selection. Transformation matrices are supposed - // to be already set. - void render(ImGuiWrapper* imgui) override; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL private: void update_render_data(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp index bb5ebfd260..69fcc54147 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp @@ -5,9 +5,7 @@ #if ENABLE_WORLD_COORDINATE #include "slic3r/GUI/GUI_ObjectManipulation.hpp" #endif // ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/Plater.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include "libslic3r/Model.hpp" #include @@ -151,18 +149,11 @@ void GLGizmoMove3D::on_render() glsafe(::glEnable(GL_DEPTH_TEST)); #if ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL calc_selection_box_and_center(); -#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 - transform_to_local(m_parent.get_selection()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const Vec3d zero = Vec3d::Zero(); const Vec3d half_box_size = 0.5 * m_bounding_box.size(); @@ -201,7 +192,6 @@ void GLGizmoMove3D::on_render() #endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE auto render_grabber_connection = [this, &zero](unsigned int id) { #else @@ -240,10 +230,8 @@ void GLGizmoMove3D::on_render() m_grabber_connections[id].model.render(); } }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (m_hover_id == -1) { -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); #else @@ -264,31 +252,14 @@ void GLGizmoMove3D::on_render() shader->set_uniform("width", 0.25f); shader->set_uniform("gap_size", 0.0f); #endif // ENABLE_GL_CORE_PROFILE -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // draw axes for (unsigned int i = 0; i < 3; ++i) { -#if ENABLE_LEGACY_OPENGL_REMOVAL render_grabber_connection(i); -#else - if (m_grabbers[i].enabled) { - glsafe(::glColor4fv(AXES_COLOR[i].data())); - ::glBegin(GL_LINES); -#if ENABLE_WORLD_COORDINATE - ::glVertex3dv(zero.data()); -#else - ::glVertex3dv(center.data()); -#endif // ENABLE_WORLD_COORDINATE - ::glVertex3dv(m_grabbers[i].center.data()); - glsafe(::glEnd()); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // draw grabbers #if ENABLE_WORLD_COORDINATE @@ -299,7 +270,6 @@ void GLGizmoMove3D::on_render() } else { // draw axis -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); #else @@ -327,19 +297,6 @@ void GLGizmoMove3D::on_render() } shader = wxGetApp().get_shader("gouraud_light"); -#else - glsafe(::glColor4fv(AXES_COLOR[m_hover_id].data())); - ::glBegin(GL_LINES); -#if ENABLE_WORLD_COORDINATE - ::glVertex3dv(zero.data()); -#else - ::glVertex3dv(center.data()); -#endif // ENABLE_WORLD_COORDINATE - ::glVertex3dv(m_grabbers[m_hover_id].center.data()); - glsafe(::glEnd()); - - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (shader != nullptr) { shader->start_using(); shader->set_uniform("emission_factor", 0.1f); @@ -354,12 +311,6 @@ void GLGizmoMove3D::on_render() shader->stop_using(); } } - -#if ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL -#endif // ENABLE_WORLD_COORDINATE } void GLGizmoMove3D::on_register_raycasters_for_picking() @@ -400,7 +351,6 @@ double GLGizmoMove3D::calc_projection(const UpdateData& data) const } #if ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL Transform3d GLGizmoMove3D::local_transform(const Selection& selection) const { Transform3d ret = Geometry::translation_transform(m_center); @@ -413,20 +363,6 @@ Transform3d GLGizmoMove3D::local_transform(const Selection& selection) const } return ret; } -#else -void GLGizmoMove3D::transform_to_local(const Selection& selection) const -{ - glsafe(::glTranslated(m_center.x(), m_center.y(), m_center.z())); - - if (!wxGetApp().obj_manipul()->is_world_coordinates()) { - const GLVolume& v = *selection.get_first_volume(); - Transform3d orient_matrix = v.get_instance_transformation().get_matrix(true, false, true, true); - if (selection.is_single_volume_or_modifier() && wxGetApp().obj_manipul()->is_local_coordinates()) - orient_matrix = orient_matrix * v.get_volume_transformation().get_matrix(true, false, true, true); - glsafe(::glMultMatrixd(orient_matrix.data())); - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoMove3D::calc_selection_box_and_center() { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp index 3a69e86efb..5f1d562e9c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp @@ -25,14 +25,12 @@ class GLGizmoMove3D : public GLGizmoBase Vec3d m_starting_box_center{ Vec3d::Zero() }; Vec3d m_starting_box_bottom_center{ Vec3d::Zero() }; -#if ENABLE_LEGACY_OPENGL_REMOVAL struct GrabberConnection { GLModel model; Vec3d old_center{ Vec3d::Zero() }; }; std::array m_grabber_connections; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL public: GLGizmoMove3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); @@ -68,11 +66,7 @@ protected: private: double calc_projection(const UpdateData& data) const; #if ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL Transform3d local_transform(const Selection& selection) const; -#else - void transform_to_local(const Selection& selection) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void calc_selection_box_and_center(); #endif // ENABLE_WORLD_COORDINATE }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp index 154d1f1be5..8d26337743 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp @@ -19,11 +19,7 @@ namespace Slic3r::GUI { -#if ENABLE_LEGACY_OPENGL_REMOVAL std::shared_ptr GLGizmoPainterBase::s_sphere = nullptr; -#else -std::shared_ptr GLGizmoPainterBase::s_sphere = nullptr; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLGizmoPainterBase::GLGizmoPainterBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) : GLGizmoBase(parent, icon_filename, sprite_id) @@ -32,13 +28,8 @@ GLGizmoPainterBase::GLGizmoPainterBase(GLCanvas3D& parent, const std::string& ic GLGizmoPainterBase::~GLGizmoPainterBase() { -#if ENABLE_LEGACY_OPENGL_REMOVAL if (s_sphere != nullptr) s_sphere.reset(); -#else - if (s_sphere != nullptr && s_sphere->has_VBOs()) - s_sphere->release_geometry(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GLGizmoPainterBase::data_changed() @@ -106,17 +97,12 @@ void GLGizmoPainterBase::render_triangles(const Selection& selection) const if (is_left_handed) glsafe(::glFrontFace(GL_CW)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader->set_uniform("view_model_matrix", view_matrix * trafo_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * trafo_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(trafo_matrix.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // For printers with multiple extruders, it is necessary to pass trafo_matrix // to the shader input variable print_box.volume_world_matrix before @@ -124,13 +110,7 @@ void GLGizmoPainterBase::render_triangles(const Selection& selection) const // wrong transformation matrix is used for "Clipping of view". shader->set_uniform("volume_world_matrix", trafo_matrix); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_triangle_selectors[mesh_id]->render(m_imgui, trafo_matrix); -#else - m_triangle_selectors[mesh_id]->render(m_imgui); - - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (is_left_handed) glsafe(::glFrontFace(GL_CCW)); } @@ -165,14 +145,7 @@ void GLGizmoPainterBase::render_cursor() void GLGizmoPainterBase::render_cursor_circle() { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - const Camera &camera = wxGetApp().plater()->get_camera(); - const float zoom = float(camera.get_zoom()); - const float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - const Size cnv_size = m_parent.get_canvas_size(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const float cnv_width = float(cnv_size.get_width()); const float cnv_height = float(cnv_size.get_height()); if (cnv_width == 0.0f || cnv_height == 0.0f) @@ -188,43 +161,19 @@ void GLGizmoPainterBase::render_cursor_circle() #else const float radius = m_cursor_radius * float(wxGetApp().plater()->get_camera().get_zoom()); #endif // ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES -#else - const float cnv_half_width = 0.5f * float(cnv_size.get_width()); - const float cnv_half_height = 0.5f * float(cnv_size.get_height()); - if (cnv_half_width == 0.0f || cnv_half_height == 0.0f) - return; - const Vec2d mouse_pos(m_parent.get_local_mouse_position().x(), m_parent.get_local_mouse_position().y()); - Vec2d center(mouse_pos.x() - cnv_half_width, cnv_half_height - mouse_pos.y()); - center = center * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE if (!OpenGLManager::get_gl_info().is_core_profile()) #endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(1.5f)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - static const std::array color = { 0.f, 1.f, 0.3f }; - glsafe(::glColor3fv(color.data())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glDisable(GL_DEPTH_TEST)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); - // ensure that the circle is renderered inside the frustrum - glsafe(::glTranslated(0.0, 0.0, -(camera.get_near_z() + 0.5))); - // ensure that the overlay fits the frustrum near z plane - const double gui_scale = camera.get_gui_scale(); - glsafe(::glScaled(gui_scale, gui_scale, 1.0)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - #if !ENABLE_GL_CORE_PROFILE && !ENABLE_OPENGL_ES glsafe(::glPushAttrib(GL_ENABLE_BIT)); glsafe(::glLineStipple(4, 0xAAAA)); glsafe(::glEnable(GL_LINE_STIPPLE)); #endif // !ENABLE_GL_CORE_PROFILE && !ENABLE_OPENGL_ES -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES if (!m_circle.is_initialized() || std::abs(m_old_cursor_radius - radius) > EPSILON) { m_old_cursor_radius = radius; @@ -299,19 +248,10 @@ void GLGizmoPainterBase::render_cursor_circle() m_circle.render(); shader->stop_using(); } -#else - ::glBegin(GL_LINE_LOOP); - for (double angle=0; angle<2*M_PI; angle+=M_PI/20.) - ::glVertex2f(GLfloat(center.x()+m_cursor_radius*cos(angle)), GLfloat(center.y()+m_cursor_radius*sin(angle))); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if !ENABLE_GL_CORE_PROFILE && !ENABLE_OPENGL_ES glsafe(::glPopAttrib()); #endif // !ENABLE_GL_CORE_PROFILE && !ENABLE_OPENGL_ES -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_DEPTH_TEST)); } @@ -319,21 +259,13 @@ void GLGizmoPainterBase::render_cursor_circle() void GLGizmoPainterBase::render_cursor_sphere(const Transform3d& trafo) const { if (s_sphere == nullptr) { -#if ENABLE_LEGACY_OPENGL_REMOVAL s_sphere = std::make_shared(); s_sphere->init_from(its_make_sphere(1.0, double(PI) / 12.0)); -#else - s_sphere = std::make_shared(); - s_sphere->load_its_flat_shading(its_make_sphere(1.0, double(PI) / 12.0)); - s_sphere->finalize_geometry(true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("flat"); if (shader == nullptr) return; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE const Transform3d complete_scaling_matrix_inverse = Geometry::Transformation(trafo).get_scaling_factor_matrix().inverse(); @@ -342,15 +274,6 @@ void GLGizmoPainterBase::render_cursor_sphere(const Transform3d& trafo) const #endif // ENABLE_WORLD_COORDINATE const bool is_left_handed = Geometry::Transformation(trafo).is_left_handed(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(trafo.data())); - // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. - glsafe(::glTranslatef(m_rr.hit.x(), m_rr.hit.y(), m_rr.hit.z())); - glsafe(::glMultMatrixd(complete_scaling_matrix_inverse.data())); - glsafe(::glScaled(m_cursor_radius, m_cursor_radius, m_cursor_radius)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - if (is_left_handed) glsafe(::glFrontFace(GL_CW)); @@ -359,7 +282,7 @@ void GLGizmoPainterBase::render_cursor_sphere(const Transform3d& trafo) const render_color = this->get_cursor_sphere_left_button_color(); else if (m_button_down == Button::Right) render_color = this->get_cursor_sphere_right_button_color(); -#if ENABLE_LEGACY_OPENGL_REMOVAL + shader->start_using(); const Camera& camera = wxGetApp().plater()->get_camera(); @@ -372,23 +295,12 @@ void GLGizmoPainterBase::render_cursor_sphere(const Transform3d& trafo) const assert(s_sphere != nullptr); s_sphere->set_color(render_color); -#else - glsafe(::glColor4fv(render_color.data())); - - assert(s_sphere != nullptr); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL s_sphere->render(); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (is_left_handed) glsafe(::glFrontFace(GL_CCW)); - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } @@ -967,11 +879,7 @@ ColorRGBA TriangleSelectorGUI::get_seed_fill_color(const ColorRGBA& base_color) return saturate(base_color, 0.75f); } -#if ENABLE_LEGACY_OPENGL_REMOVAL void TriangleSelectorGUI::render(ImGuiWrapper* imgui, const Transform3d& matrix) -#else -void TriangleSelectorGUI::render(ImGuiWrapper* imgui) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { static const ColorRGBA enforcers_color = { 0.47f, 0.47f, 1.0f, 1.0f }; static const ColorRGBA blockers_color = { 1.0f, 0.44f, 0.44f, 1.0f }; @@ -989,18 +897,10 @@ void TriangleSelectorGUI::render(ImGuiWrapper* imgui) for (auto iva : {std::make_pair(&m_iva_enforcers, enforcers_color), std::make_pair(&m_iva_blockers, blockers_color)}) { -#if ENABLE_LEGACY_OPENGL_REMOVAL iva.first->set_color(iva.second); iva.first->render(); -#else - if (iva.first->has_VBOs()) { - shader->set_uniform("uniform_color", iva.second); - iva.first->render(); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL for (auto& iva : m_iva_seed_fills) { size_t color_idx = &iva - &m_iva_seed_fills.front(); const ColorRGBA& color = TriangleSelectorGUI::get_seed_fill_color(color_idx == 1 ? enforcers_color : @@ -1009,32 +909,8 @@ void TriangleSelectorGUI::render(ImGuiWrapper* imgui) iva.set_color(color); iva.render(); } -#else - for (auto& iva : m_iva_seed_fills) - if (iva.has_VBOs()) { - size_t color_idx = &iva - &m_iva_seed_fills.front(); - const ColorRGBA& color = TriangleSelectorGUI::get_seed_fill_color(color_idx == 1 ? enforcers_color : - color_idx == 2 ? blockers_color : - GLVolume::NEUTRAL_COLOR); - shader->set_uniform("uniform_color", color); - iva.render(); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL render_paint_contour(matrix); -#else - if (m_paint_contour.has_VBO()) { - ScopeGuard guard_gouraud([shader]() { shader->start_using(); }); - shader->stop_using(); - - auto *contour_shader = wxGetApp().get_shader("mm_contour"); - contour_shader->start_using(); - contour_shader->set_uniform("offset", OpenGLManager::get_gl_info().is_mesa() ? 0.0005 : 0.00001); - m_paint_contour.render(); - contour_shader->stop_using(); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #ifdef PRUSASLICER_TRIANGLE_SELECTOR_DEBUG if (imgui) @@ -1050,7 +926,6 @@ void TriangleSelectorGUI::update_render_data() int blc_cnt = 0; std::vector seed_fill_cnt(m_iva_seed_fills.size(), 0); -#if ENABLE_LEGACY_OPENGL_REMOVAL for (auto* iva : { &m_iva_enforcers, &m_iva_blockers }) { iva->reset(); } @@ -1066,13 +941,6 @@ void TriangleSelectorGUI::update_render_data() std::array iva_seed_fills_data; for (auto& data : iva_seed_fills_data) data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; -#else - for (auto *iva : {&m_iva_enforcers, &m_iva_blockers}) - iva->release_geometry(); - - for (auto &iva : m_iva_seed_fills) - iva.release_geometry(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // small value used to offset triangles along their normal to avoid z-fighting static const float offset = 0.001f; @@ -1082,15 +950,9 @@ void TriangleSelectorGUI::update_render_data() continue; int tr_state = int(tr.get_state()); -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel::Geometry &iva = tr.is_selected_by_seed_fill() ? iva_seed_fills_data[tr_state] : tr.get_state() == EnforcerBlockerType::ENFORCER ? iva_enforcers_data : iva_blockers_data; -#else - GLIndexedVertexArray &iva = tr.is_selected_by_seed_fill() ? m_iva_seed_fills[tr_state] : - tr.get_state() == EnforcerBlockerType::ENFORCER ? m_iva_enforcers : - m_iva_blockers; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL int &cnt = tr.is_selected_by_seed_fill() ? seed_fill_cnt[tr_state] : tr.get_state() == EnforcerBlockerType::ENFORCER ? enf_cnt : blc_cnt; @@ -1102,21 +964,13 @@ void TriangleSelectorGUI::update_render_data() const Vec3f n = (v1 - v0).cross(v2 - v1).normalized(); // small value used to offset triangles along their normal to avoid z-fighting const Vec3f offset_n = offset * n; -#if ENABLE_LEGACY_OPENGL_REMOVAL iva.add_vertex(v0 + offset_n, n); iva.add_vertex(v1 + offset_n, n); iva.add_vertex(v2 + offset_n, n); iva.add_triangle((unsigned int)cnt, (unsigned int)cnt + 1, (unsigned int)cnt + 2); -#else - iva.push_geometry(v0 + offset_n, n); - iva.push_geometry(v1 + offset_n, n); - iva.push_geometry(v2 + offset_n, n); - iva.push_triangle(cnt, cnt + 1, cnt + 2); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL cnt += 3; } -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!iva_enforcers_data.is_empty()) m_iva_enforcers.init_from(std::move(iva_enforcers_data)); if (!iva_blockers_data.is_empty()) @@ -1127,94 +981,8 @@ void TriangleSelectorGUI::update_render_data() } update_paint_contour(); -#else - for (auto *iva : {&m_iva_enforcers, &m_iva_blockers}) - iva->finalize_geometry(true); - - for (auto &iva : m_iva_seed_fills) - iva.finalize_geometry(true); - - m_paint_contour.release_geometry(); - std::vector contour_edges = this->get_seed_fill_contour(); - m_paint_contour.contour_vertices.reserve(contour_edges.size() * 6); - for (const Vec2i &edge : contour_edges) { - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(0)].v.x()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(0)].v.y()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(0)].v.z()); - - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(1)].v.x()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(1)].v.y()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(1)].v.z()); - } - - m_paint_contour.contour_indices.assign(m_paint_contour.contour_vertices.size() / 3, 0); - std::iota(m_paint_contour.contour_indices.begin(), m_paint_contour.contour_indices.end(), 0); - m_paint_contour.contour_indices_size = m_paint_contour.contour_indices.size(); - - m_paint_contour.finalize_geometry(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if !ENABLE_LEGACY_OPENGL_REMOVAL -void GLPaintContour::render() const -{ - assert(m_contour_VBO_id != 0); - assert(m_contour_EBO_id != 0); - - glsafe(::glLineWidth(4.0f)); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_contour_VBO_id)); - glsafe(::glVertexPointer(3, GL_FLOAT, 3 * sizeof(float), nullptr)); - - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - - if (this->contour_indices_size > 0) { - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_contour_EBO_id)); - glsafe(::glDrawElements(GL_LINES, GLsizei(this->contour_indices_size), GL_UNSIGNED_INT, nullptr)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - } - - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); -} - -void GLPaintContour::finalize_geometry() -{ - assert(m_contour_VBO_id == 0); - assert(m_contour_EBO_id == 0); - - if (!this->contour_vertices.empty()) { - glsafe(::glGenBuffers(1, &m_contour_VBO_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_contour_VBO_id)); - glsafe(::glBufferData(GL_ARRAY_BUFFER, this->contour_vertices.size() * sizeof(float), this->contour_vertices.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - this->contour_vertices.clear(); - } - - if (!this->contour_indices.empty()) { - glsafe(::glGenBuffers(1, &m_contour_EBO_id)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_contour_EBO_id)); - glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->contour_indices.size() * sizeof(unsigned int), this->contour_indices.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - this->contour_indices.clear(); - } -} - -void GLPaintContour::release_geometry() -{ - if (m_contour_VBO_id) { - glsafe(::glDeleteBuffers(1, &m_contour_VBO_id)); - m_contour_VBO_id = 0; - } - if (m_contour_EBO_id) { - glsafe(::glDeleteBuffers(1, &m_contour_EBO_id)); - m_contour_EBO_id = 0; - } - this->clear(); -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - #ifdef PRUSASLICER_TRIANGLE_SELECTOR_DEBUG void TriangleSelectorGUI::render_debug(ImGuiWrapper* imgui) { @@ -1250,91 +1018,48 @@ void TriangleSelectorGUI::render_debug(ImGuiWrapper* imgui) INVALID }; -#if ENABLE_LEGACY_OPENGL_REMOVAL for (auto& va : m_varrays) va.reset(); -#else - for (auto& va : m_varrays) - va.release_geometry(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL std::array cnts; ::glScalef(1.01f, 1.01f, 1.01f); -#if ENABLE_LEGACY_OPENGL_REMOVAL std::array varrays_data; for (auto& data : varrays_data) data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::UINT }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (int tr_id=0; tr_idadd_vertex(m_vertices[tr.verts_idxs[i]].v, Vec3f(0.0f, 0.0f, 1.0f)); } va->add_uint_triangle((unsigned int)*cnt, (unsigned int)*cnt + 1, (unsigned int)*cnt + 2); -#else - for (int i = 0; i < 3; ++i) - va->push_geometry(double(m_vertices[tr.verts_idxs[i]].v[0]), - double(m_vertices[tr.verts_idxs[i]].v[1]), - double(m_vertices[tr.verts_idxs[i]].v[2]), - 0., 0., 1.); - va->push_triangle(*cnt, - *cnt + 1, - *cnt + 2); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL *cnt += 3; } -#if ENABLE_LEGACY_OPENGL_REMOVAL for (int i = 0; i < 3; ++i) { if (!varrays_data[i].is_empty()) m_varrays[i].init_from(std::move(varrays_data[i])); } -#else -// for (auto* iva : { &m_iva_enforcers, &m_iva_blockers }) -// iva->finalize_geometry(true); -// -// for (auto& iva : m_iva_seed_fills) -// iva.finalize_geometry(true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* curr_shader = wxGetApp().get_current_shader(); if (curr_shader != nullptr) curr_shader->stop_using(); @@ -1346,11 +1071,9 @@ void TriangleSelectorGUI::render_debug(ImGuiWrapper* imgui) const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix()); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL ::glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); for (vtype i : {ORIGINAL, SPLIT, INVALID}) { -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel& va = m_varrays[i]; switch (i) { case ORIGINAL: va.set_color({ 0.0f, 0.0f, 1.0f, 1.0f }); break; @@ -1358,32 +1081,17 @@ void TriangleSelectorGUI::render_debug(ImGuiWrapper* imgui) case INVALID: va.set_color({ 1.0f, 1.0f, 0.0f, 1.0f }); break; } va.render(); -#else - GLIndexedVertexArray& va = m_varrays[i]; - va.finalize_geometry(true); - if (va.has_VBOs()) { - switch (i) { - case ORIGINAL : ::glColor3f(0.f, 0.f, 1.f); break; - case SPLIT : ::glColor3f(1.f, 0.f, 0.f); break; - case INVALID : ::glColor3f(1.f, 1.f, 0.f); break; - } - va.render(); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } ::glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); } if (curr_shader != nullptr) curr_shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } #endif // PRUSASLICER_TRIANGLE_SELECTOR_DEBUG -#if ENABLE_LEGACY_OPENGL_REMOVAL void TriangleSelectorGUI::update_paint_contour() { m_paint_contour.reset(); @@ -1430,6 +1138,5 @@ void TriangleSelectorGUI::render_paint_contour(const Transform3d& matrix) if (curr_shader != nullptr) curr_shader->start_using(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp index d4261761f6..44c7f40ab9 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp @@ -3,11 +3,7 @@ #include "GLGizmoBase.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/GLModel.hpp" -#else -#include "slic3r/GUI/3DScene.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include "libslic3r/ObjectID.hpp" #include "libslic3r/TriangleSelector.hpp" @@ -33,59 +29,14 @@ enum class PainterGizmoType { MMU_SEGMENTATION }; -#if !ENABLE_LEGACY_OPENGL_REMOVAL -class GLPaintContour -{ -public: - GLPaintContour() = default; - - void render() const; - - inline bool has_VBO() const { return m_contour_EBO_id != 0; } - - // Release the geometry data, release OpenGL VBOs. - void release_geometry(); - - // Finalize the initialization of the contour geometry and the indices, upload both to OpenGL VBO objects - // and possibly releasing it if it has been loaded into the VBOs. - void finalize_geometry(); - - void clear() - { - this->contour_vertices.clear(); - this->contour_indices.clear(); - this->contour_indices_size = 0; - } - - std::vector contour_vertices; - std::vector contour_indices; - - // When the triangle indices are loaded into the graphics card as Vertex Buffer Objects, - // the above mentioned std::vectors are cleared and the following variables keep their original length. - size_t contour_indices_size{0}; - - // IDs of the Vertex Array Objects, into which the geometry has been loaded. - // Zero if the VBOs are not sent to GPU yet. - GLuint m_contour_VBO_id{0}; - GLuint m_contour_EBO_id{0}; -}; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - class TriangleSelectorGUI : public TriangleSelector { public: explicit TriangleSelectorGUI(const TriangleMesh& mesh) : TriangleSelector(mesh) {} virtual ~TriangleSelectorGUI() = default; -#if ENABLE_LEGACY_OPENGL_REMOVAL virtual void render(ImGuiWrapper* imgui, const Transform3d& matrix); void render(const Transform3d& matrix) { this->render(nullptr, matrix); } -#else - // Render current selection. Transformation matrices are supposed - // to be already set. - virtual void render(ImGuiWrapper *imgui); - void render() { this->render(nullptr); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void request_update_render_data() { m_update_render_data = true; } @@ -103,29 +54,18 @@ protected: private: void update_render_data(); -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel m_iva_enforcers; GLModel m_iva_blockers; std::array m_iva_seed_fills; #ifdef PRUSASLICER_TRIANGLE_SELECTOR_DEBUG std::array m_varrays; #endif // PRUSASLICER_TRIANGLE_SELECTOR_DEBUG -#else - GLIndexedVertexArray m_iva_enforcers; - GLIndexedVertexArray m_iva_blockers; - std::array m_iva_seed_fills; - std::array m_varrays; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL protected: -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel m_paint_contour; void update_paint_contour(); void render_paint_contour(const Transform3d& matrix); -#else - GLPaintContour m_paint_contour; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; @@ -208,13 +148,11 @@ protected: bool m_paint_on_overhangs_only = false; float m_highlight_by_angle_threshold_deg = 0.f; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel m_circle; #if !ENABLE_GL_CORE_PROFILE Vec2d m_old_center{ Vec2d::Zero() }; #endif // !ENABLE_GL_CORE_PROFILE float m_old_cursor_radius{ 0.0f }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL static constexpr float SmartFillAngleMin = 0.0f; static constexpr float SmartFillAngleMax = 90.f; @@ -248,11 +186,7 @@ private: const Camera& camera, const std::vector& trafo_matrices) const; -#if ENABLE_LEGACY_OPENGL_REMOVAL static std::shared_ptr s_sphere; -#else - static std::shared_ptr s_sphere; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL bool m_internal_stack_active = false; bool m_schedule_update = false; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index 5b39c09291..6e7cf9c832 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -179,18 +179,13 @@ void GLGizmoRotate::on_render() glsafe(::glEnable(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_GL_CORE_PROFILE if (!OpenGLManager::get_gl_info().is_core_profile()) #endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); -#if ENABLE_LEGACY_OPENGL_REMOVAL + #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); #else @@ -228,32 +223,12 @@ void GLGizmoRotate::on_render() render_grabber_connection(color, radius_changed); shader->stop_using(); } -#else - glsafe(::glColor4fv((m_hover_id != -1) ? m_drag_color.data() : m_highlight_color.data())); - - render_circle(); - - if (m_hover_id != -1) { - render_scale(); - render_snap_radii(); - render_reference_radius(); - } - - glsafe(::glColor4fv(m_highlight_color.data())); - - if (m_hover_id != -1) - render_angle(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE render_grabber(m_bounding_box); #else render_grabber(box); #endif // ENABLE_WORLD_COORDINATE - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } #if ENABLE_WORLD_COORDINATE @@ -336,13 +311,8 @@ void GLGizmoRotate3D::load_rotoptimize_state() } } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoRotate::render_circle(const ColorRGBA& color, bool radius_changed) -#else -void GLGizmoRotate::render_circle() const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_circle.is_initialized() || radius_changed) { m_circle.reset(); @@ -363,29 +333,13 @@ void GLGizmoRotate::render_circle() const m_circle.set_color(color); m_circle.render(); -#else - ::glBegin(GL_LINE_LOOP); - for (unsigned int i = 0; i < ScaleStepsCount; ++i) { - const float angle = float(i) * ScaleStepRad; - const float x = ::cos(angle) * m_radius; - const float y = ::sin(angle) * m_radius; - const float z = 0.0f; - ::glVertex3f((GLfloat)x, (GLfloat)y, (GLfloat)z); - } - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoRotate::render_scale(const ColorRGBA& color, bool radius_changed) -#else -void GLGizmoRotate::render_scale() const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { const float out_radius_long = m_snap_fine_out_radius; const float out_radius_short = m_radius * (1.0f + 0.5f * ScaleLongTooth); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_scale.is_initialized() || radius_changed) { m_scale.reset(); @@ -417,36 +371,14 @@ void GLGizmoRotate::render_scale() const m_scale.set_color(color); m_scale.render(); -#else - ::glBegin(GL_LINES); - for (unsigned int i = 0; i < ScaleStepsCount; ++i) { - const float angle = (float)i * ScaleStepRad; - const float cosa = ::cos(angle); - const float sina = ::sin(angle); - const float in_x = cosa * m_radius; - const float in_y = sina * m_radius; - const float in_z = 0.0f; - const float out_x = (i % ScaleLongEvery == 0) ? cosa * out_radius_long : cosa * out_radius_short; - const float out_y = (i % ScaleLongEvery == 0) ? sina * out_radius_long : sina * out_radius_short; - const float out_z = 0.0f; - ::glVertex3f((GLfloat)in_x, (GLfloat)in_y, (GLfloat)in_z); - ::glVertex3f((GLfloat)out_x, (GLfloat)out_y, (GLfloat)out_z); - } - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoRotate::render_snap_radii(const ColorRGBA& color, bool radius_changed) -#else -void GLGizmoRotate::render_snap_radii() const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { const float step = 2.0f * float(PI) / float(SnapRegionsCount); const float in_radius = m_radius / 3.0f; const float out_radius = 2.0f * in_radius; -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_snap_radii.is_initialized() || radius_changed) { m_snap_radii.reset(); @@ -478,26 +410,8 @@ void GLGizmoRotate::render_snap_radii() const m_snap_radii.set_color(color); m_snap_radii.render(); -#else - ::glBegin(GL_LINES); - for (unsigned int i = 0; i < SnapRegionsCount; ++i) { - const float angle = (float)i * step; - const float cosa = ::cos(angle); - const float sina = ::sin(angle); - const float in_x = cosa * in_radius; - const float in_y = sina * in_radius; - const float in_z = 0.0f; - const float out_x = cosa * out_radius; - const float out_y = sina * out_radius; - const float out_z = 0.0f; - ::glVertex3f((GLfloat)in_x, (GLfloat)in_y, (GLfloat)in_z); - ::glVertex3f((GLfloat)out_x, (GLfloat)out_y, (GLfloat)out_z); - } - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoRotate::render_reference_radius(const ColorRGBA& color, bool radius_changed) { if (!m_reference_radius.is_initialized() || radius_changed) { @@ -521,26 +435,12 @@ void GLGizmoRotate::render_reference_radius(const ColorRGBA& color, bool radius_ m_reference_radius.set_color(color); m_reference_radius.render(); } -#else -void GLGizmoRotate::render_reference_radius() const -{ - ::glBegin(GL_LINES); - ::glVertex3f(0.0f, 0.0f, 0.0f); - ::glVertex3f((GLfloat)(m_radius * (1.0f + GrabberOffset)), 0.0f, 0.0f); - glsafe(::glEnd()); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoRotate::render_angle_arc(const ColorRGBA& color, bool radius_changed) -#else -void GLGizmoRotate::render_angle() const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { const float step_angle = float(m_angle) / float(AngleResolution); const float ex_radius = m_radius * (1.0f + GrabberOffset); -#if ENABLE_LEGACY_OPENGL_REMOVAL const bool angle_changed = std::abs(m_old_angle - m_angle) > EPSILON; m_old_angle = m_angle; @@ -565,20 +465,8 @@ void GLGizmoRotate::render_angle() const m_angle_arc.set_color(color); m_angle_arc.render(); -#else - ::glBegin(GL_LINE_STRIP); - for (unsigned int i = 0; i <= AngleResolution; ++i) { - const float angle = float(i) * step_angle; - const float x = ::cos(angle) * ex_radius; - const float y = ::sin(angle) * ex_radius; - const float z = 0.0f; - ::glVertex3f((GLfloat)x, (GLfloat)y, (GLfloat)z); - } - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoRotate::render_grabber_connection(const ColorRGBA& color, bool radius_changed) { if (!m_grabber_connection.model.is_initialized() || radius_changed || !m_grabber_connection.old_center.isApprox(m_grabbers.front().center)) { @@ -603,28 +491,13 @@ void GLGizmoRotate::render_grabber_connection(const ColorRGBA& color, bool radiu m_grabber_connection.model.set_color(color); m_grabber_connection.model.render(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoRotate::render_grabber(const BoundingBoxf3& box) { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - const double grabber_radius = double(m_radius) * (1.0 + double(GrabberOffset)); - m_grabbers[0].center = Vec3d(::cos(m_angle) * grabber_radius, ::sin(m_angle) * grabber_radius, 0.0); - m_grabbers[0].angles.z() = m_angle; - - glsafe(::glColor4fv((m_hover_id != -1) ? m_drag_color.data() : m_highlight_color.data())); - - ::glBegin(GL_LINES); - ::glVertex3f(0.0f, 0.0f, 0.0f); - ::glVertex3dv(m_grabbers[0].center.data()); - glsafe(::glEnd()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - m_grabbers.front().color = m_highlight_color; render_grabbers(box); } -#if ENABLE_LEGACY_OPENGL_REMOVAL Transform3d GLGizmoRotate::local_transform(const Selection& selection) const { Transform3d ret; @@ -666,43 +539,6 @@ Transform3d GLGizmoRotate::local_transform(const Selection& selection) const return Geometry::assemble_transform(m_center) * ret; #endif // ENABLE_WORLD_COORDINATE } -#else -void GLGizmoRotate::transform_to_local(const Selection& selection) const -{ - glsafe(::glTranslated(m_center.x(), m_center.y(), m_center.z())); - -#if ENABLE_WORLD_COORDINATE - glsafe(::glMultMatrixd(m_orient_matrix.data())); -#else - if (selection.is_single_volume() || selection.is_single_modifier() || selection.requires_local_axes()) { - const Transform3d orient_matrix = selection.get_first_volume()->get_instance_transformation().get_matrix(true, false, true, true); - glsafe(::glMultMatrixd(orient_matrix.data())); - } -#endif // ENABLE_WORLD_COORDINATE - - switch (m_axis) - { - case X: - { - glsafe(::glRotatef(90.0f, 0.0f, 1.0f, 0.0f)); - glsafe(::glRotatef(-90.0f, 0.0f, 0.0f, 1.0f)); - break; - } - case Y: - { - glsafe(::glRotatef(-90.0f, 0.0f, 0.0f, 1.0f)); - glsafe(::glRotatef(-90.0f, 0.0f, 1.0f, 0.0f)); - break; - } - default: - case Z: - { - // no rotation - break; - } - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray) const diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp index d117a12192..fa52e3a787 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp @@ -40,7 +40,6 @@ private: Transform3d m_orient_matrix{ Transform3d::Identity() }; #endif // ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel m_circle; GLModel m_scale; GLModel m_snap_radii; @@ -55,7 +54,6 @@ private: float m_old_radius{ 0.0f }; float m_old_hover_radius{ 0.0f }; float m_old_angle{ 0.0f }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // emboss need to draw rotation gizmo in local coordinate systems bool m_using_local_coordinate{false}; @@ -100,27 +98,15 @@ protected: void on_render() override; private: -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_circle(const ColorRGBA& color, bool radius_changed); void render_scale(const ColorRGBA& color, bool radius_changed); void render_snap_radii(const ColorRGBA& color, bool radius_changed); void render_reference_radius(const ColorRGBA& color, bool radius_changed); void render_angle_arc(const ColorRGBA& color, bool radius_changed); void render_grabber_connection(const ColorRGBA& color, bool radius_changed); -#else - void render_circle() const; - void render_scale() const; - void render_snap_radii() const; - void render_reference_radius() const; - void render_angle() const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void render_grabber(const BoundingBoxf3& box); -#if ENABLE_LEGACY_OPENGL_REMOVAL Transform3d local_transform(const Selection& selection) const; -#else - void transform_to_local(const Selection& selection) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // returns the intersection of the mouse ray with the plane perpendicular to the gizmo axis, in local coordinate #if ENABLE_WORLD_COORDINATE diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp index 42c74594c7..1787e5cf89 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp @@ -5,9 +5,7 @@ #if ENABLE_WORLD_COORDINATE #include "slic3r/GUI/GUI_ObjectManipulation.hpp" #endif // ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/Plater.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include "libslic3r/Model.hpp" #include @@ -29,7 +27,6 @@ GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent, const std::string& icon_filen , m_drag_color(DEFAULT_DRAG_COLOR) , m_highlight_color(DEFAULT_HIGHLIGHT_COLOR) { -#if ENABLE_LEGACY_OPENGL_REMOVAL m_grabber_connections[0].grabber_indices = { 0, 1 }; m_grabber_connections[1].grabber_indices = { 2, 3 }; m_grabber_connections[2].grabber_indices = { 4, 5 }; @@ -37,7 +34,6 @@ GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent, const std::string& icon_filen m_grabber_connections[4].grabber_indices = { 7, 8 }; m_grabber_connections[5].grabber_indices = { 8, 9 }; m_grabber_connections[6].grabber_indices = { 9, 6 }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } std::string GLGizmoScale3D::get_tooltip() const @@ -380,15 +376,10 @@ void GLGizmoScale3D::on_render() glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); #if ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d base_matrix = local_transform(selection); for (int i = 0; i < 10; ++i) { m_grabbers[i].matrix = base_matrix; } -#else - glsafe(::glPushMatrix()); - transform_to_local(selection); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const float grabber_mean_size = (float)((m_bounding_box.size().x() + m_bounding_box.size().y() + m_bounding_box.size().z()) / 3.0); #else @@ -397,7 +388,6 @@ void GLGizmoScale3D::on_render() #endif // ENABLE_WORLD_COORDINATE if (m_hover_id == -1) { -#if ENABLE_LEGACY_OPENGL_REMOVAL // draw connections #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); @@ -431,32 +421,11 @@ void GLGizmoScale3D::on_render() render_grabbers_connection(9, 6, m_base_color); shader->stop_using(); } -#else - // draw connections - if (m_grabbers[0].enabled && m_grabbers[1].enabled) { - glsafe(::glColor4fv(m_grabbers[0].color.data())); - render_grabbers_connection(0, 1); - } - if (m_grabbers[2].enabled && m_grabbers[3].enabled) { - glsafe(::glColor4fv(m_grabbers[2].color.data())); - render_grabbers_connection(2, 3); - } - if (m_grabbers[4].enabled && m_grabbers[5].enabled) { - glsafe(::glColor4fv(m_grabbers[4].color.data())); - render_grabbers_connection(4, 5); - } - glsafe(::glColor4fv(m_base_color.data())); - render_grabbers_connection(6, 7); - render_grabbers_connection(7, 8); - render_grabbers_connection(8, 9); - render_grabbers_connection(9, 6); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // draw grabbers render_grabbers(grabber_mean_size); } else if ((m_hover_id == 0 || m_hover_id == 1) && m_grabbers[0].enabled && m_grabbers[1].enabled) { -#if ENABLE_LEGACY_OPENGL_REMOVAL // draw connections #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); @@ -484,14 +453,6 @@ void GLGizmoScale3D::on_render() // draw grabbers shader = wxGetApp().get_shader("gouraud_light"); -#else - // draw connection - glsafe(::glColor4fv(AXES_COLOR[0].data())); - render_grabbers_connection(0, 1); - - // draw grabbers - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (shader != nullptr) { shader->start_using(); shader->set_uniform("emission_factor", 0.1f); @@ -501,7 +462,6 @@ void GLGizmoScale3D::on_render() } } else if ((m_hover_id == 2 || m_hover_id == 3) && m_grabbers[2].enabled && m_grabbers[3].enabled) { -#if ENABLE_LEGACY_OPENGL_REMOVAL // draw connections #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); @@ -529,14 +489,6 @@ void GLGizmoScale3D::on_render() // draw grabbers shader = wxGetApp().get_shader("gouraud_light"); -#else - // draw connection - glsafe(::glColor4fv(AXES_COLOR[1].data())); - render_grabbers_connection(2, 3); - - // draw grabbers - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (shader != nullptr) { shader->start_using(); shader->set_uniform("emission_factor", 0.1f); @@ -546,7 +498,6 @@ void GLGizmoScale3D::on_render() } } else if ((m_hover_id == 4 || m_hover_id == 5) && m_grabbers[4].enabled && m_grabbers[5].enabled) { -#if ENABLE_LEGACY_OPENGL_REMOVAL // draw connections #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); @@ -574,14 +525,6 @@ void GLGizmoScale3D::on_render() // draw grabbers shader = wxGetApp().get_shader("gouraud_light"); -#else - // draw connection - glsafe(::glColor4fv(AXES_COLOR[2].data())); - render_grabbers_connection(4, 5); - - // draw grabbers - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (shader != nullptr) { shader->start_using(); shader->set_uniform("emission_factor", 0.1f); @@ -591,7 +534,6 @@ void GLGizmoScale3D::on_render() } } else if (m_hover_id >= 6) { -#if ENABLE_LEGACY_OPENGL_REMOVAL // draw connections #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); @@ -622,17 +564,6 @@ void GLGizmoScale3D::on_render() // draw grabbers shader = wxGetApp().get_shader("gouraud_light"); -#else - // draw connection - glsafe(::glColor4fv(m_drag_color.data())); - render_grabbers_connection(6, 7); - render_grabbers_connection(7, 8); - render_grabbers_connection(8, 9); - render_grabbers_connection(9, 6); - - // draw grabbers - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (shader != nullptr) { shader->start_using(); shader->set_uniform("emission_factor", 0.1f); @@ -642,12 +573,6 @@ void GLGizmoScale3D::on_render() shader->stop_using(); } } - -#if ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL -#endif // ENABLE_WORLD_COORDINATE } void GLGizmoScale3D::on_register_raycasters_for_picking() @@ -661,7 +586,6 @@ void GLGizmoScale3D::on_unregister_raycasters_for_picking() m_parent.set_raycaster_gizmos_on_top(false); } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2, const ColorRGBA& color) { auto grabber_connection = [this](unsigned int id_1, unsigned int id_2) { @@ -701,18 +625,6 @@ void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int m_grabber_connections[id].model.set_color(color); m_grabber_connections[id].model.render(); } -#else -void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2) const -{ - unsigned int grabbers_count = (unsigned int)m_grabbers.size(); - if (id_1 < grabbers_count && id_2 < grabbers_count) { - ::glBegin(GL_LINES); - ::glVertex3dv(m_grabbers[id_1].center.data()); - ::glVertex3dv(m_grabbers[id_2].center.data()); - glsafe(::glEnd()); - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE void GLGizmoScale3D::do_scale_along_axis(Axis axis, const UpdateData& data) @@ -884,7 +796,6 @@ double GLGizmoScale3D::calc_ratio(const UpdateData& data) const } #if ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL Transform3d GLGizmoScale3D::local_transform(const Selection& selection) const { Transform3d ret = Geometry::translation_transform(m_center); @@ -897,19 +808,6 @@ Transform3d GLGizmoScale3D::local_transform(const Selection& selection) const } return ret; } -#else -void GLGizmoScale3D::transform_to_local(const Selection& selection) const -{ - glsafe(::glTranslated(m_center.x(), m_center.y(), m_center.z())); - - if (!wxGetApp().obj_manipul()->is_world_coordinates()) { - Transform3d orient_matrix = selection.get_first_volume()->get_instance_transformation().get_matrix(true, false, true, true); - if (selection.is_single_volume_or_modifier() && wxGetApp().obj_manipul()->is_local_coordinates()) - orient_matrix = orient_matrix * selection.get_first_volume()->get_volume_transformation().get_matrix(true, false, true, true); - glsafe(::glMultMatrixd(orient_matrix.data())); - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_WORLD_COORDINATE } // namespace GUI diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp index bf55115282..96594786e1 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp @@ -48,7 +48,6 @@ class GLGizmoScale3D : public GLGizmoBase double m_snap_step{ 0.05 }; StartingData m_starting; -#if ENABLE_LEGACY_OPENGL_REMOVAL struct GrabberConnection { GLModel model; @@ -57,7 +56,6 @@ class GLGizmoScale3D : public GLGizmoBase Vec3d old_v2{ Vec3d::Zero() }; }; std::array m_grabber_connections; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL ColorRGBA m_base_color; ColorRGBA m_drag_color; @@ -98,22 +96,14 @@ protected: virtual void on_unregister_raycasters_for_picking() override; private: -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_grabbers_connection(unsigned int id_1, unsigned int id_2, const ColorRGBA& color); -#else - void render_grabbers_connection(unsigned int id_1, unsigned int id_2) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void do_scale_along_axis(Axis axis, const UpdateData& data); void do_scale_uniform(const UpdateData& data); double calc_ratio(const UpdateData& data) const; #if ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL Transform3d local_transform(const Selection& selection) const; -#else - void transform_to_local(const Selection& selection) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_WORLD_COORDINATE }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp index a127369532..177d9d5a7b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp @@ -650,25 +650,13 @@ void GLGizmoSimplify::init_model() } assert(volume != nullptr); -#if ENABLE_LEGACY_OPENGL_REMOVAL // set actual triangle count m_triangle_count += volume->mesh().its.indices.size(); -#else - const indexed_triangle_set &its = volume->mesh().its; - - // set actual triangle count - m_triangle_count += its.indices.size(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL assert(m_glmodels.find(id) == m_glmodels.end()); GLModel &glmodel = m_glmodels[id]; // create new glmodel -#if ENABLE_LEGACY_OPENGL_REMOVAL glmodel.init_from(volume->mesh()); glmodel.set_color(selected_volume->color); -#else - glmodel.init_from(its); - glmodel.set_color(-1,selected_volume->color); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_parent.toggle_model_objects_visibility(false, info->model_object(), info->get_active_instance(), @@ -720,11 +708,7 @@ void GLGizmoSimplify::update_model(const State::Data &data) #else glmodel.init_from(its); #endif // ENABLE_OPENGL_ES -#if ENABLE_LEGACY_OPENGL_REMOVAL glmodel.set_color(color); -#else - glmodel.set_color(-1, color); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_triangle_count += its.indices.size(); } @@ -759,10 +743,6 @@ void GLGizmoSimplify::on_render() GLModel &glmodel = it->second; const Transform3d trafo_matrix = selected_volume->world_matrix(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(trafo_matrix.data())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL auto* gouraud_shader = wxGetApp().get_shader("gouraud_light"); #if ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES bool depth_test_enabled = ::glIsEnabled(GL_DEPTH_TEST); @@ -771,7 +751,6 @@ void GLGizmoSimplify::on_render() #endif // ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES glsafe(::glEnable(GL_DEPTH_TEST)); gouraud_shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); const Transform3d view_model_matrix = view_matrix * trafo_matrix; @@ -779,7 +758,6 @@ void GLGizmoSimplify::on_render() gouraud_shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * trafo_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); gouraud_shader->set_uniform("view_normal_matrix", view_normal_matrix); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glmodel.render(); gouraud_shader->stop_using(); @@ -791,12 +769,10 @@ void GLGizmoSimplify::on_render() #endif // ENABLE_OPENGL_ES contour_shader->start_using(); contour_shader->set_uniform("offset", OpenGLManager::get_gl_info().is_mesa() ? 0.0005 : 0.00001); -#if ENABLE_LEGACY_OPENGL_REMOVAL contour_shader->set_uniform("view_model_matrix", view_model_matrix); contour_shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const ColorRGBA color = glmodel.get_color(); glmodel.set_color(ColorRGBA::WHITE()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE if (!OpenGLManager::get_gl_info().is_core_profile()) #endif // ENABLE_GL_CORE_PROFILE @@ -808,9 +784,7 @@ void GLGizmoSimplify::on_render() #if !ENABLE_OPENGL_ES glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)); #endif // !ENABLE_OPENGL_ES -#if ENABLE_LEGACY_OPENGL_REMOVAL glmodel.set_color(color); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL contour_shader->stop_using(); } #if ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES @@ -819,9 +793,6 @@ void GLGizmoSimplify::on_render() #else glsafe(::glPopAttrib()); #endif // ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 1520a2ef14..c22cdf606a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -151,22 +151,12 @@ void GLGizmoSlaSupports::render_points(const Selection& selection) if (! has_points && ! has_holes) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); if (shader == nullptr) return; shader->start_using(); ScopeGuard guard([shader]() { shader->stop_using(); }); -#else - GLShaderProgram* shader = picking ? nullptr : wxGetApp().get_shader("gouraud_light"); - if (shader != nullptr) - shader->start_using(); - ScopeGuard guard([shader]() { - if (shader != nullptr) - shader->stop_using(); - }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const GLVolume* vol = selection.get_first_volume(); const Geometry::Transformation transformation(vol->world_matrix()); @@ -175,17 +165,9 @@ void GLGizmoSlaSupports::render_points(const Selection& selection) #else const Transform3d& instance_scaling_matrix_inverse = transformation.get_matrix(true, true, false, true).inverse(); #endif // ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#else - const Transform3d& instance_matrix = transformation.get_matrix(); - const float z_shift = m_c->selection_info()->get_sla_shift(); - glsafe(::glPushMatrix()); - glsafe(::glTranslated(0.0, 0.0, z_shift)); - glsafe(::glMultMatrixd(instance_matrix.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL ColorRGBA render_color; for (size_t i = 0; i < cache_size; ++i) { @@ -218,24 +200,12 @@ void GLGizmoSlaSupports::render_points(const Selection& selection) render_color = { 0.5f, 0.5f, 0.5f, 1.f }; } -#if ENABLE_LEGACY_OPENGL_REMOVAL m_cone.model.set_color(render_color); m_sphere.model.set_color(render_color); -#else - m_cone.set_color(-1, render_color); - m_sphere.set_color(-1, render_color); - if (shader && !picking) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - shader->set_uniform("emission_factor", 0.5f); + shader->set_uniform("emission_factor", 0.5f); // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d support_matrix = Geometry::translation_transform(support_point.pos.cast()) * instance_scaling_matrix_inverse; -#else - glsafe(::glPushMatrix()); - glsafe(::glTranslatef(support_point.pos.x(), support_point.pos.y(), support_point.pos.z())); - glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (vol->is_left_handed()) glsafe(::glFrontFace(GL_CW)); @@ -250,7 +220,6 @@ void GLGizmoSlaSupports::render_points(const Selection& selection) Eigen::Quaterniond q; q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * m_editing_cache[i].normal.cast()); const Eigen::AngleAxisd aa(q); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d model_matrix = vol->world_matrix() * support_matrix * Transform3d(aa.toRotationMatrix()) * 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 }); @@ -258,64 +227,30 @@ void GLGizmoSlaSupports::render_points(const Selection& selection) 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(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glPushMatrix()); - glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z())); - glsafe(::glTranslatef(0.f, 0.f, cone_height + support_point.head_front_radius * RenderPointScale)); - glsafe(::glRotated(180., 1., 0., 0.)); - glsafe(::glScaled(cone_radius, cone_radius, cone_height)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_cone.model.render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } const double radius = (double)support_point.head_front_radius * RenderPointScale; -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d model_matrix = vol->world_matrix() * support_matrix * Geometry::scale_transform(radius); 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(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glPushMatrix()); - glsafe(::glScaled(radius, radius, radius)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_sphere.model.render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL if (vol->is_left_handed()) glsafe(::glFrontFace(GL_CCW)); - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } // Now render the drain holes: if (has_holes) { render_color = { 0.7f, 0.7f, 0.7f, 0.7f }; -#if ENABLE_LEGACY_OPENGL_REMOVAL m_cylinder.set_color(render_color); -#else - m_cylinder.set_color(-1, render_color); - if (shader != nullptr) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("emission_factor", 0.5f); for (const sla::DrainHole& drain_hole : m_c->selection_info()->model_object()->sla_drain_holes) { if (is_mesh_point_clipped(drain_hole.pos.cast())) continue; -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d hole_matrix = Geometry::translation_transform(drain_hole.pos.cast()) * instance_scaling_matrix_inverse; -#else - // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. - glsafe(::glPushMatrix()); - glsafe(::glTranslatef(drain_hole.pos.x(), drain_hole.pos.y(), drain_hole.pos.z())); - glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (vol->is_left_handed()) glsafe(::glFrontFace(GL_CW)); @@ -324,30 +259,17 @@ void GLGizmoSlaSupports::render_points(const Selection& selection) Eigen::Quaterniond q; q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * (-drain_hole.normal).cast()); const Eigen::AngleAxisd aa(q); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d model_matrix = vol->world_matrix() * hole_matrix * Transform3d(aa.toRotationMatrix()) * Geometry::translation_transform(-drain_hole.height * Vec3d::UnitZ()) * Geometry::scale_transform(Vec3d(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); 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(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z())); - glsafe(::glTranslated(0., 0., -drain_hole.height)); - glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_cylinder.render(); if (vol->is_left_handed()) glsafe(::glFrontFace(GL_CCW)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp index b044cc5c85..0e1d5ae0c7 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp @@ -217,35 +217,19 @@ void InstancesHider::render_cut() const else clipper->set_limiting_plane(ClippingPlane::ClipsNothing()); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - if (mv->is_model_part()) - glsafe(::glColor3f(0.8f, 0.3f, 0.0f)); - else { - const ColorRGBA color = color_from_model_volume(*mv); - glsafe(::glColor4fv(color.data())); - } -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES bool depth_test_enabled = ::glIsEnabled(GL_DEPTH_TEST); #else glsafe(::glPushAttrib(GL_DEPTH_TEST)); #endif // ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES glsafe(::glDisable(GL_DEPTH_TEST)); -#if ENABLE_LEGACY_OPENGL_REMOVAL clipper->render_cut(mv->is_model_part() ? ColorRGBA(0.8f, 0.3f, 0.0f, 1.0f) : color_from_model_volume(*mv)); -#else - clipper->render_cut(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES if (depth_test_enabled) glsafe(::glEnable(GL_DEPTH_TEST)); #else glsafe(::glPopAttrib()); #endif // ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL ++clipper_id; } @@ -445,16 +429,8 @@ void ObjectClipper::render_cut() const clipper->set_plane(*m_clp); clipper->set_transformation(trafo); clipper->set_limiting_plane(ClippingPlane(Vec3d::UnitZ(), -SINKING_Z_THRESHOLD)); -#if ENABLE_LEGACY_OPENGL_REMOVAL clipper->render_cut({ 1.0f, 0.37f, 0.0f, 1.0f }); clipper->render_contour({ 1.f, 1.f, 1.f, 1.f}); -#else - glsafe(::glPushMatrix()); - glsafe(::glColor3f(1.0f, 0.37f, 0.0f)); - clipper->render_cut(); - glsafe(::glColor3f(1.f, 1.f, 1.f)); - clipper->render_contour(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL ++clipper_id; } @@ -602,16 +578,8 @@ void SupportsClipper::render_cut() const m_clipper->set_plane(*ocl->get_clipping_plane()); m_clipper->set_transformation(supports_trafo); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_clipper->render_cut({ 1.0f, 0.f, 0.37f, 1.0f }); m_clipper->render_contour({ 1.f, 1.f, 1.f, 1.f }); -#else - glsafe(::glPushMatrix()); - glsafe(::glColor3f(1.0f, 0.f, 0.37f)); - m_clipper->render_cut(); - glsafe(::glColor3f(1.0f, 1.f, 1.f)); - m_clipper->render_contour(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 9c0f50c8f8..0a229caf91 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -128,7 +128,6 @@ bool GLGizmosManager::init() return true; } -#if ENABLE_LEGACY_OPENGL_REMOVAL bool GLGizmosManager::init_arrow(const std::string& filename) { if (m_arrow_texture.get_id() != 0) @@ -137,23 +136,6 @@ bool GLGizmosManager::init_arrow(const std::string& filename) const std::string path = resources_dir() + "/icons/"; return (!filename.empty()) ? m_arrow_texture.load_from_svg_file(path + filename, false, false, false, 512) : false; } -#else -bool GLGizmosManager::init_arrow(const BackgroundTexture::Metadata & arrow_texture) -{ - if (m_arrow_texture.texture.get_id() != 0) - return true; - - std::string path = resources_dir() + "/icons/"; - bool res = false; - - if (!arrow_texture.filename.empty()) - res = m_arrow_texture.texture.load_from_svg_file(path + arrow_texture.filename, false, false, false, 1000); - if (res) - m_arrow_texture.metadata = arrow_texture; - - return res; -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmosManager::set_overlay_icon_size(float size) { @@ -678,7 +660,6 @@ void GLGizmosManager::update_after_undo_redo(const UndoRedo::Snapshot& snapshot) dynamic_cast(m_gizmos[SlaSupports].get())->reslice_SLA_supports(true); } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmosManager::render_background(float left, float top, float right, float bottom, float border_w, float border_h) const { const unsigned int tex_id = m_background_texture.texture.get_id(); @@ -731,62 +712,7 @@ void GLGizmosManager::render_background(float left, float top, float right, floa GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_right_uv, bottom_uv }, { right_uv, bottom_uv }, { right_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv } }); } } -#else -void GLGizmosManager::render_background(float left, float top, float right, float bottom, float border) const -{ - const unsigned int tex_id = m_background_texture.texture.get_id(); - const float tex_width = float(m_background_texture.texture.get_width()); - const float tex_height = float(m_background_texture.texture.get_height()); - if (tex_id != 0 && tex_width > 0 && tex_height > 0) { - const float inv_tex_width = (tex_width != 0.0f) ? 1.0f / tex_width : 0.0f; - const float inv_tex_height = (tex_height != 0.0f) ? 1.0f / tex_height : 0.0f; - const float internal_left = left + border; - const float internal_right = right - border; - const float internal_top = top - border; - const float internal_bottom = bottom + border; - - // float left_uv = 0.0f; - const float right_uv = 1.0f; - const float top_uv = 1.0f; - const float bottom_uv = 0.0f; - - const float internal_left_uv = float(m_background_texture.metadata.left) * inv_tex_width; - const float internal_right_uv = 1.0f - float(m_background_texture.metadata.right) * inv_tex_width; - const float internal_top_uv = 1.0f - float(m_background_texture.metadata.top) * inv_tex_height; - const float internal_bottom_uv = float(m_background_texture.metadata.bottom) * inv_tex_height; - - // top-left corner - GLTexture::render_sub_texture(tex_id, left, internal_left, internal_top, top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - - // top edge - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_top, top, { { internal_left_uv, internal_top_uv }, { internal_right_uv, internal_top_uv }, { internal_right_uv, top_uv }, { internal_left_uv, top_uv } }); - - // top-right corner - GLTexture::render_sub_texture(tex_id, internal_right, right, internal_top, top, { { internal_right_uv, internal_top_uv }, { right_uv, internal_top_uv }, { right_uv, top_uv }, { internal_right_uv, top_uv } }); - - // center-left edge - GLTexture::render_sub_texture(tex_id, left, internal_left, internal_bottom, internal_top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - - // center - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_bottom, internal_top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - - // center-right edge - GLTexture::render_sub_texture(tex_id, internal_right, right, internal_bottom, internal_top, { { internal_right_uv, internal_bottom_uv }, { right_uv, internal_bottom_uv }, { right_uv, internal_top_uv }, { internal_right_uv, internal_top_uv } }); - - // bottom-left corner - GLTexture::render_sub_texture(tex_id, left, internal_left, bottom, internal_bottom, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - - // bottom edge - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, bottom, internal_bottom, { { internal_left_uv, bottom_uv }, { internal_right_uv, bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_left_uv, internal_bottom_uv } }); - - // bottom-right corner - GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_right_uv, bottom_uv }, { right_uv, bottom_uv }, { right_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv } }); - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmosManager::render_arrow(const GLCanvas3D& parent, EType highlighted_type) const { const std::vector selectable_idxs = get_selectable_idxs(); @@ -833,48 +759,7 @@ void GLGizmosManager::render_arrow(const GLCanvas3D& parent, EType highlighted_t top_y -= stride_y; } } -#else -void GLGizmosManager::render_arrow(const GLCanvas3D& parent, EType highlighted_type) const -{ - std::vector selectable_idxs = get_selectable_idxs(); - if (selectable_idxs.empty()) - return; - float cnv_w = (float)m_parent.get_canvas_size().get_width(); - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float height = get_scaled_total_height(); - float zoomed_border = m_layout.scaled_border() * inv_zoom; - float zoomed_top_x = (-0.5f * cnv_w) * inv_zoom; - float zoomed_top_y = (0.5f * height) * inv_zoom; - zoomed_top_x += zoomed_border; - zoomed_top_y -= zoomed_border; - float icons_size = m_layout.scaled_icons_size(); - float zoomed_icons_size = icons_size * inv_zoom; - float zoomed_stride_y = m_layout.scaled_stride_y() * inv_zoom; - for (size_t idx : selectable_idxs) - { - if (idx == highlighted_type) { - int tex_width = m_icons_texture.get_width(); - int tex_height = m_icons_texture.get_height(); - unsigned int tex_id = m_arrow_texture.texture.get_id(); - float inv_tex_width = (tex_width != 0.0f) ? 1.0f / tex_width : 0.0f; - float inv_tex_height = (tex_height != 0.0f) ? 1.0f / tex_height : 0.0f; - float internal_left_uv = (float)m_arrow_texture.metadata.left * inv_tex_width; - float internal_right_uv = 1.0f - (float)m_arrow_texture.metadata.right * inv_tex_width; - float internal_top_uv = 1.0f - (float)m_arrow_texture.metadata.top * inv_tex_height; - float internal_bottom_uv = (float)m_arrow_texture.metadata.bottom * inv_tex_height; - - float arrow_sides_ratio = (float)m_arrow_texture.texture.get_height() / (float)m_arrow_texture.texture.get_width(); - - GLTexture::render_sub_texture(tex_id, zoomed_top_x + zoomed_icons_size * 1.2f, zoomed_top_x + zoomed_icons_size * 1.2f + zoomed_icons_size * 2.2f * arrow_sides_ratio, zoomed_top_y - zoomed_icons_size * 1.6f , zoomed_top_y + zoomed_icons_size * 0.6f, { { internal_left_uv, internal_bottom_uv }, { internal_left_uv, internal_top_uv }, { internal_right_uv, internal_top_uv }, { internal_right_uv, internal_bottom_uv } }); - break; - } - zoomed_top_y -= zoomed_stride_y; - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmosManager::do_render_overlay() const { const std::vector selectable_idxs = get_selectable_idxs(); @@ -946,80 +831,6 @@ void GLGizmosManager::do_render_overlay() const if (m_current != Undefined) m_gizmos[m_current]->render_input_window(get_scaled_total_width(), current_y, cnv_h - wxGetApp().plater()->get_view_toolbar().get_height()); } -#else -void GLGizmosManager::do_render_overlay() const -{ - std::vector selectable_idxs = get_selectable_idxs(); - if (selectable_idxs.empty()) - return; - - const float cnv_w = (float)m_parent.get_canvas_size().get_width(); - const float cnv_h = (float)m_parent.get_canvas_size().get_height(); - const float zoom = (float)wxGetApp().plater()->get_camera().get_zoom(); - const float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - - const float height = get_scaled_total_height(); - const float width = get_scaled_total_width(); - const float zoomed_border = m_layout.scaled_border() * inv_zoom; - - float zoomed_top_x = (-0.5f * cnv_w) * inv_zoom; - float zoomed_top_y = (0.5f * height) * inv_zoom; - - float zoomed_left = zoomed_top_x; - float zoomed_top = zoomed_top_y; - float zoomed_right = zoomed_left + width * inv_zoom; - float zoomed_bottom = zoomed_top - height * inv_zoom; - - render_background(zoomed_left, zoomed_top, zoomed_right, zoomed_bottom, zoomed_border); - - zoomed_top_x += zoomed_border; - zoomed_top_y -= zoomed_border; - - const float icons_size = m_layout.scaled_icons_size(); - const float zoomed_icons_size = icons_size * inv_zoom; - const float zoomed_stride_y = m_layout.scaled_stride_y() * inv_zoom; - - const unsigned int icons_texture_id = m_icons_texture.get_id(); - const int tex_width = m_icons_texture.get_width(); - const int tex_height = m_icons_texture.get_height(); - - if (icons_texture_id == 0 || tex_width <= 1 || tex_height <= 1) - return; - - const float du = (float)(tex_width - 1) / (6.0f * (float)tex_width); // 6 is the number of possible states if the icons - const float dv = (float)(tex_height - 1) / (float)(m_gizmos.size() * tex_height); - - // tiles in the texture are spaced by 1 pixel - const float u_offset = 1.0f / (float)tex_width; - const float v_offset = 1.0f / (float)tex_height; - - float current_y = FLT_MAX; - for (size_t idx : selectable_idxs) { - GLGizmoBase* gizmo = m_gizmos[idx].get(); - const unsigned int sprite_id = gizmo->get_sprite_id(); - // higlighted state needs to be decided first so its highlighting in every other state - const int icon_idx = (m_highlight.first == idx ? (m_highlight.second ? 4 : 5) : (m_current == idx) ? 2 : ((m_hover == idx) ? 1 : (gizmo->is_activable()? 0 : 3))); - - const float u_left = u_offset + icon_idx * du; - const float u_right = u_left + du - u_offset; - const float v_top = v_offset + sprite_id * dv; - const float v_bottom = v_top + dv - v_offset; - - GLTexture::render_sub_texture(icons_texture_id, zoomed_top_x, zoomed_top_x + zoomed_icons_size, zoomed_top_y - zoomed_icons_size, zoomed_top_y, { { u_left, v_bottom }, { u_right, v_bottom }, { u_right, v_top }, { u_left, v_top } }); - if (idx == m_current || current_y == FLT_MAX) { - // The FLT_MAX trick is here so that even non-selectable but activable - // gizmos are passed some meaningful value. - current_y = 0.5f * cnv_h - zoomed_top_y * zoom; - } - zoomed_top_y -= zoomed_stride_y; - } - - if (m_current != Undefined) { - const float toolbar_top = cnv_h - wxGetApp().plater()->get_view_toolbar().get_height(); - m_gizmos[m_current]->render_input_window(width, current_y, toolbar_top); - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL float GLGizmosManager::get_scaled_total_height() const { diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp index b380c55c46..8c98596bfd 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp @@ -34,7 +34,6 @@ public: Rect() = default; Rect(float left, float top, float right, float bottom) : m_left(left) , m_top(top) , m_right(right) , m_bottom(bottom) {} -#if ENABLE_LEGACY_OPENGL_REMOVAL bool operator == (const Rect& other) const { if (std::abs(m_left - other.m_left) > EPSILON) return false; if (std::abs(m_top - other.m_top) > EPSILON) return false; @@ -43,7 +42,6 @@ public: return true; } bool operator != (const Rect& other) const { return !operator==(other); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL float get_left() const { return m_left; } void set_left(float left) { m_left = left; } @@ -107,11 +105,7 @@ private: GLTexture m_icons_texture; bool m_icons_texture_dirty; BackgroundTexture m_background_texture; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLTexture m_arrow_texture; -#else - BackgroundTexture m_arrow_texture; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL Layout m_layout; EType m_current; EType m_hover; @@ -139,11 +133,7 @@ public: bool init(); -#if ENABLE_LEGACY_OPENGL_REMOVAL bool init_arrow(const std::string& filename); -#else - bool init_arrow(const BackgroundTexture::Metadata& arrow_texture); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL template void load(Archive& ar) @@ -244,11 +234,7 @@ private: bool alt_down = false, bool control_down = false); -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_background(float left, float top, float right, float bottom, float border_w, float border_h) const; -#else - void render_background(float left, float top, float right, float bottom, float border) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void do_render_overlay() const; diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 17709788d7..64cf7d9eda 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -1764,11 +1764,9 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) if (draw_data == nullptr || draw_data->CmdListsCount == 0) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("imgui"); if (shader == nullptr) return; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) ImGuiIO& io = ImGui::GetIO(); @@ -1777,15 +1775,11 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) if (fb_width == 0 || fb_height == 0) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* curr_shader = wxGetApp().get_current_shader(); if (curr_shader != nullptr) curr_shader->stop_using(); shader->start_using(); -#else - draw_data->ScaleClipRects(io.DisplayFramebufferScale); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES // Backup GL state @@ -1834,19 +1828,11 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_STENCIL_TEST)); glsafe(::glEnable(GL_SCISSOR_TEST)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glDisable(GL_LIGHTING)); - glsafe(::glDisable(GL_COLOR_MATERIAL)); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glEnableClientState(GL_TEXTURE_COORD_ARRAY)); - glsafe(::glEnableClientState(GL_COLOR_ARRAY)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_TEXTURE_2D)); glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)); glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)); #endif // ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES -#if ENABLE_LEGACY_OPENGL_REMOVAL // Setup viewport, orthographic projection matrix // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps. glsafe(::glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height)); @@ -1864,18 +1850,6 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) shader->set_uniform("Texture", 0); shader->set_uniform("ProjMtx", ortho_projection); -#else - // Setup viewport, orthographic projection matrix - // Our visible imgui space lies from draw_data->DisplayPps (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is typically (0,0) for single viewport apps. - glsafe(::glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height)); - glsafe(::glMatrixMode(GL_PROJECTION)); - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); - glsafe(::glOrtho(draw_data->DisplayPos.x, draw_data->DisplayPos.x + draw_data->DisplaySize.x, draw_data->DisplayPos.y + draw_data->DisplaySize.y, draw_data->DisplayPos.y, -1.0f, +1.0f)); - glsafe(::glMatrixMode(GL_MODELVIEW)); - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Will project scissor/clipping rectangles into framebuffer space const ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports @@ -1886,7 +1860,6 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) const ImDrawList* cmd_list = draw_data->CmdLists[n]; const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data; const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data; -#if ENABLE_LEGACY_OPENGL_REMOVAL const GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert); const GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx); @@ -1923,11 +1896,6 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) glsafe(::glGenBuffers(1, &ibo_id)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id)); glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx_buffer_size, idx_buffer, GL_STATIC_DRAW)); -#else - glsafe(::glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, pos)))); - glsafe(::glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, uv)))); - glsafe(::glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, col)))); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; ++cmd_i) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; @@ -1935,7 +1903,6 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) // User callback (registered via ImDrawList::AddCallback) pcmd->UserCallback(cmd_list, pcmd); else { -#if ENABLE_LEGACY_OPENGL_REMOVAL // Project scissor/clipping rectangles into framebuffer space const ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y); const ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y); @@ -1948,24 +1915,9 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) // Bind texture, Draw glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID())); glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)))); -#else - // Project scissor/clipping rectangles into framebuffer space - const ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y); - const ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y); - if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) - continue; - - // Apply scissor/clipping rectangle (Y is inverted in OpenGL) - glsafe(::glScissor((int)clip_min.x, (int)(fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y))); - - // Bind texture, Draw - glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID())); - glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer + pcmd->IdxOffset)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } -#if ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); if (color_id != -1) @@ -1983,7 +1935,6 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) if (vao_id > 0) glsafe(::glDeleteVertexArrays(1, &vao_id)); #endif // ENABLE_GL_CORE_PROFILE -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } #if ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES @@ -2006,15 +1957,6 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) // Restore modified state glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, last_texture_env_mode)); glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glDisableClientState(GL_COLOR_ARRAY)); - glsafe(::glDisableClientState(GL_TEXTURE_COORD_ARRAY)); - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - glsafe(::glMatrixMode(GL_MODELVIEW)); - glsafe(::glPopMatrix()); - glsafe(::glMatrixMode(GL_PROJECTION)); - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glPopAttrib()); glsafe(::glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glsafe(::glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]))); @@ -2022,12 +1964,10 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) glsafe(::glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3])); #endif // ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); if (curr_shader != nullptr) curr_shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } bool ImGuiWrapper::display_initialized() const diff --git a/src/slic3r/GUI/MeshUtils.cpp b/src/slic3r/GUI/MeshUtils.cpp index 8ac1af7dcd..39e463a19b 100644 --- a/src/slic3r/GUI/MeshUtils.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -6,10 +6,8 @@ #include "libslic3r/ClipperUtils.hpp" #include "libslic3r/Model.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/Plater.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/Camera.hpp" #include @@ -77,15 +75,10 @@ void MeshClipper::set_transformation(const Geometry::Transformation& trafo) } } -#if ENABLE_LEGACY_OPENGL_REMOVAL void MeshClipper::render_cut(const ColorRGBA& color) -#else -void MeshClipper::render_cut() -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (! m_result) recalculate_triangles(); -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* curr_shader = wxGetApp().get_current_shader(); if (curr_shader != nullptr) curr_shader->stop_using(); @@ -105,22 +98,14 @@ void MeshClipper::render_cut() if (curr_shader != nullptr) curr_shader->start_using(); -#else - if (m_vertex_array.has_VBOs()) - m_vertex_array.render(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void MeshClipper::render_contour(const ColorRGBA& color) -#else -void MeshClipper::render_contour() -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (! m_result) recalculate_triangles(); -#if ENABLE_LEGACY_OPENGL_REMOVAL + GLShaderProgram* curr_shader = wxGetApp().get_current_shader(); if (curr_shader != nullptr) curr_shader->stop_using(); @@ -140,10 +125,6 @@ void MeshClipper::render_contour() if (curr_shader != nullptr) curr_shader->start_using(); -#else - if (m_vertex_array_expanded.has_VBOs()) - m_vertex_array_expanded.render(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } bool MeshClipper::is_projection_inside_cut(const Vec3d& point_in) const @@ -265,7 +246,6 @@ void MeshClipper::recalculate_triangles() tr2.pretranslate(0.002 * m_plane.get_normal().normalized()); -#if ENABLE_LEGACY_OPENGL_REMOVAL std::vector triangles2d; for (const ExPolygon& exp : expolys) { @@ -352,16 +332,6 @@ void MeshClipper::recalculate_triangles() isl.expoly = std::move(exp); isl.expoly_bb = get_extents(exp); } -#else - #error NOT IMPLEMENTED -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - - - -#if ENABLE_LEGACY_OPENGL_REMOVAL -#else - #error NOT IMPLEMENTED -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } diff --git a/src/slic3r/GUI/MeshUtils.hpp b/src/slic3r/GUI/MeshUtils.hpp index f1225c4ff9..441532fdb2 100644 --- a/src/slic3r/GUI/MeshUtils.hpp +++ b/src/slic3r/GUI/MeshUtils.hpp @@ -7,11 +7,7 @@ #include "libslic3r/AABBMesh.hpp" #include "admesh/stl.h" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/GLModel.hpp" -#else -#include "slic3r/GUI/3DScene.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include #include @@ -102,12 +98,8 @@ public: // Render the triangulated cut. Transformation matrices should // be set in world coords. -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_cut(const ColorRGBA& color); void render_contour(const ColorRGBA& color); -#else - void render_cut(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void pass_mouse_click(const Vec3d& pt); @@ -122,7 +114,6 @@ private: const TriangleMesh* m_negative_mesh = nullptr; ClippingPlane m_plane; ClippingPlane m_limiting_plane = ClippingPlane::ClipsNothing(); -#if ENABLE_LEGACY_OPENGL_REMOVAL struct CutIsland { GLModel model; @@ -136,11 +127,6 @@ private: Transform3d trafo; // this rotates the cut into world coords }; std::optional m_result; - -#else - #error NOT IMLEMENTED - GLIndexedVertexArray m_vertex_array; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL bool m_fill_cut = true; double m_contour_width = 0.; }; diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index c3a7ec18be..2dde431f09 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -584,8 +584,16 @@ bool Selection::is_sla_compliant() const bool Selection::is_single_text() const { +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#if ENABLE_WORLD_COORDINATE +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ if (!is_single_volume_or_modifier()) - return false; +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#else + if (!is_single_volume() && !is_single_modifier()) +#endif // ENABLE_WORLD_COORDINATE +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + return false; const GLVolume* gl_volume = (*m_volumes)[*m_list.begin()]; const ModelVolume* model_volume = m_model->objects[gl_volume->object_idx()]->volumes[gl_volume->volume_idx()]; @@ -1693,7 +1701,6 @@ void Selection::render(float scale_factor) m_scale_factor = scale_factor; // render cumulative bounding box of selected volumes -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE BoundingBoxf3 box; Transform3d trafo; @@ -1722,9 +1729,6 @@ void Selection::render(float scale_factor) #else render_bounding_box(get_bounding_box(), ColorRGB::WHITE()); #endif // ENABLE_WORLD_COORDINATE -#else - render_selected_volumes(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL render_synchronized_volumes(); } @@ -1734,38 +1738,26 @@ void Selection::render_center(bool gizmo_is_dragging) if (!m_valid || is_empty()) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("flat"); if (shader == nullptr) return; shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const Vec3d center = gizmo_is_dragging ? m_cache.dragging_center : get_bounding_box().center(); glsafe(::glDisable(GL_DEPTH_TEST)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); Transform3d view_model_matrix = camera.get_view_matrix() * Geometry::assemble_transform(center); shader->set_uniform("view_model_matrix", view_model_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); m_vbo_sphere.set_color(ColorRGBA::WHITE()); -#else - glsafe(::glPushMatrix()); - glsafe(::glTranslated(center.x(), center.y(), center.z())); - m_vbo_sphere.set_color(-1, ColorRGBA::WHITE()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_vbo_sphere.render(); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); -#else - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } #endif // ENABLE_RENDER_SELECTION_CENTER @@ -1774,33 +1766,16 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field) if (sidebar_field.empty()) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader(boost::starts_with(sidebar_field, "layer") ? "flat" : "gouraud_light"); if (shader == nullptr) return; shader->start_using(); -#else - GLShaderProgram* shader = nullptr; - - if (!boost::starts_with(sidebar_field, "layer")) { - shader = wxGetApp().get_shader("gouraud_light"); - if (shader == nullptr) - return; - - shader->start_using(); - glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_DEPTH_TEST)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d base_matrix = Geometry::translation_transform(get_bounding_box().center()); Transform3d orient_matrix = Transform3d::Identity(); -#else - glsafe(::glPushMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE const Vec3d center = get_bounding_box().center(); @@ -1808,28 +1783,16 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field) #endif // ENABLE_WORLD_COORDINATE if (!boost::starts_with(sidebar_field, "layer")) { -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("emission_factor", 0.05f); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if !ENABLE_LEGACY_OPENGL_REMOVAL&& !ENABLE_WORLD_COORDINATE - const Vec3d& center = get_bounding_box().center(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL&& !ENABLE_WORLD_COORDINATE #if ENABLE_WORLD_COORDINATE if (is_single_full_instance() && !wxGetApp().obj_manipul()->is_world_coordinates()) { + orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_rotation_matrix(); + axes_center = (*m_volumes)[*m_list.begin()]->get_instance_offset(); #else + const Vec3d& center = get_bounding_box().center(); if (is_single_full_instance() && !wxGetApp().obj_manipul()->get_world_coordinates()) { -#endif // ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL&& !ENABLE_WORLD_COORDINATE glsafe(::glTranslated(center.x(), center.y(), center.z())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL&& !ENABLE_WORLD_COORDINATE -#if ENABLE_WORLD_COORDINATE - orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_rotation_matrix(); - axes_center = (*m_volumes)[*m_list.begin()]->get_instance_offset(); -#else if (!boost::starts_with(sidebar_field, "position")) { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - Transform3d orient_matrix = Transform3d::Identity(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL if (boost::starts_with(sidebar_field, "scale")) orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); else if (boost::starts_with(sidebar_field, "rotation")) { @@ -1843,21 +1806,11 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field) orient_matrix.rotate(Eigen::AngleAxisd(rotation.z(), Vec3d::UnitZ())); } } -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glMultMatrixd(orient_matrix.data())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } #endif // ENABLE_WORLD_COORDINATE } #if ENABLE_WORLD_COORDINATE else if (is_single_volume_or_modifier()) { -#else - else if (is_single_volume() || is_single_modifier()) { -#endif // ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL&& !ENABLE_WORLD_COORDINATE - glsafe(::glTranslated(center.x(), center.y(), center.z())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL&& !ENABLE_WORLD_COORDINATE -#if ENABLE_WORLD_COORDINATE if (!wxGetApp().obj_manipul()->is_world_coordinates()) { if (wxGetApp().obj_manipul()->is_local_coordinates()) { const GLVolume* v = (*m_volumes)[*m_list.begin()]; @@ -1870,55 +1823,32 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field) } } #else -#if ENABLE_LEGACY_OPENGL_REMOVAL - orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); -#else + else if (is_single_volume() || is_single_modifier()) { glsafe(::glTranslated(center.x(), center.y(), center.z())); - Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL + orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); if (!boost::starts_with(sidebar_field, "position")) orient_matrix = orient_matrix * (*m_volumes)[*m_list.begin()]->get_volume_transformation().get_matrix(true, false, true, true); - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glMultMatrixd(orient_matrix.data())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_WORLD_COORDINATE } else { -#if ENABLE_LEGACY_OPENGL_REMOVAL|| ENABLE_WORLD_COORDINATE if (requires_local_axes()) #if ENABLE_WORLD_COORDINATE orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_rotation_matrix(); #else orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); #endif // ENABLE_WORLD_COORDINATE -#else - glsafe(::glTranslated(center.x(), center.y(), center.z())); - if (requires_local_axes()) { - const Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); - glsafe(::glMultMatrixd(orient_matrix.data())); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL|| ENABLE_WORLD_COORDINATE } } -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!boost::starts_with(sidebar_field, "layer")) glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE if (!boost::starts_with(sidebar_field, "layer")) { shader->set_uniform("emission_factor", 0.1f); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glTranslated(center.x(), center.y(), center.z())); - glsafe(::glMultMatrixd(orient_matrix.data())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } #endif // ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL if (boost::starts_with(sidebar_field, "position")) render_sidebar_position_hints(sidebar_field, *shader, base_matrix * orient_matrix); else if (boost::starts_with(sidebar_field, "rotation")) @@ -1934,39 +1864,8 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field) m_axes.render(Geometry::translation_transform(axes_center) * orient_matrix, 0.25f); } #endif // ENABLE_WORLD_COORDINATE -#else - if (boost::starts_with(sidebar_field, "position")) - render_sidebar_position_hints(sidebar_field); - else if (boost::starts_with(sidebar_field, "rotation")) - render_sidebar_rotation_hints(sidebar_field); - else if (boost::starts_with(sidebar_field, "scale") || boost::starts_with(sidebar_field, "size")) - render_sidebar_scale_hints(sidebar_field); - else if (boost::starts_with(sidebar_field, "layer")) - render_sidebar_layers_hints(sidebar_field); -#if ENABLE_WORLD_COORDINATE - if (!boost::starts_with(sidebar_field, "layer")) { - glsafe(::glPopMatrix()); - glsafe(::glPushMatrix()); - glsafe(::glTranslated(axes_center.x(), axes_center.y(), axes_center.z())); - glsafe(::glMultMatrixd(orient_matrix.data())); - if (!wxGetApp().obj_manipul()->is_world_coordinates()) - m_axes.render(0.25f); - glsafe(::glPopMatrix()); - } -#endif // ENABLE_WORLD_COORDINATE -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL -#endif // ENABLE_WORLD_COORDINATE - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - if (!boost::starts_with(sidebar_field, "layer")) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - shader->stop_using(); + shader->stop_using(); } bool Selection::requires_local_axes() const @@ -2380,23 +2279,11 @@ void Selection::do_remove_object(unsigned int object_idx) } } -#if !ENABLE_LEGACY_OPENGL_REMOVAL -void Selection::render_selected_volumes() const -{ - float color[3] = { 1.0f, 1.0f, 1.0f }; - render_bounding_box(get_bounding_box(), color); -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - void Selection::render_synchronized_volumes() { if (m_mode == Instance) return; -#if !ENABLE_LEGACY_OPENGL_REMOVAL - float color[3] = { 1.0f, 1.0f, 0.0f }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - #if ENABLE_WORLD_COORDINATE const ECoordinatesType coordinates_type = wxGetApp().obj_manipul()->get_coordinates_type(); BoundingBoxf3 box; @@ -2415,7 +2302,6 @@ void Selection::render_synchronized_volumes() if (v.object_idx() != object_idx || v.volume_idx() != volume_idx) continue; -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE if (coordinates_type == ECoordinatesType::World) { box = v.transformed_convex_hull_bounding_box(); @@ -2433,36 +2319,16 @@ void Selection::render_synchronized_volumes() #else render_bounding_box(v.transformed_convex_hull_bounding_box(), ColorRGB::YELLOW()); #endif // ENABLE_WORLD_COORDINATE -#else - render_bounding_box(v.transformed_convex_hull_bounding_box(), color); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } } -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE void Selection::render_bounding_box(const BoundingBoxf3& box, const Transform3d& trafo, const ColorRGB& color) #else void Selection::render_bounding_box(const BoundingBoxf3& box, const ColorRGB& color) #endif // ENABLE_WORLD_COORDINATE { -#else -void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) const -{ - if (color == nullptr) - return; - - const Vec3f b_min = box.min.cast(); - const Vec3f b_max = box.max.cast(); - const Vec3f size = 0.2f * box.size().cast(); - - glsafe(::glEnable(GL_DEPTH_TEST)); - glsafe(::glColor3fv(color)); - glsafe(::glLineWidth(2.0f * m_scale_factor)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL const BoundingBoxf3& curr_box = m_box.get_bounding_box(); if (!m_box.is_initialized() || !is_approx(box.min, curr_box.min) || !is_approx(box.max, curr_box.max)) { @@ -2556,13 +2422,6 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con if (shader == nullptr) return; -#if ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(trafo.data())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL -#endif // ENABLE_WORLD_COORDINATE - shader->start_using(); const Camera& camera = wxGetApp().plater()->get_camera(); #if ENABLE_WORLD_COORDINATE @@ -2580,49 +2439,6 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con m_box.set_color(to_rgba(color)); m_box.render(); shader->stop_using(); - -#if ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL -#endif // ENABLE_WORLD_COORDINATE -#else - ::glBegin(GL_LINES); - - ::glVertex3f(b_min(0), b_min(1), b_min(2)); ::glVertex3f(b_min(0) + size(0), b_min(1), b_min(2)); - ::glVertex3f(b_min(0), b_min(1), b_min(2)); ::glVertex3f(b_min(0), b_min(1) + size(1), b_min(2)); - ::glVertex3f(b_min(0), b_min(1), b_min(2)); ::glVertex3f(b_min(0), b_min(1), b_min(2) + size(2)); - - ::glVertex3f(b_max(0), b_min(1), b_min(2)); ::glVertex3f(b_max(0) - size(0), b_min(1), b_min(2)); - ::glVertex3f(b_max(0), b_min(1), b_min(2)); ::glVertex3f(b_max(0), b_min(1) + size(1), b_min(2)); - ::glVertex3f(b_max(0), b_min(1), b_min(2)); ::glVertex3f(b_max(0), b_min(1), b_min(2) + size(2)); - - ::glVertex3f(b_max(0), b_max(1), b_min(2)); ::glVertex3f(b_max(0) - size(0), b_max(1), b_min(2)); - ::glVertex3f(b_max(0), b_max(1), b_min(2)); ::glVertex3f(b_max(0), b_max(1) - size(1), b_min(2)); - ::glVertex3f(b_max(0), b_max(1), b_min(2)); ::glVertex3f(b_max(0), b_max(1), b_min(2) + size(2)); - - ::glVertex3f(b_min(0), b_max(1), b_min(2)); ::glVertex3f(b_min(0) + size(0), b_max(1), b_min(2)); - ::glVertex3f(b_min(0), b_max(1), b_min(2)); ::glVertex3f(b_min(0), b_max(1) - size(1), b_min(2)); - ::glVertex3f(b_min(0), b_max(1), b_min(2)); ::glVertex3f(b_min(0), b_max(1), b_min(2) + size(2)); - - ::glVertex3f(b_min(0), b_min(1), b_max(2)); ::glVertex3f(b_min(0) + size(0), b_min(1), b_max(2)); - ::glVertex3f(b_min(0), b_min(1), b_max(2)); ::glVertex3f(b_min(0), b_min(1) + size(1), b_max(2)); - ::glVertex3f(b_min(0), b_min(1), b_max(2)); ::glVertex3f(b_min(0), b_min(1), b_max(2) - size(2)); - - ::glVertex3f(b_max(0), b_min(1), b_max(2)); ::glVertex3f(b_max(0) - size(0), b_min(1), b_max(2)); - ::glVertex3f(b_max(0), b_min(1), b_max(2)); ::glVertex3f(b_max(0), b_min(1) + size(1), b_max(2)); - ::glVertex3f(b_max(0), b_min(1), b_max(2)); ::glVertex3f(b_max(0), b_min(1), b_max(2) - size(2)); - - ::glVertex3f(b_max(0), b_max(1), b_max(2)); ::glVertex3f(b_max(0) - size(0), b_max(1), b_max(2)); - ::glVertex3f(b_max(0), b_max(1), b_max(2)); ::glVertex3f(b_max(0), b_max(1) - size(1), b_max(2)); - ::glVertex3f(b_max(0), b_max(1), b_max(2)); ::glVertex3f(b_max(0), b_max(1), b_max(2) - size(2)); - - ::glVertex3f(b_min(0), b_max(1), b_max(2)); ::glVertex3f(b_min(0) + size(0), b_max(1), b_max(2)); - ::glVertex3f(b_min(0), b_max(1), b_max(2)); ::glVertex3f(b_min(0), b_max(1) - size(1), b_max(2)); - ::glVertex3f(b_min(0), b_max(1), b_max(2)); ::glVertex3f(b_min(0), b_max(1), b_max(2) - size(2)); - - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } static ColorRGBA get_color(Axis axis) @@ -2630,13 +2446,8 @@ static ColorRGBA get_color(Axis axis) return AXES_COLOR[axis]; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Selection::render_sidebar_position_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix) -#else -void Selection::render_sidebar_position_hints(const std::string& sidebar_field) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader.set_uniform("projection_matrix", camera.get_projection_matrix()); @@ -2663,31 +2474,10 @@ void Selection::render_sidebar_position_hints(const std::string& sidebar_field) m_arrow.set_color(get_color(Z)); m_arrow.render(); } -#else - if (boost::ends_with(sidebar_field, "x")) { - glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0)); - m_arrow.set_color(-1, get_color(X)); - m_arrow.render(); - } - else if (boost::ends_with(sidebar_field, "y")) { - m_arrow.set_color(-1, get_color(Y)); - m_arrow.render(); - } - else if (boost::ends_with(sidebar_field, "z")) { - glsafe(::glRotated(90.0, 1.0, 0.0, 0.0)); - m_arrow.set_color(-1, get_color(Z)); - m_arrow.render(); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix) -#else -void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { -#if ENABLE_LEGACY_OPENGL_REMOVAL auto render_sidebar_rotation_hint = [this](GLShaderProgram& shader, const Transform3d& view_matrix, const Transform3d& model_matrix) { shader.set_uniform("view_model_matrix", view_matrix * model_matrix); Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); @@ -2716,35 +2506,9 @@ void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field) m_curved_arrow.set_color(get_color(Z)); render_sidebar_rotation_hint(shader, view_matrix, matrix); } -#else - auto render_sidebar_rotation_hint = [this]() { - m_curved_arrow.render(); - glsafe(::glRotated(180.0, 0.0, 0.0, 1.0)); - m_curved_arrow.render(); - }; - - if (boost::ends_with(sidebar_field, "x")) { - glsafe(::glRotated(90.0, 0.0, 1.0, 0.0)); - m_curved_arrow.set_color(-1, get_color(X)); - render_sidebar_rotation_hint(); - } - else if (boost::ends_with(sidebar_field, "y")) { - glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0)); - m_curved_arrow.set_color(-1, get_color(Y)); - render_sidebar_rotation_hint(); - } - else if (boost::ends_with(sidebar_field, "z")) { - m_curved_arrow.set_color(-1, get_color(Z)); - render_sidebar_rotation_hint(); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Selection::render_sidebar_scale_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix) -#else -void Selection::render_sidebar_scale_hints(const std::string& sidebar_field) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { #if ENABLE_WORLD_COORDINATE const bool uniform_scale = wxGetApp().obj_manipul()->get_uniform_scaling(); @@ -2752,80 +2516,36 @@ void Selection::render_sidebar_scale_hints(const std::string& sidebar_field) const bool uniform_scale = requires_uniform_scale() || wxGetApp().obj_manipul()->get_uniform_scaling(); #endif // ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL auto render_sidebar_scale_hint = [this, uniform_scale](Axis axis, GLShaderProgram& shader, const Transform3d& view_matrix, const Transform3d& model_matrix) { m_arrow.set_color(uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis)); Transform3d matrix = model_matrix * Geometry::translation_transform(5.0 * Vec3d::UnitY()); shader.set_uniform("view_model_matrix", view_matrix * matrix); Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader.set_uniform("view_normal_matrix", view_normal_matrix); -#else - auto render_sidebar_scale_hint = [this, uniform_scale](Axis axis) { - m_arrow.set_color(-1, uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis)); - GLShaderProgram* shader = wxGetApp().get_current_shader(); - if (shader != nullptr) - shader->set_uniform("emission_factor", 0.0f); - - glsafe(::glTranslated(0.0, 5.0, 0.0)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.render(); -#if ENABLE_LEGACY_OPENGL_REMOVAL matrix = model_matrix * Geometry::translation_transform(-5.0 * Vec3d::UnitY()) * Geometry::rotation_transform(PI * Vec3d::UnitZ()); shader.set_uniform("view_model_matrix", view_matrix * matrix); view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader.set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glTranslated(0.0, -10.0, 0.0)); - glsafe(::glRotated(180.0, 0.0, 0.0, 1.0)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.render(); }; -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader.set_uniform("projection_matrix", camera.get_projection_matrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - if (boost::ends_with(sidebar_field, "x") || uniform_scale) { -#if ENABLE_LEGACY_OPENGL_REMOVAL + if (boost::ends_with(sidebar_field, "x") || uniform_scale) render_sidebar_scale_hint(X, shader, view_matrix, matrix * Geometry::rotation_transform(-0.5 * PI * Vec3d::UnitZ())); -#else - glsafe(::glPushMatrix()); - glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0)); - render_sidebar_scale_hint(X); - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - } - if (boost::ends_with(sidebar_field, "y") || uniform_scale) { -#if ENABLE_LEGACY_OPENGL_REMOVAL + if (boost::ends_with(sidebar_field, "y") || uniform_scale) render_sidebar_scale_hint(Y, shader, view_matrix, matrix); -#else - glsafe(::glPushMatrix()); - render_sidebar_scale_hint(Y); - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - } - if (boost::ends_with(sidebar_field, "z") || uniform_scale) { -#if ENABLE_LEGACY_OPENGL_REMOVAL + if (boost::ends_with(sidebar_field, "z") || uniform_scale) render_sidebar_scale_hint(Z, shader, view_matrix, matrix * Geometry::rotation_transform(0.5 * PI * Vec3d::UnitX())); -#else - glsafe(::glPushMatrix()); - glsafe(::glRotated(90.0, 1.0, 0.0, 0.0)); - render_sidebar_scale_hint(Z); - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - } } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Selection::render_sidebar_layers_hints(const std::string& sidebar_field, GLShaderProgram& shader) -#else -void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { static const float Margin = 10.0f; @@ -2856,29 +2576,19 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) const BoundingBoxf3& box = get_bounding_box(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - const float min_x = float(box.min.x()) - Margin; - const float max_x = float(box.max.x()) + Margin; - const float min_y = float(box.min.y()) - Margin; - const float max_y = float(box.max.y()) + Margin; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - // view dependend order of rendering to keep correct transparency const bool camera_on_top = wxGetApp().plater()->get_camera().is_looking_downward(); const float z1 = camera_on_top ? min_z : max_z; const float z2 = camera_on_top ? max_z : min_z; -#if ENABLE_LEGACY_OPENGL_REMOVAL const Vec3f p1 = { float(box.min.x()) - Margin, float(box.min.y()) - Margin, z1 }; const Vec3f p2 = { float(box.max.x()) + Margin, float(box.max.y()) + Margin, z2 }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_CULL_FACE)); glsafe(::glEnable(GL_BLEND)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_planes.models[0].is_initialized() || !is_approx(m_planes.check_points[0], p1)) { m_planes.check_points[0] = p1; m_planes.models[0].reset(); @@ -2931,23 +2641,6 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) m_planes.models[0].render(); m_planes.models[1].set_color((camera_on_top && type == 2) || (!camera_on_top && type == 1) ? SOLID_PLANE_COLOR : TRANSPARENT_PLANE_COLOR); m_planes.models[1].render(); -#else - ::glBegin(GL_QUADS); - ::glColor4fv((camera_on_top && type == 1) || (!camera_on_top && type == 2) ? SOLID_PLANE_COLOR.data() : TRANSPARENT_PLANE_COLOR.data()); - ::glVertex3f(min_x, min_y, z1); - ::glVertex3f(max_x, min_y, z1); - ::glVertex3f(max_x, max_y, z1); - ::glVertex3f(min_x, max_y, z1); - glsafe(::glEnd()); - - ::glBegin(GL_QUADS); - ::glColor4fv((camera_on_top && type == 2) || (!camera_on_top && type == 1) ? SOLID_PLANE_COLOR.data() : TRANSPARENT_PLANE_COLOR.data()); - ::glVertex3f(min_x, min_y, z2); - ::glVertex3f(max_x, min_y, z2); - ::glVertex3f(max_x, max_y, z2); - ::glVertex3f(min_x, max_y, z2); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_CULL_FACE)); glsafe(::glDisable(GL_BLEND)); diff --git a/src/slic3r/GUI/Selection.hpp b/src/slic3r/GUI/Selection.hpp index 6468f6a87d..107e56f41c 100644 --- a/src/slic3r/GUI/Selection.hpp +++ b/src/slic3r/GUI/Selection.hpp @@ -253,7 +253,6 @@ private: #endif // ENABLE_WORLD_COORDINATE GLModel m_arrow; GLModel m_curved_arrow; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel m_box; struct Planes { @@ -261,7 +260,6 @@ private: std::array models; }; Planes m_planes; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL float m_scale_factor; @@ -467,7 +465,6 @@ private: void set_bounding_boxes_dirty() { m_bounding_box.reset(); m_unscaled_instance_bounding_box.reset(); m_scaled_instance_bounding_box.reset(); } #endif // ENABLE_WORLD_COORDINATE void render_synchronized_volumes(); -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE void render_bounding_box(const BoundingBoxf3& box, const Transform3d& trafo, const ColorRGB& color); #else @@ -479,14 +476,6 @@ private: void render_sidebar_rotation_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix); void render_sidebar_scale_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix); void render_sidebar_layers_hints(const std::string& sidebar_field, GLShaderProgram& shader); -#else - void render_selected_volumes() const; - void render_bounding_box(const BoundingBoxf3& box, float* color) const; - void render_sidebar_position_hints(const std::string& sidebar_field); - void render_sidebar_rotation_hints(const std::string& sidebar_field); - void render_sidebar_scale_hints(const std::string& sidebar_field); - void render_sidebar_layers_hints(const std::string& sidebar_field); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL public: enum class SyncRotationType { diff --git a/src/slic3r/Utils/UndoRedo.cpp b/src/slic3r/Utils/UndoRedo.cpp index 8fe20d0122..67cb23d57b 100644 --- a/src/slic3r/Utils/UndoRedo.cpp +++ b/src/slic3r/Utils/UndoRedo.cpp @@ -21,9 +21,7 @@ #include #include -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/3DScene.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include From 6ee7445fe1aa12f4d124cbb37fb6377f4df809b1 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 6 Dec 2022 13:07:08 +0100 Subject: [PATCH 098/109] Tech ENABLE_USED_FILAMENT_POST_PROCESS set as default --- src/libslic3r/GCode/GCodeProcessor.cpp | 333 ------------------------- src/libslic3r/GCode/GCodeProcessor.hpp | 14 -- src/libslic3r/Technologies.hpp | 2 - 3 files changed, 349 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index d9492cb2a7..c74513c623 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -35,9 +35,7 @@ static const float DEFAULT_TRAVEL_ACCELERATION = 1250.0f; static const size_t MIN_EXTRUDERS_COUNT = 5; static const float DEFAULT_FILAMENT_DIAMETER = 1.75f; static const float DEFAULT_FILAMENT_DENSITY = 1.245f; -#if ENABLE_USED_FILAMENT_POST_PROCESS static const float DEFAULT_FILAMENT_COST = 0.0f; -#endif // ENABLE_USED_FILAMENT_POST_PROCESS static const Slic3r::Vec3f DEFAULT_EXTRUDER_OFFSET = Slic3r::Vec3f::Zero(); // taken from PrusaResearch.ini - [printer:Original Prusa i3 MK2.5 MMU2] static const std::vector DEFAULT_EXTRUDER_COLORS = { "#FF8000", "#DB5182", "#3EC0FF", "#FF4F4F", "#FBEB7D" }; @@ -357,314 +355,6 @@ void GCodeProcessor::TimeProcessor::reset() machines[static_cast(PrintEstimatedStatistics::ETimeMode::Normal)].enabled = true; } -#if !ENABLE_USED_FILAMENT_POST_PROCESS -void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, std::vector& moves, std::vector& lines_ends) -{ - FilePtr in{ boost::nowide::fopen(filename.c_str(), "rb") }; - if (in.f == nullptr) - throw Slic3r::RuntimeError(std::string("Time estimator post process export failed.\nCannot open file for reading.\n")); - - // temporary file to contain modified gcode - std::string out_path = filename + ".postprocess"; - FilePtr out{ boost::nowide::fopen(out_path.c_str(), "wb") }; - if (out.f == nullptr) { - throw Slic3r::RuntimeError(std::string("Time estimator post process export failed.\nCannot open file for writing.\n")); - } - - auto time_in_minutes = [](float time_in_seconds) { - assert(time_in_seconds >= 0.f); - return int((time_in_seconds + 0.5f) / 60.0f); - }; - - auto time_in_last_minute = [](float time_in_seconds) { - assert(time_in_seconds <= 60.0f); - return time_in_seconds / 60.0f; - }; - - auto format_line_M73_main = [](const std::string& mask, int percent, int time) { - char line_M73[64]; - sprintf(line_M73, mask.c_str(), - std::to_string(percent).c_str(), - std::to_string(time).c_str()); - return std::string(line_M73); - }; - - auto format_line_M73_stop_int = [](const std::string& mask, int time) { - char line_M73[64]; - sprintf(line_M73, mask.c_str(), std::to_string(time).c_str()); - return std::string(line_M73); - }; - - auto format_time_float = [](float time) { - return Slic3r::float_to_string_decimal_point(time, 2); - }; - - auto format_line_M73_stop_float = [format_time_float](const std::string& mask, float time) { - char line_M73[64]; - sprintf(line_M73, mask.c_str(), format_time_float(time).c_str()); - return std::string(line_M73); - }; - - std::string gcode_line; - size_t g1_lines_counter = 0; - // keeps track of last exported pair - std::array, static_cast(PrintEstimatedStatistics::ETimeMode::Count)> last_exported_main; - for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { - last_exported_main[i] = { 0, time_in_minutes(machines[i].time) }; - } - - // keeps track of last exported remaining time to next printer stop - std::array(PrintEstimatedStatistics::ETimeMode::Count)> last_exported_stop; - for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { - last_exported_stop[i] = time_in_minutes(machines[i].time); - } - - // buffer line to export only when greater than 64K to reduce writing calls - std::string export_line; - - // replace placeholder lines with the proper final value - // gcode_line is in/out parameter, to reduce expensive memory allocation - auto process_placeholders = [&](std::string& gcode_line) { - unsigned int extra_lines_count = 0; - - // remove trailing '\n' - auto line = std::string_view(gcode_line).substr(0, gcode_line.length() - 1); - - std::string ret; - if (line.length() > 1) { - line = line.substr(1); - if (export_remaining_time_enabled && - (line == reserved_tag(ETags::First_Line_M73_Placeholder) || line == reserved_tag(ETags::Last_Line_M73_Placeholder))) { - for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { - const TimeMachine& machine = machines[i]; - if (machine.enabled) { - // export pair - ret += format_line_M73_main(machine.line_m73_main_mask.c_str(), - (line == reserved_tag(ETags::First_Line_M73_Placeholder)) ? 0 : 100, - (line == reserved_tag(ETags::First_Line_M73_Placeholder)) ? time_in_minutes(machine.time) : 0); - ++extra_lines_count; - - // export remaining time to next printer stop - if (line == reserved_tag(ETags::First_Line_M73_Placeholder) && !machine.stop_times.empty()) { - int to_export_stop = time_in_minutes(machine.stop_times.front().elapsed_time); - ret += format_line_M73_stop_int(machine.line_m73_stop_mask.c_str(), to_export_stop); - last_exported_stop[i] = to_export_stop; - ++extra_lines_count; - } - } - } - } - else if (line == reserved_tag(ETags::Estimated_Printing_Time_Placeholder)) { - for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { - const TimeMachine& machine = machines[i]; - PrintEstimatedStatistics::ETimeMode mode = static_cast(i); - if (mode == PrintEstimatedStatistics::ETimeMode::Normal || machine.enabled) { - char buf[128]; - sprintf(buf, "; estimated printing time (%s mode) = %s\n", - (mode == PrintEstimatedStatistics::ETimeMode::Normal) ? "normal" : "silent", - get_time_dhms(machine.time).c_str()); - ret += buf; - } - } - } - } - - if (! ret.empty()) - // Not moving the move operator on purpose, so that the gcode_line allocation will grow and it will not be reallocated after handful of lines are processed. - gcode_line = ret; - return std::tuple(!ret.empty(), (extra_lines_count == 0) ? extra_lines_count : extra_lines_count - 1); - }; - - // check for temporary lines - auto is_temporary_decoration = [](const std::string_view gcode_line) { - // remove trailing '\n' - assert(! gcode_line.empty()); - assert(gcode_line.back() == '\n'); - - // return true for decorations which are used in processing the gcode but that should not be exported into the final gcode - // i.e.: - // bool ret = gcode_line.substr(0, gcode_line.length() - 1) == ";" + Layer_Change_Tag; - // ... - // return ret; - return false; - }; - - // Iterators for the normal and silent cached time estimate entry recently processed, used by process_line_G1. - auto g1_times_cache_it = Slic3r::reserve_vector::const_iterator>(machines.size()); - for (const auto& machine : machines) - g1_times_cache_it.emplace_back(machine.g1_times_cache.begin()); - - // add lines M73 to exported gcode - auto process_line_G1 = [ - // Lambdas, mostly for string formatting, all with an empty capture block. - time_in_minutes, format_time_float, format_line_M73_main, format_line_M73_stop_int, format_line_M73_stop_float, time_in_last_minute, - &self = std::as_const(*this), - // Caches, to be modified - &g1_times_cache_it, &last_exported_main, &last_exported_stop, - // String output - &export_line] - (const size_t g1_lines_counter) { - unsigned int exported_lines_count = 0; - if (self.export_remaining_time_enabled) { - for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { - const TimeMachine& machine = self.machines[i]; - if (machine.enabled) { - // export pair - // Skip all machine.g1_times_cache below g1_lines_counter. - auto& it = g1_times_cache_it[i]; - while (it != machine.g1_times_cache.end() && it->id < g1_lines_counter) - ++it; - if (it != machine.g1_times_cache.end() && it->id == g1_lines_counter) { - std::pair to_export_main = { int(100.0f * it->elapsed_time / machine.time), - time_in_minutes(machine.time - it->elapsed_time) }; - if (last_exported_main[i] != to_export_main) { - export_line += format_line_M73_main(machine.line_m73_main_mask.c_str(), - to_export_main.first, to_export_main.second); - last_exported_main[i] = to_export_main; - ++exported_lines_count; - } - // export remaining time to next printer stop - auto it_stop = std::upper_bound(machine.stop_times.begin(), machine.stop_times.end(), it->elapsed_time, - [](float value, const TimeMachine::StopTime& t) { return value < t.elapsed_time; }); - if (it_stop != machine.stop_times.end()) { - int to_export_stop = time_in_minutes(it_stop->elapsed_time - it->elapsed_time); - if (last_exported_stop[i] != to_export_stop) { - if (to_export_stop > 0) { - if (last_exported_stop[i] != to_export_stop) { - export_line += format_line_M73_stop_int(machine.line_m73_stop_mask.c_str(), to_export_stop); - last_exported_stop[i] = to_export_stop; - ++exported_lines_count; - } - } - else { - bool is_last = false; - auto next_it = it + 1; - is_last |= (next_it == machine.g1_times_cache.end()); - - if (next_it != machine.g1_times_cache.end()) { - auto next_it_stop = std::upper_bound(machine.stop_times.begin(), machine.stop_times.end(), next_it->elapsed_time, - [](float value, const TimeMachine::StopTime& t) { return value < t.elapsed_time; }); - is_last |= (next_it_stop != it_stop); - - std::string time_float_str = format_time_float(time_in_last_minute(it_stop->elapsed_time - it->elapsed_time)); - std::string next_time_float_str = format_time_float(time_in_last_minute(it_stop->elapsed_time - next_it->elapsed_time)); - is_last |= (string_to_double_decimal_point(time_float_str) > 0. && string_to_double_decimal_point(next_time_float_str) == 0.); - } - - if (is_last) { - if (std::distance(machine.stop_times.begin(), it_stop) == static_cast(machine.stop_times.size() - 1)) - export_line += format_line_M73_stop_int(machine.line_m73_stop_mask.c_str(), to_export_stop); - else - export_line += format_line_M73_stop_float(machine.line_m73_stop_mask.c_str(), time_in_last_minute(it_stop->elapsed_time - it->elapsed_time)); - - last_exported_stop[i] = to_export_stop; - ++exported_lines_count; - } - } - } - } - } - } - } - } - return exported_lines_count; - }; - - // helper function to write to disk - size_t out_file_pos = 0; - lines_ends.clear(); - auto write_string = [&export_line, &out, &out_path, &out_file_pos, &lines_ends](const std::string& str) { - fwrite((const void*)export_line.c_str(), 1, export_line.length(), out.f); - if (ferror(out.f)) { - out.close(); - boost::nowide::remove(out_path.c_str()); - throw Slic3r::RuntimeError(std::string("Time estimator post process export failed.\nIs the disk full?\n")); - } - for (size_t i = 0; i < export_line.size(); ++ i) - if (export_line[i] == '\n') - lines_ends.emplace_back(out_file_pos + i + 1); - out_file_pos += export_line.size(); - export_line.clear(); - }; - - unsigned int line_id = 0; - std::vector> offsets; - - { - // Read the input stream 64kB at a time, extract lines and process them. - std::vector buffer(65536 * 10, 0); - // Line buffer. - assert(gcode_line.empty()); - for (;;) { - size_t cnt_read = ::fread(buffer.data(), 1, buffer.size(), in.f); - if (::ferror(in.f)) - throw Slic3r::RuntimeError(std::string("Time estimator post process export failed.\nError while reading from file.\n")); - bool eof = cnt_read == 0; - auto it = buffer.begin(); - auto it_bufend = buffer.begin() + cnt_read; - while (it != it_bufend || (eof && ! gcode_line.empty())) { - // Find end of line. - bool eol = false; - auto it_end = it; - for (; it_end != it_bufend && ! (eol = *it_end == '\r' || *it_end == '\n'); ++ it_end) ; - // End of line is indicated also if end of file was reached. - eol |= eof && it_end == it_bufend; - gcode_line.insert(gcode_line.end(), it, it_end); - if (eol) { - ++line_id; - - gcode_line += "\n"; - // replace placeholder lines - auto [processed, lines_added_count] = process_placeholders(gcode_line); - if (processed && lines_added_count > 0) - offsets.push_back({ line_id, lines_added_count }); - if (! processed && ! is_temporary_decoration(gcode_line) && GCodeReader::GCodeLine::cmd_is(gcode_line, "G1")) { - // remove temporary lines, add lines M73 where needed - unsigned int extra_lines_count = process_line_G1(g1_lines_counter ++); - if (extra_lines_count > 0) - offsets.push_back({ line_id, extra_lines_count }); - } - - export_line += gcode_line; - if (export_line.length() > 65535) - write_string(export_line); - gcode_line.clear(); - } - // Skip EOL. - it = it_end; - if (it != it_bufend && *it == '\r') - ++ it; - if (it != it_bufend && *it == '\n') - ++ it; - } - if (eof) - break; - } - } - - if (!export_line.empty()) - write_string(export_line); - - out.close(); - in.close(); - - // updates moves' gcode ids which have been modified by the insertion of the M73 lines - unsigned int curr_offset_id = 0; - unsigned int total_offset = 0; - for (GCodeProcessorResult::MoveVertex& move : moves) { - while (curr_offset_id < static_cast(offsets.size()) && offsets[curr_offset_id].first <= move.gcode_id) { - total_offset += offsets[curr_offset_id].second; - ++curr_offset_id; - } - move.gcode_id += total_offset; - } - - if (rename_file(out_path, filename)) - throw Slic3r::RuntimeError(std::string("Failed to rename the output G-code file from ") + out_path + " to " + filename + '\n' + - "Is " + out_path + " locked?" + '\n'); -} -#endif // !ENABLE_USED_FILAMENT_POST_PROCESS - void GCodeProcessor::UsedFilaments::reset() { color_change_cache = 0.0; @@ -755,9 +445,7 @@ void GCodeProcessorResult::reset() { extruder_colors = std::vector(); filament_diameters = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DIAMETER); filament_densities = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DENSITY); -#if ENABLE_USED_FILAMENT_POST_PROCESS filament_cost = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_COST); -#endif // ENABLE_USED_FILAMENT_POST_PROCESS custom_gcode_per_print_z = std::vector(); spiral_vase_layers = std::vector>>(); time = 0; @@ -774,9 +462,7 @@ void GCodeProcessorResult::reset() { extruder_colors = std::vector(); filament_diameters = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DIAMETER); filament_densities = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DENSITY); -#if ENABLE_USED_FILAMENT_POST_PROCESS filament_cost = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_COST); -#endif // ENABLE_USED_FILAMENT_POST_PROCESS custom_gcode_per_print_z = std::vector(); spiral_vase_layers = std::vector>>(); } @@ -873,9 +559,7 @@ void GCodeProcessor::apply_config(const PrintConfig& config) m_extruder_colors.resize(extruders_count); m_result.filament_diameters.resize(extruders_count); m_result.filament_densities.resize(extruders_count); -#if ENABLE_USED_FILAMENT_POST_PROCESS m_result.filament_cost.resize(extruders_count); -#endif // ENABLE_USED_FILAMENT_POST_PROCESS m_extruder_temps.resize(extruders_count); for (size_t i = 0; i < extruders_count; ++ i) { @@ -883,9 +567,7 @@ void GCodeProcessor::apply_config(const PrintConfig& config) m_extruder_colors[i] = static_cast(i); m_result.filament_diameters[i] = static_cast(config.filament_diameter.get_at(i)); m_result.filament_densities[i] = static_cast(config.filament_density.get_at(i)); -#if ENABLE_USED_FILAMENT_POST_PROCESS m_result.filament_cost[i] = static_cast(config.filament_cost.get_at(i)); -#endif // ENABLE_USED_FILAMENT_POST_PROCESS } if ((m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware || m_flavor == gcfRepRapFirmware) && config.machine_limits_usage.value != MachineLimitsUsage::Ignore) { @@ -1006,7 +688,6 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) } } -#if ENABLE_USED_FILAMENT_POST_PROCESS const ConfigOptionFloats* filament_cost = config.option("filament_cost"); if (filament_cost != nullptr) { m_result.filament_cost.clear(); @@ -1021,7 +702,6 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) m_result.filament_cost.emplace_back(DEFAULT_FILAMENT_COST); } } -#endif // ENABLE_USED_FILAMENT_POST_PROCESS const ConfigOptionPoints* extruder_offset = config.option("extruder_offset"); if (extruder_offset != nullptr) { @@ -1438,11 +1118,7 @@ void GCodeProcessor::finalize(bool perform_post_process) #endif // ENABLE_GCODE_VIEWER_DATA_CHECKING if (perform_post_process) -#if ENABLE_USED_FILAMENT_POST_PROCESS post_process(); -#else - m_time_processor.post_process(m_result.filename, m_result.moves, m_result.lines_ends); -#endif // ENABLE_USED_FILAMENT_POST_PROCESS #if ENABLE_GCODE_VIEWER_STATISTICS m_result.time = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - m_start_time).count(); #endif // ENABLE_GCODE_VIEWER_STATISTICS @@ -1688,12 +1364,10 @@ void GCodeProcessor::apply_config_simplify3d(const std::string& filename) } else if (comment.find("filamentDensities") != comment.npos) { m_result.filament_densities.clear(); extract_floats(comment, "filamentDensities", m_result.filament_densities); -#if ENABLE_USED_FILAMENT_POST_PROCESS } else if (comment.find("filamentPricesPerKg") != comment.npos) { m_result.filament_cost.clear(); extract_floats(comment, "filamentPricesPerKg", m_result.filament_cost); -#endif // ENABLE_USED_FILAMENT_POST_PROCESS } else if (comment.find("extruderDiameter") != comment.npos) { std::vector extruder_diameters; extract_floats(comment, "extruderDiameter", extruder_diameters); @@ -1709,14 +1383,9 @@ void GCodeProcessor::apply_config_simplify3d(const std::string& filename) } }); -#if ENABLE_USED_FILAMENT_POST_PROCESS if (m_result.extruders_count == 0) m_result.extruders_count = std::max(1, std::min(m_result.filament_diameters.size(), std::min(m_result.filament_densities.size(), m_result.filament_cost.size()))); -#else - if (m_result.extruders_count == 0) - m_result.extruders_count = std::max(1, std::min(m_result.filament_diameters.size(), m_result.filament_densities.size())); -#endif // ENABLE_USED_FILAMENT_POST_PROCESS if (bed_size.is_defined()) { m_result.bed_shape = { @@ -3757,7 +3426,6 @@ void GCodeProcessor::process_T(const std::string_view command) } } -#if ENABLE_USED_FILAMENT_POST_PROCESS void GCodeProcessor::post_process() { FilePtr in{ boost::nowide::fopen(m_result.filename.c_str(), "rb") }; @@ -4110,7 +3778,6 @@ void GCodeProcessor::post_process() throw Slic3r::RuntimeError(std::string("Failed to rename the output G-code file from ") + out_path + " to " + m_result.filename + '\n' + "Is " + out_path + " locked?" + '\n'); } -#endif // ENABLE_USED_FILAMENT_POST_PROCESS #if ENABLE_PROCESS_G2_G3_LINES void GCodeProcessor::store_move_vertex(EMoveType type, bool internal_only) diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 37c0eda417..d333bbb44a 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -63,9 +63,7 @@ namespace Slic3r { std::vector volumes_per_color_change; std::map volumes_per_extruder; std::map> used_filaments_per_role; -#if ENABLE_USED_FILAMENT_POST_PROCESS std::map cost_per_extruder; -#endif // ENABLE_USED_FILAMENT_POST_PROCESS std::array(ETimeMode::Count)> modes; @@ -78,9 +76,7 @@ namespace Slic3r { volumes_per_color_change.clear(); volumes_per_extruder.clear(); used_filaments_per_role.clear(); -#if ENABLE_USED_FILAMENT_POST_PROCESS cost_per_extruder.clear(); -#endif // ENABLE_USED_FILAMENT_POST_PROCESS } }; @@ -134,9 +130,7 @@ namespace Slic3r { std::vector extruder_colors; std::vector filament_diameters; std::vector filament_densities; -#if ENABLE_USED_FILAMENT_POST_PROCESS std::vector filament_cost; -#endif // ENABLE_USED_FILAMENT_POST_PROCESS PrintEstimatedStatistics print_statistics; std::vector custom_gcode_per_print_z; @@ -356,13 +350,7 @@ namespace Slic3r { void reset(); -#if ENABLE_USED_FILAMENT_POST_PROCESS friend class GCodeProcessor; -#else - // post process the file with the given filename to add remaining time lines M73 - // and updates moves' gcode ids accordingly - void post_process(const std::string& filename, std::vector& moves, std::vector& lines_ends); -#endif // !ENABLE_USED_FILAMENT_POST_PROCESS }; struct UsedFilaments // filaments per ColorChange @@ -766,12 +754,10 @@ namespace Slic3r { void process_T(const GCodeReader::GCodeLine& line); void process_T(const std::string_view command); -#if ENABLE_USED_FILAMENT_POST_PROCESS // post process the file with the given filename to: // 1) add remaining time lines M73 and update moves' gcode ids accordingly // 2) update used filament data void post_process(); -#endif // ENABLE_USED_FILAMENT_POST_PROCESS #if ENABLE_PROCESS_G2_G3_LINES void store_move_vertex(EMoveType type, bool internal_only = false); diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 996bc2fdfc..067d2647ad 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -59,8 +59,6 @@ #define ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR (1 && ENABLE_2_6_0_ALPHA1) // Enable processing of gcode G2 and G3 lines #define ENABLE_PROCESS_G2_G3_LINES (1 && ENABLE_2_6_0_ALPHA1) -// Enable fix of used filament data exported to gcode file -#define ENABLE_USED_FILAMENT_POST_PROCESS (1 && ENABLE_2_6_0_ALPHA1) #endif // _prusaslicer_technologies_h_ From cf37f154ee33e5912237115d3e840302ebcf2e4a Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 6 Dec 2022 13:21:06 +0100 Subject: [PATCH 099/109] Tech ENABLE_PROCESS_G2_G3_LINES set as default --- src/libslic3r/GCode/GCodeProcessor.cpp | 54 -------------------------- src/libslic3r/GCode/GCodeProcessor.hpp | 10 ----- src/libslic3r/Technologies.hpp | 2 - src/slic3r/GUI/GCodeViewer.cpp | 4 -- src/slic3r/GUI/GUI_Preview.cpp | 17 -------- 5 files changed, 87 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index c74513c623..0fde8c5ad3 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -40,9 +40,7 @@ static const Slic3r::Vec3f DEFAULT_EXTRUDER_OFFSET = Slic3r::Vec3f::Zero(); // taken from PrusaResearch.ini - [printer:Original Prusa i3 MK2.5 MMU2] static const std::vector DEFAULT_EXTRUDER_COLORS = { "#FF8000", "#DB5182", "#3EC0FF", "#FF4F4F", "#FBEB7D" }; -#if ENABLE_PROCESS_G2_G3_LINES static const std::string INTERNAL_G2G3_TAG = "!#!#! internal only - from G2/G3 expansion !#!#!"; -#endif // ENABLE_PROCESS_G2_G3_LINES namespace Slic3r { @@ -1418,10 +1416,8 @@ void GCodeProcessor::process_gcode_line(const GCodeReader::GCodeLine& line, bool switch (cmd[1]) { case '0': { process_G0(line); break; } // Move case '1': { process_G1(line); break; } // Move -#if ENABLE_PROCESS_G2_G3_LINES case '2': { process_G2_G3(line, true); break; } // CW Arc Move case '3': { process_G2_G3(line, false); break; } // CCW Arc Move -#endif // ENABLE_PROCESS_G2_G3_LINES default: break; } break; @@ -2337,23 +2333,6 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) const float filament_diameter = (static_cast(m_extruder_id) < m_result.filament_diameters.size()) ? m_result.filament_diameters[m_extruder_id] : m_result.filament_diameters.back(); const float filament_radius = 0.5f * filament_diameter; const float area_filament_cross_section = static_cast(M_PI) * sqr(filament_radius); -#if !ENABLE_PROCESS_G2_G3_LINES - auto absolute_position = [this, area_filament_cross_section](Axis axis, const GCodeReader::GCodeLine& lineG1) { - bool is_relative = (m_global_positioning_type == EPositioningType::Relative); - if (axis == E) - is_relative |= (m_e_local_positioning_type == EPositioningType::Relative); - - if (lineG1.has(Slic3r::Axis(axis))) { - float lengthsScaleFactor = (m_units == EUnits::Inches) ? INCHES_TO_MM : 1.0f; - float ret = lineG1.value(Slic3r::Axis(axis)) * lengthsScaleFactor; - if (axis == E && m_use_volumetric_e) - ret /= area_filament_cross_section; - return is_relative ? m_start_position[axis] + ret : m_origin[axis] + ret; - } - else - return m_start_position[axis]; - }; -#endif // !ENABLE_PROCESS_G2_G3_LINES auto move_type = [this](const AxisCoords& delta_pos) { EMoveType type = EMoveType::Noop; @@ -2381,11 +2360,7 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) // updates axes positions from line for (unsigned char a = X; a <= E; ++a) { -#if ENABLE_PROCESS_G2_G3_LINES m_end_position[a] = extract_absolute_position_on_axis((Axis)a, line, double(area_filament_cross_section)); -#else - m_end_position[a] = absolute_position((Axis)a, line); -#endif // ENABLE_PROCESS_G2_G3_LINES } // updates feedrate from line, if present @@ -2418,7 +2393,6 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) m_mm3_per_mm_compare.update(area_toolpath_cross_section, m_extrusion_role); #endif // ENABLE_GCODE_VIEWER_DATA_CHECKING -#if ENABLE_PROCESS_G2_G3_LINES if (m_forced_height > 0.0f) m_height = m_forced_height; else if (m_layer_id == 0) @@ -2427,16 +2401,6 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) if (m_end_position[Z] > m_extruded_last_z + EPSILON && delta_pos[Z] == 0.0) m_height = m_end_position[Z] - m_extruded_last_z; } -#else - if (m_forced_height > 0.0f) - m_height = m_forced_height; - else if (m_layer_id == 0) - m_height = (m_end_position[Z] <= double(m_first_layer_height)) ? m_end_position[Z] : m_first_layer_height; - else { - if (m_end_position[Z] > m_extruded_last_z + EPSILON) - m_height = m_end_position[Z] - m_extruded_last_z; - } -#endif // ENABLE_PROCESS_G2_G3_LINES if (m_height == 0.0f) m_height = DEFAULT_TOOLPATH_HEIGHT; @@ -2444,9 +2408,7 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) if (m_end_position[Z] == 0.0f || (m_extrusion_role == erCustom && m_layer_id == 0)) m_end_position[Z] = m_height; -#if ENABLE_PROCESS_G2_G3_LINES if (line.comment() != INTERNAL_G2G3_TAG) -#endif // ENABLE_PROCESS_G2_G3_LINES m_extruded_last_z = m_end_position[Z]; m_options_z_corrector.update(m_height); @@ -2679,14 +2641,9 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) } // store move -#if ENABLE_PROCESS_G2_G3_LINES store_move_vertex(type, line.comment() == INTERNAL_G2G3_TAG); -#else - store_move_vertex(type); -#endif // ENABLE_PROCESS_G2_G3_LINES } -#if ENABLE_PROCESS_G2_G3_LINES void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool clockwise) { if (!line.has('I') || !line.has('J')) @@ -2888,7 +2845,6 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc process_gcode_line(line, false); }); } -#endif // ENABLE_PROCESS_G2_G3_LINES void GCodeProcessor::process_G10(const GCodeReader::GCodeLine& line) { @@ -3779,11 +3735,7 @@ void GCodeProcessor::post_process() "Is " + out_path + " locked?" + '\n'); } -#if ENABLE_PROCESS_G2_G3_LINES void GCodeProcessor::store_move_vertex(EMoveType type, bool internal_only) -#else -void GCodeProcessor::store_move_vertex(EMoveType type) -#endif // ENABLE_PROCESS_G2_G3_LINES { m_last_line_id = (type == EMoveType::Color_change || type == EMoveType::Pause_Print || type == EMoveType::Custom_GCode) ? m_line_id + 1 : @@ -3803,12 +3755,8 @@ void GCodeProcessor::store_move_vertex(EMoveType type) m_mm3_per_mm, m_fan_speed, m_extruder_temps[m_extruder_id], -#if ENABLE_PROCESS_G2_G3_LINES static_cast(m_result.moves.size()), internal_only -#else - static_cast(m_result.moves.size()) -#endif // ENABLE_PROCESS_G2_G3_LINES }); // stores stop time placeholders for later use @@ -4003,7 +3951,6 @@ void GCodeProcessor::update_estimated_times_stats() m_result.print_statistics.used_filaments_per_role = m_used_filaments.filaments_per_role; } -#if ENABLE_PROCESS_G2_G3_LINES double GCodeProcessor::extract_absolute_position_on_axis(Axis axis, const GCodeReader::GCodeLine& line, double area_filament_cross_section) { if (line.has(Slic3r::Axis(axis))) { @@ -4020,7 +3967,6 @@ double GCodeProcessor::extract_absolute_position_on_axis(Axis axis, const GCodeR else return m_start_position[axis]; } -#endif // ENABLE_PROCESS_G2_G3_LINES } /* namespace Slic3r */ diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index d333bbb44a..3baff69aaf 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -111,9 +111,7 @@ namespace Slic3r { float fan_speed{ 0.0f }; // percentage float temperature{ 0.0f }; // Celsius degrees float time{ 0.0f }; // s -#if ENABLE_PROCESS_G2_G3_LINES bool internal_only{ false }; -#endif // ENABLE_PROCESS_G2_G3_LINES float volumetric_rate() const { return feedrate * mm3_per_mm; } }; @@ -649,10 +647,8 @@ namespace Slic3r { void process_G0(const GCodeReader::GCodeLine& line); void process_G1(const GCodeReader::GCodeLine& line); -#if ENABLE_PROCESS_G2_G3_LINES // Arc Move void process_G2_G3(const GCodeReader::GCodeLine& line, bool clockwise); -#endif // ENABLE_PROCESS_G2_G3_LINES // Retract or Set tool temperature void process_G10(const GCodeReader::GCodeLine& line); @@ -759,11 +755,7 @@ namespace Slic3r { // 2) update used filament data void post_process(); -#if ENABLE_PROCESS_G2_G3_LINES void store_move_vertex(EMoveType type, bool internal_only = false); -#else - void store_move_vertex(EMoveType type); -#endif // ENABLE_PROCESS_G2_G3_LINES void set_extrusion_role(ExtrusionRole role); @@ -789,9 +781,7 @@ namespace Slic3r { void update_estimated_times_stats(); -#if ENABLE_PROCESS_G2_G3_LINES double extract_absolute_position_on_axis(Axis axis, const GCodeReader::GCodeLine& line, double area_filament_cross_section); -#endif // ENABLE_PROCESS_G2_G3_LINES }; } /* namespace Slic3r */ diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 067d2647ad..87406d724d 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -57,8 +57,6 @@ #define ENABLE_WORLD_COORDINATE (1 && ENABLE_2_6_0_ALPHA1) // Enable alternative version of file_wildcards() #define ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR (1 && ENABLE_2_6_0_ALPHA1) -// Enable processing of gcode G2 and G3 lines -#define ENABLE_PROCESS_G2_G3_LINES (1 && ENABLE_2_6_0_ALPHA1) #endif // _prusaslicer_technologies_h_ diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index bfd4379b41..b0e11422db 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -2153,9 +2153,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) size_t move_id = i - seams_count; if (move.type == EMoveType::Extrude) { -#if ENABLE_PROCESS_G2_G3_LINES if (!move.internal_only) { -#endif // ENABLE_PROCESS_G2_G3_LINES // layers zs const double* const last_z = m_layers.empty() ? nullptr : &m_layers.get_zs().back(); const double z = static_cast(move.position.z()); @@ -2163,9 +2161,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) m_layers.append(z, { last_travel_s_id, move_id }); else m_layers.get_ranges().back().last = move_id; -#if ENABLE_PROCESS_G2_G3_LINES } -#endif // ENABLE_PROCESS_G2_G3_LINES // extruder ids m_extruder_ids.emplace_back(move.extruder_id); // roles diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 93cbca3c4f..7bfb252482 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -692,7 +692,6 @@ void Preview::update_moves_slider() if (view.endpoints.last < view.endpoints.first) return; -#if ENABLE_PROCESS_G2_G3_LINES assert(view.endpoints.first <= view.current.first && view.current.first <= view.endpoints.last); assert(view.endpoints.first <= view.current.last && view.current.last <= view.endpoints.last); @@ -721,22 +720,6 @@ void Preview::update_moves_slider() m_moves_slider->SetSliderAlternateValues(alternate_values); m_moves_slider->SetMaxValue(int(values.size()) - 1); m_moves_slider->SetSelectionSpan(values.front() - 1 - view.endpoints.first, values.back() - 1 - view.endpoints.first); -#else - std::vector values(view.endpoints.last - view.endpoints.first + 1); - std::vector alternate_values(view.endpoints.last - view.endpoints.first + 1); - unsigned int count = 0; - for (unsigned int i = view.endpoints.first; i <= view.endpoints.last; ++i) { - values[count] = static_cast(i + 1); - if (view.gcode_ids[i] > 0) - alternate_values[count] = static_cast(view.gcode_ids[i]); - ++count; - } - - m_moves_slider->SetSliderValues(values); - m_moves_slider->SetSliderAlternateValues(alternate_values); - m_moves_slider->SetMaxValue(view.endpoints.last - view.endpoints.first); - m_moves_slider->SetSelectionSpan(view.current.first - view.endpoints.first, view.current.last - view.endpoints.first); -#endif // ENABLE_PROCESS_G2_G3_LINES } void Preview::enable_moves_slider(bool enable) From 53511371836b782f995b09f44979836560403767 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 6 Dec 2022 13:49:05 +0100 Subject: [PATCH 100/109] (Win Only) Detection of cursor size, to place tooltips on scene, performed on tooltip text setting instead of being repeated every frame --- src/slic3r/GUI/GLCanvas3D.cpp | 72 ++++++++++++++++++----------------- src/slic3r/GUI/GLCanvas3D.hpp | 1 + src/slic3r/GUI/Selection.cpp | 4 -- 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 9fa54b9a02..79370022b2 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -773,53 +773,55 @@ void GLCanvas3D::Labels::render(const std::vector& sorted_ } } +static float get_cursor_height() +{ + float ret = 16.0f; +#ifdef _WIN32 + // see: https://forums.codeguru.com/showthread.php?449040-get-the-system-current-cursor-size + // this code is not perfect because it returns a maximum height equal to 31 even if the cursor bitmap shown on screen is bigger + // but at least it gives the same result as wxWidgets in the settings tabs + ICONINFO ii; + if (::GetIconInfo((HICON)GetCursor(), &ii) != 0) { + BITMAP bitmap; + ::GetObject(ii.hbmMask, sizeof(BITMAP), &bitmap); + const int width = bitmap.bmWidth; + const int height = (ii.hbmColor == nullptr) ? bitmap.bmHeight / 2 : bitmap.bmHeight; + HDC dc = ::CreateCompatibleDC(nullptr); + if (dc != nullptr) { + if (::SelectObject(dc, ii.hbmMask) != nullptr) { + for (int i = 0; i < width; ++i) { + for (int j = 0; j < height; ++j) { + if (::GetPixel(dc, i, j) != RGB(255, 255, 255)) { + if (ret < float(j)) + ret = float(j); + } + } + } + ::DeleteDC(dc); + } + } + ::DeleteObject(ii.hbmColor); + ::DeleteObject(ii.hbmMask); + } +#endif // _WIN32 + return ret; +} + void GLCanvas3D::Tooltip::set_text(const std::string& text) { // If the mouse is inside an ImGUI dialog, then the tooltip is suppressed. m_text = m_in_imgui ? std::string() : text; + m_cursor_height = get_cursor_height(); } void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position, GLCanvas3D& canvas) { static ImVec2 size(0.0f, 0.0f); - auto validate_position = [](const Vec2d& position, const GLCanvas3D& canvas, const ImVec2& wnd_size) { - auto calc_cursor_height = []() { - float ret = 16.0f; -#ifdef _WIN32 - // see: https://forums.codeguru.com/showthread.php?449040-get-the-system-current-cursor-size - // this code is not perfect because it returns a maximum height equal to 31 even if the cursor bitmap shown on screen is bigger - // but at least it gives the same result as wxWidgets in the settings tabs - ICONINFO ii; - if (::GetIconInfo((HICON)GetCursor(), &ii) != 0) { - BITMAP bitmap; - ::GetObject(ii.hbmMask, sizeof(BITMAP), &bitmap); - int width = bitmap.bmWidth; - int height = (ii.hbmColor == nullptr) ? bitmap.bmHeight / 2 : bitmap.bmHeight; - HDC dc = ::CreateCompatibleDC(nullptr); - if (dc != nullptr) { - if (::SelectObject(dc, ii.hbmMask) != nullptr) { - for (int i = 0; i < width; ++i) { - for (int j = 0; j < height; ++j) { - if (::GetPixel(dc, i, j) != RGB(255, 255, 255)) { - if (ret < float(j)) - ret = float(j); - } - } - } - ::DeleteDC(dc); - } - } - ::DeleteObject(ii.hbmColor); - ::DeleteObject(ii.hbmMask); - } -#endif // _WIN32 - return ret; - }; - + auto validate_position = [this](const Vec2d& position, const GLCanvas3D& canvas, const ImVec2& wnd_size) { const Size cnv_size = canvas.get_canvas_size(); const float x = std::clamp(float(position.x()), 0.0f, float(cnv_size.get_width()) - wnd_size.x); - const float y = std::clamp(float(position.y()) + calc_cursor_height(), 0.0f, float(cnv_size.get_height()) - wnd_size.y); + const float y = std::clamp(float(position.y()) + m_cursor_height, 0.0f, float(cnv_size.get_height()) - wnd_size.y); return Vec2f(x, y); }; diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 41880d2b27..7b5a1084c1 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -400,6 +400,7 @@ class GLCanvas3D std::chrono::steady_clock::time_point m_start_time; // Indicator that the mouse is inside an ImGUI dialog, therefore the tooltip should be suppressed. bool m_in_imgui = false; + float m_cursor_height{ 16.0f }; public: bool is_empty() const { return m_text.empty(); } diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index 2dde431f09..e242b6e6f3 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -584,15 +584,11 @@ bool Selection::is_sla_compliant() const bool Selection::is_single_text() const { -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #if ENABLE_WORLD_COORDINATE -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ if (!is_single_volume_or_modifier()) -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #else if (!is_single_volume() && !is_single_modifier()) #endif // ENABLE_WORLD_COORDINATE -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ return false; const GLVolume* gl_volume = (*m_volumes)[*m_list.begin()]; From b7740743b8ff3ccdeb81d13c1957819c6e7c273b Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 6 Dec 2022 14:07:51 +0100 Subject: [PATCH 101/109] Gizmo measure fixed to work with mirrored objects --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 6994bfa329..cc786b1ad8 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1052,6 +1052,10 @@ void GLGizmoMeasure::update_if_needed() TriangleMesh volume_mesh = vol.volume->mesh(); volume_mesh.transform(vol.world_trafo); + + if (vol.world_trafo.matrix().determinant() < 0.0) + volume_mesh.flip_triangles(); + composite_mesh.merge(volume_mesh); } From 05ee2a06ff2836fb1fe687696832a633191ca4e7 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Wed, 7 Dec 2022 13:27:03 +0100 Subject: [PATCH 102/109] Don't allow short if and for statements on one line Make debugging harder --- .clang-format | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.clang-format b/.clang-format index 6ec205af84..42ac9f1a07 100644 --- a/.clang-format +++ b/.clang-format @@ -13,8 +13,8 @@ AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: true AllowShortCaseLabelsOnASingleLine: true AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: true -AllowShortLoopsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false From b037e5f024d1c6e7dea90daf4f8e31b95117d5ae Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 5 Dec 2022 22:10:33 +0100 Subject: [PATCH 103/109] Optimization: do not regenerate toolbar texture in each frame --- src/slic3r/GUI/GLCanvas3D.cpp | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 79370022b2..b7988ea7ca 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5653,9 +5653,9 @@ void GLCanvas3D::_check_and_update_toolbar_icon_scale() collapse_toolbar.set_scale(sc); size *= m_retina_helper->get_scale_factor(); #else - m_main_toolbar.set_icons_size(size); - m_undoredo_toolbar.set_icons_size(size); - collapse_toolbar.set_icons_size(size); + m_main_toolbar.set_icons_size(int(size)); + m_undoredo_toolbar.set_icons_size(int(size)); + collapse_toolbar.set_icons_size(int(size)); #endif // ENABLE_RETINA_GL float top_tb_width = m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar.get_width(); @@ -5687,24 +5687,12 @@ void GLCanvas3D::_render_overlays() { glsafe(::glDisable(GL_DEPTH_TEST)); + // main toolbar and undoredo toolbar need to be both updated before rendering because both their sizes are needed + // to correctly place them _check_and_update_toolbar_icon_scale(); _render_gizmos_overlay(); - // main toolbar and undoredo toolbar need to be both updated before rendering because both their sizes are needed - // to correctly place them -#if ENABLE_RETINA_GL - const float scale = m_retina_helper->get_scale_factor() * wxGetApp().toolbar_icon_scale(/*true*/); - m_main_toolbar.set_scale(scale); - m_undoredo_toolbar.set_scale(scale); - wxGetApp().plater()->get_collapse_toolbar().set_scale(scale); -#else - const float size = int(GLToolbar::Default_Icons_Size * wxGetApp().toolbar_icon_scale(/*true*/)); - m_main_toolbar.set_icons_size(size); - m_undoredo_toolbar.set_icons_size(size); - wxGetApp().plater()->get_collapse_toolbar().set_icons_size(size); -#endif // ENABLE_RETINA_GL - _render_main_toolbar(); _render_undoredo_toolbar(); _render_collapse_toolbar(); From fe3a15942bae16e7d8bf70ac66a7625c983f5963 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 7 Dec 2022 14:50:20 +0100 Subject: [PATCH 104/109] Follow-up of 6d737f7081883071a547e0c9960813342e8388e3 - Ensure icon size is a whole number wherever is used --- src/slic3r/GUI/GLCanvas3D.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index b7988ea7ca..d93a76cc15 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5639,10 +5639,10 @@ void GLCanvas3D::_check_and_update_toolbar_icon_scale() if (wxGetApp().plater()->is_preview_shown()) return; - float scale = wxGetApp().toolbar_icon_scale(); - Size cnv_size = get_canvas_size(); + const float scale = wxGetApp().toolbar_icon_scale(); + const Size cnv_size = get_canvas_size(); - float size = GLToolbar::Default_Icons_Size * scale; + int size = int(GLToolbar::Default_Icons_Size * scale); // Set current size for all top toolbars. It will be used for next calculations GLToolbar& collapse_toolbar = wxGetApp().plater()->get_collapse_toolbar(); @@ -5651,28 +5651,28 @@ void GLCanvas3D::_check_and_update_toolbar_icon_scale() m_main_toolbar.set_scale(sc); m_undoredo_toolbar.set_scale(sc); collapse_toolbar.set_scale(sc); - size *= m_retina_helper->get_scale_factor(); + size *= int(m_retina_helper->get_scale_factor()); #else - m_main_toolbar.set_icons_size(int(size)); - m_undoredo_toolbar.set_icons_size(int(size)); - collapse_toolbar.set_icons_size(int(size)); + m_main_toolbar.set_icons_size(size); + m_undoredo_toolbar.set_icons_size(size); + collapse_toolbar.set_icons_size(size); #endif // ENABLE_RETINA_GL - float top_tb_width = m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar.get_width(); + const float top_tb_width = m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar.get_width(); int items_cnt = m_main_toolbar.get_visible_items_cnt() + m_undoredo_toolbar.get_visible_items_cnt() + collapse_toolbar.get_visible_items_cnt(); - float noitems_width = top_tb_width - size * items_cnt; // width of separators and borders in top toolbars + const float noitems_width = top_tb_width - float(size) * items_cnt; // width of separators and borders in top toolbars // calculate scale needed for items in all top toolbars // the std::max() is there because on some Linux dialects/virtual machines this code is called when the canvas has not been properly initialized yet, // leading to negative values for the scale. // See: https://github.com/prusa3d/PrusaSlicer/issues/8563 // https://github.com/supermerill/SuperSlicer/issues/854 - float new_h_scale = std::max((cnv_size.get_width() - noitems_width), 1.0f) / (items_cnt * GLToolbar::Default_Icons_Size); + const float new_h_scale = std::max((cnv_size.get_width() - noitems_width), 1.0f) / (items_cnt * GLToolbar::Default_Icons_Size); items_cnt = m_gizmos.get_selectable_icons_cnt() + 3; // +3 means a place for top and view toolbars and separators in gizmos toolbar // calculate scale needed for items in the gizmos toolbar - float new_v_scale = cnv_size.get_height() / (items_cnt * GLGizmosManager::Default_Icons_Size); + const float new_v_scale = cnv_size.get_height() / (items_cnt * GLGizmosManager::Default_Icons_Size); // set minimum scale as a auto scale for the toolbars float new_scale = std::min(new_h_scale, new_v_scale); From 85ad56b43bedf882097255e643b8ab974943f7b0 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 6 Dec 2022 12:18:05 +0100 Subject: [PATCH 105/109] Optimization: std::vector can be quite slow to access --- src/libslic3r/TriangleMesh.cpp | 2 +- src/libslic3r/TriangleMesh.hpp | 2 +- src/libslic3r/TriangleMeshSlicer.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/TriangleMesh.cpp b/src/libslic3r/TriangleMesh.cpp index 6e17daa564..d5fe83c265 100644 --- a/src/libslic3r/TriangleMesh.cpp +++ b/src/libslic3r/TriangleMesh.cpp @@ -622,7 +622,7 @@ std::vector its_face_edge_ids(const indexed_triangle_set &its, std::funct return its_face_edge_ids_impl(its, [](const uint32_t){ return true; }, throw_on_cancel_callback); } -std::vector its_face_edge_ids(const indexed_triangle_set &its, const std::vector &face_mask) +std::vector its_face_edge_ids(const indexed_triangle_set &its, const std::vector &face_mask) { return its_face_edge_ids_impl(its, [&face_mask](const uint32_t idx){ return face_mask[idx]; }, [](){}); } diff --git a/src/libslic3r/TriangleMesh.hpp b/src/libslic3r/TriangleMesh.hpp index d8096eae2d..26701bdf53 100644 --- a/src/libslic3r/TriangleMesh.hpp +++ b/src/libslic3r/TriangleMesh.hpp @@ -188,7 +188,7 @@ private: // Used for chaining slice lines into polygons. std::vector its_face_edge_ids(const indexed_triangle_set &its); std::vector its_face_edge_ids(const indexed_triangle_set &its, std::function throw_on_cancel_callback); -std::vector its_face_edge_ids(const indexed_triangle_set &its, const std::vector &face_mask); +std::vector its_face_edge_ids(const indexed_triangle_set &its, const std::vector &face_mask); // Having the face neighbors available, assign unique edge IDs to face edges for chaining of polygons over slices. std::vector its_face_edge_ids(const indexed_triangle_set &its, std::vector &face_neighbors, bool assign_unbound_edges = false, int *num_edges = nullptr); diff --git a/src/libslic3r/TriangleMeshSlicer.cpp b/src/libslic3r/TriangleMeshSlicer.cpp index 63802961b9..461d8c22e5 100644 --- a/src/libslic3r/TriangleMeshSlicer.cpp +++ b/src/libslic3r/TriangleMeshSlicer.cpp @@ -1805,7 +1805,7 @@ Polygons slice_mesh( { bool trafo_identity = is_identity(params.trafo); Transform3f tf; - std::vector face_mask(mesh.indices.size(), false); + std::vector face_mask(mesh.indices.size(), 0); { // 1) Mark vertices as below or above the slicing plane. From 595ef873ad0fb3c52ce3705bc80569326c089ec3 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 7 Dec 2022 15:23:38 +0100 Subject: [PATCH 106/109] Change the way how cut gizmo detects hits on cut plane: it did not work well on meshes with overlapping surfaces --- src/slic3r/GUI/Gizmos/GLGizmoCut.cpp | 73 +++++++++++++--------------- src/slic3r/GUI/Gizmos/GLGizmoCut.hpp | 2 +- src/slic3r/GUI/MeshUtils.cpp | 45 ++--------------- src/slic3r/GUI/MeshUtils.hpp | 8 +-- 4 files changed, 40 insertions(+), 88 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp index 29d578fba9..3cd661ba3f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp @@ -1144,11 +1144,11 @@ void GLGizmoCut3D::dragging_grabber_xy(const GLGizmoBase::UpdateData &data) void GLGizmoCut3D::dragging_connector(const GLGizmoBase::UpdateData &data) { CutConnectors& connectors = m_c->selection_info()->model_object()->cut_connectors; - std::pair pos_and_normal; + Vec3d pos; Vec3d pos_world; - if (unproject_on_cut_plane(data.mouse_pos.cast(), pos_and_normal, pos_world)) { - connectors[m_hover_id - m_connectors_group_id].pos = pos_and_normal.first; + if (unproject_on_cut_plane(data.mouse_pos.cast(), pos, pos_world)) { + connectors[m_hover_id - m_connectors_group_id].pos = pos; update_raycasters_for_picking_transform(); } } @@ -2006,44 +2006,41 @@ void GLGizmoCut3D::perform_cut(const Selection& selection) // Unprojects the mouse position on the mesh and saves hit point and normal of the facet into pos_and_normal // Return false if no intersection was found, true otherwise. -bool GLGizmoCut3D::unproject_on_cut_plane(const Vec2d& mouse_position, std::pair& pos_and_normal, Vec3d& pos_world) +bool GLGizmoCut3D::unproject_on_cut_plane(const Vec2d& mouse_position, Vec3d& pos, Vec3d& pos_world) { const float sla_shift = m_c->selection_info()->get_sla_shift(); const ModelObject* mo = m_c->selection_info()->model_object(); const ModelInstance* mi = mo->instances[m_c->selection_info()->get_active_instance()]; - const Transform3d instance_trafo = sla_shift > 0.f ? - translation_transform(sla_shift * Vec3d::UnitZ()) * mi->get_transformation().get_matrix() : mi->get_transformation().get_matrix(); const Camera& camera = wxGetApp().plater()->get_camera(); - int mesh_id = -1; - for (const ModelVolume* mv : mo->volumes) { - ++mesh_id; - if (!mv->is_model_part()) - continue; - Vec3f normal; - Vec3f hit; - bool clipping_plane_was_hit = false; + // Calculate intersection with the clipping plane. + const ClippingPlane* cp = m_c->object_clipper()->get_clipping_plane(true); + Vec3d point; + Vec3d direction; + Vec3d hit; + MeshRaycaster::line_from_mouse_pos(mouse_position, Transform3d::Identity(), camera, point, direction); + Vec3d normal = -cp->get_normal().cast(); + double den = normal.dot(direction); + if (den != 0.) { + double t = (-cp->get_offset() - normal.dot(point))/den; + hit = (point + t * direction); + } else + return false; + + if (! m_c->object_clipper()->is_projection_inside_cut(hit)) + return false; -// const Transform3d volume_trafo = get_volume_transformation(mv); - const Transform3d volume_trafo = mv->get_transformation().get_matrix(); + // recalculate hit to object's local position + Vec3d hit_d = hit; + hit_d -= mi->get_offset(); + hit_d[Z] -= sla_shift; - m_c->raycaster()->raycasters()[mesh_id]->unproject_on_mesh(mouse_position, instance_trafo * volume_trafo, - camera, hit, normal, m_c->object_clipper()->get_clipping_plane(true), - nullptr, &clipping_plane_was_hit); - if (clipping_plane_was_hit) { - // recalculate hit to object's local position - Vec3d hit_d = hit.cast(); - hit_d -= mi->get_offset(); - hit_d[Z] -= sla_shift; + // Return both the point and the facet normal. + pos = hit_d; + pos_world = hit; - // Return both the point and the facet normal. - pos_and_normal = std::make_pair(hit_d, normal.cast()); - pos_world = hit.cast(); - return true; - } - } - return false; + return true; } void GLGizmoCut3D::clear_selection() @@ -2139,17 +2136,13 @@ bool GLGizmoCut3D::add_connector(CutConnectors& connectors, const Vec2d& mouse_p if (!m_connectors_editing) return false; - std::pair pos_and_normal; + Vec3d pos; Vec3d pos_world; - if (unproject_on_cut_plane(mouse_position.cast(), pos_and_normal, pos_world)) { - // check if pos is out of enabled clipping plane - if (m_c->object_clipper() && !m_c->object_clipper()->is_projection_inside_cut(pos_world)) - return true; - + if (unproject_on_cut_plane(mouse_position.cast(), pos, pos_world)) { Plater::TakeSnapshot snapshot(wxGetApp().plater(), _L("Add connector"), UndoRedo::SnapshotType::GizmoAction); unselect_all_connectors(); - connectors.emplace_back(pos_and_normal.first, m_rotation_m, + connectors.emplace_back(pos, m_rotation_m, m_connector_size * 0.5f, m_connector_depth_ratio, m_connector_size_tolerance, m_connector_depth_ratio_tolerance, CutConnectorAttributes( CutConnectorType(m_connector_type), @@ -2247,9 +2240,9 @@ bool GLGizmoCut3D::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_posi if (!m_connectors_editing) { if (0 && action == SLAGizmoEventType::LeftDown) { // disable / enable current contour - std::pair pos_and_normal; + Vec3d pos; Vec3d pos_world; - if (unproject_on_cut_plane(mouse_position.cast(), pos_and_normal, pos_world)) { + if (unproject_on_cut_plane(mouse_position.cast(), pos, pos_world)) { // Following would inform the clipper about the mouse click, so it can // toggle the respective contour as disabled. m_c->object_clipper()->pass_mouse_click(pos_world); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp index 8a3ee6d074..e9412357d7 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp @@ -155,7 +155,7 @@ public: GLGizmoCut3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); std::string get_tooltip() const override; - bool unproject_on_cut_plane(const Vec2d& mouse_pos, std::pair& pos_and_normal, Vec3d& pos_world); + bool unproject_on_cut_plane(const Vec2d& mouse_pos, Vec3d& pos, Vec3d& pos_world); bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down); bool is_in_editing_mode() const override { return m_connectors_editing; } diff --git a/src/slic3r/GUI/MeshUtils.cpp b/src/slic3r/GUI/MeshUtils.cpp index 39e463a19b..a581915282 100644 --- a/src/slic3r/GUI/MeshUtils.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -365,11 +365,8 @@ void MeshRaycaster::line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3 bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera, Vec3f& position, Vec3f& normal, const ClippingPlane* clipping_plane, - size_t* facet_idx, bool* was_clipping_plane_hit) const + size_t* facet_idx) const { - if (was_clipping_plane_hit) - *was_clipping_plane_hit = false; - Vec3d point; Vec3d direction; line_from_mouse_pos(mouse_pos, trafo, camera, point, direction); @@ -390,26 +387,9 @@ bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& break; } - if (i==hits.size()) { - // All hits are clipped. - return false; - } - if (clipping_plane && (hits.size()-i) % 2 != 0) { - // There is an odd number of unclipped hits - meaning the nearest must be from inside the mesh. - // In that case, calculate intersection with the clipping place. - if (was_clipping_plane_hit) { - direction = direction + point; - point = trafo * point; // transform to world coords - direction = trafo * direction - point; - - Vec3d normal = -clipping_plane->get_normal().cast(); - double den = normal.dot(direction); - if (den != 0.) { - double t = (-clipping_plane->get_offset() - normal.dot(point))/den; - position = (point + t * direction).cast(); - *was_clipping_plane_hit = true; - } - } + if (i==hits.size() || (hits.size()-i) % 2 != 0) { + // All hits are either clipped, or there is an odd number of unclipped + // hits - meaning the nearest must be from inside the mesh. return false; } @@ -423,24 +403,7 @@ bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& return true; } -bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera, - Vec3d& position, Vec3d& normal) const -{ - Vec3d point; - Vec3d direction; - line_from_mouse_pos(mouse_pos, trafo, camera, point, direction); - std::vector hits = m_emesh.query_ray_hits(point, direction); - - if (hits.empty()) - return false; // no intersection found - - // Now stuff the points in the provided vector and calculate normals if asked about them: - position = hits[0].position(); - normal = hits[0].normal(); - - return true; -} bool MeshRaycaster::is_valid_intersection(Vec3d point, Vec3d direction, const Transform3d& trafo) const { diff --git a/src/slic3r/GUI/MeshUtils.hpp b/src/slic3r/GUI/MeshUtils.hpp index 441532fdb2..401ba22f17 100644 --- a/src/slic3r/GUI/MeshUtils.hpp +++ b/src/slic3r/GUI/MeshUtils.hpp @@ -153,16 +153,12 @@ public: const Vec2d& mouse_pos, const Transform3d& trafo, // how to get the mesh into world coords const Camera& camera, // current camera position - Vec3f& position, // where to save the positibon of the hit (mesh coords if mesh, world coords if clipping plane) + Vec3f& position, // where to save the positibon of the hit (mesh coords) Vec3f& normal, // normal of the triangle that was hit const ClippingPlane* clipping_plane = nullptr, // clipping plane (if active) - size_t* facet_idx = nullptr, // index of the facet hit - bool* was_clipping_plane_hit = nullptr // is the hit on the clipping place cross section? + size_t* facet_idx = nullptr // index of the facet hit ) const; - // Given a mouse position, this returns true in case it is on the mesh. - bool unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera, Vec3d& position, Vec3d& normal) const; - bool is_valid_intersection(Vec3d point, Vec3d direction, const Transform3d& trafo) const; // Given a vector of points in woorld coordinates, this returns vector From d2c8d628b96f8e3e0b4fe8ac6a9879c33521c037 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 7 Dec 2022 16:06:43 +0100 Subject: [PATCH 107/109] Fixed a bug in Cut gizmo - contour width was not updating correctly --- src/slic3r/GUI/MeshUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/MeshUtils.cpp b/src/slic3r/GUI/MeshUtils.cpp index a581915282..9246c4cdf5 100644 --- a/src/slic3r/GUI/MeshUtils.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -22,7 +22,7 @@ namespace GUI { void MeshClipper::set_behaviour(bool fill_cut, double contour_width) { - if (fill_cut != m_fill_cut || is_approx(contour_width, m_contour_width)) + if (fill_cut != m_fill_cut || ! is_approx(contour_width, m_contour_width)) m_result.reset(); m_fill_cut = fill_cut; m_contour_width = contour_width; From 71a0b626a9d15a61dbd9a87f25c28001cb631292 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 7 Dec 2022 16:52:52 +0100 Subject: [PATCH 108/109] Fixed memory leaks on switch between parameter pages --- src/slic3r/GUI/Field.cpp | 9 +++ src/slic3r/GUI/Field.hpp | 2 +- src/slic3r/GUI/OptionsGroup.cpp | 130 ++++++++++++++++---------------- src/slic3r/GUI/OptionsGroup.hpp | 1 + src/slic3r/GUI/Tab.cpp | 2 + 5 files changed, 78 insertions(+), 66 deletions(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index d3fef44d3c..40cd7f8893 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -1416,6 +1416,15 @@ void ColourPicker::sys_color_changed() #endif } +PointCtrl::~PointCtrl() +{ + if (sizer) { + sizer->Clear(); + delete sizer; + sizer = nullptr; + } +} + void PointCtrl::BUILD() { auto temp = new wxBoxSizer(wxHORIZONTAL); diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index 60a06427d7..eaa4fe4812 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -425,7 +425,7 @@ class PointCtrl : public Field { public: PointCtrl(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} PointCtrl(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} - ~PointCtrl() {} + ~PointCtrl(); wxSizer* sizer{ nullptr }; wxTextCtrl* x_textctrl{ nullptr }; diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index cfa2ef15a6..0534446f01 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -118,6 +118,24 @@ OptionsGroup::OptionsGroup( wxWindow* _parent, const wxString& title, { } +void Line::clear() +{ + if (near_label_widget_win) + near_label_widget_win = nullptr; + + if (widget_sizer) { + widget_sizer->Clear(true); + delete widget_sizer; + widget_sizer = nullptr; + } + + if (extra_widget_sizer) { + extra_widget_sizer->Clear(true); + delete extra_widget_sizer; + extra_widget_sizer = nullptr; + } +} + wxWindow* OptionsGroup::ctrl_parent() const { return this->custom_ctrl && m_use_custom_ctrl_as_parent ? static_cast(this->custom_ctrl) : (this->stb ? static_cast(this->stb) : this->parent()); @@ -231,7 +249,7 @@ void OptionsGroup::activate_line(Line& line) } } - auto option_set = line.get_options(); + const std::vector