Measuring - Refactoring in GLGizmoMeasure related to scene raycasters state cache
This commit is contained in:
parent
4dd005a554
commit
b71d61f0f7
@ -5517,11 +5517,11 @@ void GLCanvas3D::_picking_pass()
|
||||
|
||||
ImGui::Separator();
|
||||
imgui.text("Registered for picking:");
|
||||
sprintf(buf, "Beds: %d", (int)m_scene_raycaster.beds_count());
|
||||
sprintf(buf, "Beds: %d (%d)", (int)m_scene_raycaster.beds_count(), (int)m_scene_raycaster.active_beds_count());
|
||||
imgui.text(std::string(buf));
|
||||
sprintf(buf, "Volumes: %d", (int)m_scene_raycaster.volumes_count());
|
||||
sprintf(buf, "Volumes: %d (%d)", (int)m_scene_raycaster.volumes_count(), (int)m_scene_raycaster.active_volumes_count());
|
||||
imgui.text(std::string(buf));
|
||||
sprintf(buf, "Gizmo elements: %d", (int)m_scene_raycaster.gizmos_count());
|
||||
sprintf(buf, "Gizmo elements: %d (%d)", (int)m_scene_raycaster.gizmos_count(), (int)m_scene_raycaster.active_gizmos_count());
|
||||
imgui.text(std::string(buf));
|
||||
imgui.end();
|
||||
#endif // ENABLE_RAYCAST_PICKING_DEBUG
|
||||
|
@ -372,11 +372,13 @@ void GLGizmoMeasure::on_set_state()
|
||||
else {
|
||||
m_mode = EMode::BasicSelection;
|
||||
// store current state of scene raycaster for later use
|
||||
m_scene_raycaster_state.clear();
|
||||
m_scene_raycasters = m_parent.get_raycasters_for_picking(SceneRaycaster::EType::Volume);
|
||||
if (m_scene_raycasters != nullptr) {
|
||||
for (const auto& r : *m_scene_raycasters) {
|
||||
m_scene_raycaster_state.emplace_back(r->is_active());
|
||||
m_scene_raycasters.clear();
|
||||
auto scene_raycasters = m_parent.get_raycasters_for_picking(SceneRaycaster::EType::Volume);
|
||||
if (scene_raycasters != nullptr) {
|
||||
m_scene_raycasters.reserve(scene_raycasters->size());
|
||||
for (auto r : *scene_raycasters) {
|
||||
SceneRaycasterState state = { r, r->is_active() };
|
||||
m_scene_raycasters.emplace_back(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -772,20 +774,15 @@ void GLGizmoMeasure::update_if_needed()
|
||||
|
||||
void GLGizmoMeasure::disable_scene_raycasters()
|
||||
{
|
||||
if (m_scene_raycasters != nullptr) {
|
||||
for (auto r : *m_scene_raycasters) {
|
||||
r->set_active(false);
|
||||
}
|
||||
for (auto r : m_scene_raycasters) {
|
||||
r.raycaster->set_active(false);
|
||||
}
|
||||
}
|
||||
|
||||
void GLGizmoMeasure::restore_scene_raycasters_state()
|
||||
{
|
||||
if (m_scene_raycasters != nullptr) {
|
||||
assert(m_scene_raycasters->size() == m_scene_raycaster_state.size());
|
||||
for (size_t i = 0; i < m_scene_raycasters->size(); ++i) {
|
||||
(*m_scene_raycasters)[i]->set_active(m_scene_raycaster_state[i]);
|
||||
}
|
||||
for (auto r : m_scene_raycasters) {
|
||||
r.raycaster->set_active(r.state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,8 +89,13 @@ class GLGizmoMeasure : public GLGizmoBase
|
||||
std::map<int, std::shared_ptr<SceneRaycasterItem>> m_raycasters;
|
||||
std::optional<Measure::SurfaceFeature> m_curr_feature;
|
||||
std::optional<Vec3d> m_curr_point_on_feature_position;
|
||||
std::vector<std::shared_ptr<SceneRaycasterItem>>* m_scene_raycasters{ nullptr };
|
||||
std::vector<bool> m_scene_raycaster_state;
|
||||
struct SceneRaycasterState
|
||||
{
|
||||
std::shared_ptr<SceneRaycasterItem> raycaster{ nullptr };
|
||||
bool state{true};
|
||||
|
||||
};
|
||||
std::vector<SceneRaycasterState> m_scene_raycasters;
|
||||
|
||||
// These hold information to decide whether recalculation is necessary:
|
||||
std::vector<Transform3d> m_volumes_matrices;
|
||||
|
@ -173,6 +173,31 @@ void SceneRaycaster::render_hit(const Camera& camera)
|
||||
|
||||
shader->stop_using();
|
||||
}
|
||||
|
||||
size_t SceneRaycaster::active_beds_count() const {
|
||||
size_t count = 0;
|
||||
for (const auto& b : m_bed) {
|
||||
if (b->is_active())
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
size_t SceneRaycaster::active_volumes_count() const {
|
||||
size_t count = 0;
|
||||
for (const auto& v : m_volumes) {
|
||||
if (v->is_active())
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
size_t SceneRaycaster::active_gizmos_count() const {
|
||||
size_t count = 0;
|
||||
for (const auto& g : m_gizmos) {
|
||||
if (g->is_active())
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
#endif // ENABLE_RAYCAST_PICKING_DEBUG
|
||||
|
||||
std::vector<std::shared_ptr<SceneRaycasterItem>>* SceneRaycaster::get_raycasters(EType type)
|
||||
|
@ -100,6 +100,10 @@ public:
|
||||
size_t beds_count() const { return m_bed.size(); }
|
||||
size_t volumes_count() const { return m_volumes.size(); }
|
||||
size_t gizmos_count() const { return m_gizmos.size(); }
|
||||
|
||||
size_t active_beds_count() const;
|
||||
size_t active_volumes_count() const;
|
||||
size_t active_gizmos_count() const;
|
||||
#endif // ENABLE_RAYCAST_PICKING_DEBUG
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user