Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gizmo not showing in custom window ( docking branch ) #327

Open
v71 opened this issue Apr 6, 2024 · 6 comments
Open

Gizmo not showing in custom window ( docking branch ) #327

v71 opened this issue Apr 6, 2024 · 6 comments

Comments

@v71
Copy link

v71 commented Apr 6, 2024

When using a custom window in docking branch, the gizmo library creates a debug window , detached from input ( gizmos are drawn but not clickable ) . I have tried using ImGuizmo::SetDrawlist(I); , with various position in the code and derivations , like this
ImGuizmo::SetDrawlist(ImGui::GetBackgroundDrawList(ImGui::GetMainViewport()));
without success, what I am doing wrong ?
this is the code I use

ImGuiIO& io = ImGui::GetIO();
float viewManipulateRight = io.DisplaySize.x;
float viewManipulateTop = 0;
static ImGuiWindowFlags gizmoWindowFlags = 0;
ImGuizmo::BeginFrame();
ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
ImGuizmo::SetDrawlist(ImGui::GetBackgroundDrawList(ImGui::GetMainViewport()));
ImGuizmo::DrawGrid(cameraView, cameraProjection, identityMatrix, 100.f);
ImGuizmo::DrawCubes(cameraView, cameraProjection, &objectMatrix[0][0], gizmoCount);
ImGuizmo::Manipulate(cameraView, cameraProjection, mCurrentGizmoOperation, mCurrentGizmoMode, matrix, NULL, useSnap ? &snap[0] : NULL, boundSizing ? bounds : NULL, boundSizingSnap ? boundsSnap : NULL);
ImGuizmo::ViewManipulate(cameraView, camDistance, ImVec2(viewManipulateRight - 128, viewManipulateTop), ImVec2(128, 128), 0x10101010);

@edin-m
Copy link

edin-m commented May 27, 2024

This works for me:

            ImVec2 windowPos = ImGui::GetWindowPos();
            ImVec2 windowSize = ImGui::GetWindowSize();

            // imguizmo
            ImGuizmo::SetOrthographic(false);
            ImGuizmo::AllowAxisFlip(false);
            ImGuizmo::SetDrawlist();
            // ImGuizmo::SetRect(windowPos.x, windowPos.y, windowSize.x, windowSize.y);
            vec4 vp = d->viewport.GetViewport();
            ImGuizmo::SetRect(vp.x, vp.y, vp.z, vp.w);
            // ImGuizmo::GetStyle().CenterCircleSize = 3.0f;

            glm::mat4 viewMatrix = d->scene->GetCameras()[0]->GetViewMatrix();
            glm::mat4 projectionMatrix = d->scene->GetCameras()[0]->GetProjectionMatrix();
            glm::mat4 modelMatrix = d->scene->GetSelectedEntities()[0]->GetTransform().GetWorldMatrix();

            static ImGuizmo::OPERATION currentGizmoOperation = ImGuizmo::TRANSLATE;
            if (ImGui::IsKeyPressed(ImGuiKey_T)) currentGizmoOperation = ImGuizmo::TRANSLATE;
            if (ImGui::IsKeyPressed(ImGuiKey_R)) currentGizmoOperation = ImGuizmo::ROTATE;
            if (ImGui::IsKeyPressed(ImGuiKey_S)) currentGizmoOperation = ImGuizmo::SCALE;

            // Define the mode (local or world space)
            static ImGuizmo::MODE currentGizmoMode = ImGuizmo::LOCAL;
            if (ImGui::IsKeyPressed(ImGuiKey_L)) currentGizmoMode = ImGuizmo::LOCAL;
            if (ImGui::IsKeyPressed(ImGuiKey_W)) currentGizmoMode = ImGuizmo::WORLD;

            // Manipulate the model matrix
            ImGuizmo::Manipulate(glm::value_ptr(viewMatrix), glm::value_ptr(projectionMatrix), currentGizmoOperation, currentGizmoMode, glm::value_ptr(modelMatrix));

            d->scene->GetSelectedEntities()[0]->GetTransform().CopyFrom(modelMatrix);

@maritim
Copy link
Contributor

maritim commented May 29, 2024

Hello @v71.

Since pull request #203, a special behavior has been introduced which I'm unsure is always desirable. Specifically, this pull request fixes a bug that allowed interaction with the gizmo even when another window was blocking it. The solution introduced a behavior where, when the docking branch is used, you must use ImGuizmo inside the code to create the window over which you want the gizmo to be visible. If you use ImGuizmo outside, it will be considered that the window covers the gizmo. Are you currently using this approach?

I'm considering adding a pull request to change this, as it's not always feasible to use ImGuizmo inside a window. Additionally, the use of _OwnerName is questionable. Issues with its use were mentioned in #267 and #319.

@v71
Copy link
Author

v71 commented May 31, 2024

Yes I am currently using what you have mentioned, the problem still persists.

@maritim
Copy link
Contributor

maritim commented Jun 1, 2024

I made commit 315acb2 in a fork, which introduces a few changes and hopefully addresses the issue you mentioned. By using the changes from that commit, you need to explicitly specify the name of the ImGui window in which you want the gizmo to be interactable, before the Manipulate() method is called.

Example of use:

ImGuizmo::SetOwnerWindowName(<name of the window>);

Can you check the modifications and let me know if the issue is resolved now?

@v71
Copy link
Author

v71 commented Jun 1, 2024

Will do as soons as possible and will let you know, i have to add that to use the docking window, i had to use another fbo ad address all the rendering there, could this be a problem ?

@mgerhardy
Copy link
Contributor

I did almost the same in my fork vengi-voxel/vengi@59cd9c3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants