diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 3ff5c5c9..1d9ca802 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -68,6 +68,8 @@ namespace Nuake { EditorSelection EditorInterface::Selection; int SelectedViewport = 0; + bool displayVirtualCameraOverlay = false; + Ref virtualCamera; glm::vec3 DepthToWorldPosition(const glm::vec2& pixelPos, float depth, const glm::mat4& projectionMatrix, const glm::mat4& viewMatrix, const glm::vec2& viewportSize) { @@ -120,6 +122,8 @@ namespace Nuake { using namespace Nuake::StaticResources; ImGui::LoadIniSettingsFromMemory((const char*)StaticResources::Resources_default_layout_ini); + virtualCamera = CreateRef(true, Vector2{ 1280, 720 }); + virtualCamera->SetTexture(CreateRef(Vector2{ 1280, 720 }, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE), GL_COLOR_ATTACHMENT0); //ScriptingContext::Get().Initialize(); } @@ -2608,6 +2612,60 @@ namespace Nuake { ImGui::PopStyleVar(); ImGui::End(); + + corner = 2; + + if (Selection.Type == EditorSelectionType::Entity && Selection.Entity.IsValid() && Selection.Entity.HasComponent()) + { + window_flags |= ImGuiWindowFlags_NoMove; + viewport = ImGui::GetWindowViewport(); + work_area_pos = ImGui::GetCurrentWindow()->Pos; // Instead of using viewport->Pos we use GetWorkPos() to avoid menu bars, if any! + work_area_size = ImGui::GetCurrentWindow()->Size; + window_pos = ImVec2((corner & 1) ? (work_area_pos.x + work_area_size.x - DISTANCE) : (work_area_pos.x + DISTANCE), (corner & 2) ? (work_area_pos.y + work_area_size.y - DISTANCE) : (work_area_pos.y + DISTANCE)); + window_pos_pivot = ImVec2((corner & 1) ? 1.0f : 0.0f, (corner & 2) ? 1.0f : 0.0f); + ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot); + ImGui::SetNextWindowViewport(viewport->ID); + + ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 32.0f); + if (ImGui::Begin("VirtualViewport", &m_ShowOverlay, window_flags)) + { + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(2, 2)); + ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0)); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 100); + ImGui::PushStyleColor(ImGuiCol_FrameBg, IM_COL32(20, 20, 20, 0)); + ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, IM_COL32(20, 20, 20, 60)); + ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, IM_COL32(33, 33, 33, 45)); + + CameraComponent& camera = Selection.Entity.GetComponent(); + Ref cam = camera.CameraInstance; + auto& transform = Selection.Entity.GetComponent(); + + const Quat& globalRotation = transform.GetGlobalRotation(); + const Matrix4& translationMatrix = glm::translate(Matrix4(1.0f), transform.GetGlobalPosition()); + const Matrix4& rotationMatrix = glm::mat4_cast(globalRotation); + const Vector4& forward = Vector4(0, 0, -1, 1); + const Vector4& globalForward = rotationMatrix * forward; + + const Vector4& right = Vector4(1, 0, 0, 1); + const Vector4& globalRight = rotationMatrix * right; + cam->Direction = globalForward; + cam->Right = globalRight; + + auto sceneRenderer = Engine::GetCurrentScene()->m_SceneRenderer; + sceneRenderer->BeginRenderScene(cam->GetPerspective(), cam->GetTransform(), transform.GlobalTranslation); + sceneRenderer->RenderScene(*Engine::GetCurrentScene().get(), *virtualCamera.get()); + + virtualCamera->Clear(); + ImGui::Image((void*)virtualCamera->GetTexture()->GetID(), { 1280, 720 }, { 0, 1 }, {1, 0}); + + ImGui::PopStyleVar(2); + ImGui::PopStyleColor(4); + } + + ImGui::PopStyleVar(); + ImGui::End(); + } } void NewProject() @@ -3025,7 +3083,6 @@ namespace Nuake { } auto& editorCam = Engine::GetCurrentScene()->m_EditorCamera; - editorCam->Update(ts, m_IsHoveringViewport && m_IsViewportFocused); const bool entityIsSelected = Selection.Type == EditorSelectionType::Entity && Selection.Entity.IsValid(); @@ -3035,6 +3092,15 @@ namespace Nuake { editorCam->TargetPos = Selection.Entity.GetComponent().GetGlobalPosition(); } + if (entityIsSelected && Selection.Type == EditorSelectionType::Entity && Selection.Entity.IsValid() && Selection.Entity.HasComponent()) + { + displayVirtualCameraOverlay = true; + } + else + { + displayVirtualCameraOverlay = false; + } + if (entityIsSelected && Input::IsKeyPressed(Key::ESCAPE)) { Selection = EditorSelection(); diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index 9a514d56..eddec7e0 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -13,8 +13,13 @@ #include #include +using namespace Nuake; + EditorSelectionPanel::EditorSelectionPanel() { + virtualScene = CreateRef(); + virtualScene->SetName("Virtual Scene"); + virtualScene->CreateEntity("Camera").AddComponent(); } void EditorSelectionPanel::ResolveFile(Ref file) @@ -228,6 +233,11 @@ void EditorSelectionPanel::DrawResource(Nuake::Resource resource) } +void EditorSelectionPanel::DrawPrefabPanel(Ref prefab) +{ + +} + void EditorSelectionPanel::DrawMaterialPanel(Ref material) { using namespace Nuake; diff --git a/Editor/src/Windows/EditorSelectionPanel.h b/Editor/src/Windows/EditorSelectionPanel.h index 5171010f..e380af3b 100644 --- a/Editor/src/Windows/EditorSelectionPanel.h +++ b/Editor/src/Windows/EditorSelectionPanel.h @@ -27,8 +27,14 @@ #include "../ComponentsPanel/NavMeshVolumePanel.h" #include +#include +namespace Nuake +{ + class Scene; +} + class EditorSelectionPanel { private: @@ -56,6 +62,7 @@ private: Ref currentFile; Ref selectedResource; + Ref virtualScene; public: EditorSelectionPanel(); @@ -67,7 +74,7 @@ public: void DrawFile(Ref file); void DrawResource(Nuake::Resource resource); - + void DrawPrefabPanel(Ref prefab); private: void ResolveFile(Ref file); void DrawMaterialPanel(Ref material); diff --git a/Editor/src/Windows/MapImporterWindow.cpp b/Editor/src/Windows/MapImporterWindow.cpp index 55548088..788d7d2e 100644 --- a/Editor/src/Windows/MapImporterWindow.cpp +++ b/Editor/src/Windows/MapImporterWindow.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include @@ -16,6 +18,7 @@ #include #include +using namespace Nuake; void MapImporterWindow::Draw() { diff --git a/Editor/src/Windows/ProjectSettings/ProjectSettingsWindow.cpp b/Editor/src/Windows/ProjectSettings/ProjectSettingsWindow.cpp index 144f0995..7cf52849 100644 --- a/Editor/src/Windows/ProjectSettings/ProjectSettingsWindow.cpp +++ b/Editor/src/Windows/ProjectSettings/ProjectSettingsWindow.cpp @@ -122,7 +122,7 @@ ProjectSettingsCategoryWindowViewport::ProjectSettingsCategoryWindowViewport(Ref void ProjectSettingsCategoryWindowViewport::Draw() { - ImGui::DragFloat("Outline Radius", &m_Project->Settings.OutlineRadius, 0.1f, 1.0f, 10.0f); + ImGui::DragFloat("Outline Radius", &m_Project->Settings.OutlineRadius, 0.1f, 1.0f, 90.0f); ImGui::DragFloat("Gizmo Size", &m_Project->Settings.GizmoSize, 0.01f, 0.05f, 0.5f); ImGui::Separator(); ImGui::Checkbox("Smooth Camera", &m_Project->Settings.SmoothCamera); diff --git a/Nuake/src/FileSystem/File.cpp b/Nuake/src/FileSystem/File.cpp index a44e13ca..e25ee1be 100644 --- a/Nuake/src/FileSystem/File.cpp +++ b/Nuake/src/FileSystem/File.cpp @@ -15,7 +15,7 @@ File::File(Ref parentDir, const std::string& fullPath, const std::str FileType File::GetFileType() const { - const std::string_view ext = GetExtension(); + const std::string ext = GetExtension(); if (ext == ".png" || ext == ".jpg") { return FileType::Image; diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index ab05e890..cfe519b2 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -73,7 +73,7 @@ namespace Nuake return this->Name; } - bool Scene::SetName(std::string& newName) + bool Scene::SetName(const std::string& newName) { if (newName == "") return false; @@ -317,7 +317,6 @@ namespace Nuake cam = camera.CameraInstance; cam->Translation = transform.GetGlobalPosition(); - break; } if (!cam) diff --git a/Nuake/src/Scene/Scene.h b/Nuake/src/Scene/Scene.h index aad130a2..47cd63cf 100644 --- a/Nuake/src/Scene/Scene.h +++ b/Nuake/src/Scene/Scene.h @@ -56,7 +56,7 @@ namespace Nuake void Draw(FrameBuffer& framebuffer, const Matrix4& projection, const Matrix4& view); std::string GetName(); - bool SetName(std::string& newName); + bool SetName(const std::string& newName); Ref GetCurrentCamera(); diff --git a/Nuake/src/Window.cpp b/Nuake/src/Window.cpp index e8ac2046..dc75d2af 100644 --- a/Nuake/src/Window.cpp +++ b/Nuake/src/Window.cpp @@ -149,9 +149,6 @@ void Window::Draw() cam->AspectRatio = size.x / size.y; - float resolutionScale = glm::clamp(Engine::GetProject()->Settings.ResolutionScale, 0.5f, 2.0f); - this->scene->m_EditorCamera->OnWindowResize(size.x * resolutionScale, size.y * resolutionScale); - if (Engine::IsPlayMode()) { ZoneScopedN("PIE Draw"); @@ -160,6 +157,8 @@ void Window::Draw() else { ZoneScopedN("Non-playmode Draw"); + float resolutionScale = glm::clamp(Engine::GetProject()->Settings.ResolutionScale, 0.5f, 2.0f); + this->scene->m_EditorCamera->OnWindowResize(size.x * resolutionScale, size.y * resolutionScale); this->scene->Draw(*this->framebuffer.get(), this->scene->m_EditorCamera->GetPerspective(), this->scene->m_EditorCamera->GetTransform()); }