diff --git a/.gitmodules b/.gitmodules index 0722fbdf..442ccb09 100644 --- a/.gitmodules +++ b/.gitmodules @@ -17,4 +17,4 @@ url = https://github.com/epezent/implot [submodule "deps/imgui/ImGuizmo"] path = deps/imgui/ImGuizmo - url = https://github.com/CedricGuillemet/ImGuizmo.git + url = https://github.com/nmwsharp/ImGuizmo.git diff --git a/deps/imgui/ImGuizmo b/deps/imgui/ImGuizmo index df1c3014..1af90340 160000 --- a/deps/imgui/ImGuizmo +++ b/deps/imgui/ImGuizmo @@ -1 +1 @@ -Subproject commit df1c30142e7c3fb13c171aaeb328bb338fa7aaa6 +Subproject commit 1af903403f68ffe0d3894eeeb73fbe9dc6124f35 diff --git a/include/polyscope/transformation_gizmo.h b/include/polyscope/transformation_gizmo.h index 6b2a98d8..abd21cbd 100644 --- a/include/polyscope/transformation_gizmo.h +++ b/include/polyscope/transformation_gizmo.h @@ -59,9 +59,8 @@ class TransformationGizmo : public Widget { bool getAllowScaling(); void setAllowScaling(bool newVal); - // sadly this is not really supported by ImGuizmo - // bool getUniformScaling(); - // void setUniformScaling(bool newVal); + bool getAllowNonUniformScaling(); + void setAllowNonUniformScaling(bool newVal); // must also set allowScaling to true bool getInteractInLocalSpace(); void setInteractInLocalSpace(bool newVal); @@ -99,7 +98,7 @@ class TransformationGizmo : public Widget { PersistentValue allowTranslation; PersistentValue allowRotation; PersistentValue allowScaling; - // PersistentValue uniformScaling; // not really supported by the ImGuizmo + PersistentValue allowNonUniformScaling; PersistentValue interactInLocalSpace; PersistentValue showUIWindow; PersistentValue gizmoSize; diff --git a/src/polyscope.cpp b/src/polyscope.cpp index 1fe6b1dc..7553f15c 100644 --- a/src/polyscope.cpp +++ b/src/polyscope.cpp @@ -7,6 +7,7 @@ #include #include +#include "ImGuizmo.h" #include "imgui.h" #include "implot.h" @@ -269,6 +270,7 @@ void pushContext(std::function callbackFunction, bool drawDefaultUI) { #endif ImGui::SetCurrentContext(newContext); ImPlot::SetCurrentContext(newPlotContext); + ImGuizmo::PushContext(); #ifdef IMGUI_HAS_DOCK // Propagate GLFW window handle to new context ImGui::GetMainViewport()->PlatformHandle = oldPlatformIO.Viewports[0]->PlatformHandle; @@ -318,6 +320,7 @@ void pushContext(std::function callbackFunction, bool drawDefaultUI) { if (!contextStack.empty()) { ImGui::SetCurrentContext(contextStack.back().context); ImPlot::SetCurrentContext(contextStack.back().plotContext); + ImGuizmo::PopContext(); } } diff --git a/src/screenshot.cpp b/src/screenshot.cpp index e65ff92e..8488196e 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -6,6 +6,10 @@ #include "stb_image_write.h" +#include "imgui.h" +#include "implot.h" +#include "ImGuizmo.h" + #include #include @@ -69,6 +73,7 @@ std::vector getRenderInBuffer(const ScreenshotOptions& options = #endif ImGui::SetCurrentContext(newContext); ImPlot::SetCurrentContext(newPlotContext); + ImGuizmo::PushContext(); #ifdef IMGUI_HAS_DOCK // Propagate GLFW window handle to new context @@ -101,6 +106,7 @@ std::vector getRenderInBuffer(const ScreenshotOptions& options = ImGui::SetCurrentContext(oldContext); ImPlot::SetCurrentContext(oldPlotContext); + ImGuizmo::PopContext(); } diff --git a/src/transformation_gizmo.cpp b/src/transformation_gizmo.cpp index 2ce6ecb6..6d6e2ddd 100644 --- a/src/transformation_gizmo.cpp +++ b/src/transformation_gizmo.cpp @@ -20,7 +20,7 @@ TransformationGizmo::TransformationGizmo(std::string name_, glm::mat4* externalT allowTranslation(name + "#allowTranslation", true), allowRotation(name + "#allowRotation", true), allowScaling(name + "#allowScaling", false), - // uniformScaling(name + "#uniformScaling", true), + allowNonUniformScaling(name + "#allowNonUniformScaling", false), interactInLocalSpace(name + "#interactInLocalSpace", false), showUIWindow(name + "#showUIWindow", false), gizmoSize(name + "#gizmoSize", 1.0) @@ -62,12 +62,8 @@ void TransformationGizmo::draw() { if (allowRotation.get()) gizmoOpModeInt |= ImGuizmo::ROTATE; if (allowScaling.get()) { gizmoOpModeInt |= ImGuizmo::SCALEU; - // if(uniformScaling.get()) { - // gizmoOpModeInt |= ImGuizmo::SCALEU; - // } else { - // gizmoOpModeInt |= ImGuizmo::SCALE; - // } } + ImGuizmo::SetAllowNonUniformScaling(allowNonUniformScaling.get()); ImGuizmo::OPERATION gizmoOpMode = static_cast(gizmoOpModeInt); ImGuizmo::MODE gizmoCoordSpace = interactInLocalSpace.get() ? ImGuizmo::LOCAL : ImGuizmo::WORLD; @@ -94,7 +90,7 @@ void TransformationGizmo::buildMenuItems() { ImGui::MenuItem("Allow Translation", NULL, &allowTranslation.get()); ImGui::MenuItem("Allow Rotation", NULL, &allowRotation.get()); ImGui::MenuItem("Allow Scaling", NULL, &allowScaling.get()); - // ImGui::MenuItem("Uniform Scaling", NULL, &uniformScaling.get()); + ImGui::MenuItem("Allow Non-Uniform Scaling", NULL, &allowNonUniformScaling.get()); } bool TransformationGizmo::interact() { @@ -134,19 +130,10 @@ void TransformationGizmo::buildInlineTransformUI() { ImGui::SameLine(); ImGui::Checkbox("Scaling", &allowScaling.get()); - // if (allowScaling.get()) { - // ImGui::Checkbox("Uniform Scaling", &uniformScaling.get()); - // } + if (allowScaling.get()) { + ImGui::Checkbox("Allow Non-Uniform Scaling", &allowNonUniformScaling.get()); + } - static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::ROTATE); - static ImGuizmo::MODE mCurrentGizmoMode(ImGuizmo::WORLD); - if (ImGui::RadioButton("Translate", mCurrentGizmoOperation == ImGuizmo::TRANSLATE)) - mCurrentGizmoOperation = ImGuizmo::TRANSLATE; - ImGui::SameLine(); - if (ImGui::RadioButton("Rotate", mCurrentGizmoOperation == ImGuizmo::ROTATE)) - mCurrentGizmoOperation = ImGuizmo::ROTATE; - ImGui::SameLine(); - if (ImGui::RadioButton("Scale", mCurrentGizmoOperation == ImGuizmo::SCALE)) mCurrentGizmoOperation = ImGuizmo::SCALE; float matrixTranslation[3], matrixRotation[3], matrixScale[3]; ImGuizmo::DecomposeMatrixToComponents(glm::value_ptr(Tref), matrixTranslation, matrixRotation, matrixScale); ImGui::InputFloat3("Tr", matrixTranslation); @@ -154,7 +141,6 @@ void TransformationGizmo::buildInlineTransformUI() { ImGui::InputFloat3("Sc", matrixScale); ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, glm::value_ptr(Tref)); - // TODO these don't seem to be doing anything? if (ImGui::RadioButton("Local", interactInLocalSpace.get())) interactInLocalSpace = true; ImGui::SameLine(); if (ImGui::RadioButton("World", !interactInLocalSpace.get())) interactInLocalSpace = false; @@ -188,6 +174,9 @@ void TransformationGizmo::setAllowRotation(bool newVal) { allowRotation = newVal bool TransformationGizmo::getAllowScaling() { return allowScaling.get(); } void TransformationGizmo::setAllowScaling(bool newVal) { allowScaling = newVal; } +bool TransformationGizmo::getAllowNonUniformScaling() { return allowNonUniformScaling.get(); } +void TransformationGizmo::setAllowNonUniformScaling(bool newVal) { allowNonUniformScaling = newVal; } + bool TransformationGizmo::getInteractInLocalSpace() { return interactInLocalSpace.get(); } void TransformationGizmo::setInteractInLocalSpace(bool newVal) { interactInLocalSpace = newVal; } diff --git a/test/src/misc_test.cpp b/test/src/misc_test.cpp index e7d2b00b..af1b3ec6 100644 --- a/test/src/misc_test.cpp +++ b/test/src/misc_test.cpp @@ -81,6 +81,7 @@ TEST_F(PolyscopeTest, TransformationGizmoTest) { gizmo.setAllowTranslation(true); gizmo.setAllowRotation(true); gizmo.setAllowScaling(true); + gizmo.setAllowNonUniformScaling(true); gizmo.setInteractInLocalSpace(false); polyscope::show(3); @@ -102,6 +103,8 @@ TEST_F(PolyscopeTest, TransformationGizmoStandaloneTest) { // create by name polyscope::TransformationGizmo* gizmo2 = polyscope::addTransformationGizmo("my_gizmo"); + gizmo2->setEnabled(true); + gizmo2->setAllowScaling(true); polyscope::show(3); polyscope::removeTransformationGizmo("my_gizmo"); @@ -125,6 +128,22 @@ TEST_F(PolyscopeTest, TransformationGizmoStandaloneTest) { polyscope::removeAllTransformationGizmos(); } +TEST_F(PolyscopeTest, TransformationGizmoNestedShowTest) { + + polyscope::TransformationGizmo* gizmo1 = polyscope::addTransformationGizmo(); + gizmo1->setEnabled(true); + polyscope::show(3); + + auto showCallback = [&]() { + polyscope::show(3); + }; + polyscope::state::userCallback = showCallback; + polyscope::show(3); + + polyscope::state::userCallback = nullptr; + polyscope::removeAllTransformationGizmos(); +} + // ============================================================ // =============== Slice Plane Tests // ============================================================