Measurement: refactoring - do not touch common raycaster interface when there is no need

This commit is contained in:
Lukas Matena 2022-11-15 16:07:38 +01:00 committed by enricoturri1966
parent 4606d8266a
commit 268365b92d
4 changed files with 5 additions and 31 deletions

View File

@ -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<MeshRaycaster>(std::make_shared<const TriangleMesh>(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<const TriangleMesh>(m_measuring->get_mesh())));
m_volumes_cache = volumes_cache;
};
#else

View File

@ -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<MeshRaycaster> m_raycaster;
#else
Transform3d m_volume_matrix{ Transform3d::Identity() };
#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES

View File

@ -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<const TriangleMesh*> meshes = { &mesh };
if (meshes != m_old_meshes) {
wxBusyCursor wait;
m_raycasters.clear();
m_raycasters.emplace_back(new MeshRaycaster(std::make_shared<const TriangleMesh>(mesh)));
m_old_meshes = meshes;
}
validate();
}
#endif // ENABLE_GIZMO_MEASURE_WORLD_COORDINATES
void Raycaster::on_update()
{
wxBusyCursor wait;

View File

@ -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<const MeshRaycaster*> 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;