From 145338d666c4bf2f2454ec0fbe7902d7f30f6788 Mon Sep 17 00:00:00 2001 From: Nigel Barink Date: Sat, 14 Jan 2023 17:27:37 +0100 Subject: [PATCH] Editor Refactor This refactor of the editor code makes the code more maintainable. All widget objects have now moved away from RAII and are now just allocated object that live for the entirety of the applications lifetime. This feels better as I am used to this style plus constantly pushing and popping objects from the stack seems a little wasteful (although I as of right now have no way to prove that it is ). --- Editor/src/AssetManagement/AssetFinder.h | 68 ++++ .../src/AssetManagement/SceneSerializer.cpp | 129 ++++++ Editor/src/AssetManagement/SceneSerializer.h | 16 + .../src/{UI/EditorConsole.cpp => Console.cpp} | 23 +- Editor/src/Console.h | 22 + Editor/src/{UI => }/Dialog.h | 2 +- Editor/src/EditorWindow.h | 26 ++ Editor/src/MainMenuBar.cpp | 188 +++++++++ Editor/src/MainMenuBar.h | 30 ++ Editor/src/Project/Project.cpp | 7 +- Editor/src/Project/Project.h | 2 +- Editor/src/Project/ProjectInfo.cpp | 7 + Editor/src/Project/ProjectInfo.h | 15 + Editor/src/Project/Settings.cpp | 48 +++ Editor/src/Project/Settings.h | 30 ++ Editor/src/PropertyPanels/Inspector.cpp | 104 +++++ Editor/src/PropertyPanels/Inspector.h | 20 + Editor/src/PropertyPanels/SceneExplorer.cpp | 13 + Editor/src/PropertyPanels/SceneExplorer.h | 20 + Editor/src/Runtime/RuntimeControls.cpp | 27 ++ Editor/src/Runtime/RuntimeControls.h | 26 ++ Editor/src/SceneSerializer.h | 134 ------- Editor/src/UI/EditorConsole.h | 18 - Editor/src/UI/EditorWindow.h | 11 - Editor/src/UI/GUIRenderer.h | 70 ---- Editor/src/UI/MainMenuBar.h | 187 --------- Editor/src/UI/widgets.h | 377 ------------------ Editor/src/Views/Viewport.cpp | 55 +++ Editor/src/Views/Viewport.h | 24 ++ Editor/src/app.cpp | 326 ++++++--------- YoggieEngine/src/Application.cpp | 66 ++- YoggieEngine/src/Application.h | 8 + YoggieEngine/src/Graphics/Primitives/Camera.h | 1 + YoggieEngine/src/Graphics/Renderer.cpp | 28 +- YoggieEngine/src/Graphics/Renderer.h | 8 +- YoggieEngine/src/Physics/Physics.cpp | 14 +- YoggieEngine/src/Physics/Physics.h | 14 +- YoggieEngine/src/Scene/Components.h | 15 + YoggieEngine/src/Scene/Scene.cpp | 1 + YoggieEngine/src/YoggieEngine.h | 2 + 40 files changed, 1138 insertions(+), 1044 deletions(-) create mode 100644 Editor/src/AssetManagement/AssetFinder.h create mode 100644 Editor/src/AssetManagement/SceneSerializer.cpp create mode 100644 Editor/src/AssetManagement/SceneSerializer.h rename Editor/src/{UI/EditorConsole.cpp => Console.cpp} (56%) create mode 100644 Editor/src/Console.h rename Editor/src/{UI => }/Dialog.h (98%) create mode 100644 Editor/src/EditorWindow.h create mode 100644 Editor/src/MainMenuBar.cpp create mode 100644 Editor/src/MainMenuBar.h create mode 100644 Editor/src/Project/ProjectInfo.cpp create mode 100644 Editor/src/Project/ProjectInfo.h create mode 100644 Editor/src/Project/Settings.cpp create mode 100644 Editor/src/Project/Settings.h create mode 100644 Editor/src/PropertyPanels/Inspector.cpp create mode 100644 Editor/src/PropertyPanels/Inspector.h create mode 100644 Editor/src/PropertyPanels/SceneExplorer.cpp create mode 100644 Editor/src/PropertyPanels/SceneExplorer.h create mode 100644 Editor/src/Runtime/RuntimeControls.cpp create mode 100644 Editor/src/Runtime/RuntimeControls.h delete mode 100644 Editor/src/SceneSerializer.h delete mode 100644 Editor/src/UI/EditorConsole.h delete mode 100644 Editor/src/UI/EditorWindow.h delete mode 100644 Editor/src/UI/GUIRenderer.h delete mode 100644 Editor/src/UI/MainMenuBar.h delete mode 100644 Editor/src/UI/widgets.h create mode 100644 Editor/src/Views/Viewport.cpp create mode 100644 Editor/src/Views/Viewport.h diff --git a/Editor/src/AssetManagement/AssetFinder.h b/Editor/src/AssetManagement/AssetFinder.h new file mode 100644 index 0000000..f6cdba4 --- /dev/null +++ b/Editor/src/AssetManagement/AssetFinder.h @@ -0,0 +1,68 @@ +#pragma once +#include "../../YoggieEngine/src/YoggieEngine.h" +#include "EditorWindow.h" +#include "AssetManagement/AssetManager.h" + +class AssetFinder : EditorWindow { +public: + AssetFinder() : EditorWindow("Assets") {} + + void Draw() override { + + + ImGui::DragInt("IconSize", &iconSize, 1, 30, 90); + + + if (ImGui::BeginTable("##resources", 3)) + { + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.f, 0.f, 0.f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.f, 0.f, 0.f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.f, 1.f, 1.f, 0.2f)); + + YoggieEngine::Texture folderIcon = YoggieEngine::Texture("rsc/folderIcon.png"); + YoggieEngine::Texture assetIcon = YoggieEngine::Texture("rsc/assetIcon.png"); + + + int row = 0; + int column = 0; + for (auto& asset : AssetManager::assets) { + if (column % 3 == 0) { + ImGui::TableNextRow(); + column = 0; + row++; + } + + ImGui::TableSetColumnIndex(column); + + if (asset.isFolder) { + ImGui::ImageButton( + (ImTextureID)folderIcon.GetID(), + ImVec2{ (float)iconSize,(float)iconSize }); + ImGui::Text(asset.GetName(), row); + + } + else { + ImGui::ImageButton( + (ImTextureID)assetIcon.GetID(), + ImVec2{ (float)iconSize, (float)iconSize }); + ImGui::Text(asset.GetName(), row); + + } + + + column++; + } + + + ImGui::PopStyleColor(3); + ImGui::EndTable(); + const GLuint textures[2]{ assetIcon.GetID(), folderIcon.GetID() }; + glDeleteTextures(2, textures); + + } + } + +private: + int iconSize = 60; +}; + diff --git a/Editor/src/AssetManagement/SceneSerializer.cpp b/Editor/src/AssetManagement/SceneSerializer.cpp new file mode 100644 index 0000000..d4c863e --- /dev/null +++ b/Editor/src/AssetManagement/SceneSerializer.cpp @@ -0,0 +1,129 @@ +#include "SceneSerializer.h" +#include "../../YoggieEngine/src/YoggieEngine.h" +#include +#include +#include + +void WriteFile(std::string& emitter, std::filesystem::path path) +{ + std::cout << "Writing Scene file to: " << path.u8string() << std::endl; + std::ofstream sceneFile; + sceneFile.open(path.u8string()); + + sceneFile << emitter.c_str(); + + sceneFile.close(); +} + +YAML::Emitter& operator<< (YAML::Emitter& emitter, glm::vec3& vector) { + emitter << YAML::Flow << YAML::BeginSeq << vector.x << vector.y << vector.x << YAML::EndSeq; + return emitter; +} + + + +std::string Serialize(YoggieEngine::Scene& scene) { + YAML::Emitter emitter; + + emitter << YAML::BeginMap; + emitter << YAML::Key << "Scene" << YAML::Value << "test-Scene"; + emitter << YAML::Key << "Entities" << YAML::Value << YAML::BeginSeq; + + scene.getReg().each([&emitter, &scene](entt::entity enttNumber) { + + YoggieEngine::Entity entity = YoggieEngine::Entity(enttNumber, &scene); + + emitter << YAML::BeginMap; + emitter << YAML::Key << "Entity" << YAML::Value << entity.GetComponent().name; + + if (entity.HasComponent()) { + emitter << YAML::Key << "Ident"; + emitter << YAML::BeginMap; + emitter << YAML::Value << entity.GetComponent().name; + emitter << YAML::EndMap; + } + + if (entity.HasComponent()) { + emitter << YAML::Key << "Transform" << YAML::Value; + + emitter << YAML::BeginMap; + + emitter << YAML::Key << "Position"; + emitter << YAML::Value << entity.GetComponent().Position; + + emitter << YAML::Key << "Rotation"; + emitter << YAML::Value << entity.GetComponent().Rotation; + + emitter << YAML::Key << "Scale"; + emitter << YAML::Value << entity.GetComponent().Scale; + + emitter << YAML::EndMap; + } + + + if (entity.HasComponent()) { + emitter << YAML::Key << "Light"; + emitter << YAML::Value; + emitter << YAML::BeginMap; + emitter << YAML::Key << "Color"; + emitter << YAML::Value << entity.GetComponent().Color; + emitter << YAML::EndMap; + } + + + emitter << YAML::EndMap; + }); + + emitter << YAML::EndSeq; + emitter << YAML::EndMap; + + return std::string(emitter.c_str()); +} + + +void SaveScene(std::filesystem::path path, YoggieEngine::Scene& scene) { + std::string YAMLString = Serialize(scene); + WriteFile(YAMLString, path); +} + + +void LoadScene(std::filesystem::path path, YoggieEngine::Scene& scene) +{ + auto sceneYAML = YAML::LoadFile(path.u8string()); + + if (!sceneYAML["Scene"]) { + spdlog::error("Not a scene file!"); + return; + } + + scene.getReg().clear(); + + std::string SceneName = sceneYAML["Scene"].as(); + + auto entities = sceneYAML["Entities"]; + + for (const auto& entity : entities) { + + std::string entityID = entity["Ident"].as(); + YoggieEngine::Entity SE = scene.AddEntity(entityID); + if (entity["Transform"]) + { + YoggieEngine::TransformComponent tc = SE.GetComponent (); + auto positionNode = entity["Transform"]["Position"]; + tc.Position = glm::vec3(positionNode[0].as(), positionNode[1].as(), positionNode[2].as()); + + auto rotationNode = entity["Transform"]["Rotation"]; + tc.Rotation = glm::vec3(rotationNode[0].as(), rotationNode[1].as(), rotationNode[2].as()); + + auto scaleNode = entity["Transform"]["Scale"]; + tc.Scale = glm::vec3(scaleNode[0].as(), scaleNode[1].as(), scaleNode[2].as()); + } + if (entity["Light"]) { + YoggieEngine::LightComponent lc = SE.AddComponent(); + lc.Color = glm::vec3(entity["Light"]["Color"][0].as(), entity["Light"]["Color"][1].as(), entity["Light"]["Color"][2].as()); + } + + } + + +} \ No newline at end of file diff --git a/Editor/src/AssetManagement/SceneSerializer.h b/Editor/src/AssetManagement/SceneSerializer.h new file mode 100644 index 0000000..08a672d --- /dev/null +++ b/Editor/src/AssetManagement/SceneSerializer.h @@ -0,0 +1,16 @@ +#pragma once +#include +#include +#include +#include +#include "../../YoggieEngine/src/YoggieEngine.h" + +void WriteFile(std::string& emitter, std::filesystem::path path); + +YAML::Emitter& operator<< (YAML::Emitter& emitter, glm::vec3& vector); + +std::string Serialize(YoggieEngine::Scene& scene); + +void SaveScene(std::filesystem::path path, YoggieEngine::Scene& scene); + +void LoadScene(std::filesystem::path path, YoggieEngine::Scene& scene); \ No newline at end of file diff --git a/Editor/src/UI/EditorConsole.cpp b/Editor/src/Console.cpp similarity index 56% rename from Editor/src/UI/EditorConsole.cpp rename to Editor/src/Console.cpp index b69a3cc..68f8fc2 100644 --- a/Editor/src/UI/EditorConsole.cpp +++ b/Editor/src/Console.cpp @@ -1,22 +1,25 @@ +#include "Console.h" #include -#include "EditorConsole.h" - -EditorConsole::EditorConsole() - : Items(ImVector()), AutoScroll(false), ScrollToBottom(false) +Console::Console() + : EditorWindow("Console"), Items(ImVector()), AutoScroll(false), ScrollToBottom(false) { AddLog("Hello Editor console!"); } -EditorConsole::~EditorConsole() { +Console::~Console() { } -void EditorConsole::Draw() { - ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver); - +void Console::Show() { + Draw(); +} - for (int i = 0; i < Items.Size; i++) +void Console::Draw() { + ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver); + + + for (int i = 0; i < Items.Size; i++) { const char* item = Items[i]; ImGui::TextUnformatted(item); @@ -24,7 +27,7 @@ void EditorConsole::Draw() { } -void EditorConsole::AddLog(const char* fmt, ...) { +void Console::AddLog(const char* fmt, ...) { char buf[1024]; va_list args; va_start(args, fmt); diff --git a/Editor/src/Console.h b/Editor/src/Console.h new file mode 100644 index 0000000..89e6db0 --- /dev/null +++ b/Editor/src/Console.h @@ -0,0 +1,22 @@ +#pragma once +#include "../../YoggieEngine/src/YoggieEngine.h" +#include "EditorWindow.h" +#include + +class Console : public EditorWindow { +public: + + Console(); + ~Console(); + + void Draw() override; + + void Show(); + + void AddLog(const char* fmt, ...); + +private: + ImVector Items; + bool AutoScroll; + bool ScrollToBottom; +}; \ No newline at end of file diff --git a/Editor/src/UI/Dialog.h b/Editor/src/Dialog.h similarity index 98% rename from Editor/src/UI/Dialog.h rename to Editor/src/Dialog.h index 6459601..e09566d 100644 --- a/Editor/src/UI/Dialog.h +++ b/Editor/src/Dialog.h @@ -4,7 +4,7 @@ #include #include #include -#include "Project.h" +#include "Project/Project.h" struct DialogSpec { const std::string& id; const std::string& Title; diff --git a/Editor/src/EditorWindow.h b/Editor/src/EditorWindow.h new file mode 100644 index 0000000..0df6677 --- /dev/null +++ b/Editor/src/EditorWindow.h @@ -0,0 +1,26 @@ +#pragma once +#include +#include + +class EditorWindow { + +public: + EditorWindow (const std::string& name, ImGuiWindowFlags_ flags = ImGuiWindowFlags_None ) : name(name) , flags(flags) {} + + void Update() + { + ImGui::Begin(name.c_str(), false, flags); + Draw(); + ImGui::End(); + } + + ~EditorWindow() = default; + +protected: + std::string name; + +private: + ImGuiWindowFlags_ flags; + + virtual void Draw() = 0; +}; \ No newline at end of file diff --git a/Editor/src/MainMenuBar.cpp b/Editor/src/MainMenuBar.cpp new file mode 100644 index 0000000..1f73a22 --- /dev/null +++ b/Editor/src/MainMenuBar.cpp @@ -0,0 +1,188 @@ +#include "MainMenuBar.h" +#include +#include "AssetManagement/AssetManager.h" + + + +MainMenuBar::MainMenuBar() +{ + ImGui::BeginMainMenuBar(); +} + +void MainMenuBar::ApplicationMenu(Project& project) { + + if (ImGui::BeginMenu("Application")) { + + if (ImGui::MenuItem("Load Project")) + { + nfdresult_t result = NFD_OpenDialog({ "yproj" }, NULL, &path); + switch (result) { + case(NFD_OKAY): + Project::LoadProject(path, project); + AssetManager::setAssetPath(project.GetProjectDirectory()); + AssetManager::BuildAssetView(); + break; + case(NFD_CANCEL): + break; + case(NFD_ERROR): + std::cout << "NFD_Error: " << NFD_GetError() << std::endl; + break; + } + + } + + if (ImGui::MenuItem("Save project as...")) { + nfdresult_t result = NFD_SaveDialog({ "yproj" }, NULL, &path); + switch (result) { + case(NFD_OKAY): + std::cout << "Save as: " << path << std::endl; + Project::SaveProject(path, project); + break; + case(NFD_CANCEL): + break; + case(NFD_ERROR): + std::cout << "NFD_Error: " << NFD_GetError() << std::endl; + break; + } + } + + + + if (ImGui::MenuItem("Preferences")) + { + + } + + if (ImGui::MenuItem("Exit")) + { + // TODO: Exit application + } + + ImGui::EndMenu(); + } +} + +void MainMenuBar::SceneMenu(Project& project, YoggieEngine::Scene& scene) { + + if (ImGui::BeginMenu("Scene")) { + + if (ImGui::MenuItem("Save scene")) + { + nfdresult_t result = NFD_SaveDialog({ "yscene" }, NULL, &path); + switch (result) { + case(NFD_OKAY): + SaveScene(path, scene); + break; + case(NFD_CANCEL): + break; + case(NFD_ERROR): + std::cout << "NFD_Error: " << NFD_GetError() << std::endl; + break; + } + + } + + if (ImGui::MenuItem("Load scene")) + { + auto result = NFD_OpenDialog({ "yscene" }, NULL, &path); + switch (result) { + case (NFD_OKAY): + LoadScene(path, scene); + break; + case(NFD_CANCEL): + break; + case(NFD_ERROR): + std::cout << "NFD_Error: " << NFD_GetError() << std::endl; + break; + } + + } + + if (ImGui::MenuItem("Add Entity")) + { + scene.AddEntity("New Entity"); + } + + if (ImGui::MenuItem("Import Model")) + { + auto result = NFD_OpenDialog("obj,fbx,gltf", NULL, &path); + switch (result) { + case(NFD_OKAY): + // Import Model + + AssetManager::LoadFromSource( + path, + "build/Debug/Assets"//project.get()->GetProjectDirectory() / "Assets" + ); + break; + case(NFD_CANCEL): + break; + case(NFD_ERROR): + std::cout << "NFD_Error: " << NFD_GetError() << std::endl; + break; + } + } + + if (ImGui::MenuItem("Import MeshAsset (temp)")) + { + auto result = NFD_OpenDialog("mesh", NULL, &path); + + switch (result) { + case(NFD_OKAY): + { + YoggieEngine::Mesh* importedMesh = AssetManager::LoadFromAssetFile(path); + if (importedMesh != nullptr) + { + auto full_name = std::filesystem::path(path); + auto importedModel = scene.AddEntity(full_name.filename().u8string()); + auto& rendererComponent = importedModel.AddComponent(); + rendererComponent.mesh = *importedMesh; + + } + } + break; + + case(NFD_CANCEL): + spdlog::debug("User cancelled action"); + break; + case(NFD_ERROR): + spdlog::warn("Something went wrong!"); + break; + } + + } + + ImGui::EndMenu(); + } +} + +void MainMenuBar::DebugMenu() +{ + if (ImGui::BeginMenu("Debug")) { + ImGui::EndMenu(); + } +} + +void MainMenuBar::SelectMenu() { + if (ImGui::BeginMenu("Select")) { + ImGui::EndMenu(); + } +} + +void MainMenuBar::WindowMenu() { + if (ImGui::BeginMenu("Window")) { + + ImGui::EndMenu(); + } +} + +void MainMenuBar::Help() { + if (ImGui::BeginMenu("Help")) { + ImGui::EndMenu(); + } +} + +MainMenuBar::~MainMenuBar() +{ + ImGui::EndMainMenuBar(); +} \ No newline at end of file diff --git a/Editor/src/MainMenuBar.h b/Editor/src/MainMenuBar.h new file mode 100644 index 0000000..23d7444 --- /dev/null +++ b/Editor/src/MainMenuBar.h @@ -0,0 +1,30 @@ +#pragma once +#include +#include "AssetManagement/SceneSerializer.h" +#include "../../YoggieEngine/src/Scene/Scene.h" +#include "Project/Project.h" + + +class MainMenuBar { + +public: + MainMenuBar(); + + void ApplicationMenu(Project& project); + + void SceneMenu(Project& project, YoggieEngine::Scene& scene); + + void DebugMenu(); + + void SelectMenu(); + + void WindowMenu(); + + void Help(); + + ~MainMenuBar(); + +private: + char* path = nullptr; + +}; \ No newline at end of file diff --git a/Editor/src/Project/Project.cpp b/Editor/src/Project/Project.cpp index baba0ee..9cbcf71 100644 --- a/Editor/src/Project/Project.cpp +++ b/Editor/src/Project/Project.cpp @@ -20,7 +20,7 @@ void Project::SaveProject(std::filesystem::path path, Project& project) projectFile.close(); } -void Project::LoadProject(std::filesystem::path path, std::unique_ptr& project) +void Project::LoadProject(std::filesystem::path path, Project& project) { std::string YAMLProject; std::stringstream sstream; @@ -36,10 +36,9 @@ void Project::LoadProject(std::filesystem::path path, std::unique_ptr& YAML::Node node = YAML::Load(YAMLProject); // this is probably not perfect but it seems to work for now - project.release(); - project = std::make_unique(node.as()); + project = node.as(); - std::cout << "loading..." << project.get()->Name << std::endl; + std::cout << "loading..." << project.Name << std::endl; diff --git a/Editor/src/Project/Project.h b/Editor/src/Project/Project.h index f82561a..836ce0b 100644 --- a/Editor/src/Project/Project.h +++ b/Editor/src/Project/Project.h @@ -14,7 +14,7 @@ public: const std::filesystem::path GetProjectDirectory() { return ProjectDirectory; } static void SaveProject(std::filesystem::path path, Project& project); - static void LoadProject(std::filesystem::path path, std::unique_ptr& project); + static void LoadProject(std::filesystem::path path, Project& project); private: std::string Name; std::filesystem::path ProjectDirectory; diff --git a/Editor/src/Project/ProjectInfo.cpp b/Editor/src/Project/ProjectInfo.cpp new file mode 100644 index 0000000..cdabbed --- /dev/null +++ b/Editor/src/Project/ProjectInfo.cpp @@ -0,0 +1,7 @@ +#include "ProjectInfo.h" + +void ProjectInfo::Draw() +{ + ImGui::Text("Project: %s", project.GetName().c_str()); + ImGui::Text("Directory: %s", project.GetProjectDirectory().u8string().c_str()); +} \ No newline at end of file diff --git a/Editor/src/Project/ProjectInfo.h b/Editor/src/Project/ProjectInfo.h new file mode 100644 index 0000000..f9ca200 --- /dev/null +++ b/Editor/src/Project/ProjectInfo.h @@ -0,0 +1,15 @@ +#pragma once +#include "../../YoggieEngine/src/YoggieEngine.h" +#include "../EditorWindow.h" +#include "Project.h" + +class ProjectInfo : public EditorWindow { +public: + ProjectInfo(Project& project) : EditorWindow("Project Info"), project(project) {} + + void Draw() override; + +private: + Project& project; + +}; diff --git a/Editor/src/Project/Settings.cpp b/Editor/src/Project/Settings.cpp new file mode 100644 index 0000000..e9c7e83 --- /dev/null +++ b/Editor/src/Project/Settings.cpp @@ -0,0 +1,48 @@ +#include "Settings.h" + +void Settings::Draw() { + ImGui::LabelText("##title-settings", "Fine grain control over the engine!"); + + if (ImGui::BeginCombo("Graphics API", GraphicsAPI[selectedGfxAPI])) { + for (int i = 0; i < 3; i++) { + bool isSelected = i == selectedGfxAPI; + if (ImGui::Selectable(GraphicsAPI[i], isSelected)) { + selectedGfxAPI = i; + } + + if (isSelected) + ImGui::SetItemDefaultFocus(); + } + + ImGui::EndCombo(); + } + + ImGui::NewLine(); + + if (ImGui::BeginCombo("Physics Engine", PhysicsEngine[selectedPhysicsEngine])) { + for (int i = 0; i < 2; i++) { + bool isSelected = i == selectedPhysicsEngine; + if (ImGui::Selectable(PhysicsEngine[i], isSelected)) { + selectedGfxAPI = i; + } + + if (isSelected) + ImGui::SetItemDefaultFocus(); + } + + ImGui::EndCombo(); + } + + ImGui::InputFloat3("Gravity", glm::value_ptr(Gravity)); + + ImGui::NewLine(); + if (ImGui::Button("Show Advanced options ")) { + ShowAdvancedOptions = !ShowAdvancedOptions; + } + + if (ShowAdvancedOptions) + { + ImGui::Checkbox("Debug Engine", &DebugEngine); + + } +} \ No newline at end of file diff --git a/Editor/src/Project/Settings.h b/Editor/src/Project/Settings.h new file mode 100644 index 0000000..20138bf --- /dev/null +++ b/Editor/src/Project/Settings.h @@ -0,0 +1,30 @@ +#pragma once +#include "../../YoggieEngine/src/YoggieEngine.h" +#include "../EditorWindow.h" + + +class Settings : public EditorWindow { +public: + Settings() : EditorWindow("Settings") {} + + void Draw() override; + +private: + int selectedGfxAPI = 0; + int selectedPhysicsEngine = 0; + glm::vec3 Gravity = glm::vec3(0.0f, -9.81f, 0.0f); + bool ShowAdvancedOptions = false; + bool DebugEngine = false; + + const char* PhysicsEngine[2] = { + "PhysX", + "Jolt Physics" + }; + + const char* GraphicsAPI[3] = { + "OpenGL", + "Vulkan", + "Metal (Apple)" + }; + +}; diff --git a/Editor/src/PropertyPanels/Inspector.cpp b/Editor/src/PropertyPanels/Inspector.cpp new file mode 100644 index 0000000..126c4dd --- /dev/null +++ b/Editor/src/PropertyPanels/Inspector.cpp @@ -0,0 +1,104 @@ +#include "Inspector.h" + + +void Inspector::Draw() +{ + +} + + +void Inspector::AddComponentDropDown(YoggieEngine::Entity& selected) +{ + static char* names[] = { "Script Component", "Camera Component", "Light Component" }; + if (ImGui::Button("Add Component")) + ImGui::OpenPopup("Component picker"); + + ImGui::SameLine(); + if (ImGui::BeginPopup("Component picker")) { + + for (int i = 0; i < IM_ARRAYSIZE(names); i++) + if (ImGui::MenuItem(names[i])) { + std::cout << "Add a " << names[i] << " to " + << selected.GetComponent().name << std::endl; + } + + ImGui::EndPopup(); + } + ImGui::NewLine(); +} + + +void Inspector::ShowComponents(YoggieEngine::Entity& selected) +{ + auto component = selected.GetComponent(); + ImGui::InputText("Name:", (char*)component.name.c_str(), component.name.size() * sizeof(char), ImGuiInputTextFlags_ReadOnly); + + + if (selected.HasComponent()) { + auto& transform = selected.GetComponent(); + if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) { + ImGui::DragFloat3("Position", glm::value_ptr(transform.Position), 0.1f); + ImGui::DragFloat3("Rotation", glm::value_ptr(transform.Rotation), 0.1f); + ImGui::DragFloat3("Scale", glm::value_ptr(transform.Scale), 0.1f, 0.0f); + } + if (selected.HasComponent()) { + ImGui::Text("Has relation"); + } + + + } + + + if (selected.HasComponent()) { + auto& render3d = selected.GetComponent(); + if (ImGui::CollapsingHeader("Render3D", ImGuiTreeNodeFlags_DefaultOpen)) { + ImGui::ColorEdit3("Colour", glm::value_ptr(render3d.color)); + + ImGui::Checkbox("Use static rendering:", &render3d.isStatic); + } + } + static bool deferred = true; + if (selected.HasComponent()) { + auto& light = selected.GetComponent(); + if (ImGui::CollapsingHeader("Light", ImGuiTreeNodeFlags_DefaultOpen)) { + ImGui::ColorEdit3("Colour", glm::value_ptr(light.Color)); + ImGui::Checkbox("Deferred", &deferred); + } + + } + + if (selected.HasComponent ()) { + auto& camera = selected.GetComponent(); + if (ImGui::CollapsingHeader("Camera")) { + ImGui::DragFloat3("Position:", glm::value_ptr(camera.Position), 0.01f); + ImGui::DragFloat3("Rotation:", glm::value_ptr(camera.Rotation), 0.01f); + + } + } + + if (selected.HasComponent()) { + auto& rigibody = selected.GetComponent(); + if (ImGui::CollapsingHeader("RigidBody")) { + + } + } + + if (selected.HasComponent()) { + ComponentView("Scripting", [] { + ImGui::LabelText("##--", "Hello scripting"); + }); + } +} + + +void ComponentView(const std::string& componentName, voidFunction func) +{ + ImGuiWindowFlags_ window_flags = ImGuiWindowFlags_None; + ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f); + ImGui::BeginChild(componentName.c_str()); + + func(); + + ImGui::EndChild(); + ImGui::PopStyleVar(); +} diff --git a/Editor/src/PropertyPanels/Inspector.h b/Editor/src/PropertyPanels/Inspector.h new file mode 100644 index 0000000..e61657e --- /dev/null +++ b/Editor/src/PropertyPanels/Inspector.h @@ -0,0 +1,20 @@ +#pragma once +#include "../../YoggieEngine/src/YoggieEngine.h" +#include "../EditorWindow.h" + +typedef void (*voidFunction) (void); + +inline void ComponentView(const std::string& componentName, voidFunction func); + +class Inspector : public EditorWindow { +public: + Inspector() : EditorWindow("Inspector") {} + + void Draw()override; + + + void AddComponentDropDown(YoggieEngine::Entity& selected); + + void ShowComponents(YoggieEngine::Entity& selected); + +}; diff --git a/Editor/src/PropertyPanels/SceneExplorer.cpp b/Editor/src/PropertyPanels/SceneExplorer.cpp new file mode 100644 index 0000000..a2fc08b --- /dev/null +++ b/Editor/src/PropertyPanels/SceneExplorer.cpp @@ -0,0 +1,13 @@ +#include "SceneExplorer.h" + +void SceneExplorer::Draw() +{ + scene.getReg().each([&](entt::entity enttNumber) { + YoggieEngine::Entity entity = YoggieEngine::Entity(enttNumber, &scene); + auto id = entity.GetComponent(); + + if (ImGui::Selectable(id.name.c_str(), enttNumber == selected)) { + selected = enttNumber; + } + }); +} \ No newline at end of file diff --git a/Editor/src/PropertyPanels/SceneExplorer.h b/Editor/src/PropertyPanels/SceneExplorer.h new file mode 100644 index 0000000..5defc18 --- /dev/null +++ b/Editor/src/PropertyPanels/SceneExplorer.h @@ -0,0 +1,20 @@ +#pragma once +#include "../../YoggieEngine/src/YoggieEngine.h" +#include "../EditorWindow.h" +#include "../../src/Scene/Entity.h" + +class SceneExplorer : public EditorWindow { +public: + SceneExplorer(entt::entity& selected, YoggieEngine::Scene& scene) + : EditorWindow("SceneExplorer"), scene(scene), selected(selected) + {} + + void Draw() override; + + +private: + entt::entity selected; + YoggieEngine::Scene& scene; + + +}; diff --git a/Editor/src/Runtime/RuntimeControls.cpp b/Editor/src/Runtime/RuntimeControls.cpp new file mode 100644 index 0000000..c7ab03e --- /dev/null +++ b/Editor/src/Runtime/RuntimeControls.cpp @@ -0,0 +1,27 @@ +#include "RuntimeControls.h" + +void RuntimeControls::Draw() { + ImGui::SameLine((ImGui::GetWindowContentRegionMax().x / 2) - (numButtons * buttonSize.x)); + for (int i = 0; i < numButtons; i++) { + ImVec4 color = button[i].Color; + ImGui::PushStyleColor(ImGuiCol_Button, color); + const float strengthIncrease = 1.5f; + ImGui::PushStyleColor( + ImGuiCol_ButtonHovered, + ImVec4{ + color.x * strengthIncrease, + color.y * strengthIncrease, + color.z * strengthIncrease, + color.w + } + ); + if (ImGui::Button(button[i].Name, buttonSize)) { + + } + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::SameLine(); + + } + +} \ No newline at end of file diff --git a/Editor/src/Runtime/RuntimeControls.h b/Editor/src/Runtime/RuntimeControls.h new file mode 100644 index 0000000..9e29301 --- /dev/null +++ b/Editor/src/Runtime/RuntimeControls.h @@ -0,0 +1,26 @@ +#pragma once +#include "../../YoggieEngine/src/YoggieEngine.h" +#include "../EditorWindow.h" + +#define RuntimeControlWindowFlags (ImGuiWindowFlags_)(ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse) + +struct ButtonInfo { + const char* Name; + ImVec4 Color; +}; + +class RuntimeControls : public EditorWindow { +public: + RuntimeControls() : EditorWindow("RuntimeControls", RuntimeControlWindowFlags) {} + + void Draw() override; + +private: + ImVec2 buttonSize = ImVec2{ 90 ,25 }; + unsigned int numButtons = 2; + ButtonInfo button[2] = { + {"Play" , ImVec4{ 0.001 * 12 , 0.001 * 201 , 0.001 * 69, 1.0f}}, + {"Simulate", ImVec4{ 0.001 * 14, 0.001 * 157, 0.001 * 201, 1.0f}} + }; + +}; \ No newline at end of file diff --git a/Editor/src/SceneSerializer.h b/Editor/src/SceneSerializer.h deleted file mode 100644 index ea8d115..0000000 --- a/Editor/src/SceneSerializer.h +++ /dev/null @@ -1,134 +0,0 @@ -#pragma once -#include -#include - -#include -#include -#include - -#include "../../YoggieEngine/src/Scene/Entity.h" - -void WriteFile(std::string& emitter, std::filesystem::path path) -{ - std::cout << "Writing Scene file to: " << path.u8string() << std::endl; - std::ofstream sceneFile; - sceneFile.open(path.u8string()); - - sceneFile << emitter.c_str(); - - sceneFile.close(); -} - -YAML::Emitter& operator<< (YAML::Emitter& emitter, glm::vec3& vector) { - emitter << YAML::Flow << YAML::BeginSeq << vector.x << vector.y << vector.x << YAML::EndSeq; - return emitter; -} - - std::string Serialize( Scene& scene) { - YAML::Emitter emitter; - - emitter << YAML::BeginMap; - emitter << YAML::Key << "Scene" << YAML::Value << "test-Scene"; - emitter << YAML::Key << "Entities" << YAML::Value << YAML::BeginSeq; - - scene.getReg().each([&scene, &emitter](auto enttNumber) { - Entity entity = Entity(enttNumber, &scene); - - emitter << YAML::BeginMap; - emitter << YAML::Key << "Entity" << YAML::Value << entity.GetComponent().name; - - if (entity.HasComponent()) { - emitter << YAML::Key << "Ident"; - emitter << YAML::BeginMap; - emitter << YAML::Value << entity.GetComponent().name; - emitter << YAML::EndMap; - } - - if (entity.HasComponent()) { - emitter << YAML::Key << "Transform" << YAML::Value ; - - emitter << YAML::BeginMap; - - emitter << YAML::Key << "Position"; - emitter << YAML::Value << entity.GetComponent().Position; - - emitter << YAML::Key << "Rotation"; - emitter << YAML::Value << entity.GetComponent().Rotation; - - emitter << YAML::Key << "Scale"; - emitter << YAML::Value << entity.GetComponent().Scale; - - emitter << YAML::EndMap; - } - - - if (entity.HasComponent()) { - emitter << YAML::Key << "Light"; - emitter << YAML::Value; - emitter << YAML::BeginMap; - emitter << YAML::Key << "Color"; - emitter << YAML::Value << entity.GetComponent().Color; - emitter << YAML::EndMap; - } - - - emitter << YAML::EndMap; - - }); - - emitter << YAML::EndSeq; - emitter << YAML::EndMap; - - return std::string(emitter.c_str()); -} - - - void SaveScene(std::filesystem::path path, Scene& scene) { - std::string YAMLString = Serialize(scene); - WriteFile(YAMLString, path); - } - - - void LoadScene(std::filesystem::path path, Scene& scene) - { - auto sceneYAML = YAML::LoadFile(path.u8string()); - - if (!sceneYAML["Scene"]) { - spdlog::error("Not a scene file!"); - return; - } - - scene.getReg().clear(); - - - - std::string SceneName = sceneYAML["Scene"].as(); - - - auto entities = sceneYAML["Entities"]; - - for (const auto& entity : entities) { - - std::string entityID = entity["Ident"].as(); - YoggieEngine::Entity SE = scene.AddEntity(entityID); - if (entity["Transform"]) - { - TransformComponent tc = SE.GetComponent(); - auto positionNode = entity["Transform"]["Position"]; - tc.Position = glm::vec3(positionNode[0].as(), positionNode[1].as(), positionNode[2].as()); - - auto rotationNode = entity["Transform"]["Rotation"]; - tc.Rotation = glm::vec3(rotationNode[0].as(), rotationNode[1].as(), rotationNode[2].as()); - - auto scaleNode = entity["Transform"]["Scale"]; - tc.Scale = glm::vec3(scaleNode[0].as(), scaleNode[1].as(), scaleNode[2].as()); - } - if (entity["Light"]) { - LightComponent lc = SE.AddComponent(); - lc.Color = glm::vec3(entity["Light"]["Color"][0].as(), entity["Light"]["Color"][1].as(), entity["Light"]["Color"][2].as()); - } - - } - - - } \ No newline at end of file diff --git a/Editor/src/UI/EditorConsole.h b/Editor/src/UI/EditorConsole.h deleted file mode 100644 index 51194ec..0000000 --- a/Editor/src/UI/EditorConsole.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include - -class EditorConsole -{ -public: - EditorConsole(); - ~EditorConsole(); - - void Draw(); - void AddLog(const char* fmt, ...); - -private: - ImVector Items; - bool AutoScroll; - bool ScrollToBottom; - -}; \ No newline at end of file diff --git a/Editor/src/UI/EditorWindow.h b/Editor/src/UI/EditorWindow.h deleted file mode 100644 index 4745f61..0000000 --- a/Editor/src/UI/EditorWindow.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once -#include -#include - -class EditorWindow { - -public: - EditorWindow(const std::string& name, ImGuiWindowFlags_ flags = ImGuiWindowFlags_None ) { ImGui::Begin(name.c_str(), false ,flags); } - ~EditorWindow() { ImGui::End(); } - -}; \ No newline at end of file diff --git a/Editor/src/UI/GUIRenderer.h b/Editor/src/UI/GUIRenderer.h deleted file mode 100644 index 749af2e..0000000 --- a/Editor/src/UI/GUIRenderer.h +++ /dev/null @@ -1,70 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include "../../src/YoggieEngine.h" - - -class GUIRenderer { -public: - GUIRenderer(YoggieEngine::NativeWindow& window ) { - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); - io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_ViewportsEnable; - io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_DockingEnable; - io.Fonts->AddFontFromFileTTF("build/Debug/Fonts/Roboto-Regular.ttf", 18); - - ImGui::StyleColorsDark(); - - ImGui_ImplGlfw_InitForOpenGL(window.GetGLFWHandle(), true); - ImGui_ImplOpenGL3_Init("#version 450"); - - ImGuizmo::SetImGuiContext(ImGui::GetCurrentContext()); - ImGuizmo::SetOrthographic(true); - - } - - void Begin () - { - ImGui_ImplGlfw_NewFrame(); - ImGui_ImplOpenGL3_NewFrame(); - - ImGui::NewFrame(); - ImGuizmo::BeginFrame(); - } - - void End() - { - - ImGui::EndFrame(); - - - ImGui::Render(); - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - - - if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) - { - GLFWwindow* last_context = glfwGetCurrentContext(); - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindowsDefault(); - glfwMakeContextCurrent(last_context); - } - - - - } - - - ~GUIRenderer(){ - - - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); - - - } -}; diff --git a/Editor/src/UI/MainMenuBar.h b/Editor/src/UI/MainMenuBar.h deleted file mode 100644 index 0c8a32a..0000000 --- a/Editor/src/UI/MainMenuBar.h +++ /dev/null @@ -1,187 +0,0 @@ -#pragma once -#include - -class MainMenuBar { - -public: - MainMenuBar() { ImGui::BeginMainMenuBar(); } - - void ApplicationMenu(std::unique_ptr& project) { - - if (ImGui::BeginMenu("Application")) { - - if (ImGui::MenuItem("Load Project")) - { - nfdresult_t result = NFD_OpenDialog({ "yproj" }, NULL, &path); - switch (result) { - case(NFD_OKAY): - Project::LoadProject(path, project); - AssetManager::setAssetPath(project.get()->GetProjectDirectory()); - AssetManager::BuildAssetView(); - break; - case(NFD_CANCEL): - break; - case(NFD_ERROR): - std::cout << "NFD_Error: " << NFD_GetError() << std::endl; - break; - } - - } - - if (ImGui::MenuItem("Save project as...")) { - nfdresult_t result = NFD_SaveDialog({ "yproj" }, NULL, &path); - switch (result) { - case(NFD_OKAY): - std::cout << "Save as: " << path << std::endl; - Project::SaveProject(path, *project.get()); - break; - case(NFD_CANCEL): - break; - case(NFD_ERROR): - std::cout << "NFD_Error: " << NFD_GetError() << std::endl; - break; - } - } - - - - if (ImGui::MenuItem("Preferences")) - { - - } - - if (ImGui::MenuItem("Exit")) - { - // TODO: Exit application - } - - ImGui::EndMenu(); - } - } - - void SceneMenu(std::unique_ptr& project, Scene& scene) { - - if (ImGui::BeginMenu("Scene")) { - - if (ImGui::MenuItem("Save scene")) - { - nfdresult_t result = NFD_SaveDialog({ "yscene" }, NULL, &path); - switch (result) { - case(NFD_OKAY): - SaveScene(path, scene); - break; - case(NFD_CANCEL): - break; - case(NFD_ERROR): - std::cout << "NFD_Error: " << NFD_GetError() << std::endl; - break; - } - - } - - if (ImGui::MenuItem("Load scene")) - { - auto result = NFD_OpenDialog({ "yscene" }, NULL, &path); - switch (result) { - case (NFD_OKAY): - LoadScene(path, scene); - break; - case(NFD_CANCEL): - break; - case(NFD_ERROR): - std::cout << "NFD_Error: " << NFD_GetError() << std::endl; - break; - } - - } - - if (ImGui::MenuItem("Add Entity")) - { - scene.AddEntity("New Entity"); - } - - if (ImGui::MenuItem("Import Model")) - { - auto result = NFD_OpenDialog("obj,fbx,gltf", NULL, &path); - switch (result) { - case(NFD_OKAY): - // Import Model - - AssetManager::LoadFromSource( - path, - "build/Debug/Assets"//project.get()->GetProjectDirectory() / "Assets" - ); - break; - case(NFD_CANCEL): - break; - case(NFD_ERROR): - std::cout << "NFD_Error: " << NFD_GetError() << std::endl; - break; - } - } - - if (ImGui::MenuItem("Import MeshAsset (temp)")) - { - auto result = NFD_OpenDialog("mesh", NULL, &path); - - switch (result) { - case(NFD_OKAY): - { - YoggieEngine::Mesh* importedMesh = AssetManager::LoadFromAssetFile(path); - if (importedMesh != nullptr) - { - auto full_name = std::filesystem::path(path); - auto importedModel = scene.AddEntity(full_name.filename().u8string()); - auto& rendererComponent = importedModel.AddComponent(); - rendererComponent.mesh = *importedMesh; - - } - } - break; - - case(NFD_CANCEL): - spdlog::debug("User cancelled action"); - break; - case(NFD_ERROR): - spdlog::warn("Something went wrong!"); - break; - } - - } - - ImGui::EndMenu(); - } - } - - void DebugMenu() - { - if (ImGui::BeginMenu("Debug")) { - ImGui::EndMenu(); - } - } - - void SelectMenu() { - if (ImGui::BeginMenu("Select")) { - ImGui::EndMenu(); - } - } - - void WindowMenu() { - if (ImGui::BeginMenu("Window")) { - - ImGui::EndMenu(); - } - } - - void Help() { - if (ImGui::BeginMenu("Help")) { - ImGui::EndMenu(); - } - } - - - ~MainMenuBar() { ImGui::EndMainMenuBar(); } -private: - char* path = nullptr; - -}; \ No newline at end of file diff --git a/Editor/src/UI/widgets.h b/Editor/src/UI/widgets.h deleted file mode 100644 index eafde61..0000000 --- a/Editor/src/UI/widgets.h +++ /dev/null @@ -1,377 +0,0 @@ -#pragma once -#include - -#include - -#include -#include "../../libs/guizmo/ImGuizmo.h" - -#include "../../YoggieEngine/src/YoggieEngine.h" -#include "../../src/Scene/Entity.h" - -#include "EditorWindow.h" -#include "EditorConsole.h" -#include "../Project/Project.h" -#include "../AssetManagement/AssetManager.h" - -typedef void ( *voidFunction ) (void); -using namespace YoggieEngine; - -auto matrix = glm::mat4(1.0f); -auto worldOrigin = glm::mat4(1.0f); - - -inline void ComponentView(const std::string& componentName, voidFunction func) -{ - ImGuiWindowFlags_ window_flags = ImGuiWindowFlags_None; - ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f); - ImGui::BeginChild(componentName.c_str()); - - func(); - - ImGui::EndChild(); - ImGui::PopStyleVar(); -} - -class Inspector : EditorWindow { -public: - Inspector() : EditorWindow("Inspector") {} - - void AddComponentDropDown(Entity& selected ) - { - static char* names[] = { "Script Component", "Camera Component", "Light Component"}; - if (ImGui::Button("Add Component")) - ImGui::OpenPopup("Component picker"); - - ImGui::SameLine(); - if (ImGui::BeginPopup("Component picker")) { - - for (int i = 0; i < IM_ARRAYSIZE(names); i++) - if (ImGui::MenuItem(names[i])) { - std::cout << "Add a " << names[i] << " to " - << selected.GetComponent().name << std::endl; - } - - ImGui::EndPopup(); - } - ImGui::NewLine(); - } - - void ShowComponents(Entity& selected) - { - auto component = selected.GetComponent(); - ImGui::InputText("Name:", (char*)component.name.c_str(), component.name.size() * sizeof(char), ImGuiInputTextFlags_ReadOnly); - - - if (selected.HasComponent()) { - auto& transform = selected.GetComponent(); - if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) { - ImGui::DragFloat3("Position", glm::value_ptr(transform.Position), 0.1f); - ImGui::DragFloat3("Rotation", glm::value_ptr(transform.Rotation), 0.1f); - ImGui::DragFloat3("Scale", glm::value_ptr(transform.Scale), 0.1f, 0.0f); - } - if (selected.HasComponent()) { - ImGui::Text("Has relation"); - } - - - } - - - if (selected.HasComponent()) { - auto& render3d = selected.GetComponent(); - if (ImGui::CollapsingHeader("Render3D", ImGuiTreeNodeFlags_DefaultOpen)) { - ImGui::ColorEdit3("Colour", glm::value_ptr(render3d.color)); - - ImGui::Checkbox("Use static rendering:", &render3d.isStatic); - } - } - static bool deferred = true; - if (selected.HasComponent()) { - auto& light = selected.GetComponent(); - if (ImGui::CollapsingHeader("Light", ImGuiTreeNodeFlags_DefaultOpen)) { - ImGui::ColorEdit3("Colour", glm::value_ptr(light.Color)); - ImGui::Checkbox("Deferred", &deferred); - } - - } - - if (selected.HasComponent ()) { - auto& camera = selected.GetComponent(); - if (ImGui::CollapsingHeader("Camera")) { - ImGui::DragFloat3("Position:",glm::value_ptr(camera.Position), 0.01f); - ImGui::DragFloat3("Rotation:", glm::value_ptr(camera.Rotation), 0.01f); - - } - } - - if (selected.HasComponent()) { - ComponentView("Scripting", [] { - ImGui::LabelText("##--", "Hello scripting"); - }); - } - } - -}; - -class SceneExplorer : EditorWindow { -public: - SceneExplorer(entt::entity& selected , Scene& scene) : EditorWindow("SceneExplorer") { - scene.getReg().each([&](entt::entity enttNumber) { - Entity entity = Entity(enttNumber, &scene); - auto id = entity.GetComponent(); - - if (ImGui::Selectable(id.name.c_str(), enttNumber == selected)) { - selected = enttNumber; - } - - }); - - } -}; - - -class Viewport : EditorWindow { -public: - Viewport (Framebuffer& fb, Camera cam) : EditorWindow("SceneView") - { - ImVec2 WinPos = ImGui::GetWindowPos(); - ImVec2 ContentRegionMin = ImGui::GetWindowContentRegionMin(); - ImVec2 ContentRegionMax = ImGui::GetWindowContentRegionMax(); - ImVec2 ScreenSpaceMin = { ContentRegionMin.x + WinPos.x, ContentRegionMin.y + WinPos.y }; - ImVec2 ScreenSpaceMax = { ContentRegionMax.x + WinPos.x,ContentRegionMax.y + WinPos.y }; - - - ImGui::Image( - (void*)(intptr_t)fb.GetColourAttachment(), - ImVec2{ (float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight() } - ); - - - ImGuizmo::Enable(true); - ImGuizmo::SetRect(ScreenSpaceMin.x, ScreenSpaceMin.y,ContentRegionMax.x, ContentRegionMax.y); - - glm::mat4 transposed_view = glm::transpose(cam.ViewMatrix); - - ImGuizmo::DrawGrid(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), glm::value_ptr(worldOrigin), 100.0f); - ImGuizmo::ViewManipulate(glm::value_ptr(transposed_view), 1, { ScreenSpaceMin.x,ScreenSpaceMin.y }, { 90,90 }, 0x22CCCCCC); - - // Matrix is the model matrix we would want to manipulate - //ImGuizmo::Manipulate(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(cam.ViewMatrix)); - - if (ImGui::IsWindowFocused() ) - { - isFocused = true; - - } - else { - isFocused = false; - } - - } - - bool isFocused = false; - -}; - - -int selectedGfxAPI = 0; -int selectedPhysicsEngine = 0; -glm::vec3 Gravity = glm::vec3(0.0f, -9.81f, 0.0f); -bool ShowAdvancedOptions = false; -bool DebugEngine = false; -class Settings : EditorWindow { -public: - Settings() : EditorWindow("Settings") - { - ImGui::LabelText("##title-settings", "Fine grain control over the engine!"); - - if (ImGui::BeginCombo("Graphics API", GraphicsAPI[selectedGfxAPI])) { - for (int i = 0; i < 3; i++) { - bool isSelected = i == selectedGfxAPI; - if (ImGui::Selectable(GraphicsAPI[i], isSelected)) { - selectedGfxAPI = i; - } - - if(isSelected) - ImGui::SetItemDefaultFocus(); - } - - ImGui::EndCombo(); - } - - ImGui::NewLine(); - - if (ImGui::BeginCombo("Physics Engine", PhysicsEngine[selectedPhysicsEngine])) { - for (int i = 0; i < 2; i++) { - bool isSelected = i == selectedPhysicsEngine; - if (ImGui::Selectable(PhysicsEngine[i], isSelected)) { - selectedGfxAPI = i; - } - - if (isSelected) - ImGui::SetItemDefaultFocus(); - } - - ImGui::EndCombo(); - } - - ImGui::InputFloat3("Gravity", glm::value_ptr(Gravity)); - - ImGui::NewLine(); - if (ImGui::Button("Show Advanced options ")) { - ShowAdvancedOptions = !ShowAdvancedOptions; - } - - if (ShowAdvancedOptions) - { - ImGui::Checkbox("Debug Engine", &DebugEngine); - - } - - } - -private: - - - const char* PhysicsEngine[2] = { - "PhysX", - "Jolt Physics" - }; - - const char* GraphicsAPI[3] = { - "OpenGL", - "Vulkan", - "Metal (Apple)" - }; - -}; - -class ProjectInfo : EditorWindow { -public: - ProjectInfo(Project& project) : EditorWindow("Project Info") { - ImGui::Text("Project: %s", project.GetName().c_str()); - ImGui::Text("Directory: %s", project.GetProjectDirectory().u8string().c_str()); - } -}; - -class Console : EditorWindow { -public: - -Console() : EditorWindow("Console") { - s_console = std::make_unique(); -} -void Show() { - s_console.get()->Draw(); -} - -private: - std::unique_ptr s_console; -}; - -class AssetFinder : EditorWindow { -public: - AssetFinder() : EditorWindow("Assets") { - - - ImGui::DragInt("IconSize", &iconSize, 1, 30, 90); - - - if (ImGui::BeginTable("##resources", 3)) - { - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.f, 0.f, 0.f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.f, 0.f, 0.f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.f, 1.f, 1.f, 0.2f)); - - Texture folderIcon = Texture("rsc/folderIcon.png"); - Texture assetIcon = Texture("rsc/assetIcon.png"); - - - int row = 0; - int column = 0; - for (auto& asset : AssetManager::assets) { - if (column % 3 == 0) { - ImGui::TableNextRow(); - column = 0; - row++; - } - - ImGui::TableSetColumnIndex(column); - - if (asset.isFolder) { - ImGui::ImageButton( - (ImTextureID)folderIcon.GetID(), - ImVec2{ (float)iconSize,(float)iconSize }); - ImGui::Text(asset.GetName(), row); - - } - else { - ImGui::ImageButton( - (ImTextureID)assetIcon.GetID(), - ImVec2{ (float)iconSize, (float)iconSize }); - ImGui::Text(asset.GetName(), row); - - } - - - column++; - } - - - ImGui::PopStyleColor(3); - ImGui::EndTable(); - const GLuint textures[2]{ assetIcon.GetID(), folderIcon.GetID() }; - glDeleteTextures(2, textures ); - - } - - } -private: - int iconSize = 60; -}; - -#define RuntimeControlWindowFlags (ImGuiWindowFlags_)(ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse) - -struct ButtonInfo { - const char* Name; - ImVec4 Color; -}; - - -class RuntimeControls : EditorWindow { -public: - RuntimeControls() : EditorWindow("RuntimeControls", RuntimeControlWindowFlags) { - - ImGui::SameLine((ImGui::GetWindowContentRegionMax().x / 2) - ( numButtons * buttonSize.x )); - for (int i = 0; i < numButtons; i++) { - ImVec4 color = button[i].Color; - ImGui::PushStyleColor(ImGuiCol_Button, color); - const float strengthIncrease = 1.5f; - ImGui::PushStyleColor( - ImGuiCol_ButtonHovered, - ImVec4{ - color.x * strengthIncrease, - color.y * strengthIncrease, - color.z * strengthIncrease, - color.w - } - ); - if (ImGui::Button(button[i].Name, buttonSize)) { - - } - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::SameLine(); - - } - } - -private: - ImVec2 buttonSize = ImVec2{ 90 ,25 }; - unsigned int numButtons = 2; - ButtonInfo button[2] = { - {"Play" , ImVec4{ 0.001 * 12 , 0.001 * 201 , 0.001* 69, 1.0f}}, - {"Simulate", ImVec4{ 0.001 * 14, 0.001 * 157, 0.001 * 201, 1.0f}} - }; - -}; \ No newline at end of file diff --git a/Editor/src/Views/Viewport.cpp b/Editor/src/Views/Viewport.cpp new file mode 100644 index 0000000..428dd44 --- /dev/null +++ b/Editor/src/Views/Viewport.cpp @@ -0,0 +1,55 @@ +#include "Viewport.h" + +Viewport::Viewport(YoggieEngine::Scene& scene ): + EditorWindow("SceneView"), + renderer(YoggieEngine::RendererConfig{ 1200, 700, glm::vec3(0), true }), + cam(glm::vec3(14.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90), + scene(scene) +{ + renderer.SetMainCamera(cam); + +} + +void Viewport::Draw() { + + auto group = scene.getReg().view(); + group.each([&](auto enity, YoggieEngine::TransformComponent& t, YoggieEngine::Render3DComponent& renderComponent) { + renderer.Submit(renderComponent, t); + }); + + cam.Update(); + renderer.Render(scene); + + ImVec2 WinPos = ImGui::GetWindowPos(); + ImVec2 ContentRegionMin = ImGui::GetWindowContentRegionMin(); + ImVec2 ContentRegionMax = ImGui::GetWindowContentRegionMax(); + ImVec2 ScreenSpaceMin = { ContentRegionMin.x + WinPos.x, ContentRegionMin.y + WinPos.y }; + ImVec2 ScreenSpaceMax = { ContentRegionMax.x + WinPos.x,ContentRegionMax.y + WinPos.y }; + + + ImGui::Image( + (void*)(intptr_t)renderer.getCurrentFrameBuffer().GetColourAttachment(), + ImVec2{ (float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight() } + ); + + + ImGuizmo::Enable(true); + ImGuizmo::SetRect(ScreenSpaceMin.x, ScreenSpaceMin.y, ContentRegionMax.x, ContentRegionMax.y); + + glm::mat4 transposed_view = glm::transpose(cam.ViewMatrix); + + //ImGuizmo::DrawGrid(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), glm::value_ptr(worldOrigin), 100.0f); + //ImGuizmo::ViewManipulate(glm::value_ptr(cam.ViewMatrix), 1, { ScreenSpaceMin.x,ScreenSpaceMin.y }, { 90,90 }, 0x22CCCCCC); + + // Matrix is the model matrix we would want to manipulate + //ImGuizmo::Manipulate(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(cam.ViewMatrix)); + + if (ImGui::IsWindowFocused()) + { + isFocused = true; + + } + else { + isFocused = false; + } +} \ No newline at end of file diff --git a/Editor/src/Views/Viewport.h b/Editor/src/Views/Viewport.h new file mode 100644 index 0000000..e41c4fb --- /dev/null +++ b/Editor/src/Views/Viewport.h @@ -0,0 +1,24 @@ +#pragma once +#include "../../YoggieEngine/src/YoggieEngine.h" +#include "../EditorWindow.h" + +#include + +#include +#include "../../libs/guizmo/ImGuizmo.h" + + +class Viewport : public EditorWindow { +public: + bool isFocused = false; + YoggieEngine::Camera cam; + + Viewport(YoggieEngine::Scene& scene); + + void Draw() override; + +private: + YoggieEngine::Renderer renderer; + YoggieEngine::Scene& scene; + +}; \ No newline at end of file diff --git a/Editor/src/app.cpp b/Editor/src/app.cpp index 44da576..471e267 100644 --- a/Editor/src/app.cpp +++ b/Editor/src/app.cpp @@ -8,84 +8,63 @@ #include #include -#include "UI/GUIRenderer.h" -#include "UI/Widgets.h" #include "Project/Project.h" -#include "SceneSerializer.h" +#include "AssetManagement/SceneSerializer.h" #include "AssetManagement/AssetManager.h" -#include "UI/MainMenuBar.h" -void CreateTestProject(std::unique_ptr& project, Scene& scene); -RendererConfig EditorSceneRendererConfig{ - 1200, // Screen Width - 700, // Screen Height - glm::vec3{0,0,0}, // Clear Color - true // Depth testing -}; -glm::vec3 temp = glm::vec3(0); -Camera cam = Camera(glm::vec3(14.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90); +#include "Views/Viewport.h" +#include "PropertyPanels/SceneExplorer.h" +#include "AssetManagement/AssetFinder.h" +#include "MainMenuBar.h" +#include "PropertyPanels/Inspector.h" +#include "Project/ProjectInfo.h" +#include "Runtime/RuntimeControls.h" +#include "Project/Settings.h" +#include "Console.h" + +using namespace YoggieEngine; class Editor : public Application { public: - Editor() - : Application("Editor"), - AppWindow(1200,700), - framebuffer(new Framebuffer(1200,700)), - viewportRenderer(EditorSceneRendererConfig), - EditorGUIRenderer(AppWindow), - Selected((entt::entity)-1) + Editor() : Application("Editor"), Selected((entt::entity)-1){} + + void Run() override { + LoadLastOrEmptyProject(); - init_inputSystem(&AppWindow); - viewportRenderer.setCurrentFrameBuffer(*framebuffer); - } + MainMenuBar menuBar = MainMenuBar(); + ProjectInfo projectInfo(project); + Viewport sceneview = Viewport(scene); + RuntimeControls rc = RuntimeControls(); + SceneExplorer explorer(Selected, scene); + Inspector inspector = Inspector(); + Settings settings = Settings(); + // AssetFinder assetsView = AssetFinder(); + Console console = Console(); - void RenderScene() { - // submit DrawCommands for all render3DComponents - auto group = ActiveScene.getReg().view(); - group.each([&](auto enity, TransformComponent& t, Render3DComponent& renderComponent) { - viewportRenderer.Submit(renderComponent, t); - }); - - // Render scene - viewportRenderer.Render(ActiveScene); - - } - - void RenderEditorGUI() { - EditorGUIRenderer.Begin(); - ImGui::DockSpaceOverViewport(ImGui::GetMainViewport()); - - // Show a menu bar + double previous = glfwGetTime(); + double lag = 0.0; + while (!appWindow.WindowShouldClose()) { - MainMenuBar menuBar = MainMenuBar(); - menuBar.ApplicationMenu(CurrentProject); - menuBar.SceneMenu(CurrentProject, ActiveScene); - menuBar.SelectMenu(); - menuBar.WindowMenu(); - menuBar.DebugMenu(); - menuBar.Help(); - } - - { - ProjectInfo projectInfo(*(CurrentProject.get())); - } - - { - Viewport sceneview = Viewport(*framebuffer, viewportRenderer.getCamera()); - if (sceneview.isFocused) + PollEvents(); + double now = glfwGetTime(); + double elapsed = now - previous ; + previous = now; + lag += elapsed; + + if (sceneview.isFocused) { const float movement_speed = 0.1f; static float lastX = 400, lastY = 300; const float sensitivity = 0.1; static bool firstMouse = true; - if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_RIGHT) ){ - - glfwSetInputMode(AppWindow.GetGLFWHandle(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN); - auto newX = getCursorPosX(&AppWindow); - auto newY = getCursorPosY(&AppWindow); + if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_RIGHT)) { + + glfwSetInputMode(appWindow.GetGLFWHandle(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN); + auto newX = getCursorPosX(&appWindow); + auto newY = getCursorPosY(&appWindow); if (firstMouse) { @@ -104,139 +83,124 @@ public: xoffset *= sensitivity; yoffset *= sensitivity; - cam.yaw += xoffset; - cam.pitch += yoffset; + sceneview.cam.yaw += xoffset; + sceneview.cam.pitch += yoffset; - if (cam.pitch > 89.0f) - cam.pitch = 89.0f; - if (cam.pitch < -89.0f) - cam.pitch = -89.0f; + if (sceneview.cam.pitch > 89.0f) + sceneview.cam.pitch = 89.0f; + if (sceneview.cam.pitch < -89.0f) + sceneview.cam.pitch = -89.0f; } else if (firstMouse == false) { - glfwSetInputMode(AppWindow.GetGLFWHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL); - firstMouse = true; + glfwSetInputMode(appWindow.GetGLFWHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL); + firstMouse = true; } - + // Check for Camara movement input here! if (keyIsPressed(YOGGIE_KEY_W)) - cam.Position += cam.Front * movement_speed; + sceneview.cam.Position += sceneview.cam.Front * movement_speed; if (keyIsPressed(YOGGIE_KEY_A)) - cam.Position -= cam.Right * movement_speed; + sceneview.cam.Position -= sceneview.cam.Right * movement_speed; if (keyIsPressed(YOGGIE_KEY_S)) - cam.Position -= cam.Front * movement_speed; + sceneview.cam.Position -= sceneview.cam.Front * movement_speed; if (keyIsPressed(YOGGIE_KEY_D)) - cam.Position += cam.Right * movement_speed; + sceneview.cam.Position += sceneview.cam.Right * movement_speed; } - } + GuiBegin(); - { - RuntimeControls rc = RuntimeControls(); - } - - - { - SceneExplorer explorer(Selected, ActiveScene); - } - - - { - Inspector inspector = Inspector(); - if (ActiveScene.getReg().valid(Selected)) { - Entity SelectedEntity = Entity(Selected, &ActiveScene); + // Show a menu bar + menuBar.ApplicationMenu(project); + menuBar.SceneMenu(project, scene); + menuBar.SelectMenu(); + menuBar.WindowMenu(); + menuBar.DebugMenu(); + menuBar.Help(); + + + if (scene.getReg().valid(Selected)) { + Entity SelectedEntity = Entity(Selected, &scene); inspector.AddComponentDropDown(SelectedEntity); inspector.ShowComponents(SelectedEntity); } - } - - { - Settings settings = Settings(); - } - - { - // AssetFinder assetsView = AssetFinder(); - } - { - Console console = Console(); - console.Show(); - } - - ImGui::ShowDemoWindow(); - ImGui::ShowMetricsWindow(); - EditorGUIRenderer.End(); - } - - void Run() override - { - CreateTestProject(CurrentProject, ActiveScene); - ActiveScene.Start(); - - - // Create the physics engine demo! - Physics Physics; - Physics.Demo(); - /*Physics.EnableDebugVisuals(); - Physics.Step(0); - Physics.SubmitMesh(); - */ - - double previous = glfwGetTime(); - double lag = 0.0; - while (!AppWindow.WindowShouldClose()) - { - - double current = glfwGetTime(); - double elapsed = current - previous; - previous = current; - lag += elapsed; - - AppWindow.Poll(); - cam.Update(); + projectInfo.Update(); + sceneview.Update(); + rc.Update(); + explorer.Update(); + settings.Update(); + inspector.Update(); + console.Update(); - Physics.Step(elapsed); - ActiveScene.Update(); - - RenderScene(); - /*Physics.DebugRender(*framebuffer);*/ - - RenderEditorGUI(); - - AppWindow.SwapBuffers(); - glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); - + ImGui::ShowDemoWindow(); + ImGui::ShowMetricsWindow(); + + GuiEnd(); + SwapBuffers(); } - - delete framebuffer; - ActiveScene.Stop(); - } + void LoadLastOrEmptyProject() { + // Check if there is a last known loaded project and + // load that one . + + // Otherwise load no project.. + // OR + // Load an empty project. + + std::string path = (std::filesystem::current_path()).string(); + project.setProjectDirectory(path); + + AssetManager::Init(); + AssetManager::setAssetPath(project.GetProjectDirectory()); + AssetManager::BuildAssetView(); + + // Create a level and load it as the current level + auto importer = ModelImporter(); + + + // create an ambient light source + auto light = scene.AddEntity("Light"); + auto& lightComponent = light.AddComponent(); + lightComponent.Color = glm::vec3(1.0f); + + + // Create a cube + auto model = importer.Import("build/Debug/Models/Cube.obj"); + + auto cube = scene.AddEntity("Cube"); + auto& render3DComponent = cube.AddComponent(); + render3DComponent.mesh = *(model->renderable->mesh); + + cube.GetComponent().Position = glm::vec3(1.0f, 0.0f, 5.0f); + + auto cube2 = scene.AddEntity("Cube2"); + auto& rendercube2 = cube2.AddComponent(); + rendercube2.mesh = *(model->renderable->mesh); + auto& relationcube = cube.AddComponent(cube2); + auto& rigidbodycomp = cube.AddComponent(); + auto& rigidbodycomp2 = cube2.AddComponent(); + + + auto Grass = scene.AddEntity("Grass/Window-Pane"); + //auto& renderGrass = Grass.AddComponent(); + } + private: - NativeWindow AppWindow; - - Framebuffer* framebuffer; - Renderer viewportRenderer; - - GUIRenderer EditorGUIRenderer; - - // Editor State bool SimulatePhysics = true; entt::entity Selected; - - - std::unique_ptr CurrentProject; - Scene ActiveScene; + Project project; + Scene scene; }; @@ -245,43 +209,3 @@ YoggieEngine::Application* CreateApplication() { return new Editor(); } - -void CreateTestProject(std::unique_ptr& project, Scene& scene ) { - project = std::make_unique(); - std::string path = (std::filesystem::current_path()).string(); - project.get()->setProjectDirectory(path); - - AssetManager::Init(); - AssetManager::setAssetPath(project.get()->GetProjectDirectory()); - AssetManager::BuildAssetView(); - - // Create a level and load it as the current level - auto importer = ModelImporter(); - - - // create an ambient light source - auto light = scene.AddEntity("Light"); - auto lightComponent = light.AddComponent(); - lightComponent.Color = glm::vec3(1.0f); - - - // Create a cube - auto model = importer.Import("build/Debug/Models/Cube.obj"); - - auto cube = scene.AddEntity("Cube"); - auto& render3DComponent = cube.AddComponent(); - render3DComponent.mesh = *(model->renderable->mesh); - - cube.GetComponent().Position = glm::vec3(1.0f, 0.0f, 5.0f); - - auto cube2 = scene.AddEntity("Cube2"); - auto& rendercube2 = cube2.AddComponent(); - rendercube2.mesh = *(model->renderable->mesh); - auto relationcube = cube.AddComponent(cube2); - - auto Grass = scene.AddEntity("Grass/Window-Pane"); - //auto& renderGrass = Grass.AddComponent(); - - - -} diff --git a/YoggieEngine/src/Application.cpp b/YoggieEngine/src/Application.cpp index 8baf113..a21187a 100644 --- a/YoggieEngine/src/Application.cpp +++ b/YoggieEngine/src/Application.cpp @@ -1,16 +1,37 @@ #include #include "Application.h" +#include +#include +#include +#include "../../libs/guizmo/ImGuizmo.h" + namespace YoggieEngine { Application::Application(const std::string& name) - : m_AppName(name) + : m_AppName(name), appWindow(1200, 700) { // Initialize engine should possibly happen here EngineInstrumentation::PerfomanceSamplerInit(); + // Initilize ImGui for this application + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); + io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_ViewportsEnable; + io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_DockingEnable; + io.Fonts->AddFontFromFileTTF("build/Debug/Fonts/Roboto-Regular.ttf", 18); + + ImGui::StyleColorsDark(); + + ImGui_ImplGlfw_InitForOpenGL(appWindow.GetGLFWHandle(), true); + ImGui_ImplOpenGL3_Init("#version 450"); + + ImGuizmo::SetImGuiContext(ImGui::GetCurrentContext()); + ImGuizmo::SetOrthographic(true); + init_inputSystem(&appWindow); } @@ -19,5 +40,46 @@ namespace YoggieEngine { } - Application::~Application() {} + void Application::PollEvents() { + appWindow.Poll(); + } + + void Application::SwapBuffers() + { + appWindow.SwapBuffers(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } + + void Application::GuiBegin() { + ImGui_ImplGlfw_NewFrame(); + ImGui_ImplOpenGL3_NewFrame(); + + ImGui::NewFrame(); + ImGuizmo::BeginFrame(); + ImGui::DockSpaceOverViewport(ImGui::GetMainViewport()); + } + + void Application::GuiEnd() { + ImGui::EndFrame(); + + + ImGui::Render(); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + + + if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + { + GLFWwindow* last_context = glfwGetCurrentContext(); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); + glfwMakeContextCurrent(last_context); + } + } + + Application::~Application() { + + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); + } } diff --git a/YoggieEngine/src/Application.h b/YoggieEngine/src/Application.h index 47b2db9..e8b4716 100644 --- a/YoggieEngine/src/Application.h +++ b/YoggieEngine/src/Application.h @@ -10,9 +10,17 @@ namespace YoggieEngine { ~Application(); virtual void Run(); + void PollEvents(); + + void SwapBuffers(); + + void GuiBegin(); + void GuiEnd(); + protected: std::string m_AppName; + NativeWindow appWindow; friend class ApplicationRuntime; }; diff --git a/YoggieEngine/src/Graphics/Primitives/Camera.h b/YoggieEngine/src/Graphics/Primitives/Camera.h index db6392a..438bf81 100644 --- a/YoggieEngine/src/Graphics/Primitives/Camera.h +++ b/YoggieEngine/src/Graphics/Primitives/Camera.h @@ -3,6 +3,7 @@ namespace YoggieEngine { class Camera { public: + Camera() = default; Camera(const Camera& other); Camera(glm::vec3 position, glm::vec3 rotation, float zoom); ~Camera(); diff --git a/YoggieEngine/src/Graphics/Renderer.cpp b/YoggieEngine/src/Graphics/Renderer.cpp index 09cff82..c6c27ad 100644 --- a/YoggieEngine/src/Graphics/Renderer.cpp +++ b/YoggieEngine/src/Graphics/Renderer.cpp @@ -6,7 +6,6 @@ #include "../Graphics/Memory/VertexArray.h" #include "../Graphics/Primitives/DrawCommand.h" -extern YoggieEngine::Camera cam; namespace YoggieEngine { unsigned int quadVAO = 0; unsigned int quadVBO = 0; @@ -159,10 +158,6 @@ Renderer::Renderer(RendererConfig& config) Renderer::~Renderer(){} -Camera& Renderer::getCamera() { - return cam; -} - void SubmitVegetationDemo() { @@ -250,8 +245,8 @@ void Renderer::GeometryPass() { gBufferShader.setUniformVec3("Color", command.color); gBufferShader.setUniformMat4("Model", command.transform.LocalTransform); - gBufferShader.setUniformMat4("View", cam.ViewMatrix); - gBufferShader.setUniformMat4("Projection", cam.ProjectionMatrix); + gBufferShader.setUniformMat4("View", MainCamera.ViewMatrix); + gBufferShader.setUniformMat4("Projection", MainCamera.ProjectionMatrix); glDrawElements(GL_TRIANGLES, static_cast(command.num_elements), GL_UNSIGNED_INT, NULL); @@ -266,8 +261,8 @@ void Renderer::SkyboxPass() { // Render skybox glDepthMask(GL_FALSE); SkyboxShader.Use(); - SkyboxShader.setUniformMat4("projection", cam.ProjectionMatrix); - SkyboxShader.setUniformMat4("view", glm::mat4(glm::mat3(cam.ViewMatrix))); // remove rotation from the view matrix + SkyboxShader.setUniformMat4("projection", MainCamera.ProjectionMatrix); + SkyboxShader.setUniformMat4("view", glm::mat4(glm::mat3(MainCamera.ViewMatrix))); // remove rotation from the view matrix glBindVertexArray(skyboxVAO); glBindTexture(GL_TEXTURE_CUBE_MAP, sky.getID()); glDrawArrays(GL_TRIANGLES, 0, 36); @@ -314,7 +309,7 @@ void Renderer::lightingPass(Scene& scene){ lightnr++; }); - lightingPassShader.setUniformVec3("viewPos", getCamera().Position); + lightingPassShader.setUniformVec3("viewPos", MainCamera.Position); // render to quad if (quadVAO == 0) @@ -353,8 +348,8 @@ void Renderer::BlendingPass() { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, grassTexture.GetID()); - BlendingShader.setUniformMat4("V", cam.ViewMatrix); - BlendingShader.setUniformMat4("P", cam.ProjectionMatrix); + BlendingShader.setUniformMat4("V", MainCamera.ViewMatrix); + BlendingShader.setUniformMat4("P", MainCamera.ProjectionMatrix); for (unsigned int i = 0; i < vegetation.size(); i++) { @@ -372,10 +367,6 @@ void Renderer::BlendingPass() { } - - - - void Renderer::Render(Scene& scene) { SubmitVegetationDemo(); @@ -409,8 +400,8 @@ void Renderer::Render(Scene& scene) forwardShader.setUniformVec3("Color", command.color); forwardShader.setUniformMat4("M", command.transform.LocalTransform); - forwardShader.setUniformMat4("V", cam.ViewMatrix); - forwardShader.setUniformMat4("P", cam.ProjectionMatrix); + forwardShader.setUniformMat4("V", MainCamera.ViewMatrix); + forwardShader.setUniformMat4("P", MainCamera.ProjectionMatrix); glDrawElements(GL_TRIANGLES, static_cast(command.num_elements), GL_UNSIGNED_INT, NULL); @@ -432,7 +423,6 @@ void Renderer::Render(Scene& scene) */ - commands.clear(); glBindFramebuffer(GL_FRAMEBUFFER, 0); } diff --git a/YoggieEngine/src/Graphics/Renderer.h b/YoggieEngine/src/Graphics/Renderer.h index f0bab2b..5cf2a0f 100644 --- a/YoggieEngine/src/Graphics/Renderer.h +++ b/YoggieEngine/src/Graphics/Renderer.h @@ -8,6 +8,7 @@ #include "../Scene/Components.h" #include"../Scene/Scene.h" #include "Graphics/Primitives/DrawCommand.h" +#include "Primitives/Camera.h" namespace YoggieEngine { @@ -29,8 +30,9 @@ namespace YoggieEngine { void setCurrentFrameBuffer(const Framebuffer& fb); void setClearColor(const glm::vec3& ClearColor); - Camera& getCamera(); - + void SetMainCamera(const Camera& camera) { MainCamera = camera; } + + Framebuffer& getCurrentFrameBuffer() { return m_framebuffer; } private: void GeometryPass(); void SkyboxPass(); @@ -45,7 +47,7 @@ namespace YoggieEngine { glm::vec3 m_clearColor; bool m_depthTest; std::vector commands; - + Camera MainCamera; unsigned int skyboxVAO = 0; CubeMap sky; diff --git a/YoggieEngine/src/Physics/Physics.cpp b/YoggieEngine/src/Physics/Physics.cpp index 5176a1d..1e771f0 100644 --- a/YoggieEngine/src/Physics/Physics.cpp +++ b/YoggieEngine/src/Physics/Physics.cpp @@ -28,7 +28,6 @@ namespace YoggieEngine { gMaterial = nullptr; mScene = nullptr; - } Physics::~Physics() @@ -153,6 +152,19 @@ namespace YoggieEngine { } + void Physics::addRigidBody(glm::mat4& transform) + { + PxShape* shape = mPhysics->createShape(PxBoxGeometry(1.0f, 1.0f, 1.0f), *gMaterial); + PxTransform localtm = PxTransform((const PxMat44&) transform); + PxRigidDynamic* body = mPhysics->createRigidDynamic(localtm); + body->attachShape(*shape); + PxRigidBodyExt::updateMassAndInertia(*body, 10.0f); + mScene->addActor(*body); + + } + + + void Physics::createScene() { PxSceneDesc sceneDesc(mPhysics->getTolerancesScale()); diff --git a/YoggieEngine/src/Physics/Physics.h b/YoggieEngine/src/Physics/Physics.h index c0cfadd..164dadd 100644 --- a/YoggieEngine/src/Physics/Physics.h +++ b/YoggieEngine/src/Physics/Physics.h @@ -31,17 +31,21 @@ namespace YoggieEngine { void DebugRender(Framebuffer& framebuffer); + void addRigidBody(glm::mat4& transform); + + void createScene(); + void createGroundPlane(); + + void SetupPvdDebug(); + private: Shader debugDraw = Shader("build/Debug/Shaders/forward/debug.vert", "build/Debug/Shaders/forward/debug.frag"); PxRigidDynamic* createDynamic(const PxTransform& t, const PxGeometry& geometry, const PxVec3& velocity); void createStack(const PxTransform& t, PxU32 size, PxReal halfextent); - void createScene(); - void createGroundPlane(); - - void SetupPvdDebug(); - + + // Memory Management diff --git a/YoggieEngine/src/Scene/Components.h b/YoggieEngine/src/Scene/Components.h index faa7a3e..2140d47 100644 --- a/YoggieEngine/src/Scene/Components.h +++ b/YoggieEngine/src/Scene/Components.h @@ -42,6 +42,21 @@ namespace YoggieEngine { std::string file; // TODO : replace with proper properties }; + + struct RigidBody { + float Mass; + // Physics Material + }; + + struct BoxCollider { + glm::vec3 extents; + }; + + struct PlaneCollider { + + }; + + struct Render3DComponent { unsigned int VAO = 0; unsigned int IBO = 0; diff --git a/YoggieEngine/src/Scene/Scene.cpp b/YoggieEngine/src/Scene/Scene.cpp index abede83..3e26f0a 100644 --- a/YoggieEngine/src/Scene/Scene.cpp +++ b/YoggieEngine/src/Scene/Scene.cpp @@ -26,6 +26,7 @@ namespace YoggieEngine{ void Scene::Start() { // Execute start functions in scripts etc.... + } void Scene::Update() diff --git a/YoggieEngine/src/YoggieEngine.h b/YoggieEngine/src/YoggieEngine.h index 7d78f5c..b2faf11 100644 --- a/YoggieEngine/src/YoggieEngine.h +++ b/YoggieEngine/src/YoggieEngine.h @@ -31,6 +31,7 @@ extern "C" // Main library stuff + #include "Platform/Window.h" #include "Graphics/Primitives/Mesh.h" @@ -53,3 +54,4 @@ extern "C" #include "Scene/Scene.h" #include "Scene/Components.h" #include "Application.h" +