From 7b068573b6f1766f95a7018820050d4d84223093 Mon Sep 17 00:00:00 2001 From: Nicholas Sharp Date: Sun, 21 Dec 2025 22:46:43 -0800 Subject: [PATCH 1/4] use gizmo context stack --- .gitmodules | 2 +- deps/imgui/ImGuizmo | 2 +- src/polyscope.cpp | 3 +++ src/screenshot.cpp | 6 ++++++ 4 files changed, 11 insertions(+), 2 deletions(-) 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..e4e0c10d 160000 --- a/deps/imgui/ImGuizmo +++ b/deps/imgui/ImGuizmo @@ -1 +1 @@ -Subproject commit df1c30142e7c3fb13c171aaeb328bb338fa7aaa6 +Subproject commit e4e0c10d226fccccadb77e659b79ace50d5294c0 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(); } From e062b966d5c8010c48c62968e834e5e0e4c4624f Mon Sep 17 00:00:00 2001 From: Nicholas Sharp Date: Sun, 21 Dec 2025 22:46:52 -0800 Subject: [PATCH 2/4] add test for gizmo nested show bug --- test/src/misc_test.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/src/misc_test.cpp b/test/src/misc_test.cpp index e7d2b00b..b3059f52 100644 --- a/test/src/misc_test.cpp +++ b/test/src/misc_test.cpp @@ -125,6 +125,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 // ============================================================ From b240a5e951d9c4a777c52d598eccfb1788898d80 Mon Sep 17 00:00:00 2001 From: Nicholas Sharp Date: Sun, 21 Dec 2025 23:25:26 -0800 Subject: [PATCH 3/4] add nonuniform scaling option --- deps/imgui/ImGuizmo | 2 +- include/polyscope/transformation_gizmo.h | 7 +++---- src/transformation_gizmo.cpp | 19 +++++++++---------- test/src/misc_test.cpp | 3 +++ 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/deps/imgui/ImGuizmo b/deps/imgui/ImGuizmo index e4e0c10d..1af90340 160000 --- a/deps/imgui/ImGuizmo +++ b/deps/imgui/ImGuizmo @@ -1 +1 @@ -Subproject commit e4e0c10d226fccccadb77e659b79ace50d5294c0 +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/transformation_gizmo.cpp b/src/transformation_gizmo.cpp index 2ce6ecb6..41970e37 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,9 +130,9 @@ 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); @@ -188,6 +184,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 b3059f52..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"); From 23939f0fcf76de75db56bffd2ec4300c1f1dac67 Mon Sep 17 00:00:00 2001 From: Nicholas Sharp Date: Sun, 21 Dec 2025 23:27:47 -0800 Subject: [PATCH 4/4] cleanup unused UI elements --- src/transformation_gizmo.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/transformation_gizmo.cpp b/src/transformation_gizmo.cpp index 41970e37..6d6e2ddd 100644 --- a/src/transformation_gizmo.cpp +++ b/src/transformation_gizmo.cpp @@ -134,15 +134,6 @@ void TransformationGizmo::buildInlineTransformUI() { 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); @@ -150,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;