Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion deps/imgui/ImGuizmo
Submodule ImGuizmo updated 2 files
+72 −36 ImGuizmo.cpp
+7 −0 ImGuizmo.h
7 changes: 3 additions & 4 deletions include/polyscope/transformation_gizmo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -99,7 +98,7 @@ class TransformationGizmo : public Widget {
PersistentValue<bool> allowTranslation;
PersistentValue<bool> allowRotation;
PersistentValue<bool> allowScaling;
// PersistentValue<bool> uniformScaling; // not really supported by the ImGuizmo
PersistentValue<bool> allowNonUniformScaling;
PersistentValue<bool> interactInLocalSpace;
PersistentValue<bool> showUIWindow;
PersistentValue<float> gizmoSize;
Expand Down
3 changes: 3 additions & 0 deletions src/polyscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <iostream>
#include <thread>

#include "ImGuizmo.h"
#include "imgui.h"
#include "implot.h"

Expand Down Expand Up @@ -269,6 +270,7 @@ void pushContext(std::function<void()> 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;
Expand Down Expand Up @@ -318,6 +320,7 @@ void pushContext(std::function<void()> callbackFunction, bool drawDefaultUI) {
if (!contextStack.empty()) {
ImGui::SetCurrentContext(contextStack.back().context);
ImPlot::SetCurrentContext(contextStack.back().plotContext);
ImGuizmo::PopContext();
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/screenshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include "stb_image_write.h"

#include "imgui.h"
#include "implot.h"
#include "ImGuizmo.h"

#include <algorithm>
#include <string>

Expand Down Expand Up @@ -69,6 +73,7 @@ std::vector<unsigned char> getRenderInBuffer(const ScreenshotOptions& options =
#endif
ImGui::SetCurrentContext(newContext);
ImPlot::SetCurrentContext(newPlotContext);
ImGuizmo::PushContext();

#ifdef IMGUI_HAS_DOCK
// Propagate GLFW window handle to new context
Expand Down Expand Up @@ -101,6 +106,7 @@ std::vector<unsigned char> getRenderInBuffer(const ScreenshotOptions& options =

ImGui::SetCurrentContext(oldContext);
ImPlot::SetCurrentContext(oldPlotContext);
ImGuizmo::PopContext();
}


Expand Down
29 changes: 9 additions & 20 deletions src/transformation_gizmo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<ImGuizmo::OPERATION>(gizmoOpModeInt);

ImGuizmo::MODE gizmoCoordSpace = interactInLocalSpace.get() ? ImGuizmo::LOCAL : ImGuizmo::WORLD;
Expand All @@ -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() {
Expand Down Expand Up @@ -134,27 +130,17 @@ 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);
ImGui::InputFloat3("Rt", matrixRotation);
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;
Expand Down Expand Up @@ -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; }

Expand Down
19 changes: 19 additions & 0 deletions test/src/misc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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");

Expand All @@ -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
// ============================================================
Expand Down