Measuring: Optimization into GLGizmoMeasure::on_render()

This commit is contained in:
enricoturri1966 2022-09-01 09:44:40 +02:00
parent 58da6e994c
commit ec9001c57e
2 changed files with 35 additions and 28 deletions

View file

@ -106,6 +106,9 @@ void GLGizmoMeasure::data_changed()
}
if (model_object != m_old_model_object || model_volume != m_old_model_volume)
update_if_needed();
m_last_inv_zoom = 0.0f;
m_last_plane_idx = -1;
}
bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down)
@ -211,12 +214,13 @@ void GLGizmoMeasure::on_render()
{
const auto& [center, radius, normal] = m_curr_feature->get_circle();
// TODO: check for changed inv_zoom
if (m_last_inv_zoom != inv_zoom) {
m_last_inv_zoom = inv_zoom;
m_circle.reset();
GLModel::Geometry circle_geometry = smooth_torus(64, 16, float(radius), 5.0f * inv_zoom);
m_circle.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(circle_geometry.get_as_indexed_triangle_set())));
m_circle.model.init_from(std::move(circle_geometry));
}
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) });
@ -225,9 +229,8 @@ void GLGizmoMeasure::on_render()
case Measure::SurfaceFeatureType::Plane:
{
const auto& [idx, normal, point] = m_curr_feature->get_plane();
// TODO: check for changed idx
if (m_last_plane_idx != idx) {
m_last_plane_idx = idx;
const std::vector<std::vector<int>> planes_triangles = m_measuring->get_planes_triangle_indices();
const std::vector<int>& triangle_indices = planes_triangles[idx];
@ -251,6 +254,8 @@ void GLGizmoMeasure::on_render()
m_plane.reset();
m_plane.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(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;
}

View file

@ -44,11 +44,13 @@ class GLGizmoMeasure : public GLGizmoBase
std::optional<Measure::SurfaceFeature> m_curr_feature;
std::optional<Vec3d> m_curr_ex_feature_position;
// This holds information to decide whether recalculation is necessary:
// These hold information to decide whether recalculation is necessary:
std::vector<Transform3d> m_volumes_matrices;
std::vector<ModelVolumeType> m_volumes_types;
Vec3d m_first_instance_scale{ Vec3d::Ones() };
Vec3d m_first_instance_mirror{ Vec3d::Ones() };
float m_last_inv_zoom{ 0.0f };
int m_last_plane_idx{ -1 };
bool m_mouse_left_down{ false }; // for detection left_up of this gizmo
const ModelObject* m_old_model_object{ nullptr };