Transform gizmo finally rendering correctly

This commit is contained in:
Sri Sham Haran 2022-10-20 19:16:03 +08:00
parent 6051b7ded5
commit e01a608d8c
8 changed files with 46 additions and 33 deletions

View File

@ -55,7 +55,11 @@ namespace SHADE
{
EntityID const& eid = editor->selectedEntities[0];
SHEntity* entity = SHEntityManager::GetEntityByID(eid);
if(!entity)
{
ImGui::End();
return;
}
ImGui::TextColored(ImGuiColors::green, "EID: %zu", eid);
SHEditorWidgets::CheckBox("##IsActive", [entity]()->bool {return entity->GetActive(); }, [entity](bool const& active) {entity->SetActive(active); });
ImGui::SameLine();

View File

@ -43,9 +43,12 @@ namespace SHADE
bool result = ImGui::Begin(windowName.data(), &isOpen, windowFlags);
auto wndSize = ImGui::GetWindowSize();
if(windowSize.x != wndSize.x || windowSize.y != wndSize.y)
auto contentRegionAvail = ImGui::GetContentRegionAvail();
if( beginContentRegionAvailable.x != contentRegionAvail.x || beginContentRegionAvailable.y != contentRegionAvail.y || windowSize.x != wndSize.x || windowSize.y != wndSize.y)
{
windowSize = {wndSize.x, wndSize.y};
beginContentRegionAvailable = {contentRegionAvail.x, contentRegionAvail.y};
OnResize();
}
auto wndPos = ImGui::GetWindowPos();

View File

@ -26,6 +26,10 @@ namespace SHADE
bool isOpen;
bool isWindowHovered;
std::string_view windowName;
SHVec2 windowSize;
SHVec2 windowPos;
SHVec2 viewportMousePos;
SHVec2 beginContentRegionAvailable;
protected:
virtual bool Begin();
virtual void OnResize();
@ -33,8 +37,6 @@ namespace SHADE
ImGuiWindowFlags windowFlags = 0;
ImGuiIO& io;
SHVec2 windowSize;
SHVec2 windowPos;
SHVec2 viewportMousePos;
};//class SHEditorWindow
}//namespace SHADE

View File

@ -1,6 +1,8 @@
#include "SHpch.h"
#include "Editor/SHImGuiHelpers.hpp"
#include "SHEditorViewport.h"
#include "ImGuizmo.h"
#include "ECS_Base/Managers/SHSystemManager.h"
#include "Editor/SHEditor.hpp"
#include "Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h"
@ -24,31 +26,21 @@ namespace SHADE
void SHEditorViewport::Update()
{
SHEditorWindow::Update();
//ImGuizmo::SetDrawlist(ImGui::GetBackgroundDrawList(ImGui::GetMainViewport()));
ImGuizmo::SetRect(beginCursorPos.x, beginCursorPos.y, beginContentRegionAvailable.x, beginContentRegionAvailable.y);
transfromGizmo.Draw();
if(Begin())
{
DrawMenuBar();
auto gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
auto const& descriptorSet = gfxSystem->GetPostOffscreenRenderSystem()->GetDescriptorSetGroup()->GetVkHandle()[0];
auto mousePos = ImGui::GetMousePos();
auto cursorPos = ImGui::GetCursorScreenPos();
viewportMousePos = {mousePos.x - cursorPos.x, mousePos.y - cursorPos.y};
beginCursorPos = ImGui::GetCursorScreenPos();
viewportMousePos = {mousePos.x - beginCursorPos.x, mousePos.y - beginCursorPos.y};
gfxSystem->GetMousePickSystem ()->SetViewportMousePos (viewportMousePos);
//if (ImGui::IsMouseReleased(ImGuiMouseButton_Left))
//{
// auto eid = gfxSystem->GetMousePickSystem ()->GetPickedEntity();
// if(eid != MAX_EID)
// {
// auto editor = SHSystemManager::GetSystem<SHEditor>();
// editor->selectedEntities.clear();
// editor->selectedEntities.push_back(eid);
// if (const auto hierarchyPanel = SHEditorWindowManager::GetEditorWindow<SHHierarchyPanel>())
// {
// hierarchyPanel->SetScrollTo(eid);
// }
// }
//}
ImGui::Image((ImTextureID)descriptorSet, ImGui::GetWindowSize());
ImGui::Image((ImTextureID)descriptorSet, {beginContentRegionAvailable.x, beginContentRegionAvailable.y});
}
ImGui::End();
}
@ -66,7 +58,11 @@ namespace SHADE
//auto pos = ImGui::GetCursorPos();
//windowCursorPos = {}
gfxSystem->PrepareResize(static_cast<uint32_t>(windowSize.x), static_cast<uint32_t>(windowSize.y));
if(beginContentRegionAvailable.x == 0 || beginContentRegionAvailable.y == 0)
{
beginContentRegionAvailable = windowSize;
}
gfxSystem->PrepareResize(static_cast<uint32_t>(beginContentRegionAvailable.x), static_cast<uint32_t>(beginContentRegionAvailable.y));
}
void SHEditorViewport::OnPosChange()

View File

@ -10,6 +10,7 @@
#include "imgui_internal.h"
#include "ECS_Base/SHECSMacros.h"
#include "Editor/EditorWindow/SHEditorWindow.h"
#include "Editor/Gizmos/SHTransformGizmo.h"
namespace SHADE
{
@ -25,5 +26,7 @@ namespace SHADE
void OnPosChange() override;
private:
void DrawMenuBar() const noexcept;
SHTransformGizmo transfromGizmo;
SHVec2 beginCursorPos;
};//class SHEditorViewport
}//namespace SHADE

View File

@ -8,6 +8,7 @@
#include <ImGuizmo.h>
#include "Camera/SHCameraSystem.h"
#include "Editor/EditorWindow/ViewportWindow/SHEditorViewport.h"
namespace SHADE
{
@ -21,20 +22,25 @@ namespace SHADE
EntityID eid = editor->selectedEntities.back();
selectedEntityTranformComponent = SHComponentManager::GetComponent_s<SHTransformComponent>(eid);
}
if(selectedEntityTranformComponent == nullptr)
return;
if(!editorCamera)
{
auto const cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
editorCamera = cameraSystem->GetEditorCamera();
}
auto viewportWindow = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>();
ImGuizmo::SetOrthographic(false);
SHMatrix view = editorCamera->GetViewMatrix();
SHMatrix proj = editorCamera->GetProjMatrix();
SHMatrix view = SHMatrix::Transpose(editorCamera->GetViewMatrix());
view(3, 1) = -view(3, 1);
SHMatrix proj = SHMatrix::Transpose(editorCamera->GetProjMatrix());
SHMatrix mat = selectedEntityTranformComponent->GetTRS();
ImGuizmo::DrawGrid(view.m[0], proj.m[0], mat.m[0], 10.f);
if(ImGuizmo::Manipulate(view.m[0], proj.m[0], ImGuizmo::OPERATION::UNIVERSAL, ImGuizmo::MODE::WORLD, mat.m[0]))
SHMatrix gridMat = SHMatrix::Identity;
ImGuizmo::DrawGrid(&view._11, &proj._11, &gridMat._11, 0.1f);
//ImGuizmo::ViewManipulate()
if(ImGuizmo::Manipulate(&view._11, &proj._11, ImGuizmo::OPERATION::UNIVERSAL, ImGuizmo::MODE::WORLD, &mat._11))
{
}

View File

@ -88,10 +88,10 @@ namespace SHADE
//Add editor windows
SHEditorWindowManager::CreateEditorWindow<SHEditorMenuBar>();
SHEditorWindowManager::CreateEditorWindow<SHEditorViewport>();
SHEditorWindowManager::CreateEditorWindow<SHHierarchyPanel>();
SHEditorWindowManager::CreateEditorWindow<SHEditorInspector>();
SHEditorWindowManager::CreateEditorWindow<SHEditorProfiler>();
SHEditorWindowManager::CreateEditorWindow<SHEditorViewport>();
io = &ImGui::GetIO();
@ -128,11 +128,10 @@ namespace SHADE
for (const auto& window : SHEditorWindowManager::editorWindows | std::views::values)
{
if(window->isOpen)
{
window->Update();
}
}
ImGuizmo::SetDrawlist(ImGui::GetForegroundDrawList());
transformGizmo.Draw();
if(ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_Z))
{

View File

@ -203,6 +203,6 @@ namespace SHADE
ImGuiIO* io{nullptr};
SHTransformGizmo transformGizmo;
//SHTransformGizmo transformGizmo;
};//class SHEditor
}//namespace SHADE