Progress towards gizmo mouse picking

This commit is contained in:
Antoine Pilote
2023-10-10 00:06:21 -04:00
parent 84bd2f3399
commit 90732fca50
13 changed files with 113 additions and 41 deletions

View File

@@ -270,27 +270,43 @@ namespace Nuake {
if (ImGui::GetIO().WantCaptureMouse && m_IsHoveringViewport && Input::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_1) && !ImGuizmo::IsUsing() && m_IsViewportFocused)
{
const auto windowPosNuake = Vector2(windowPos.x, windowPos.y);
auto& gbuffer = Engine::GetCurrentScene()->m_SceneRenderer->GetGBuffer();
auto pixelPos = Input::GetMousePosition() - windowPosNuake;
pixelPos.y = gbuffer.GetSize().y - pixelPos.y; // imgui coords are inverted on the Y axis
gbuffer.Bind();
if (const int result = gbuffer.ReadPixel(3, pixelPos); result > 0)
auto gizmoBuffer = Engine::GetCurrentWindow()->GetFrameBuffer();
gizmoBuffer->Bind();
bool foundSomethingToSelect = false;
if (const int result = gizmoBuffer->ReadPixel(3, pixelPos); result > 0)
{
auto ent = Entity{ (entt::entity)(result - 1), Engine::GetCurrentScene().get() };
if (ent.IsValid())
{
Selection = EditorSelection(ent);
foundSomethingToSelect = true;
}
}
else
gizmoBuffer->Unbind();
if(!foundSomethingToSelect)
{
Selection = EditorSelection(); // None
gbuffer.Bind();
if (const int result = gbuffer.ReadPixel(3, pixelPos); result > 0)
{
auto ent = Entity{ (entt::entity)(result - 1), Engine::GetCurrentScene().get() };
if (ent.IsValid())
{
Selection = EditorSelection(ent);
}
}
else
{
Selection = EditorSelection(); // None
}
gbuffer.Unbind();
}
gbuffer.Unbind();
}
}
else