add ImGuizmo
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -14,3 +14,6 @@
|
|||||||
[submodule "Prism/vendor/assimp"]
|
[submodule "Prism/vendor/assimp"]
|
||||||
path = Prism/vendor/assimp
|
path = Prism/vendor/assimp
|
||||||
url = https://github.com/assimp/assimp.git
|
url = https://github.com/assimp/assimp.git
|
||||||
|
[submodule "Prism/vendor/ImGuizmo"]
|
||||||
|
path = Prism/vendor/ImGuizmo
|
||||||
|
url = https://github.com/CedricGuillemet/ImGuizmo.git
|
||||||
|
|||||||
@ -4,6 +4,9 @@
|
|||||||
|
|
||||||
#include "EditorLayer.h"
|
#include "EditorLayer.h"
|
||||||
|
|
||||||
|
#include "ImGuizmo.h"
|
||||||
|
#include "Prism/Core/KeyCodes.h"
|
||||||
|
|
||||||
namespace Prism
|
namespace Prism
|
||||||
{
|
{
|
||||||
enum class PropertyFlag
|
enum class PropertyFlag
|
||||||
@ -201,6 +204,9 @@ namespace Prism
|
|||||||
|
|
||||||
m_Light.Direction = {-0.5f, -0.5f, 1.0f};
|
m_Light.Direction = {-0.5f, -0.5f, 1.0f};
|
||||||
m_Light.Radiance = {1.0f, 1.0f, 1.0f};
|
m_Light.Radiance = {1.0f, 1.0f, 1.0f};
|
||||||
|
|
||||||
|
|
||||||
|
m_Transform = glm::scale(glm::mat4(1.0f), glm::vec3(m_MeshScale));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorLayer::OnDetach()
|
void EditorLayer::OnDetach()
|
||||||
@ -305,7 +311,7 @@ namespace Prism
|
|||||||
{
|
{
|
||||||
if (m_Mesh)
|
if (m_Mesh)
|
||||||
{
|
{
|
||||||
m_Mesh->Render(deltaTime, scale(mat4(1.0f), vec3(m_MeshScale)), m_MeshMaterial);
|
m_Mesh->Render(deltaTime, m_Transform, m_MeshMaterial);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -678,9 +684,20 @@ namespace Prism
|
|||||||
auto viewportSize = ImGui::GetContentRegionAvail();
|
auto viewportSize = ImGui::GetContentRegionAvail();
|
||||||
m_Framebuffer->Resize((uint32_t)viewportSize.x, (uint32_t)viewportSize.y);
|
m_Framebuffer->Resize((uint32_t)viewportSize.x, (uint32_t)viewportSize.y);
|
||||||
m_FinalPresentBuffer->Resize((uint32_t)viewportSize.x, (uint32_t)viewportSize.y);
|
m_FinalPresentBuffer->Resize((uint32_t)viewportSize.x, (uint32_t)viewportSize.y);
|
||||||
m_Camera.SetProjectionMatrix(glm::perspectiveFov(glm::radians(45.0f), viewportSize.x, viewportSize.y, 0.1f,
|
m_Camera.SetProjectionMatrix(glm::perspectiveFov(glm::radians(45.0f), viewportSize.x, viewportSize.y, 0.1f, 10000.0f));
|
||||||
10000.0f));
|
|
||||||
ImGui::Image((ImTextureRef)m_FinalPresentBuffer->GetColorAttachmentRendererID(), viewportSize, {0, 1}, {1, 0});
|
ImGui::Image((ImTextureRef)m_FinalPresentBuffer->GetColorAttachmentRendererID(), viewportSize, {0, 1}, {1, 0});
|
||||||
|
|
||||||
|
// ImGuizmo
|
||||||
|
if (m_GizmoType != -1)
|
||||||
|
{
|
||||||
|
const float rw = (float)ImGui::GetWindowWidth();
|
||||||
|
const float rh = (float)ImGui::GetWindowHeight();
|
||||||
|
ImGuizmo::SetOrthographic(false);
|
||||||
|
ImGuizmo::SetDrawlist();
|
||||||
|
ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, rw, rh);
|
||||||
|
ImGuizmo::Manipulate(glm::value_ptr(m_Camera.GetViewMatrix()), glm::value_ptr(m_Camera.GetProjectionMatrix()), (ImGuizmo::OPERATION)m_GizmoType, ImGuizmo::LOCAL, glm::value_ptr(m_Transform));
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
@ -702,6 +719,27 @@ namespace Prism
|
|||||||
|
|
||||||
void EditorLayer::OnEvent(Event& e)
|
void EditorLayer::OnEvent(Event& e)
|
||||||
{
|
{
|
||||||
Layer::OnEvent(e);
|
EventDispatcher dispatcher(e);
|
||||||
|
dispatcher.Dispatch<KeyPressedEvent>(HZ_BIND_EVENT_FN(EditorLayer::OnKeyPressedEvent));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EditorLayer::OnKeyPressedEvent(KeyPressedEvent& e)
|
||||||
|
{
|
||||||
|
switch (e.GetKeyCode())
|
||||||
|
{
|
||||||
|
case PM_KEY_Q:
|
||||||
|
m_GizmoType = -1;
|
||||||
|
break;
|
||||||
|
case PM_KEY_W:
|
||||||
|
m_GizmoType = ImGuizmo::OPERATION::TRANSLATE;
|
||||||
|
break;
|
||||||
|
case PM_KEY_E:
|
||||||
|
m_GizmoType = ImGuizmo::OPERATION::ROTATE;
|
||||||
|
break;
|
||||||
|
case PM_KEY_R:
|
||||||
|
m_GizmoType = ImGuizmo::OPERATION::SCALE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,9 @@ public:
|
|||||||
virtual void OnImGuiRender() override;
|
virtual void OnImGuiRender() override;
|
||||||
virtual void OnEvent(Event& e) override;
|
virtual void OnEvent(Event& e) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool OnKeyPressedEvent(KeyPressedEvent& e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float m_ClearColor[4];
|
float m_ClearColor[4];
|
||||||
|
|
||||||
@ -54,6 +57,10 @@ private:
|
|||||||
Ref<Shader> m_Shader;
|
Ref<Shader> m_Shader;
|
||||||
Ref<Shader> m_PBRShader;
|
Ref<Shader> m_PBRShader;
|
||||||
|
|
||||||
|
// Imguizmo
|
||||||
|
int m_GizmoType = -1; // -1 = no gizmo
|
||||||
|
glm::mat4 m_Transform;
|
||||||
|
|
||||||
|
|
||||||
struct AlbedoInput
|
struct AlbedoInput
|
||||||
{
|
{
|
||||||
|
|||||||
@ -17,7 +17,11 @@ add_subdirectory(vendor/TinyFileDialog EXCLUDE_FROM_ALL)
|
|||||||
|
|
||||||
# ------------- imgui -------------
|
# ------------- imgui -------------
|
||||||
set(IMGUI_DIR vendor/ImGui)
|
set(IMGUI_DIR vendor/ImGui)
|
||||||
include_directories(${IMGUI_DIR} ${IMGUI_DIR}/backends)
|
include_directories(
|
||||||
|
${IMGUI_DIR}
|
||||||
|
${IMGUI_DIR}/backends
|
||||||
|
)
|
||||||
|
|
||||||
file(GLOB IMGUI_SOURCE
|
file(GLOB IMGUI_SOURCE
|
||||||
${IMGUI_DIR}/*.cpp
|
${IMGUI_DIR}/*.cpp
|
||||||
${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp
|
${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp
|
||||||
@ -26,6 +30,17 @@ file(GLOB IMGUI_SOURCE
|
|||||||
# add imgui source
|
# add imgui source
|
||||||
list(APPEND SRC_SOURCE ${IMGUI_SOURCE})
|
list(APPEND SRC_SOURCE ${IMGUI_SOURCE})
|
||||||
|
|
||||||
|
|
||||||
|
# ------------- ImGuizmo -------------
|
||||||
|
set(IMGUIZMO_DIR vendor/ImGuizmo)
|
||||||
|
include_directories(${IMGUIZMO_DIR})
|
||||||
|
file(GLOB IMGUIZMO_SOURCE ${IMGUIZMO_DIR}/*.cpp)
|
||||||
|
|
||||||
|
# add imguizmo source
|
||||||
|
list(APPEND SRC_SOURCE ${IMGUIZMO_SOURCE})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ------------- link libraries -------------
|
# ------------- link libraries -------------
|
||||||
set(LINK_LIBRARIES_PRIVATE
|
set(LINK_LIBRARIES_PRIVATE
|
||||||
spdlog
|
spdlog
|
||||||
@ -53,6 +68,7 @@ endif()
|
|||||||
set(TARGET_INCLUDE_DIR
|
set(TARGET_INCLUDE_DIR
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
|
||||||
${IMGUI_DIR}
|
${IMGUI_DIR}
|
||||||
|
${IMGUIZMO_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
# ------------- debug Defines -------------
|
# ------------- debug Defines -------------
|
||||||
|
|||||||
@ -27,6 +27,7 @@ namespace Prism {
|
|||||||
#ifdef PRISM_SHARED
|
#ifdef PRISM_SHARED
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
BOOL APIENTRY DllMain(HMODULE hModule,
|
BOOL APIENTRY DllMain(HMODULE hModule,
|
||||||
DWORD ul_reason_for_call,
|
DWORD ul_reason_for_call,
|
||||||
|
|||||||
@ -8,8 +8,8 @@
|
|||||||
#include "imgui_impl_glfw.h"
|
#include "imgui_impl_glfw.h"
|
||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
#include "Prism/Core/Application.h"
|
#include "Prism/Core/Application.h"
|
||||||
|
#include "ImGuizmo.h"
|
||||||
|
|
||||||
#include "Prism/Core/Log.h"
|
|
||||||
|
|
||||||
namespace Prism
|
namespace Prism
|
||||||
{
|
{
|
||||||
@ -32,6 +32,7 @@ namespace Prism
|
|||||||
ImGui_ImplOpenGL3_NewFrame();
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
ImGui_ImplGlfw_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
ImGuizmo::BeginFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiLayer::End()
|
void ImGuiLayer::End()
|
||||||
@ -90,8 +91,9 @@ namespace Prism
|
|||||||
|
|
||||||
// Setup Platform/Renderer bindings
|
// Setup Platform/Renderer bindings
|
||||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||||
ImGui_ImplOpenGL3_Init("#version 410");
|
ImGui_ImplOpenGL3_Init("#version 460");
|
||||||
|
|
||||||
|
SetImGuiCustomTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiLayer::OnDetach()
|
void ImGuiLayer::OnDetach()
|
||||||
@ -105,4 +107,50 @@ namespace Prism
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
void ImGuiLayer::SetImGuiCustomTheme()
|
||||||
|
{
|
||||||
|
// ImGui Colors
|
||||||
|
ImVec4* colors = ImGui::GetStyle().Colors;
|
||||||
|
colors[ImGuiCol_Text] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
colors[ImGuiCol_TextDisabled] = ImVec4(0.5f, 0.5f, 0.5f, 1.0f);
|
||||||
|
colors[ImGuiCol_WindowBg] = ImVec4(0.18f, 0.18f, 0.18f, 1.0f); // Window background
|
||||||
|
colors[ImGuiCol_ChildBg] = ImVec4(1.0f, 1.0f, 1.0f, 0.0f);
|
||||||
|
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
|
||||||
|
colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.5f);
|
||||||
|
colors[ImGuiCol_BorderShadow] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
colors[ImGuiCol_FrameBg] = ImVec4(0.3f, 0.3f, 0.3f, 0.5f); // Widget backgrounds
|
||||||
|
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.4f, 0.4f, 0.4f, 0.4f);
|
||||||
|
colors[ImGuiCol_FrameBgActive] = ImVec4(0.4f, 0.4f, 0.4f, 0.6f);
|
||||||
|
colors[ImGuiCol_TitleBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.0f);
|
||||||
|
colors[ImGuiCol_TitleBgActive] = ImVec4(0.29f, 0.29f, 0.29f, 1.0f);
|
||||||
|
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.0f, 0.0f, 0.0f, 0.51f);
|
||||||
|
colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.0f);
|
||||||
|
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f);
|
||||||
|
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.0f);
|
||||||
|
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.0f);
|
||||||
|
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.0f);
|
||||||
|
colors[ImGuiCol_CheckMark] = ImVec4(0.94f, 0.94f, 0.94f, 1.0f);
|
||||||
|
colors[ImGuiCol_SliderGrab] = ImVec4(0.51f, 0.51f, 0.51f, 0.7f);
|
||||||
|
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.66f, 0.66f, 0.66f, 1.0f);
|
||||||
|
colors[ImGuiCol_Button] = ImVec4(0.44f, 0.44f, 0.44f, 0.4f);
|
||||||
|
colors[ImGuiCol_ButtonHovered] = ImVec4(0.46f, 0.47f, 0.48f, 1.0f);
|
||||||
|
colors[ImGuiCol_ButtonActive] = ImVec4(0.42f, 0.42f, 0.42f, 1.0f);
|
||||||
|
colors[ImGuiCol_Header] = ImVec4(0.7f, 0.7f, 0.7f, 0.31f);
|
||||||
|
colors[ImGuiCol_HeaderHovered] = ImVec4(0.7f, 0.7f, 0.7f, 0.8f);
|
||||||
|
colors[ImGuiCol_HeaderActive] = ImVec4(0.48f, 0.5f, 0.52f, 1.0f);
|
||||||
|
colors[ImGuiCol_Separator] = ImVec4(0.43f, 0.43f, 0.5f, 0.5f);
|
||||||
|
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.72f, 0.72f, 0.72f, 0.78f);
|
||||||
|
colors[ImGuiCol_SeparatorActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.0f);
|
||||||
|
colors[ImGuiCol_ResizeGrip] = ImVec4(0.91f, 0.91f, 0.91f, 0.25f);
|
||||||
|
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.81f, 0.81f, 0.81f, 0.67f);
|
||||||
|
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.46f, 0.46f, 0.46f, 0.95f);
|
||||||
|
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.0f);
|
||||||
|
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.0f, 0.43f, 0.35f, 1.0f);
|
||||||
|
colors[ImGuiCol_PlotHistogram] = ImVec4(0.73f, 0.6f, 0.15f, 1.0f);
|
||||||
|
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.0f, 0.6f, 0.0f, 1.0f);
|
||||||
|
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.87f, 0.87f, 0.87f, 0.35f);
|
||||||
|
colors[ImGuiCol_DragDropTarget] = ImVec4(1.0f, 1.0f, 0.0f, 0.9f);
|
||||||
|
colors[ImGuiCol_NavHighlight] = ImVec4(0.60f, 0.6f, 0.6f, 1.0f);
|
||||||
|
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.0f, 1.0f, 1.0f, 0.7f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -25,6 +25,8 @@ namespace Prism
|
|||||||
virtual void OnDetach() override;
|
virtual void OnDetach() override;
|
||||||
virtual void OnImGuiRender() override;
|
virtual void OnImGuiRender() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void SetImGuiCustomTheme();
|
||||||
private:
|
private:
|
||||||
float m_Time = 0.0f;
|
float m_Time = 0.0f;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -5,8 +5,6 @@
|
|||||||
#ifndef KEYCODES_H
|
#ifndef KEYCODES_H
|
||||||
#define KEYCODES_H
|
#define KEYCODES_H
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// From glfw3.h
|
// From glfw3.h
|
||||||
#define PM_KEY_SPACE 32
|
#define PM_KEY_SPACE 32
|
||||||
#define PM_KEY_APOSTROPHE 39 /* ' */
|
#define PM_KEY_APOSTROPHE 39 /* ' */
|
||||||
|
|||||||
@ -170,6 +170,8 @@ namespace Prism
|
|||||||
|
|
||||||
void MaterialInstance::Bind() const
|
void MaterialInstance::Bind() const
|
||||||
{
|
{
|
||||||
|
m_Material->m_Shader->Bind();
|
||||||
|
|
||||||
if (m_VSUniformStorageBuffer)
|
if (m_VSUniformStorageBuffer)
|
||||||
m_Material->m_Shader->SetVSMaterialUniformBuffer(m_VSUniformStorageBuffer);
|
m_Material->m_Shader->SetVSMaterialUniformBuffer(m_VSUniformStorageBuffer);
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,6 @@
|
|||||||
#ifndef PMPCH_H
|
#ifndef PMPCH_H
|
||||||
#define PMPCH_H
|
#define PMPCH_H
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#include <Windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|||||||
1
Prism/vendor/ImGuizmo
vendored
Submodule
1
Prism/vendor/ImGuizmo
vendored
Submodule
Submodule Prism/vendor/ImGuizmo added at b3a3ccfc4b
Reference in New Issue
Block a user