From 57b630cb54072650adce2bf8a595c590b52db4c9 Mon Sep 17 00:00:00 2001 From: T1ti <40864460+T1ti@users.noreply.github.com> Date: Wed, 2 Oct 2024 06:39:52 +0200 Subject: [PATCH] optimize gizmos: only calculate and update stuff if values changed --- .../ui/tools/ViewportGizmo/ViewportGizmo.cpp | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/noggit/ui/tools/ViewportGizmo/ViewportGizmo.cpp b/src/noggit/ui/tools/ViewportGizmo/ViewportGizmo.cpp index 7a0fb93e..367a7a0a 100755 --- a/src/noggit/ui/tools/ViewportGizmo/ViewportGizmo.cpp +++ b/src/noggit/ui/tools/ViewportGizmo/ViewportGizmo.cpp @@ -77,7 +77,7 @@ void ViewportGizmo::handleTransformGizmo(MapView* map_view case WMO: { obj_instance = std::get(selection[0]); - obj_instance->recalcExtents(); + obj_instance->ensureExtents(); object_matrix = obj_instance->transformMatrix(); ImGuizmo::Manipulate(glm::value_ptr(model_view_trs), glm::value_ptr(projection_trs), _gizmo_operation, _gizmo_mode, glm::value_ptr(object_matrix), glm::value_ptr(delta_matrix), nullptr); break; @@ -115,6 +115,34 @@ void ViewportGizmo::handleTransformGizmo(MapView* map_view new_orientation = glm::conjugate(new_orientation); + // if nothing was changed, just return early + switch (_gizmo_operation) + { + case ImGuizmo::TRANSLATE: + { + if (new_translation.x == 0.0f && new_translation.y == 0.0f && new_translation.z == 0.0f) + return; + break; + } + case ImGuizmo::ROTATE: + { + + if (new_orientation.x == -0.0f && new_orientation.y == -0.0f && new_orientation.z == -0.0f) + return; + break; + } + case ImGuizmo::SCALE: + { + if (new_scale.x == 1.0f && new_scale.y == 1.0f && new_scale.z == 1.0f) + return; + break; + } + case ImGuizmo::BOUNDS: + { + throw std::logic_error("Bounds are not supported by this gizmo."); + } + } + NOGGIT_ACTION_MGR->beginAction(map_view, Noggit::ActionFlags::eOBJECTS_TRANSFORMED, Noggit::ActionModalityControllers::eLMB); @@ -130,7 +158,7 @@ void ViewportGizmo::handleTransformGizmo(MapView* map_view obj_instance = std::get(selected); NOGGIT_CUR_ACTION->registerObjectTransformed(obj_instance); - obj_instance->recalcExtents(); + obj_instance->ensureExtents(); object_matrix = obj_instance->transformMatrix(); glm::vec3& pos = obj_instance->pos; @@ -230,7 +258,7 @@ void ViewportGizmo::handleTransformGizmo(MapView* map_view break; } } - obj_instance->recalcExtents(); + obj_instance->ensureExtents(); if (_world) _world->updateTilesEntry(selected, model_update::add); @@ -246,7 +274,7 @@ void ViewportGizmo::handleTransformGizmo(MapView* map_view obj_instance = std::get(selected); NOGGIT_CUR_ACTION->registerObjectTransformed(obj_instance); - obj_instance->recalcExtents(); + obj_instance->ensureExtents(); object_matrix = obj_instance->transformMatrix(); glm::vec3& pos = obj_instance->pos;