Transform gizmo finally rendering correctly
This commit is contained in:
parent
6051b7ded5
commit
e01a608d8c
|
@ -55,7 +55,11 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
EntityID const& eid = editor->selectedEntities[0];
|
EntityID const& eid = editor->selectedEntities[0];
|
||||||
SHEntity* entity = SHEntityManager::GetEntityByID(eid);
|
SHEntity* entity = SHEntityManager::GetEntityByID(eid);
|
||||||
|
if(!entity)
|
||||||
|
{
|
||||||
|
ImGui::End();
|
||||||
|
return;
|
||||||
|
}
|
||||||
ImGui::TextColored(ImGuiColors::green, "EID: %zu", eid);
|
ImGui::TextColored(ImGuiColors::green, "EID: %zu", eid);
|
||||||
SHEditorWidgets::CheckBox("##IsActive", [entity]()->bool {return entity->GetActive(); }, [entity](bool const& active) {entity->SetActive(active); });
|
SHEditorWidgets::CheckBox("##IsActive", [entity]()->bool {return entity->GetActive(); }, [entity](bool const& active) {entity->SetActive(active); });
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
|
@ -43,9 +43,12 @@ namespace SHADE
|
||||||
bool result = ImGui::Begin(windowName.data(), &isOpen, windowFlags);
|
bool result = ImGui::Begin(windowName.data(), &isOpen, windowFlags);
|
||||||
|
|
||||||
auto wndSize = ImGui::GetWindowSize();
|
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};
|
windowSize = {wndSize.x, wndSize.y};
|
||||||
|
beginContentRegionAvailable = {contentRegionAvail.x, contentRegionAvail.y};
|
||||||
|
|
||||||
OnResize();
|
OnResize();
|
||||||
}
|
}
|
||||||
auto wndPos = ImGui::GetWindowPos();
|
auto wndPos = ImGui::GetWindowPos();
|
||||||
|
|
|
@ -26,6 +26,10 @@ namespace SHADE
|
||||||
bool isOpen;
|
bool isOpen;
|
||||||
bool isWindowHovered;
|
bool isWindowHovered;
|
||||||
std::string_view windowName;
|
std::string_view windowName;
|
||||||
|
SHVec2 windowSize;
|
||||||
|
SHVec2 windowPos;
|
||||||
|
SHVec2 viewportMousePos;
|
||||||
|
SHVec2 beginContentRegionAvailable;
|
||||||
protected:
|
protected:
|
||||||
virtual bool Begin();
|
virtual bool Begin();
|
||||||
virtual void OnResize();
|
virtual void OnResize();
|
||||||
|
@ -33,8 +37,6 @@ namespace SHADE
|
||||||
|
|
||||||
ImGuiWindowFlags windowFlags = 0;
|
ImGuiWindowFlags windowFlags = 0;
|
||||||
ImGuiIO& io;
|
ImGuiIO& io;
|
||||||
SHVec2 windowSize;
|
|
||||||
SHVec2 windowPos;
|
|
||||||
SHVec2 viewportMousePos;
|
|
||||||
};//class SHEditorWindow
|
};//class SHEditorWindow
|
||||||
}//namespace SHADE
|
}//namespace SHADE
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "SHpch.h"
|
#include "SHpch.h"
|
||||||
|
#include "Editor/SHImGuiHelpers.hpp"
|
||||||
#include "SHEditorViewport.h"
|
#include "SHEditorViewport.h"
|
||||||
|
|
||||||
|
#include "ImGuizmo.h"
|
||||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||||
#include "Editor/SHEditor.hpp"
|
#include "Editor/SHEditor.hpp"
|
||||||
#include "Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h"
|
#include "Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h"
|
||||||
|
@ -24,31 +26,21 @@ namespace SHADE
|
||||||
void SHEditorViewport::Update()
|
void SHEditorViewport::Update()
|
||||||
{
|
{
|
||||||
SHEditorWindow::Update();
|
SHEditorWindow::Update();
|
||||||
|
//ImGuizmo::SetDrawlist(ImGui::GetBackgroundDrawList(ImGui::GetMainViewport()));
|
||||||
|
|
||||||
|
ImGuizmo::SetRect(beginCursorPos.x, beginCursorPos.y, beginContentRegionAvailable.x, beginContentRegionAvailable.y);
|
||||||
|
transfromGizmo.Draw();
|
||||||
if(Begin())
|
if(Begin())
|
||||||
{
|
{
|
||||||
DrawMenuBar();
|
DrawMenuBar();
|
||||||
auto gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
|
auto gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
|
||||||
auto const& descriptorSet = gfxSystem->GetPostOffscreenRenderSystem()->GetDescriptorSetGroup()->GetVkHandle()[0];
|
auto const& descriptorSet = gfxSystem->GetPostOffscreenRenderSystem()->GetDescriptorSetGroup()->GetVkHandle()[0];
|
||||||
auto mousePos = ImGui::GetMousePos();
|
auto mousePos = ImGui::GetMousePos();
|
||||||
auto cursorPos = ImGui::GetCursorScreenPos();
|
beginCursorPos = ImGui::GetCursorScreenPos();
|
||||||
viewportMousePos = {mousePos.x - cursorPos.x, mousePos.y - cursorPos.y};
|
viewportMousePos = {mousePos.x - beginCursorPos.x, mousePos.y - beginCursorPos.y};
|
||||||
gfxSystem->GetMousePickSystem ()->SetViewportMousePos (viewportMousePos);
|
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();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
@ -66,7 +58,11 @@ namespace SHADE
|
||||||
|
|
||||||
//auto pos = ImGui::GetCursorPos();
|
//auto pos = ImGui::GetCursorPos();
|
||||||
//windowCursorPos = {}
|
//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()
|
void SHEditorViewport::OnPosChange()
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "imgui_internal.h"
|
#include "imgui_internal.h"
|
||||||
#include "ECS_Base/SHECSMacros.h"
|
#include "ECS_Base/SHECSMacros.h"
|
||||||
#include "Editor/EditorWindow/SHEditorWindow.h"
|
#include "Editor/EditorWindow/SHEditorWindow.h"
|
||||||
|
#include "Editor/Gizmos/SHTransformGizmo.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -25,5 +26,7 @@ namespace SHADE
|
||||||
void OnPosChange() override;
|
void OnPosChange() override;
|
||||||
private:
|
private:
|
||||||
void DrawMenuBar() const noexcept;
|
void DrawMenuBar() const noexcept;
|
||||||
|
SHTransformGizmo transfromGizmo;
|
||||||
|
SHVec2 beginCursorPos;
|
||||||
};//class SHEditorViewport
|
};//class SHEditorViewport
|
||||||
}//namespace SHADE
|
}//namespace SHADE
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <ImGuizmo.h>
|
#include <ImGuizmo.h>
|
||||||
|
|
||||||
#include "Camera/SHCameraSystem.h"
|
#include "Camera/SHCameraSystem.h"
|
||||||
|
#include "Editor/EditorWindow/ViewportWindow/SHEditorViewport.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -21,20 +22,25 @@ namespace SHADE
|
||||||
EntityID eid = editor->selectedEntities.back();
|
EntityID eid = editor->selectedEntities.back();
|
||||||
selectedEntityTranformComponent = SHComponentManager::GetComponent_s<SHTransformComponent>(eid);
|
selectedEntityTranformComponent = SHComponentManager::GetComponent_s<SHTransformComponent>(eid);
|
||||||
}
|
}
|
||||||
|
if(selectedEntityTranformComponent == nullptr)
|
||||||
|
return;
|
||||||
if(!editorCamera)
|
if(!editorCamera)
|
||||||
{
|
{
|
||||||
auto const cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
auto const cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
||||||
editorCamera = cameraSystem->GetEditorCamera();
|
editorCamera = cameraSystem->GetEditorCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto viewportWindow = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>();
|
||||||
ImGuizmo::SetOrthographic(false);
|
ImGuizmo::SetOrthographic(false);
|
||||||
|
|
||||||
SHMatrix view = editorCamera->GetViewMatrix();
|
SHMatrix view = SHMatrix::Transpose(editorCamera->GetViewMatrix());
|
||||||
SHMatrix proj = editorCamera->GetProjMatrix();
|
view(3, 1) = -view(3, 1);
|
||||||
|
SHMatrix proj = SHMatrix::Transpose(editorCamera->GetProjMatrix());
|
||||||
SHMatrix mat = selectedEntityTranformComponent->GetTRS();
|
SHMatrix mat = selectedEntityTranformComponent->GetTRS();
|
||||||
ImGuizmo::DrawGrid(view.m[0], proj.m[0], mat.m[0], 10.f);
|
SHMatrix gridMat = SHMatrix::Identity;
|
||||||
if(ImGuizmo::Manipulate(view.m[0], proj.m[0], ImGuizmo::OPERATION::UNIVERSAL, ImGuizmo::MODE::WORLD, mat.m[0]))
|
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))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,10 +88,10 @@ namespace SHADE
|
||||||
|
|
||||||
//Add editor windows
|
//Add editor windows
|
||||||
SHEditorWindowManager::CreateEditorWindow<SHEditorMenuBar>();
|
SHEditorWindowManager::CreateEditorWindow<SHEditorMenuBar>();
|
||||||
SHEditorWindowManager::CreateEditorWindow<SHEditorViewport>();
|
|
||||||
SHEditorWindowManager::CreateEditorWindow<SHHierarchyPanel>();
|
SHEditorWindowManager::CreateEditorWindow<SHHierarchyPanel>();
|
||||||
SHEditorWindowManager::CreateEditorWindow<SHEditorInspector>();
|
SHEditorWindowManager::CreateEditorWindow<SHEditorInspector>();
|
||||||
SHEditorWindowManager::CreateEditorWindow<SHEditorProfiler>();
|
SHEditorWindowManager::CreateEditorWindow<SHEditorProfiler>();
|
||||||
|
SHEditorWindowManager::CreateEditorWindow<SHEditorViewport>();
|
||||||
|
|
||||||
io = &ImGui::GetIO();
|
io = &ImGui::GetIO();
|
||||||
|
|
||||||
|
@ -128,11 +128,10 @@ namespace SHADE
|
||||||
for (const auto& window : SHEditorWindowManager::editorWindows | std::views::values)
|
for (const auto& window : SHEditorWindowManager::editorWindows | std::views::values)
|
||||||
{
|
{
|
||||||
if(window->isOpen)
|
if(window->isOpen)
|
||||||
|
{
|
||||||
window->Update();
|
window->Update();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ImGuizmo::SetDrawlist(ImGui::GetForegroundDrawList());
|
|
||||||
transformGizmo.Draw();
|
|
||||||
|
|
||||||
if(ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_Z))
|
if(ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_Z))
|
||||||
{
|
{
|
||||||
|
|
|
@ -203,6 +203,6 @@ namespace SHADE
|
||||||
|
|
||||||
ImGuiIO* io{nullptr};
|
ImGuiIO* io{nullptr};
|
||||||
|
|
||||||
SHTransformGizmo transformGizmo;
|
//SHTransformGizmo transformGizmo;
|
||||||
};//class SHEditor
|
};//class SHEditor
|
||||||
}//namespace SHADE
|
}//namespace SHADE
|
||||||
|
|
Loading…
Reference in New Issue