From 660a06a5b9f6713126d7ad5bf04ddd270838fcc2 Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Sun, 2 Jun 2024 21:22:20 -0400 Subject: [PATCH 01/46] Switched to the dev branch of the engine; Made numerous naming changes for a clearer project structure; Moved the scene graph and content browser functionality into separate singleton classes for better separation of responsibilities; Added a draft of the new scene graph interface. --- CMakeLists.txt | 53 +- .../CombineChannelsToTexturePopUp.cpp | 4 +- .../CombineChannelsToTexturePopUp.h | 2 +- .../ContentBrowserWindow.cpp | 380 ++++++---- EditorWindows/ContentBrowserWindow.h | 115 +++ .../DebugTextureViewWindow.cpp | 8 +- EditorWindows/DebugTextureViewWindow.h | 14 + .../DeletePopups.cpp | 2 +- .../DeletePopups.h | 0 .../EditPopups.cpp | 18 +- .../EditPopups.h | 2 +- .../GyzmosSettingsWindow.h | 10 +- .../PrefabEditorWindow.cpp | 4 +- .../PrefabEditorWindow.h | 2 +- .../ProjectWasModifiedPopUp.cpp | 10 +- EditorWindows/ProjectWasModifiedPopUp.h | 17 + .../RenamePopups.cpp | 20 +- EditorWindows/RenamePopups.h | 26 + .../ResizeTexturePopup.cpp | 12 +- .../ResizeTexturePopup.h | 8 +- EditorWindows/SceneGraphWindow.cpp | 650 ++++++++++++++++ EditorWindows/SceneGraphWindow.h | 74 ++ .../SelectPopups.cpp | 32 +- .../SelectPopups.h | 8 +- .../ShaderEditorWindow.cpp | 26 +- .../ShaderEditorWindow.h | 14 +- FEEditor.cpp | 694 ++---------------- FEEditor.h | 334 +++------ FEEditorDragAndDropManager.cpp | 4 +- FEEditorDragAndDropManager.h | 8 +- FEEditorPreviewManager.h | 157 ++-- FEEditorSubWindows/debugTextureViewWindow.h | 14 - FEEditorSubWindows/projectWasModifiedPopUp.h | 17 - FEEditorSubWindows/renamePopups.h | 26 - FEProject.h | 2 - Resources/imgui.ini | 36 +- SubSystems/FocalEngine | 2 +- 37 files changed, 1522 insertions(+), 1283 deletions(-) rename FEEditorSubWindows/combineChannelsToTexturePopUp.cpp => EditorWindows/CombineChannelsToTexturePopUp.cpp (98%) rename FEEditorSubWindows/combineChannelsToTexturePopUp.h => EditorWindows/CombineChannelsToTexturePopUp.h (96%) rename FEEditorContentBrowser.cpp => EditorWindows/ContentBrowserWindow.cpp (58%) create mode 100644 EditorWindows/ContentBrowserWindow.h rename FEEditorSubWindows/debugTextureViewWindow.cpp => EditorWindows/DebugTextureViewWindow.cpp (84%) create mode 100644 EditorWindows/DebugTextureViewWindow.h rename FEEditorSubWindows/deletePopups.cpp => EditorWindows/DeletePopups.cpp (99%) rename FEEditorSubWindows/deletePopups.h => EditorWindows/DeletePopups.h (100%) rename FEEditorSubWindows/editPopups.cpp => EditorWindows/EditPopups.cpp (99%) rename FEEditorSubWindows/editPopups.h => EditorWindows/EditPopups.h (99%) rename FEEditorSubWindows/gyzmosSettingsWindow.h => EditorWindows/GyzmosSettingsWindow.h (93%) rename FEEditorSubWindows/prefabEditorWindow.cpp => EditorWindows/PrefabEditorWindow.cpp (98%) rename FEEditorSubWindows/prefabEditorWindow.h => EditorWindows/PrefabEditorWindow.h (94%) rename FEEditorSubWindows/projectWasModifiedPopUp.cpp => EditorWindows/ProjectWasModifiedPopUp.cpp (88%) create mode 100644 EditorWindows/ProjectWasModifiedPopUp.h rename FEEditorSubWindows/renamePopups.cpp => EditorWindows/RenamePopups.cpp (87%) create mode 100644 EditorWindows/RenamePopups.h rename FEEditorSubWindows/resizeTexturePopup.cpp => EditorWindows/ResizeTexturePopup.cpp (93%) rename FEEditorSubWindows/resizeTexturePopup.h => EditorWindows/ResizeTexturePopup.h (64%) create mode 100644 EditorWindows/SceneGraphWindow.cpp create mode 100644 EditorWindows/SceneGraphWindow.h rename FEEditorSubWindows/selectPopups.cpp => EditorWindows/SelectPopups.cpp (88%) rename FEEditorSubWindows/selectPopups.h => EditorWindows/SelectPopups.h (85%) rename FEEditorSubWindows/shaderEditorWindow.cpp => EditorWindows/ShaderEditorWindow.cpp (95%) rename FEEditorSubWindows/shaderEditorWindow.h => EditorWindows/ShaderEditorWindow.h (80%) delete mode 100644 FEEditorSubWindows/debugTextureViewWindow.h delete mode 100644 FEEditorSubWindows/projectWasModifiedPopUp.h delete mode 100644 FEEditorSubWindows/renamePopups.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1af174f..b4c963c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,6 @@ file(GLOB Editor_SRC "main.cpp" "FEEditor.cpp" "FEEditor.h" - "FEEditorContentBrowser.cpp" "FEEditorDragAndDropManager.cpp" "FEEditorDragAndDropManager.h" "FEEditorGizmoManager.cpp" @@ -68,28 +67,32 @@ file(GLOB FEDearImguiWrapper_SRC "FEDearImguiWrapper/FEDearImguiWrapper.h" ) -file(GLOB FEEditorSubWindows_SRC - "FEEditorSubWindows/deletePopups.cpp" - "FEEditorSubWindows/deletePopups.h" - "FEEditorSubWindows/editPopups.cpp" - "FEEditorSubWindows/editPopups.h" - "FEEditorSubWindows/gyzmosSettingsWindow.h" - "FEEditorSubWindows/combineChannelsToTexturePopUp.cpp" - "FEEditorSubWindows/combineChannelsToTexturePopUp.h" - "FEEditorSubWindows/projectWasModifiedPopUp.cpp" - "FEEditorSubWindows/projectWasModifiedPopUp.h" - "FEEditorSubWindows/renamePopups.cpp" - "FEEditorSubWindows/renamePopups.h" - "FEEditorSubWindows/selectPopups.cpp" - "FEEditorSubWindows/selectPopups.h" - "FEEditorSubWindows/shaderEditorWindow.cpp" - "FEEditorSubWindows/shaderEditorWindow.h" - "FEEditorSubWindows/resizeTexturePopup.cpp" - "FEEditorSubWindows/resizeTexturePopup.h" - "FEEditorSubWindows/prefabEditorWindow.cpp" - "FEEditorSubWindows/prefabEditorWindow.h" - "FEEditorSubWindows/debugTextureViewWindow.cpp" - "FEEditorSubWindows/debugTextureViewWindow.h" +file(GLOB EditorWindows_SRC + "EditorWindows/DeletePopups.cpp" + "EditorWindows/DeletePopups.h" + "EditorWindows/EditPopups.cpp" + "EditorWindows/EditPopups.h" + "EditorWindows/GyzmosSettingsWindow.h" + "EditorWindows/CombineChannelsToTexturePopUp.cpp" + "EditorWindows/CombineChannelsToTexturePopUp.h" + "EditorWindows/ProjectWasModifiedPopUp.cpp" + "EditorWindows/ProjectWasModifiedPopUp.h" + "EditorWindows/RenamePopups.cpp" + "EditorWindows/RenamePopups.h" + "EditorWindows/SelectPopups.cpp" + "EditorWindows/SelectPopups.h" + "EditorWindows/ShaderEditorWindow.cpp" + "EditorWindows/ShaderEditorWindow.h" + "EditorWindows/ResizeTexturePopup.cpp" + "EditorWindows/ResizeTexturePopup.h" + "EditorWindows/PrefabEditorWindow.cpp" + "EditorWindows/PrefabEditorWindow.h" + "EditorWindows/DebugTextureViewWindow.cpp" + "EditorWindows/DebugTextureViewWindow.h" + "EditorWindows/SceneGraphWindow.cpp" + "EditorWindows/SceneGraphWindow.h" + "EditorWindows/ContentBrowserWindow.cpp" + "EditorWindows/ContentBrowserWindow.h" ) file(GLOB Editor_Materials_SRC @@ -129,7 +132,7 @@ link_directories(${GLFW_LIB_DIR}) add_executable(FocalEngineEditor WIN32 ${Editor_SRC} ${FEDearImguiWrapper_SRC} - ${FEEditorSubWindows_SRC} + ${EditorWindows_SRC} ${Editor_Materials_SRC} ${VisualNodeSystem_CustomNodes_SRC} # *************** SUB_SYSTEM *************** @@ -145,7 +148,7 @@ source_group("Source Files" FILES ${Application_SRC}) # *************** EDITOR *************** source_group("Source Files/" FILES ${Editor_SRC}) source_group("Source Files/FEDearImguiWrapper" FILES ${FEDearImguiWrapper_SRC}) -source_group("Source Files/FEEditorSubWindows" FILES ${FEEditorSubWindows_SRC}) +source_group("Source Files/EditorWindows" FILES ${EditorWindows_SRC}) source_group("Source Files/Materials" FILES ${Editor_Materials_SRC}) source_group("Source Files/NodeSystem/CustomNodes" FILES ${VisualNodeSystem_CustomNodes_SRC}) # *************** SUB_SYSTEM *************** diff --git a/FEEditorSubWindows/combineChannelsToTexturePopUp.cpp b/EditorWindows/CombineChannelsToTexturePopUp.cpp similarity index 98% rename from FEEditorSubWindows/combineChannelsToTexturePopUp.cpp rename to EditorWindows/CombineChannelsToTexturePopUp.cpp index 461bae3..b6986ff 100644 --- a/FEEditorSubWindows/combineChannelsToTexturePopUp.cpp +++ b/EditorWindows/CombineChannelsToTexturePopUp.cpp @@ -1,4 +1,4 @@ -#include "combineChannelsToTexturePopUp.h" +#include "CombineChannelsToTexturePopUp.h" using namespace VisNodeSys; CombineChannelsToTexturePopUp* CombineChannelsToTexturePopUp::Instance = nullptr; @@ -123,7 +123,7 @@ void CombineChannelsToTexturePopUp::NodeSystemMainContextMenu() if (ImGui::MenuItem("Texture node")) { TextureForNewNode = RESOURCE_MANAGER.NoTexture; - SelectFeObjectPopUp::getInstance().Show(FE_TEXTURE, TextureNodeCreationCallback); + SelectFEObjectPopUp::getInstance().Show(FE_TEXTURE, TextureNodeCreationCallback); } if (ImGui::MenuItem("Float node")) diff --git a/FEEditorSubWindows/combineChannelsToTexturePopUp.h b/EditorWindows/CombineChannelsToTexturePopUp.h similarity index 96% rename from FEEditorSubWindows/combineChannelsToTexturePopUp.h rename to EditorWindows/CombineChannelsToTexturePopUp.h index 2204695..0defc52 100644 --- a/FEEditorSubWindows/combineChannelsToTexturePopUp.h +++ b/EditorWindows/CombineChannelsToTexturePopUp.h @@ -1,6 +1,6 @@ #pragma once -#include "gyzmosSettingsWindow.h" +#include "GyzmosSettingsWindow.h" class CombineChannelsToTexturePopUp : public FEImGuiWindow { diff --git a/FEEditorContentBrowser.cpp b/EditorWindows/ContentBrowserWindow.cpp similarity index 58% rename from FEEditorContentBrowser.cpp rename to EditorWindows/ContentBrowserWindow.cpp index 0f30607..c375dd1 100644 --- a/FEEditorContentBrowser.cpp +++ b/EditorWindows/ContentBrowserWindow.cpp @@ -1,4 +1,15 @@ -#include "FEEditor.h" +#include "ContentBrowserWindow.h" +using namespace FocalEngine; + +FEEditorContentBrowserWindow* FEEditorContentBrowserWindow::Instance = nullptr; +FEObject* FEEditorContentBrowserWindow::ItemInFocus = nullptr; + +FEEditorContentBrowserWindow::FEEditorContentBrowserWindow() +{ + strcpy_s(FilterForResources, ""); + + ENGINE.AddMouseButtonCallback(&FEEditorContentBrowserWindow::MouseButtonCallback); +} static FETexture* TempTexture = nullptr; static void AddTransparencyToTextureCallBack(const std::vector SelectionsResult) @@ -52,33 +63,68 @@ static void CreateNewPrefabCallBack(const std::vector SelectionsResul VIRTUAL_FILE_SYSTEM.CreateFile(NewPrefab, VIRTUAL_FILE_SYSTEM.GetCurrentPath()); } - SelectFeObjectPopUp::getInstance().SetOneObjectSelectonMode(true); + SelectFEObjectPopUp::getInstance().SetOneObjectSelectonMode(true); +} + +void FEEditorContentBrowserWindow::MouseButtonCallback(int Button, int Action, int Mods) +{ + ItemInFocus = nullptr; +} + +void FEEditorContentBrowserWindow::OpenItemParentFolder(FEObject* Object) +{ + VIRTUAL_FILE_SYSTEM.SetCurrentPath(VIRTUAL_FILE_SYSTEM.LocateFile(Object)); + ImGui::SetWindowFocus("Content Browser"); + strcpy_s(FilterForResources, ""); + ItemInFocus = Object; + + const auto Content = VIRTUAL_FILE_SYSTEM.GetDirectoryContent(VIRTUAL_FILE_SYSTEM.GetCurrentPath()); + size_t TotalItemCount = Content.size(); + + size_t ItemIndex = 0; + for (size_t i = 0; i < Content.size(); i++) + { + if (Content[i]->GetObjectID() == Object->GetObjectID()) + { + ItemIndex = i; + break; + } + } + + ImGuiWindow* ContentBrowserWindow = ImGui::FindWindowByName("Content Browser"); + const int IconsPerWindowWidth = (int)(ContentBrowserWindow->Rect().GetWidth() / (ItemIconSize + 8 + 32)); + const size_t ItemRow = ItemIndex / IconsPerWindowWidth; + + if (ContentBrowserWindow != nullptr) + { + ContentBrowserWindow->Scroll.y = float(ItemRow * (ItemIconSize + 8 + 8 + 32)); + } } -void FEEditor::DisplayContentBrowser() +void FEEditorContentBrowserWindow::Render() { - if (!bContentBrowserVisible) + if (!bVisible) return; ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); ImGui::Begin("Content Browser", nullptr, ImGuiWindowFlags_None); - DisplayContentBrowserItems(); + RenderFilterMenu(); - bool open_context_menu = false; + bool bOpenContextMenu = false; if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(1)) - open_context_menu = true; + bOpenContextMenu = true; - if (open_context_menu) + if (bOpenContextMenu) ImGui::OpenPopup("##context_menu"); - bShouldOpenContextMenuInContentBrowser = false; + bShouldOpenContextMenu = false; ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); if (ImGui::BeginPopup("##context_menu")) { - bShouldOpenContextMenuInContentBrowser = true; + bShouldOpenContextMenu = true; - if (ContentBrowserItemUnderMouse == -1) + if (ItemUnderMouse == -1) { if (ImGui::MenuItem("Import Asset...")) { @@ -125,12 +171,12 @@ void FEEditor::DisplayContentBrowser() const std::string NewDirectoryName = VIRTUAL_FILE_SYSTEM.CreateDirectory(VIRTUAL_FILE_SYSTEM.GetCurrentPath()); UpdateDirectoryDragAndDropTargets(); - for (size_t i = 0; i < FilteredResourcesContentBrowser.size(); i++) + for (size_t i = 0; i < FilteredResources.size(); i++) { - if (FilteredResourcesContentBrowser[i]->GetName() == NewDirectoryName) + if (FilteredResources[i]->GetName() == NewDirectoryName) { - ContentBrowserRenameIndex = int(i); - strcpy_s(ContentBrowserRename, FilteredResourcesContentBrowser[i]->GetName().size() + 1, FilteredResourcesContentBrowser[i]->GetName().c_str()); + RenameIndex = int(i); + strcpy_s(RenameBuffer, FilteredResources[i]->GetName().size() + 1, FilteredResources[i]->GetName().c_str()); bLastFrameRenameEditWasVisiable = false; break; } @@ -168,8 +214,8 @@ void FEEditor::DisplayContentBrowser() if (ImGui::MenuItem("Create new prefab")) { - SelectFeObjectPopUp::getInstance().SetOneObjectSelectonMode(false); - SelectFeObjectPopUp::getInstance().Show(FE_GAMEMODEL, CreateNewPrefabCallBack); + SelectFEObjectPopUp::getInstance().SetOneObjectSelectonMode(false); + SelectFEObjectPopUp::getInstance().Show(FE_GAMEMODEL, CreateNewPrefabCallBack); } ImGui::EndMenu(); @@ -180,9 +226,9 @@ void FEEditor::DisplayContentBrowser() std::string FullPath = VIRTUAL_FILE_SYSTEM.GetCurrentPath(); if (FullPath.back() != '/') FullPath += '/'; - FullPath += FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetName(); + FullPath += FilteredResources[ItemUnderMouse]->GetName(); - const bool ReadOnlyItem = VIRTUAL_FILE_SYSTEM.IsReadOnly(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse], FullPath); + const bool ReadOnlyItem = VIRTUAL_FILE_SYSTEM.IsReadOnly(FilteredResources[ItemUnderMouse], FullPath); if (ReadOnlyItem) ImGui::MenuItem("Read Only"); @@ -191,49 +237,49 @@ void FEEditor::DisplayContentBrowser() { if (ImGui::MenuItem("Rename")) { - ContentBrowserRenameIndex = ContentBrowserItemUnderMouse; + RenameIndex = ItemUnderMouse; - strcpy_s(ContentBrowserRename, FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetName().size() + 1, FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetName().c_str()); + strcpy_s(RenameBuffer, FilteredResources[ItemUnderMouse]->GetName().size() + 1, FilteredResources[ItemUnderMouse]->GetName().c_str()); bLastFrameRenameEditWasVisiable = false; } } - if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_MATERIAL) + if (FilteredResources[ItemUnderMouse]->GetType() == FE_MATERIAL) { if (ImGui::MenuItem("Edit")) { - EditMaterialPopup::getInstance().Show(RESOURCE_MANAGER.GetMaterial(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())); + EditMaterialPopup::getInstance().Show(RESOURCE_MANAGER.GetMaterial(FilteredResources[ItemUnderMouse]->GetObjectID())); } } - if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_GAMEMODEL) + if (FilteredResources[ItemUnderMouse]->GetType() == FE_GAMEMODEL) { if (ImGui::MenuItem("Edit")) { - EditGameModelPopup::getInstance().Show(RESOURCE_MANAGER.GetGameModel(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())); + EditGameModelPopup::getInstance().Show(RESOURCE_MANAGER.GetGameModel(FilteredResources[ItemUnderMouse]->GetObjectID())); } if (ImGui::MenuItem("Create Prefab out of this Game Model")) { - FEPrefab* NewPrefab = RESOURCE_MANAGER.CreatePrefab(RESOURCE_MANAGER.GetGameModel(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())); + FEPrefab* NewPrefab = RESOURCE_MANAGER.CreatePrefab(RESOURCE_MANAGER.GetGameModel(FilteredResources[ItemUnderMouse]->GetObjectID())); PROJECT_MANAGER.GetCurrent()->SetModified(true); VIRTUAL_FILE_SYSTEM.CreateFile(NewPrefab, VIRTUAL_FILE_SYSTEM.GetCurrentPath()); } } - if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_PREFAB) + if (FilteredResources[ItemUnderMouse]->GetType() == FE_PREFAB) { if (ImGui::MenuItem("Edit")) { - PrefabEditorWindow::getInstance().Show(RESOURCE_MANAGER.GetPrefab(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())); + PrefabEditorWindow::getInstance().Show(RESOURCE_MANAGER.GetPrefab(FilteredResources[ItemUnderMouse]->GetObjectID())); } } - if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_SHADER) + if (FilteredResources[ItemUnderMouse]->GetType() == FE_SHADER) { if (ImGui::MenuItem("Edit")) { - shaderEditorWindow::getInstance().Show(RESOURCE_MANAGER.GetShader(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())); + ShaderEditorWindow::getInstance().Show(RESOURCE_MANAGER.GetShader(FilteredResources[ItemUnderMouse]->GetObjectID())); } } @@ -241,40 +287,40 @@ void FEEditor::DisplayContentBrowser() { if (ImGui::MenuItem("Delete")) { - if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_NULL) + if (FilteredResources[ItemUnderMouse]->GetType() == FE_NULL) { - DeleteDirectoryPopup::getInstance().Show(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetName()); + DeleteDirectoryPopup::getInstance().Show(FilteredResources[ItemUnderMouse]->GetName()); } - else if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_MESH) + else if (FilteredResources[ItemUnderMouse]->GetType() == FE_MESH) { - DeleteMeshPopup::getInstance().Show(RESOURCE_MANAGER.GetMesh(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())); + DeleteMeshPopup::getInstance().Show(RESOURCE_MANAGER.GetMesh(FilteredResources[ItemUnderMouse]->GetObjectID())); } - else if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_TEXTURE) + else if (FilteredResources[ItemUnderMouse]->GetType() == FE_TEXTURE) { - DeleteTexturePopup::getInstance().Show(RESOURCE_MANAGER.GetTexture(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())); + DeleteTexturePopup::getInstance().Show(RESOURCE_MANAGER.GetTexture(FilteredResources[ItemUnderMouse]->GetObjectID())); } - else if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_MATERIAL) + else if (FilteredResources[ItemUnderMouse]->GetType() == FE_MATERIAL) { - DeleteMaterialPopup::getInstance().Show(RESOURCE_MANAGER.GetMaterial(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())); + DeleteMaterialPopup::getInstance().Show(RESOURCE_MANAGER.GetMaterial(FilteredResources[ItemUnderMouse]->GetObjectID())); } - else if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_GAMEMODEL) + else if (FilteredResources[ItemUnderMouse]->GetType() == FE_GAMEMODEL) { - DeleteGameModelPopup::getInstance().Show(RESOURCE_MANAGER.GetGameModel(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())); + DeleteGameModelPopup::getInstance().Show(RESOURCE_MANAGER.GetGameModel(FilteredResources[ItemUnderMouse]->GetObjectID())); } - else if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_PREFAB) + else if (FilteredResources[ItemUnderMouse]->GetType() == FE_PREFAB) { - DeletePrefabPopup::getInstance().Show(RESOURCE_MANAGER.GetPrefab(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())); + DeletePrefabPopup::getInstance().Show(RESOURCE_MANAGER.GetPrefab(FilteredResources[ItemUnderMouse]->GetObjectID())); } } } - if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_TEXTURE) + if (FilteredResources[ItemUnderMouse]->GetType() == FE_TEXTURE) { if (ImGui::BeginMenu("Convert")) { if (ImGui::MenuItem("Texture channels to individual textures")) { - const std::vector NewTextures = RESOURCE_MANAGER.ChannelsToFETextures(RESOURCE_MANAGER.GetTexture(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())); + const std::vector NewTextures = RESOURCE_MANAGER.ChannelsToFETextures(RESOURCE_MANAGER.GetTexture(FilteredResources[ItemUnderMouse]->GetObjectID())); PROJECT_MANAGER.GetCurrent()->AddUnSavedObject(NewTextures[0]); PROJECT_MANAGER.GetCurrent()->AddUnSavedObject(NewTextures[1]); @@ -291,8 +337,8 @@ void FEEditor::DisplayContentBrowser() if (ImGui::MenuItem("Resize")) { - FETexture* TextureToResize = RESOURCE_MANAGER.GetTexture(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID()); - resizeTexturePopup::getInstance().Show(TextureToResize); + FETexture* TextureToResize = RESOURCE_MANAGER.GetTexture(FilteredResources[ItemUnderMouse]->GetObjectID()); + ResizeTexturePopup::getInstance().Show(TextureToResize); } ImGui::EndMenu(); @@ -302,8 +348,8 @@ void FEEditor::DisplayContentBrowser() { if (ImGui::MenuItem("Choose transparency mask")) { - TempTexture = reinterpret_cast(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]); - SelectFeObjectPopUp::getInstance().Show(FE_TEXTURE, AddTransparencyToTextureCallBack); + TempTexture = reinterpret_cast(FilteredResources[ItemUnderMouse]); + SelectFEObjectPopUp::getInstance().Show(FE_TEXTURE, AddTransparencyToTextureCallBack); } ImGui::EndMenu(); @@ -311,7 +357,7 @@ void FEEditor::DisplayContentBrowser() if (ImGui::BeginMenu("Export")) { - FETexture* TextureToExport = RESOURCE_MANAGER.GetTexture(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID()); + FETexture* TextureToExport = RESOURCE_MANAGER.GetTexture(FilteredResources[ItemUnderMouse]->GetObjectID()); if (ImGui::MenuItem("as PNG")) { @@ -338,7 +384,63 @@ void FEEditor::DisplayContentBrowser() ImGui::End(); } -void FEEditor::ChooseTexturesForContentBrowserItem(FETexture*& PreviewTexture, FETexture*& SmallAdditionTypeIcon, ImVec2& UV0, ImVec2& UV1, FEObject* Item) +void FEEditorContentBrowserWindow::Clear() +{ + AllResources.clear(); + FilteredResources.clear(); + ItemUnderMouse = -1; + RenameIndex = -1; + strcpy_s(FilterForResources, ""); +} + +void FEEditorContentBrowserWindow::InitializeResources() +{ + FolderIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/folderIcon.png", "folderIcon"); + RESOURCE_MANAGER.MakeTextureStandard(FolderIcon); + + ShaderIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/shaderIcon.png", "shaderIcon"); + RESOURCE_MANAGER.MakeTextureStandard(ShaderIcon); + + VFSBackIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/VFSBackIcon.png", "VFSBackIcon"); + RESOURCE_MANAGER.MakeTextureStandard(VFSBackIcon); + + TextureIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/textureContentBrowserIcon.png", "textureContentBrowserIcon"); + RESOURCE_MANAGER.MakeTextureStandard(TextureIcon); + + MeshIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/meshContentBrowserIcon.png", "meshContentBrowserIcon"); + RESOURCE_MANAGER.MakeTextureStandard(MeshIcon); + + MaterialIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/materialContentBrowserIcon.png", "materialContentBrowserIcon"); + RESOURCE_MANAGER.MakeTextureStandard(MaterialIcon); + + GameModelIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/gameModelContentBrowserIcon.png", "gameModelContentBrowserIcon"); + RESOURCE_MANAGER.MakeTextureStandard(GameModelIcon); + + PrefabIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/prefabContentBrowserIcon.png", "prefabContentBrowserIcon"); + RESOURCE_MANAGER.MakeTextureStandard(PrefabIcon); + + AllIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/allContentBrowserIcon.png", "allIcon"); + FilterAllTypesButton = new ImGuiImageButton(AllIcon); + RESOURCE_MANAGER.MakeTextureStandard(AllIcon); + FilterAllTypesButton->SetSize(ImVec2(32, 32)); + + FilterTextureTypeButton = new ImGuiImageButton(TextureIcon); + FilterTextureTypeButton->SetSize(ImVec2(32, 32)); + + FilterMeshTypeButton = new ImGuiImageButton(MeshIcon); + FilterMeshTypeButton->SetSize(ImVec2(32, 32)); + + FilterMaterialTypeButton = new ImGuiImageButton(MaterialIcon); + FilterMaterialTypeButton->SetSize(ImVec2(32, 32)); + + FilterGameModelTypeButton = new ImGuiImageButton(GameModelIcon); + FilterGameModelTypeButton->SetSize(ImVec2(32, 32)); + + FilterPrefabTypeButton = new ImGuiImageButton(PrefabIcon); + FilterPrefabTypeButton->SetSize(ImVec2(32, 32)); +} + +void FEEditorContentBrowserWindow::ChooseTexturesItem(FETexture*& PreviewTexture, FETexture*& SmallAdditionTypeIcon, ImVec2& UV0, ImVec2& UV1, FEObject* Item) { if (Item->GetType() == FE_NULL) { @@ -376,12 +478,12 @@ void FEEditor::ChooseTexturesForContentBrowserItem(FETexture*& PreviewTexture, F UV1 = ImVec2(1.0f, 0.0f); PreviewTexture = PREVIEW_MANAGER.GetMeshPreview(Item->GetObjectID()); - SmallAdditionTypeIcon = MeshContentBrowserIcon; + SmallAdditionTypeIcon = MeshIcon; } else if (Item->GetType() == FE_TEXTURE) { PreviewTexture = RESOURCE_MANAGER.GetTexture(Item->GetObjectID()); - SmallAdditionTypeIcon = TextureContentBrowserIcon; + SmallAdditionTypeIcon = TextureIcon; } else if (Item->GetType() == FE_MATERIAL) { @@ -389,7 +491,7 @@ void FEEditor::ChooseTexturesForContentBrowserItem(FETexture*& PreviewTexture, F UV1 = ImVec2(1.0f, 0.0f); PreviewTexture = PREVIEW_MANAGER.GetMaterialPreview(Item->GetObjectID()); - SmallAdditionTypeIcon = MaterialContentBrowserIcon; + SmallAdditionTypeIcon = MaterialIcon; } else if (Item->GetType() == FE_GAMEMODEL) { @@ -397,7 +499,7 @@ void FEEditor::ChooseTexturesForContentBrowserItem(FETexture*& PreviewTexture, F UV1 = ImVec2(1.0f, 0.0f); PreviewTexture = PREVIEW_MANAGER.GetGameModelPreview(Item->GetObjectID()); - SmallAdditionTypeIcon = GameModelContentBrowserIcon; + SmallAdditionTypeIcon = GameModelIcon; } else if (Item->GetType() == FE_PREFAB) { @@ -405,11 +507,11 @@ void FEEditor::ChooseTexturesForContentBrowserItem(FETexture*& PreviewTexture, F UV1 = ImVec2(1.0f, 0.0f); PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Item->GetObjectID()); - SmallAdditionTypeIcon = PrefabContentBrowserIcon; + SmallAdditionTypeIcon = PrefabIcon; } } -void FEEditor::DisplayContentBrowserItems() +void FEEditorContentBrowserWindow::RenderFilterMenu() { ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); @@ -420,7 +522,7 @@ void FEEditor::DisplayContentBrowserItems() if (ImGui::ImageButton((void*)(intptr_t)VFSBackIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) { VIRTUAL_FILE_SYSTEM.SetCurrentPath(VIRTUAL_FILE_SYSTEM.GetDirectoryParent(VIRTUAL_FILE_SYSTEM.GetCurrentPath())); - strcpy_s(FilterForResourcesContentBrowser, ""); + strcpy_s(FilterForResources, ""); } VFSBackButtonTarget->StickToItem(); @@ -429,8 +531,8 @@ void FEEditor::DisplayContentBrowserItems() ImGui::PopStyleColor(); static std::string LastFramePath; - AllResourcesContentBrowser.clear(); - AllResourcesContentBrowser = VIRTUAL_FILE_SYSTEM.GetDirectoryContent(VIRTUAL_FILE_SYSTEM.GetCurrentPath()); + AllResources.clear(); + AllResources = VIRTUAL_FILE_SYSTEM.GetDirectoryContent(VIRTUAL_FILE_SYSTEM.GetCurrentPath()); ImGui::SetCursorPosX(100); ImGui::SetCursorPosY(CurrentY + 5); @@ -438,45 +540,45 @@ void FEEditor::DisplayContentBrowserItems() ImGui::SetCursorPosX(120 + 140); ImGui::SetCursorPosY(CurrentY - 5); - ObjTypeFilterForResourcesContentBrowser.empty() ? SetSelectedStyle(FilterAllTypesButton) : SetDefaultStyle(FilterAllTypesButton); + ObjTypeFilterForResources.empty() ? SetSelectedStyle(FilterAllTypesButton) : SetDefaultStyle(FilterAllTypesButton); FilterAllTypesButton->Render(); if (FilterAllTypesButton->IsClicked()) - ObjTypeFilterForResourcesContentBrowser = ""; + ObjTypeFilterForResources = ""; ImGui::SetCursorPosX(120 + 140 + 48); ImGui::SetCursorPosY(CurrentY - 5); - ObjTypeFilterForResourcesContentBrowser == FEObjectTypeToString(FE_TEXTURE) ? SetSelectedStyle(FilterTextureTypeButton) : SetDefaultStyle(FilterTextureTypeButton); + ObjTypeFilterForResources == FEObjectTypeToString(FE_TEXTURE) ? SetSelectedStyle(FilterTextureTypeButton) : SetDefaultStyle(FilterTextureTypeButton); FilterTextureTypeButton->Render(); if (FilterTextureTypeButton->IsClicked()) - ObjTypeFilterForResourcesContentBrowser = FEObjectTypeToString(FE_TEXTURE); + ObjTypeFilterForResources = FEObjectTypeToString(FE_TEXTURE); ImGui::SetCursorPosX(120 + 140 + 48 + 48); ImGui::SetCursorPosY(CurrentY - 5); - ObjTypeFilterForResourcesContentBrowser == FEObjectTypeToString(FE_MESH) ? SetSelectedStyle(FilterMeshTypeButton) : SetDefaultStyle(FilterMeshTypeButton); + ObjTypeFilterForResources == FEObjectTypeToString(FE_MESH) ? SetSelectedStyle(FilterMeshTypeButton) : SetDefaultStyle(FilterMeshTypeButton); FilterMeshTypeButton->Render(); if (FilterMeshTypeButton->IsClicked()) - ObjTypeFilterForResourcesContentBrowser = FEObjectTypeToString(FE_MESH); + ObjTypeFilterForResources = FEObjectTypeToString(FE_MESH); ImGui::SetCursorPosX(120 + 140 + 48 + 48 + 48); ImGui::SetCursorPosY(CurrentY - 5); - ObjTypeFilterForResourcesContentBrowser == FEObjectTypeToString(FE_MATERIAL) ? SetSelectedStyle(FilterMaterialTypeButton) : SetDefaultStyle(FilterMaterialTypeButton); + ObjTypeFilterForResources == FEObjectTypeToString(FE_MATERIAL) ? SetSelectedStyle(FilterMaterialTypeButton) : SetDefaultStyle(FilterMaterialTypeButton); FilterMaterialTypeButton->Render(); if (FilterMaterialTypeButton->IsClicked()) - ObjTypeFilterForResourcesContentBrowser = FEObjectTypeToString(FE_MATERIAL); + ObjTypeFilterForResources = FEObjectTypeToString(FE_MATERIAL); ImGui::SetCursorPosX(120 + 140 + 48 + 48 + 48 + 48); ImGui::SetCursorPosY(CurrentY - 5); - ObjTypeFilterForResourcesContentBrowser == FEObjectTypeToString(FE_GAMEMODEL) ? SetSelectedStyle(FilterGameModelTypeButton) : SetDefaultStyle(FilterGameModelTypeButton); + ObjTypeFilterForResources == FEObjectTypeToString(FE_GAMEMODEL) ? SetSelectedStyle(FilterGameModelTypeButton) : SetDefaultStyle(FilterGameModelTypeButton); FilterGameModelTypeButton->Render(); if (FilterGameModelTypeButton->IsClicked()) - ObjTypeFilterForResourcesContentBrowser = FEObjectTypeToString(FE_GAMEMODEL); + ObjTypeFilterForResources = FEObjectTypeToString(FE_GAMEMODEL); ImGui::SetCursorPosX(120 + 140 + 48 + 48 + 48 + 48 + 48); ImGui::SetCursorPosY(CurrentY - 5); - ObjTypeFilterForResourcesContentBrowser == FEObjectTypeToString(FE_PREFAB) ? SetSelectedStyle(FilterPrefabTypeButton) : SetDefaultStyle(FilterPrefabTypeButton); + ObjTypeFilterForResources == FEObjectTypeToString(FE_PREFAB) ? SetSelectedStyle(FilterPrefabTypeButton) : SetDefaultStyle(FilterPrefabTypeButton); FilterPrefabTypeButton->Render(); if (FilterPrefabTypeButton->IsClicked()) - ObjTypeFilterForResourcesContentBrowser = FEObjectTypeToString(FE_PREFAB); + ObjTypeFilterForResources = FEObjectTypeToString(FE_PREFAB); ImGui::SetCursorPosX(100); ImGui::SetCursorPosY(CurrentY + 50); @@ -484,12 +586,12 @@ void FEEditor::DisplayContentBrowserItems() ImGui::SetCursorPosX(120 + 140); ImGui::SetCursorPosY(CurrentY + 47); - ImGui::InputText("##filter", FilterForResourcesContentBrowser, IM_ARRAYSIZE(FilterForResourcesContentBrowser)); + ImGui::InputText("##filter", FilterForResources, IM_ARRAYSIZE(FilterForResources)); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 25); ImGui::Separator(); - UpdateFilterForResourcesContentBrowser(); + UpdateFilterForResources(); UpdateDirectoryDragAndDropTargets(); // ************** Drag&Drop ************** @@ -501,20 +603,20 @@ void FEEditor::DisplayContentBrowserItems() int DirectoryIndex = 0; // ************** Drag&Drop END ************** - int IconsPerWindowWidth = (int)(ImGui::GetCurrentContext()->CurrentWindow->Rect().GetWidth() / (ContentBrowserItemIconSize + 8 + 32)); + int IconsPerWindowWidth = (int)(ImGui::GetCurrentContext()->CurrentWindow->Rect().GetWidth() / (ItemIconSize + 8 + 32)); // Possibly window is minimized anyway ImGui::Columns can't take 0 as columns count! if (IconsPerWindowWidth == 0) return; - if (!bShouldOpenContextMenuInContentBrowser) ContentBrowserItemUnderMouse = -1; + if (!bShouldOpenContextMenu) ItemUnderMouse = -1; ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5); ImGui::Columns(IconsPerWindowWidth, "mycolumns3", false); - for (size_t i = 0; i < FilteredResourcesContentBrowser.size(); i++) + for (size_t i = 0; i < FilteredResources.size(); i++) { - ImGui::PushID(int(std::hash{}(FilteredResourcesContentBrowser[i]->GetObjectID()))); + ImGui::PushID(int(std::hash{}(FilteredResources[i]->GetObjectID()))); - if (ItemInFocus != nullptr && ItemInFocus->GetObjectID() == FilteredResourcesContentBrowser[i]->GetObjectID()) + if (ItemInFocus != nullptr && ItemInFocus->GetObjectID() == FilteredResources[i]->GetObjectID()) { ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.1f, 1.0f, 0.1f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor(0.1f, 1.0f, 0.1f, 1.0f)); @@ -533,39 +635,39 @@ void FEEditor::DisplayContentBrowserItems() FETexture* PreviewTexture = nullptr; FETexture* SmallAdditionTypeIcon = nullptr; - ChooseTexturesForContentBrowserItem(PreviewTexture, SmallAdditionTypeIcon, uv0, uv1, FilteredResourcesContentBrowser[i]); + ChooseTexturesItem(PreviewTexture, SmallAdditionTypeIcon, uv0, uv1, FilteredResources[i]); if (PreviewTexture != nullptr) - ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(ContentBrowserItemIconSize, ContentBrowserItemIconSize), uv0, uv1, 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f)); + ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(ItemIconSize, ItemIconSize), uv0, uv1, 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f)); - if (FilteredResourcesContentBrowser[i]->GetType() == FE_NULL && ContentBrowserDirectoriesTargets.size() > (size_t)DirectoryIndex) - ContentBrowserDirectoriesTargets[DirectoryIndex++]->StickToItem(); + if (FilteredResources[i]->GetType() == FE_NULL && DirectoriesTargets.size() > (size_t)DirectoryIndex) + DirectoriesTargets[DirectoryIndex++]->StickToItem(); if (ImGui::IsItemHovered()) { - if (!bShouldOpenContextMenuInContentBrowser && !DRAG_AND_DROP_MANAGER.ObjectIsDraged()) + if (!bShouldOpenContextMenu && !DRAG_AND_DROP_MANAGER.ObjectIsDraged()) { std::string AdditionalTypeInfo; - if (FilteredResourcesContentBrowser[i]->GetType() == FE_TEXTURE) + if (FilteredResources[i]->GetType() == FE_TEXTURE) { AdditionalTypeInfo += "\nTexture type: "; - AdditionalTypeInfo += FETexture::TextureInternalFormatToString(RESOURCE_MANAGER.GetTexture(FilteredResourcesContentBrowser[i]->GetObjectID())->GetInternalFormat()); + AdditionalTypeInfo += FETexture::TextureInternalFormatToString(RESOURCE_MANAGER.GetTexture(FilteredResources[i]->GetObjectID())->GetInternalFormat()); } ImGui::BeginTooltip(); ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); - ImGui::TextUnformatted(("Name: " + FilteredResourcesContentBrowser[i]->GetName() + - "\nType: " + FEObjectTypeToString(FilteredResourcesContentBrowser[i]->GetType()) + + ImGui::TextUnformatted(("Name: " + FilteredResources[i]->GetName() + + "\nType: " + FEObjectTypeToString(FilteredResources[i]->GetType()) + AdditionalTypeInfo + "\nPath: " + VIRTUAL_FILE_SYSTEM.GetCurrentPath() ).c_str()); ImGui::PopTextWrapPos(); ImGui::EndTooltip(); - ContentBrowserItemUnderMouse = int(i); + ItemUnderMouse = int(i); if (ImGui::IsMouseDragging(0)) - DRAG_AND_DROP_MANAGER.SetObject(FilteredResourcesContentBrowser[i], PreviewTexture, uv0, uv1); + DRAG_AND_DROP_MANAGER.SetObjectToDrag(FilteredResources[i], PreviewTexture, uv0, uv1); } } @@ -583,7 +685,7 @@ void FEEditor::DisplayContentBrowserItems() ImGui::PopID(); - if (ContentBrowserRenameIndex == i) + if (RenameIndex == i) { if (!bLastFrameRenameEditWasVisiable) { @@ -593,84 +695,84 @@ void FEEditor::DisplayContentBrowserItems() bLastFrameRenameEditWasVisiable = true; } - ImGui::SetNextItemWidth(ContentBrowserItemIconSize + 8.0f + 8.0f); - if (ImGui::InputText("##newNameEditor", ContentBrowserRename, IM_ARRAYSIZE(ContentBrowserRename), ImGuiInputTextFlags_EnterReturnsTrue) || + ImGui::SetNextItemWidth(ItemIconSize + 8.0f + 8.0f); + if (ImGui::InputText("##newNameEditor", RenameBuffer, IM_ARRAYSIZE(RenameBuffer), ImGuiInputTextFlags_EnterReturnsTrue) || ImGui::IsMouseClicked(0) && !ImGui::IsItemHovered() || ImGui::GetFocusID() != ImGui::GetID("##newNameEditor")) { - if (FilteredResourcesContentBrowser[ContentBrowserRenameIndex]->GetType() == FE_NULL) + if (FilteredResources[RenameIndex]->GetType() == FE_NULL) { std::string PathToDirectory = VIRTUAL_FILE_SYSTEM.GetCurrentPath(); if (PathToDirectory.back() != '/') PathToDirectory += '/'; - PathToDirectory += FilteredResourcesContentBrowser[ContentBrowserRenameIndex]->GetName(); - VIRTUAL_FILE_SYSTEM.RenameDirectory(ContentBrowserRename, PathToDirectory); + PathToDirectory += FilteredResources[RenameIndex]->GetName(); + VIRTUAL_FILE_SYSTEM.RenameDirectory(RenameBuffer, PathToDirectory); UpdateDirectoryDragAndDropTargets(); } else { - FilteredResourcesContentBrowser[ContentBrowserRenameIndex]->SetDirtyFlag(true); + FilteredResources[RenameIndex]->SetDirtyFlag(true); PROJECT_MANAGER.GetCurrent()->SetModified(true); - FilteredResourcesContentBrowser[ContentBrowserRenameIndex]->SetName(ContentBrowserRename); + FilteredResources[RenameIndex]->SetName(RenameBuffer); } - ContentBrowserRenameIndex = -1; + RenameIndex = -1; } } else { - ImVec2 TextSize = ImGui::CalcTextSize(FilteredResourcesContentBrowser[i]->GetName().c_str()); - if (TextSize.x < ContentBrowserItemIconSize + 8 + 8) + ImVec2 TextSize = ImGui::CalcTextSize(FilteredResources[i]->GetName().c_str()); + if (TextSize.x < ItemIconSize + 8 + 8) { - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (ContentBrowserItemIconSize + 8.0f + 8.0f) / 2.0f - TextSize.x / 2.0f); - ImGui::Text(FilteredResourcesContentBrowser[i]->GetName().c_str()); + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (ItemIconSize + 8.0f + 8.0f) / 2.0f - TextSize.x / 2.0f); + ImGui::Text(FilteredResources[i]->GetName().c_str()); } else { - ImGui::Text(FilteredResourcesContentBrowser[i]->GetName().c_str()); + ImGui::Text(FilteredResources[i]->GetName().c_str()); } } ImGui::NextColumn(); } - if (ImGui::IsMouseDoubleClicked(0) && ContentBrowserItemUnderMouse != -1) + if (ImGui::IsMouseDoubleClicked(0) && ItemUnderMouse != -1) { - if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_NULL) + if (FilteredResources[ItemUnderMouse]->GetType() == FE_NULL) { std::string CurrentPath = VIRTUAL_FILE_SYSTEM.GetCurrentPath(); if (CurrentPath.back() != '/') CurrentPath += '/'; - CurrentPath += FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetName(); + CurrentPath += FilteredResources[ItemUnderMouse]->GetName(); VIRTUAL_FILE_SYSTEM.SetCurrentPath(CurrentPath); } - else if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_MESH) + else if (FilteredResources[ItemUnderMouse]->GetType() == FE_MESH) { std::string MeshInfo = "Vertex count: "; - MeshInfo += std::to_string(RESOURCE_MANAGER.GetMesh(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())->GetVertexCount()); + MeshInfo += std::to_string(RESOURCE_MANAGER.GetMesh(FilteredResources[ItemUnderMouse]->GetObjectID())->GetVertexCount()); MeshInfo += "\n"; MeshInfo += "Sub material socket: "; - MeshInfo += RESOURCE_MANAGER.GetMesh(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())->GetMaterialCount() == 2 ? "Yes" : "No"; + MeshInfo += RESOURCE_MANAGER.GetMesh(FilteredResources[ItemUnderMouse]->GetObjectID())->GetMaterialCount() == 2 ? "Yes" : "No"; MessagePopUp::getInstance().Show("Mesh info", MeshInfo.c_str()); } - else if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_MATERIAL) + else if (FilteredResources[ItemUnderMouse]->GetType() == FE_MATERIAL) { - EditMaterialPopup::getInstance().Show(RESOURCE_MANAGER.GetMaterial(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())); + EditMaterialPopup::getInstance().Show(RESOURCE_MANAGER.GetMaterial(FilteredResources[ItemUnderMouse]->GetObjectID())); } - else if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_GAMEMODEL) + else if (FilteredResources[ItemUnderMouse]->GetType() == FE_GAMEMODEL) { - if (!bShouldOpenContextMenuInContentBrowser && !EditGameModelPopup::getInstance().IsVisible()) + if (!bShouldOpenContextMenu && !EditGameModelPopup::getInstance().IsVisible()) { - EditGameModelPopup::getInstance().Show(RESOURCE_MANAGER.GetGameModel(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())); + EditGameModelPopup::getInstance().Show(RESOURCE_MANAGER.GetGameModel(FilteredResources[ItemUnderMouse]->GetObjectID())); } } - else if (FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetType() == FE_PREFAB) + else if (FilteredResources[ItemUnderMouse]->GetType() == FE_PREFAB) { - if (!bShouldOpenContextMenuInContentBrowser && !PrefabEditorWindow::getInstance().IsVisible()) + if (!bShouldOpenContextMenu && !PrefabEditorWindow::getInstance().IsVisible()) { - PrefabEditorWindow::getInstance().Show(RESOURCE_MANAGER.GetPrefab(FilteredResourcesContentBrowser[ContentBrowserItemUnderMouse]->GetObjectID())); + PrefabEditorWindow::getInstance().Show(RESOURCE_MANAGER.GetPrefab(FilteredResources[ItemUnderMouse]->GetObjectID())); } } } @@ -678,20 +780,20 @@ void FEEditor::DisplayContentBrowserItems() ImGui::Columns(1); } -void FEEditor::UpdateDirectoryDragAndDropTargets() +void FEEditorContentBrowserWindow::UpdateDirectoryDragAndDropTargets() { - ContentBrowserDirectoriesTargets.clear(); + DirectoriesTargets.clear(); DirectoryDragAndDropInfo.clear(); - AllResourcesContentBrowser.clear(); - AllResourcesContentBrowser = VIRTUAL_FILE_SYSTEM.GetDirectoryContent(VIRTUAL_FILE_SYSTEM.GetCurrentPath()); + AllResources.clear(); + AllResources = VIRTUAL_FILE_SYSTEM.GetDirectoryContent(VIRTUAL_FILE_SYSTEM.GetCurrentPath()); - UpdateFilterForResourcesContentBrowser(); + UpdateFilterForResources(); DirectoryDragAndDropInfo.resize(VIRTUAL_FILE_SYSTEM.SubDirectoriesCount(VIRTUAL_FILE_SYSTEM.GetCurrentPath())); int SubDirectoryIndex = 0; - for (size_t i = 0; i < FilteredResourcesContentBrowser.size(); i++) + for (size_t i = 0; i < FilteredResources.size(); i++) { - if (FilteredResourcesContentBrowser[i]->GetType() == FE_NULL) + if (FilteredResources[i]->GetType() == FE_NULL) { DirectoryDragAndDropCallbackInfo info; @@ -699,10 +801,10 @@ void FEEditor::UpdateDirectoryDragAndDropTargets() if (VIRTUAL_FILE_SYSTEM.GetCurrentPath().back() != '/') info.DirectoryPath += "/"; - info.DirectoryPath += FilteredResourcesContentBrowser[i]->GetName() + "/"; + info.DirectoryPath += FilteredResources[i]->GetName() + "/"; DirectoryDragAndDropInfo[SubDirectoryIndex] = info; - ContentBrowserDirectoriesTargets.push_back(DRAG_AND_DROP_MANAGER.AddTarget(std::vector { FE_NULL, FE_SHADER, FE_TEXTURE, FE_MESH, FE_MATERIAL, FE_GAMEMODEL, FE_PREFAB }, + DirectoriesTargets.push_back(DRAG_AND_DROP_MANAGER.AddTarget(std::vector { FE_NULL, FE_SHADER, FE_TEXTURE, FE_MESH, FE_MATERIAL, FE_GAMEMODEL, FE_PREFAB }, DirectoryDragAndDropCallback, reinterpret_cast(&DirectoryDragAndDropInfo[SubDirectoryIndex]), std::vector { "Drop to move to folder", "Drop to move to folder", "Drop to move to folder", "Drop to move to folder", "Drop to move to folder", "Drop to move to folder", "Drop to move to folder" })); SubDirectoryIndex++; @@ -723,40 +825,40 @@ void FEEditor::UpdateDirectoryDragAndDropTargets() } } -void FEEditor::UpdateFilterForResourcesContentBrowser() +void FEEditorContentBrowserWindow::UpdateFilterForResources() { - FilteredResourcesContentBrowser.clear(); + FilteredResources.clear(); // Filter by name. - if (strlen(FilterForResourcesContentBrowser) == 0) + if (strlen(FilterForResources) == 0) { - FilteredResourcesContentBrowser = AllResourcesContentBrowser; + FilteredResources = AllResources; } else { - for (size_t i = 0; i < AllResourcesContentBrowser.size(); i++) + for (size_t i = 0; i < AllResources.size(); i++) { - if (AllResourcesContentBrowser[i]->GetName().find(FilterForResourcesContentBrowser) != -1) + if (AllResources[i]->GetName().find(FilterForResources) != -1) { - FilteredResourcesContentBrowser.push_back(AllResourcesContentBrowser[i]); + FilteredResources.push_back(AllResources[i]); } } } // Filter by type. - if (!ObjTypeFilterForResourcesContentBrowser.empty()) + if (!ObjTypeFilterForResources.empty()) { std::vector FinalFilteredList; - for (size_t i = 0; i < FilteredResourcesContentBrowser.size(); i++) + for (size_t i = 0; i < FilteredResources.size(); i++) { - if (FEObjectTypeToString(FilteredResourcesContentBrowser[i]->GetType()) == ObjTypeFilterForResourcesContentBrowser || + if (FEObjectTypeToString(FilteredResources[i]->GetType()) == ObjTypeFilterForResources || // Add folders - FilteredResourcesContentBrowser[i]->GetType() == FE_NULL) + FilteredResources[i]->GetType() == FE_NULL) { - FinalFilteredList.push_back(FilteredResourcesContentBrowser[i]); + FinalFilteredList.push_back(FilteredResources[i]); } } - FilteredResourcesContentBrowser = FinalFilteredList; + FilteredResources = FinalFilteredList; } } \ No newline at end of file diff --git a/EditorWindows/ContentBrowserWindow.h b/EditorWindows/ContentBrowserWindow.h new file mode 100644 index 0000000..7e2a8bd --- /dev/null +++ b/EditorWindows/ContentBrowserWindow.h @@ -0,0 +1,115 @@ +#pragma once + +#include "SceneGraphWindow.h" +//using namespace FocalEngine; + +//namespace FocalEngine +//{ +#ifdef FE_WIN_32 + const COMDLG_FILTERSPEC OBJ_LOAD_FILTER[] = + { + { L"Wavefront OBJ files (*.obj)", L"*.obj" } + }; + + const COMDLG_FILTERSPEC TEXTURE_LOAD_FILTER[] = + { + { L"Image files (*.png; *.jpg; *.bmp)", L"*.png;*.jpg;*.bmp" } + }; + + const COMDLG_FILTERSPEC ALL_IMPORT_LOAD_FILTER[] = + { + { L"All files (*.png; *.jpg; *.bmp; *.obj)", L"*.png;*.jpg;*.bmp;*.obj" }, + { L"Image files (*.png; *.jpg; *.bmp)", L"*.png;*.jpg;*.bmp" }, + { L"Wavefront OBJ files (*.obj)", L"*.obj" } + }; +#endif + + class FEEditorContentBrowserWindow + { + friend class FEEditor; + SINGLETON_PRIVATE_PART(FEEditorContentBrowserWindow) + + // Visibility and state + bool bVisible = true; + bool bShouldOpenContextMenu = false; + + // Callbacks and rendering + static void MouseButtonCallback(int Button, int Action, int Mods); + void Render(); + void RenderFilterMenu(); + void Clear(); + + // Resource initialization and icons + void InitializeResources(); + FETexture* FolderIcon = nullptr; + FETexture* ShaderIcon = nullptr; + FETexture* VFSBackIcon = nullptr; + FETexture* TextureIcon = nullptr; + FETexture* MeshIcon = nullptr; + FETexture* MaterialIcon = nullptr; + FETexture* GameModelIcon = nullptr; + FETexture* PrefabIcon = nullptr; + FETexture* AllIcon = nullptr; + + // Item selection and manipulation + void ChooseTexturesItem(FETexture*& PreviewTexture, FETexture*& SmallAdditionTypeIcon, ImVec2& UV0, ImVec2& UV1, FEObject* Item); + void OpenItemParentFolder(FEObject* Object); + + // Item properties and renaming + float ItemIconSize = 128.0; + int ItemUnderMouse = -1; + int RenameIndex = -1; + char RenameBuffer[1024]; + bool bLastFrameRenameEditWasVisiable = false; + static FEObject* ItemInFocus; + + // Resource filtering + std::vector AllResources; + std::vector FilteredResources; + char FilterForResources[512]; + std::string ObjTypeFilterForResources; + void UpdateFilterForResources(); + + // Filter buttons + ImGuiImageButton* FilterAllTypesButton = nullptr; + ImGuiImageButton* FilterTextureTypeButton = nullptr; + ImGuiImageButton* FilterMeshTypeButton = nullptr; + ImGuiImageButton* FilterMaterialTypeButton = nullptr; + ImGuiImageButton* FilterGameModelTypeButton = nullptr; + ImGuiImageButton* FilterPrefabTypeButton = nullptr; + + // Drag and drop + struct DirectoryDragAndDropCallbackInfo + { + std::string DirectoryPath; + }; + std::vector DirectoryDragAndDropInfo; + std::vector DirectoriesTargets; + DragAndDropTarget* VFSBackButtonTarget = nullptr; + DirectoryDragAndDropCallbackInfo VFSBackButtoninfo; + + static bool DirectoryDragAndDropCallback(FEObject* Object, void** Directory) + { + const DirectoryDragAndDropCallbackInfo* info = reinterpret_cast(Directory); + if (Object->GetType() == FE_NULL) + { + std::string OldPath = VIRTUAL_FILE_SYSTEM.GetCurrentPath(); + if (OldPath.back() != '/') + OldPath += "/"; + VIRTUAL_FILE_SYSTEM.MoveDirectory(OldPath + Object->GetName(), info->DirectoryPath); + } + else + { + VIRTUAL_FILE_SYSTEM.MoveFile(Object, VIRTUAL_FILE_SYSTEM.GetCurrentPath(), info->DirectoryPath); + } + return true; + } + + void UpdateDirectoryDragAndDropTargets(); + + public: + SINGLETON_PUBLIC_PART(FEEditorContentBrowserWindow) + }; + +#define CONTENT_BROWSER_WINDOW FEEditorContentBrowserWindow::getInstance() +//} \ No newline at end of file diff --git a/FEEditorSubWindows/debugTextureViewWindow.cpp b/EditorWindows/DebugTextureViewWindow.cpp similarity index 84% rename from FEEditorSubWindows/debugTextureViewWindow.cpp rename to EditorWindows/DebugTextureViewWindow.cpp index 02458d9..99fb395 100644 --- a/FEEditorSubWindows/debugTextureViewWindow.cpp +++ b/EditorWindows/DebugTextureViewWindow.cpp @@ -1,6 +1,6 @@ -#include "debugTextureViewWindow.h" +#include "DebugTextureViewWindow.h" -debugTextureViewWindow::debugTextureViewWindow(std::function Func) +DebugTextureViewWindow::DebugTextureViewWindow(std::function Func) { TextureToView = Func; @@ -17,13 +17,13 @@ debugTextureViewWindow::debugTextureViewWindow(std::function Func CloseButton->SetPosition(ImVec2(800.0 / 2.0 - 140.0 / 2.0, 800.0 - 35.0)); } -debugTextureViewWindow::~debugTextureViewWindow() +DebugTextureViewWindow::~DebugTextureViewWindow() { if (CloseButton != nullptr) delete CloseButton; } -void debugTextureViewWindow::Render() +void DebugTextureViewWindow::Render() { FEImGuiWindow::Render(); diff --git a/EditorWindows/DebugTextureViewWindow.h b/EditorWindows/DebugTextureViewWindow.h new file mode 100644 index 0000000..1365a16 --- /dev/null +++ b/EditorWindows/DebugTextureViewWindow.h @@ -0,0 +1,14 @@ +#pragma once + +#include "PrefabEditorWindow.h" + +class DebugTextureViewWindow : public FEImGuiWindow +{ + ImGuiButton* CloseButton = nullptr; + std::function TextureToView; +public: + DebugTextureViewWindow(std::function Func); + ~DebugTextureViewWindow(); + + void Render() override; +}; \ No newline at end of file diff --git a/FEEditorSubWindows/deletePopups.cpp b/EditorWindows/DeletePopups.cpp similarity index 99% rename from FEEditorSubWindows/deletePopups.cpp rename to EditorWindows/DeletePopups.cpp index 411b94f..a3e43bf 100644 --- a/FEEditorSubWindows/deletePopups.cpp +++ b/EditorWindows/DeletePopups.cpp @@ -1,4 +1,4 @@ -#include "deletePopups.h" +#include "DeletePopups.h" DeleteTexturePopup* DeleteTexturePopup::Instance = nullptr; diff --git a/FEEditorSubWindows/deletePopups.h b/EditorWindows/DeletePopups.h similarity index 100% rename from FEEditorSubWindows/deletePopups.h rename to EditorWindows/DeletePopups.h diff --git a/FEEditorSubWindows/editPopups.cpp b/EditorWindows/EditPopups.cpp similarity index 99% rename from FEEditorSubWindows/editPopups.cpp rename to EditorWindows/EditPopups.cpp index a014345..ec2c57b 100644 --- a/FEEditorSubWindows/editPopups.cpp +++ b/EditorWindows/EditPopups.cpp @@ -1,4 +1,4 @@ -#include "editPopups.h" +#include "EditPopups.h" EditGameModelPopup* EditGameModelPopup::Instance = nullptr; FEMesh** EditGameModelPopup::MeshToModify = nullptr; @@ -399,7 +399,7 @@ void EditGameModelPopup::Render() UpdatedLODMeshs[0] = TempModel->GetLODMesh(0); MeshToModify = &UpdatedLODMeshs[0]; - SelectFeObjectPopUp::getInstance().Show(FE_MESH, ChangeMeshCallBack, UpdatedLODMeshs[0]); + SelectFEObjectPopUp::getInstance().Show(FE_MESH, ChangeMeshCallBack, UpdatedLODMeshs[0]); } TextSize = ImGui::CalcTextSize("Material component:"); @@ -416,7 +416,7 @@ void EditGameModelPopup::Render() UpdatedMaterial = TempModel->GetMaterial(); MaterialToModify = &UpdatedMaterial; - SelectFeObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialCallBack, UpdatedMaterial); + SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialCallBack, UpdatedMaterial); } } else if (CurrentMode == HAS_LOD_MODE) @@ -441,7 +441,7 @@ void EditGameModelPopup::Render() UpdatedLODMeshs[i] = TempModel->GetLODMesh(i); MeshToModify = &UpdatedLODMeshs[i]; - SelectFeObjectPopUp::getInstance().Show(FE_MESH, ChangeMeshCallBack, UpdatedLODMeshs[i]); + SelectFEObjectPopUp::getInstance().Show(FE_MESH, ChangeMeshCallBack, UpdatedLODMeshs[i]); } AddBillboard->SetPosition(ImVec2(CurrentXPosition - AddBillboard->GetSize().x / 2, CurrentY + 210.0f + 128.0f / 2.0f + 10.0f / 2.0f)); @@ -499,7 +499,7 @@ void EditGameModelPopup::Render() UpdatedLODMeshs[i] = TempModel->GetLODMesh(i); MeshToModify = &UpdatedLODMeshs[i]; - SelectFeObjectPopUp::getInstance().Show(FE_MESH, ChangeMeshCallBack, UpdatedLODMeshs[i]); + SelectFEObjectPopUp::getInstance().Show(FE_MESH, ChangeMeshCallBack, UpdatedLODMeshs[i]); } } @@ -523,7 +523,7 @@ void EditGameModelPopup::Render() if (ChangeMaterialButton->IsClicked()) { MaterialToModify = &UpdatedMaterial; - SelectFeObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialCallBack, UpdatedMaterial); + SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialCallBack, UpdatedMaterial); } TextSize = ImGui::CalcTextSize("Billboard Material component:"); @@ -554,7 +554,7 @@ void EditGameModelPopup::Render() } BillboardMaterialToModify = &UpdatedBillboardMaterial; - SelectFeObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeBillboardMaterialCallBack, UpdatedBillboardMaterial, FinalMaterialList); + SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeBillboardMaterialCallBack, UpdatedBillboardMaterial, FinalMaterialList); } } else @@ -572,7 +572,7 @@ void EditGameModelPopup::Render() if (ChangeMaterialButton->IsClicked()) { MaterialToModify = &UpdatedMaterial; - SelectFeObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialCallBack, UpdatedMaterial); + SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialCallBack, UpdatedMaterial); } } @@ -1671,7 +1671,7 @@ void EditMaterialPopup::NodeSystemMainContextMenu() { TextureForNewNode = RESOURCE_MANAGER.NoTexture; - SelectFeObjectPopUp::getInstance().Show(FE_TEXTURE, TextureNodeCreationCallback); + SelectFEObjectPopUp::getInstance().Show(FE_TEXTURE, TextureNodeCreationCallback); } if (ImGui::MenuItem("Float node")) diff --git a/FEEditorSubWindows/editPopups.h b/EditorWindows/EditPopups.h similarity index 99% rename from FEEditorSubWindows/editPopups.h rename to EditorWindows/EditPopups.h index de79ce4..03ae62a 100644 --- a/FEEditorSubWindows/editPopups.h +++ b/EditorWindows/EditPopups.h @@ -1,6 +1,6 @@ #pragma once -#include "selectPopups.h" +#include "SelectPopups.h" class EditGameModelPopup : public FEImGuiWindow { diff --git a/FEEditorSubWindows/gyzmosSettingsWindow.h b/EditorWindows/GyzmosSettingsWindow.h similarity index 93% rename from FEEditorSubWindows/gyzmosSettingsWindow.h rename to EditorWindows/GyzmosSettingsWindow.h index 92029f8..24a1f6b 100644 --- a/FEEditorSubWindows/gyzmosSettingsWindow.h +++ b/EditorWindows/GyzmosSettingsWindow.h @@ -1,19 +1,19 @@ #pragma once -#include "shaderEditorWindow.h" +#include "ShaderEditorWindow.h" -class gyzmosSettingsWindow : public FEImGuiWindow +class GyzmosSettingsWindow : public FEImGuiWindow { ImGuiImageButton* TransformationGizmoButton = nullptr; ImGuiImageButton* ScaleGizmoButton = nullptr; ImGuiImageButton* RotateGizmoButton = nullptr; public: - gyzmosSettingsWindow() + GyzmosSettingsWindow() { Flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar; } - ~gyzmosSettingsWindow() override + ~GyzmosSettingsWindow() override { delete TransformationGizmoButton; delete ScaleGizmoButton; @@ -103,4 +103,4 @@ class gyzmosSettingsWindow : public FEImGuiWindow FEImGuiWindow::OnRenderEnd(); } }; -static gyzmosSettingsWindow GyzmosSettingsWindowObject; \ No newline at end of file +static GyzmosSettingsWindow GyzmosSettingsWindowObject; \ No newline at end of file diff --git a/FEEditorSubWindows/prefabEditorWindow.cpp b/EditorWindows/PrefabEditorWindow.cpp similarity index 98% rename from FEEditorSubWindows/prefabEditorWindow.cpp rename to EditorWindows/PrefabEditorWindow.cpp index 953e328..6458e0a 100644 --- a/FEEditorSubWindows/prefabEditorWindow.cpp +++ b/EditorWindows/PrefabEditorWindow.cpp @@ -1,4 +1,4 @@ -#include "prefabEditorWindow.h" +#include "PrefabEditorWindow.h" PrefabEditorWindow* PrefabEditorWindow::Instance = nullptr; FEPrefab* PrefabEditorWindow::ObjToWorkWith = nullptr; @@ -207,7 +207,7 @@ void PrefabEditorWindow::Render() if (ImGui::MenuItem("Add game model...")) { - SelectFeObjectPopUp::getInstance().Show(FE_GAMEMODEL, AddNewGameModelCallBack); + SelectFEObjectPopUp::getInstance().Show(FE_GAMEMODEL, AddNewGameModelCallBack); } if (HoveredGameModelItem != -1) diff --git a/FEEditorSubWindows/prefabEditorWindow.h b/EditorWindows/PrefabEditorWindow.h similarity index 94% rename from FEEditorSubWindows/prefabEditorWindow.h rename to EditorWindows/PrefabEditorWindow.h index 719c1bf..96532b4 100644 --- a/FEEditorSubWindows/prefabEditorWindow.h +++ b/EditorWindows/PrefabEditorWindow.h @@ -1,6 +1,6 @@ #pragma once -#include "combineChannelsToTexturePopUp.h" +#include "CombineChannelsToTexturePopUp.h" class PrefabEditorWindow : public FEImGuiWindow { diff --git a/FEEditorSubWindows/projectWasModifiedPopUp.cpp b/EditorWindows/ProjectWasModifiedPopUp.cpp similarity index 88% rename from FEEditorSubWindows/projectWasModifiedPopUp.cpp rename to EditorWindows/ProjectWasModifiedPopUp.cpp index c896366..066c9f3 100644 --- a/FEEditorSubWindows/projectWasModifiedPopUp.cpp +++ b/EditorWindows/ProjectWasModifiedPopUp.cpp @@ -1,21 +1,21 @@ -#include "projectWasModifiedPopUp.h" +#include "ProjectWasModifiedPopUp.h" -projectWasModifiedPopUp* projectWasModifiedPopUp::Instance = nullptr; +ProjectWasModifiedPopUp* ProjectWasModifiedPopUp::Instance = nullptr; -projectWasModifiedPopUp::projectWasModifiedPopUp() +ProjectWasModifiedPopUp::ProjectWasModifiedPopUp() { PopupCaption = "Save project ?"; ObjToWorkWith = nullptr; } -void projectWasModifiedPopUp::Show(FEProject* Project, const bool FullyCloseApplication) +void ProjectWasModifiedPopUp::Show(FEProject* Project, const bool FullyCloseApplication) { bShouldOpen = true; ObjToWorkWith = Project; bShouldTerminate = FullyCloseApplication; } -void projectWasModifiedPopUp::Render() +void ProjectWasModifiedPopUp::Render() { ImGuiModalPopup::Render(); diff --git a/EditorWindows/ProjectWasModifiedPopUp.h b/EditorWindows/ProjectWasModifiedPopUp.h new file mode 100644 index 0000000..ba00641 --- /dev/null +++ b/EditorWindows/ProjectWasModifiedPopUp.h @@ -0,0 +1,17 @@ +#pragma once + +#include "DebugTextureViewWindow.h" + +class ProjectWasModifiedPopUp : public ImGuiModalPopup +{ + FEProject* ObjToWorkWith; + bool bShouldTerminate = false; +public: + SINGLETON_PUBLIC_PART(ProjectWasModifiedPopUp) + + void Show(FEProject* Project, bool FullyCloseApplication); + void Render() override; + +private: + SINGLETON_PRIVATE_PART(ProjectWasModifiedPopUp) +}; \ No newline at end of file diff --git a/FEEditorSubWindows/renamePopups.cpp b/EditorWindows/RenamePopups.cpp similarity index 87% rename from FEEditorSubWindows/renamePopups.cpp rename to EditorWindows/RenamePopups.cpp index 2eb4f80..452fd68 100644 --- a/FEEditorSubWindows/renamePopups.cpp +++ b/EditorWindows/RenamePopups.cpp @@ -1,8 +1,8 @@ -#include "renamePopups.h" +#include "RenamePopups.h" -renameFailedPopUp* renameFailedPopUp::Instance = nullptr; +RenameFailedPopUp* RenameFailedPopUp::Instance = nullptr; -renameFailedPopUp::renameFailedPopUp() +RenameFailedPopUp::RenameFailedPopUp() { PopupCaption = "Invalid name"; OkButton = new ImGuiButton("OK"); @@ -11,12 +11,12 @@ renameFailedPopUp::renameFailedPopUp() OkButton->SetPosition(ImVec2(0, 0)); } -renameFailedPopUp::~renameFailedPopUp() +RenameFailedPopUp::~RenameFailedPopUp() { delete OkButton; } -void renameFailedPopUp::Render() +void RenameFailedPopUp::Render() { ImGuiModalPopup::Render(); @@ -42,22 +42,22 @@ void renameFailedPopUp::Render() } } -renamePopUp* renamePopUp::Instance = nullptr; +RenamePopUp* RenamePopUp::Instance = nullptr; -renamePopUp::renamePopUp() +RenamePopUp::RenamePopUp() { PopupCaption = "Rename object"; ObjToWorkWith = nullptr; } -void renamePopUp::Show(FEObject* ObjToWorkWith) +void RenamePopUp::Show(FEObject* ObjToWorkWith) { bShouldOpen = true; this->ObjToWorkWith = ObjToWorkWith; strcpy_s(NewName, ObjToWorkWith->GetName().size() + 1, ObjToWorkWith->GetName().c_str()); } -void renamePopUp::Render() +void RenamePopUp::Render() { ImGuiModalPopup::Render(); @@ -95,7 +95,7 @@ void renamePopUp::Render() { ObjToWorkWith = nullptr; ImGuiModalPopup::Close(); - renameFailedPopUp::getInstance().Show(); + RenameFailedPopUp::getInstance().Show(); } } ImGui::SetItemDefaultFocus(); diff --git a/EditorWindows/RenamePopups.h b/EditorWindows/RenamePopups.h new file mode 100644 index 0000000..79b07af --- /dev/null +++ b/EditorWindows/RenamePopups.h @@ -0,0 +1,26 @@ +#pragma once + +#include "DeletePopups.h" + +class RenameFailedPopUp : public ImGuiModalPopup +{ + ImGuiButton* OkButton = nullptr; +public: + SINGLETON_PUBLIC_PART(RenameFailedPopUp) + void Render() override; +private: + SINGLETON_PRIVATE_PART(RenameFailedPopUp) +}; + +class RenamePopUp : public ImGuiModalPopup +{ + FEObject* ObjToWorkWith; + char NewName[512]; +public: + SINGLETON_PUBLIC_PART(RenamePopUp) + + void Show(FEObject* ObjToWorkWith); + void Render() override; +private: + SINGLETON_PRIVATE_PART(RenamePopUp) +}; \ No newline at end of file diff --git a/FEEditorSubWindows/resizeTexturePopup.cpp b/EditorWindows/ResizeTexturePopup.cpp similarity index 93% rename from FEEditorSubWindows/resizeTexturePopup.cpp rename to EditorWindows/ResizeTexturePopup.cpp index 98eff32..4176cb7 100644 --- a/FEEditorSubWindows/resizeTexturePopup.cpp +++ b/EditorWindows/ResizeTexturePopup.cpp @@ -1,8 +1,8 @@ -#include "resizeTexturePopup.h" +#include "ResizeTexturePopup.h" -resizeTexturePopup* resizeTexturePopup::Instance = nullptr; +ResizeTexturePopup* ResizeTexturePopup::Instance = nullptr; -resizeTexturePopup::resizeTexturePopup() +ResizeTexturePopup::ResizeTexturePopup() { PopupCaption = "Resize texture"; ObjToWorkWith = nullptr; @@ -15,13 +15,13 @@ resizeTexturePopup::resizeTexturePopup() ApplyButton = new ImGuiButton("Apply"); } -resizeTexturePopup::~resizeTexturePopup() +ResizeTexturePopup::~ResizeTexturePopup() { delete CancelButton; delete ApplyButton; } -void resizeTexturePopup::Show(FETexture* ObjToWorkWith) +void ResizeTexturePopup::Show(FETexture* ObjToWorkWith) { if (ObjToWorkWith == nullptr) return; @@ -32,7 +32,7 @@ void resizeTexturePopup::Show(FETexture* ObjToWorkWith) NewHeight = ObjToWorkWith->GetHeight(); } -void resizeTexturePopup::Render() +void ResizeTexturePopup::Render() { ImGuiModalPopup::Render(); diff --git a/FEEditorSubWindows/resizeTexturePopup.h b/EditorWindows/ResizeTexturePopup.h similarity index 64% rename from FEEditorSubWindows/resizeTexturePopup.h rename to EditorWindows/ResizeTexturePopup.h index 8de7617..67f4239 100644 --- a/FEEditorSubWindows/resizeTexturePopup.h +++ b/EditorWindows/ResizeTexturePopup.h @@ -1,8 +1,8 @@ #pragma once -#include "renamePopups.h" +#include "RenamePopups.h" -class resizeTexturePopup : public ImGuiModalPopup +class ResizeTexturePopup : public ImGuiModalPopup { FETexture* ObjToWorkWith; int NewWidth; @@ -14,10 +14,10 @@ class resizeTexturePopup : public ImGuiModalPopup ImGuiButton* ApplyButton; ImVec2 PopupSize = ImVec2(450, 260); public: - SINGLETON_PUBLIC_PART(resizeTexturePopup) + SINGLETON_PUBLIC_PART(ResizeTexturePopup) void Show(FETexture* ObjToWorkWith); void Render() override; private: - SINGLETON_PRIVATE_PART(resizeTexturePopup) + SINGLETON_PRIVATE_PART(ResizeTexturePopup) }; \ No newline at end of file diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp new file mode 100644 index 0000000..f8fee2a --- /dev/null +++ b/EditorWindows/SceneGraphWindow.cpp @@ -0,0 +1,650 @@ +#include "SceneGraphWindow.h" + +FEEditorSceneGraphWindow* FEEditorSceneGraphWindow::Instance = nullptr; +FEEntity* FEEditorSceneGraphWindow::EntityToModify = nullptr; + +FEEditorSceneGraphWindow::FEEditorSceneGraphWindow() +{ + strcpy_s(FilterForEntities, ""); +} + +void FEEditorSceneGraphWindow::InitializeResources() +{ + EntityIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/entitySceneBrowserIcon.png", "entitySceneBrowserIcon"); + RESOURCE_MANAGER.MakeTextureStandard(EntityIcon); + InstancedEntityIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/instancedEntitySceneBrowserIcon.png", "instancedEntitySceneBrowserIcon"); + RESOURCE_MANAGER.MakeTextureStandard(InstancedEntityIcon); + + DirectionalLightIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/directionalLightSceneBrowserIcon.png", "directionalLightSceneBrowserIcon"); + RESOURCE_MANAGER.MakeTextureStandard(DirectionalLightIcon); + SpotLightIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/spotLightSceneBrowserIcon.png", "spotLightSceneBrowserIcon"); + RESOURCE_MANAGER.MakeTextureStandard(SpotLightIcon); + PointLightIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/pointLightSceneBrowserIcon.png", "pointLightSceneBrowserIcon"); + RESOURCE_MANAGER.MakeTextureStandard(PointLightIcon); + + TerrainIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/terrainSceneBrowserIcon.png", "terrainSceneBrowserIcon"); + RESOURCE_MANAGER.MakeTextureStandard(TerrainIcon); + + CameraIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/cameraSceneBrowserIcon.png", "cameraSceneBrowserIcon"); + RESOURCE_MANAGER.MakeTextureStandard(CameraIcon); +} + +void FEEditorSceneGraphWindow::Clear() +{ + strcpy_s(FilterForEntities, ""); +} + +void FEEditorSceneGraphWindow::SetCorrectItemColor(FEObject* SceneObject) const +{ + if (SceneObject->GetType() == FE_DIRECTIONAL_LIGHT || + SceneObject->GetType() == FE_SPOT_LIGHT || + SceneObject->GetType() == FE_POINT_LIGHT) + { + ImGui::PushStyleColor(ImGuiCol_Text, LightItemColor); + } + else if (SceneObject->GetType() == FE_CAMERA) + { + ImGui::PushStyleColor(ImGuiCol_Text, CameraItemColor); + } + else if (SceneObject->GetType() == FE_TERRAIN) + { + ImGui::PushStyleColor(ImGuiCol_Text, TerrainItemColor); + } + else if (SceneObject->GetType() == FE_ENTITY) + { + ImGui::PushStyleColor(ImGuiCol_Text, EntityItemColor); + } + else if (SceneObject->GetType() == FE_ENTITY_INSTANCED) + { + ImGui::PushStyleColor(ImGuiCol_Text, InstancedEntityItemColor); + } +} + +void FEEditorSceneGraphWindow::PopCorrectItemColor(FEObject* SceneObject) +{ + if (SceneObject->GetType() == FE_DIRECTIONAL_LIGHT || + SceneObject->GetType() == FE_SPOT_LIGHT || + SceneObject->GetType() == FE_POINT_LIGHT || + SceneObject->GetType() == FE_CAMERA || + SceneObject->GetType() == FE_TERRAIN || + SceneObject->GetType() == FE_ENTITY || + SceneObject->GetType() == FE_ENTITY_INSTANCED) + { + ImGui::PopStyleColor(); + } +} + +static void CreateNewInstancedEntityCallBack(const std::vector SelectionsResult) +{ + if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) + { + FEPrefab* SelectedPrefab = RESOURCE_MANAGER.GetPrefab(SelectionsResult[0]->GetObjectID()); + if (SelectedPrefab == nullptr) + return; + + FEEntityInstanced* NewEntity = SCENE.AddEntityInstanced(SelectedPrefab); + NewEntity->Transform.SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + SELECTED.SetSelected(NewEntity); + + PROJECT_MANAGER.GetCurrent()->SetModified(true); + } +} + +static void CreateNewEntityCallBack(const std::vector SelectionsResult) +{ + if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) + { + FEPrefab* SelectedPrefab = RESOURCE_MANAGER.GetPrefab(SelectionsResult[0]->GetObjectID()); + if (SelectedPrefab == nullptr) + return; + + FEEntity* NewEntity = SCENE.AddEntity(SelectedPrefab); + NewEntity->Transform.SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + SELECTED.SetSelected(NewEntity); + + PROJECT_MANAGER.GetCurrent()->SetModified(true); + } +} + +void FEEditorSceneGraphWindow::ChangePrefabOfEntityCallBack(const std::vector SelectionsResult) +{ + if (EntityToModify == nullptr) + return; + + if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) + { + FEPrefab* SelectedPrefab = RESOURCE_MANAGER.GetPrefab(SelectionsResult[0]->GetObjectID()); + if (SelectedPrefab == nullptr) + return; + + EntityToModify->Prefab = SelectedPrefab; + } +} + +void FEEditorSceneGraphWindow::DrawCorrectIcon(const FEObject* SceneObject) const +{ + ImGui::SetCursorPosX(20); + + if (SceneObject->GetType() == FE_ENTITY || SceneObject->GetType() == FE_ENTITY_INSTANCED) + { + const FEEntity* entity = SCENE.GetEntity(SceneObject->GetObjectID()); + + if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(entity)) + return; + + if (entity->GetType() == FE_ENTITY_INSTANCED) + { + + ImGui::Image((void*)(intptr_t)InstancedEntityIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); + } + else + { + ImGui::Image((void*)(intptr_t)EntityIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); + } + } + + if (SceneObject->GetType() == FE_DIRECTIONAL_LIGHT) + { + ImGui::Image((void*)(intptr_t)DirectionalLightIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); + + } + + if (SceneObject->GetType() == FE_SPOT_LIGHT) + { + ImGui::Image((void*)(intptr_t)SpotLightIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); + + } + + if (SceneObject->GetType() == FE_POINT_LIGHT) + { + ImGui::Image((void*)(intptr_t)PointLightIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); + + } + + if (SceneObject->GetType() == FE_TERRAIN) + { + ImGui::Image((void*)(intptr_t)TerrainIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); + } + + if (SceneObject->GetType() == FE_CAMERA) + { + ImGui::Image((void*)(intptr_t)CameraIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); + } + + ImGui::SameLine(); + return; +} + +DragAndDropTarget* FEEditorSceneGraphWindow::GetSceneNodeDragAndDropTarget(FENaiveSceneEntity* NodeToFind) +{ + int64_t UniqueID = 0; + // If it is Root. + if (NodeToFind->GetOldStyleEntity() == nullptr) + { + UniqueID = 1; + } + else + { + UniqueID = static_cast(std::hash{}(NodeToFind->GetOldStyleEntity()->GetObjectID().c_str())); + } + + if (SceneNodeDragAndDropTargets.find(UniqueID) == SceneNodeDragAndDropTargets.end()) + { + SceneNodeDragAndDropTargets[UniqueID] = DRAG_AND_DROP_MANAGER.AddTarget(std::vector { FE_SCENE_ENTITY }, + SceneNodeDragAndDropCallback, reinterpret_cast(NodeToFind), + std::vector { "Drop move to that parent" }); + } + + return SceneNodeDragAndDropTargets[UniqueID]; +} + +void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneEntity* SubTreeRoot) +{ + + SceneNodeDragAndDropTargetIndex++; + int64_t UniqueID = 0; + bool bIsLeaf = SubTreeRoot->GetChildren().size() == 0; + ImGuiTreeNodeFlags NodeFlags = bIsLeaf ? ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen : ImGuiTreeNodeFlags_OpenOnArrow; + std::string Name = SubTreeRoot->GetOldStyleEntity() == nullptr ? PROJECT_MANAGER.GetCurrent()->GetName() : SubTreeRoot->GetName(); + + if (SELECTED.GetSelected() != nullptr && SubTreeRoot->GetOldStyleEntity() != nullptr) + { + if (SELECTED.GetSelected()->GetObjectID() == SubTreeRoot->GetOldStyleEntity()->GetObjectID()) + { + NodeFlags |= ImGuiTreeNodeFlags_Selected; + } + } + + // If it is Root. + if (SubTreeRoot->GetOldStyleEntity() == nullptr) + { + UniqueID = 1; + } + else + { + UniqueID = static_cast(std::hash{}(SubTreeRoot->GetOldStyleEntity()->GetObjectID().c_str())); + } + + bool bOpened = ImGui::TreeNodeEx((void*)UniqueID, NodeFlags, Name.c_str(), 0); + GetSceneNodeDragAndDropTarget(SubTreeRoot)->StickToItem(); + + if (ImGui::IsItemHovered()) + { + if (!bShouldOpenContextMenu && !DRAG_AND_DROP_MANAGER.ObjectIsDraged()) + { + /*std::string AdditionalTypeInfo; + if (FilteredResources[i]->GetType() == FE_TEXTURE) + { + AdditionalTypeInfo += "\nTexture type: "; + AdditionalTypeInfo += FETexture::TextureInternalFormatToString(RESOURCE_MANAGER.GetTexture(FilteredResources[i]->GetObjectID())->GetInternalFormat()); + } + + ImGui::BeginTooltip(); + ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); + ImGui::TextUnformatted(("Name: " + FilteredResources[i]->GetName() + + "\nType: " + FEObjectTypeToString(FilteredResources[i]->GetType()) + + AdditionalTypeInfo + + "\nPath: " + VIRTUAL_FILE_SYSTEM.GetCurrentPath() + ).c_str()); + ImGui::PopTextWrapPos(); + ImGui::EndTooltip();*/ + + ItemUnderMouse = UniqueID; + + if (ImGui::IsMouseDragging(0)) + DRAG_AND_DROP_MANAGER.SetObjectToDrag(SubTreeRoot, nullptr, ImVec2(), ImVec2()); + } + } + + if (bOpened) + { + auto Children = SubTreeRoot->GetChildren(); + if (!Children.empty()) + { + for (size_t i = 0; i < Children.size(); i++) + RenderSubTree(Children[i]); + + ImGui::TreePop(); + } + } +} + +void FEEditorSceneGraphWindow::RenderNewSceneGraph() +{ + FENaiveSceneEntity* Root = SCENE.SceneGraph.GetRoot(); + + if (bSceneNodeTargetsDirty) + SceneNodeDragAndDropTargets.clear(); + + SceneNodeDragAndDropTargetIndex = -1; + RenderSubTree(Root); + + if (bSceneNodeTargetsDirty) + bSceneNodeTargetsDirty = false; +} + +void FEEditorSceneGraphWindow::Render() +{ + if (!bVisible) + return; + + static int SceneObjectHoveredIndex = -1; + + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); + ImGui::Begin("Scene Entities", nullptr, ImGuiWindowFlags_None); + + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::ImColor(0.6f, 0.24f, 0.24f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.7f, 0.21f, 0.21f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.8f, 0.16f, 0.16f)); + + RenderNewSceneGraph(); + + /*if (ImGui::Button("Enter game mode", ImVec2(220, 0))) + { + FEEditor::getInstance().SetGameMode(true); + }*/ + + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + + const std::vector EntityList = SCENE.GetEntityList(); + std::vector SceneObjectsList; + for (size_t i = 0; i < EntityList.size(); i++) + { + if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(SCENE.GetEntity(EntityList[i]))) + continue; + SceneObjectsList.push_back(EntityList[i]); + } + + const std::vector LightList = SCENE.GetLightsList(); + for (size_t i = 0; i < LightList.size(); i++) + { + SceneObjectsList.push_back(LightList[i]); + } + + const std::vector TerrainList = SCENE.GetTerrainList(); + for (size_t i = 0; i < TerrainList.size(); i++) + { + SceneObjectsList.push_back(TerrainList[i]); + } + + SceneObjectsList.push_back(ENGINE.GetCamera()->GetObjectID()); + + // Filtering. + ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5.0f); + ImGui::Text("Filter: "); + ImGui::SameLine(); + + ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 5.0f); + ImGui::InputText("##selectFEObjectPopUpFilter", FilterForEntities, IM_ARRAYSIZE(FilterForEntities)); + + std::vector FilteredSceneObjectsList; + if (strlen(FilterForEntities) == 0) + { + FilteredSceneObjectsList = SceneObjectsList; + } + else + { + FilteredSceneObjectsList.clear(); + for (size_t i = 0; i < SceneObjectsList.size(); i++) + { + if (OBJECT_MANAGER.GetFEObject(SceneObjectsList[i])->GetName().find(FilterForEntities) != -1) + { + FilteredSceneObjectsList.push_back(SceneObjectsList[i]); + } + } + } + + if (!bShouldOpenContextMenu) + SceneObjectHoveredIndex = -1; + + for (size_t i = 0; i < FilteredSceneObjectsList.size(); i++) + { + DrawCorrectIcon(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); + + ImGuiTreeNodeFlags NodeFlags = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; + if (SELECTED.GetSelected() != nullptr) + { + if (SELECTED.GetSelected()->GetObjectID() == FilteredSceneObjectsList[i]) + { + NodeFlags |= ImGuiTreeNodeFlags_Selected; + } + } + + SetCorrectItemColor(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); + ImGui::TreeNodeEx((void*)(intptr_t)i, NodeFlags, OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])->GetName().c_str(), i); + PopCorrectItemColor(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); + + if (ImGui::IsItemClicked()) + { + SELECTED.SetSelected(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); + SELECTED.SetDirtyFlag(false); + } + + if (ImGui::IsItemHovered()) + { + SceneObjectHoveredIndex = int(i); + } + } + + bool bOpenContextMenu = false; + if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(1)) + bOpenContextMenu = true; + + if (bOpenContextMenu) + ImGui::OpenPopup("##context_menu"); + + bShouldOpenContextMenu = false; + + if (ImGui::BeginPopup("##context_menu")) + { + bShouldOpenContextMenu = true; + + if (SceneObjectHoveredIndex == -1) + { + if (ImGui::BeginMenu("Add")) + { + if (ImGui::MenuItem("Entity")) + { + SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, CreateNewEntityCallBack); + //selectGameModelPopUp::getInstance().show(nullptr, true); + } + + if (ImGui::MenuItem("Instanced entity")) + { + SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, CreateNewInstancedEntityCallBack); + //selectGameModelPopUp::getInstance().show(nullptr, true, true); + } + + if (ImGui::MenuItem("Terrain")) + { + const std::vector TerrainList = SCENE.GetTerrainList(); + const size_t NextId = TerrainList.size(); + size_t index = 0; + std::string NewName = "terrain_" + std::to_string(NextId + index); + + while (true) + { + bool bCorrectName = true; + for (size_t i = 0; i < TerrainList.size(); i++) + { + if (TerrainList[i] == NewName) + { + bCorrectName = false; + break; + } + } + + if (bCorrectName) + break; + + index++; + NewName = "terrain_" + std::to_string(NextId + index); + } + + FETerrain* NewTerrain = RESOURCE_MANAGER.CreateTerrain(true, NewName); + SCENE.AddTerrain(NewTerrain); + NewTerrain->HeightMap->SetDirtyFlag(true); + PROJECT_MANAGER.GetCurrent()->SetModified(true); + } + + if (ImGui::BeginMenu("Light")) + { + if (ImGui::MenuItem("Directional")) + { + SCENE.AddLight(FE_DIRECTIONAL_LIGHT, ""); + } + + if (ImGui::MenuItem("Spot")) + { + SCENE.AddLight(FE_SPOT_LIGHT, ""); + } + + if (ImGui::MenuItem("Point")) + { + SCENE.AddLight(FE_POINT_LIGHT, ""); + } + + ImGui::EndMenu(); + } + + ImGui::EndMenu(); + } + } + else + { + if (ImGui::MenuItem("Rename")) + { + if (SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) + { + RenamePopUp::getInstance().Show(SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex])); + } + else if (SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) + { + RenamePopUp::getInstance().Show(SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex])); + } + else if (SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) + { + RenamePopUp::getInstance().Show(SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex])); + //renameLightWindow.show(SCENE.getLight(filteredSceneObjectsList[sceneObjectHoveredIndex])); + } + } + + if (ImGui::MenuItem("Delete")) + { + if (SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) + { + const FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); + if (SELECTED.GetEntity() == Entity) + SELECTED.Clear(); + + SCENE.DeleteEntity(Entity->GetObjectID()); + } + else if (SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) + { + const FETerrain* Terrain = SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex]); + if (SELECTED.GetTerrain() == Terrain) + SELECTED.Clear(); + + SCENE.DeleteTerrain(Terrain->GetObjectID()); + } + else if (SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) + { + const FELight* Light = SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]); + if (SELECTED.GetLight() == Light) + SELECTED.Clear(); + + SCENE.DeleteLight(Light->GetObjectID()); + } + } + + /*if (ImGui::MenuItem("*DEBUG* Test model camera on this")) + { + FEModelViewCamera* NewCamera = new FEModelViewCamera("New ModelViewCamera"); + NewCamera->SetAspectRatio(static_cast(ENGINE.GetRenderTargetWidth()) / static_cast(ENGINE.GetRenderTargetHeight())); + + glm::vec3 Position = glm::vec3(0.0f); + if (SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) + { + const FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); + Position = Entity->Transform.GetPosition(); + } + else if (SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) + { + const FETerrain* Terrain = SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex]); + Position = Terrain->Transform.GetPosition(); + } + else if (SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) + { + const FELight* Light = SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]); + Position = Light->Transform.GetPosition(); + } + + NewCamera->SetTrackingObjectPosition(Position); + NewCamera->SetOnUpdate(OnCameraUpdate); + ENGINE.SetCamera(NewCamera); + }*/ + } + + ImGui::EndPopup(); + } + + // It should not be here. + static bool bDisplayGrid = true; + ImGui::Checkbox("Display grid", &bDisplayGrid); + + static glm::vec3 color = glm::vec3(0.2f, 0.3f, 0.4f); + + const float BasicW = 0.1f; + float width = BasicW * 4.0f; + if (bDisplayGrid) + { + const int GridSize = 200; + for (int i = -GridSize / 2; i < GridSize / 2; i++) + { + color = glm::vec3(0.4f, 0.65f, 0.73f); + width = BasicW * 4.0f; + if (i % 2 != 0 && i != 0) + { + color = color / 4.0f; + width = width / 4.0f; + } + else if (i == 0) + { + color = glm::vec3(0.9f, 0.9f, 0.9f); + width = BasicW * 4.0f; + } + + RENDERER.DrawLine(glm::vec3(i, 0.0f, -GridSize / 2), glm::vec3(i, 0.0f, GridSize / 2), color, width); + RENDERER.DrawLine(glm::vec3(-GridSize / 2, 0.0f, i), glm::vec3(GridSize / 2, 0.0f, i), color, width); + } + } + + static float FavgTime = 0.0f; + static std::vector AvgTime; + static int counter = 0; + + ImGui::Text((std::string("Time : ") + std::to_string(RENDERER.LastTestTime)).c_str()); + + if (AvgTime.size() < 100) + { + AvgTime.push_back(RENDERER.LastTestTime); + } + else if (AvgTime.size() >= 100) + { + AvgTime[counter++ % 100] = RENDERER.LastTestTime; + } + + for (size_t i = 0; i < AvgTime.size(); i++) + { + FavgTime += AvgTime[i]; + } + FavgTime /= AvgTime.size(); + + + if (counter > 1000000) + counter = 0; + + ImGui::Text((std::string("avg Time : ") + std::to_string(FavgTime)).c_str()); + + bool bFreezeCulling = RENDERER.bFreezeCulling; + ImGui::Checkbox("bFreezeCulling", &bFreezeCulling); + RENDERER.bFreezeCulling = bFreezeCulling; + + bool bFreezeOcclusionCulling = !RENDERER.IsOcclusionCullingEnabled(); + ImGui::Checkbox("freezeOcclusionCulling", &bFreezeOcclusionCulling); + RENDERER.SetOcclusionCullingEnabled(!bFreezeOcclusionCulling); + + static bool bDisplaySelectedObjAABB = false; + ImGui::Checkbox("Display AABB of selected object", &bDisplaySelectedObjAABB); + + // draw AABB + if (SELECTED.GetSelected() != nullptr && + (SELECTED.GetSelected()->GetType() == FE_ENTITY || SELECTED.GetSelected()->GetType() == FE_ENTITY_INSTANCED || SELECTED.GetSelected()->GetType() == FE_TERRAIN) && + bDisplaySelectedObjAABB) + { + const FEAABB SelectedAabb = SELECTED.GetEntity() != nullptr ? SELECTED.GetEntity()->GetAABB() : SELECTED.GetTerrain()->GetAABB(); + RENDERER.DrawAABB(SelectedAabb); + + if (SELECTED.GetSelected()->GetType() == FE_ENTITY_INSTANCED) + { + static bool bDisplaySubObjAABB = false; + ImGui::Checkbox("Display AABB of instanced entity subobjects", &bDisplaySubObjAABB); + + if (bDisplaySubObjAABB) + { + const FEEntityInstanced* EntityInstanced = reinterpret_cast (SELECTED.GetSelected()); + const int MaxIterations = EntityInstanced->InstancedAABB.size() * 8 >= FE_MAX_LINES ? FE_MAX_LINES : int(EntityInstanced->InstancedAABB.size()); + + for (size_t j = 0; j < MaxIterations; j++) + { + RENDERER.DrawAABB(EntityInstanced->InstancedAABB[j]); + } + } + } + } + + ImGui::PopStyleVar(); + ImGui::End(); +} \ No newline at end of file diff --git a/EditorWindows/SceneGraphWindow.h b/EditorWindows/SceneGraphWindow.h new file mode 100644 index 0000000..27b19fc --- /dev/null +++ b/EditorWindows/SceneGraphWindow.h @@ -0,0 +1,74 @@ +#pragma once + +#include "ProjectWasModifiedPopUp.h" +//using namespace FocalEngine; + +class FEEditorSceneGraphWindow +{ + friend class FEEditor; + SINGLETON_PRIVATE_PART(FEEditorSceneGraphWindow) + + // Visibility + bool bVisible = true; + + // Item color management + void SetCorrectItemColor(FEObject* SceneObject) const; + void PopCorrectItemColor(FEObject* SceneObject); + ImVec4 TerrainItemColor = ImVec4(67.0f / 255.0f, 155.0f / 255.0f, 60.0f / 255.0f, 1.0f); + ImVec4 EntityItemColor = ImVec4(141.0f / 255.0f, 141.0f / 255.0f, 233.0f / 255.0f, 1.0f); + ImVec4 InstancedEntityItemColor = ImVec4(80.0f / 255.0f, 72.0f / 255.0f, 1.0f, 1.0f); + ImVec4 CameraItemColor = ImVec4(0.0f, 215.0f / 255.0f, 201.0f / 255.0f, 1.0f); + ImVec4 LightItemColor = ImVec4(243.0f / 255.0f, 230.0f / 255.0f, 31.0f / 255.0f, 1.0f); + + // Icon management + void DrawCorrectIcon(const FEObject* SceneObject) const; + FETexture* EntityIcon = nullptr; + FETexture* InstancedEntityIcon = nullptr; + FETexture* DirectionalLightIcon = nullptr; + FETexture* SpotLightIcon = nullptr; + FETexture* PointLightIcon = nullptr; + FETexture* TerrainIcon = nullptr; + FETexture* CameraIcon = nullptr; + + // Entity filtering + char FilterForEntities[512]; + + // Context menu + bool bShouldOpenContextMenu = false; + + // Entity modification + static FEEntity* EntityToModify; + static void ChangePrefabOfEntityCallBack(std::vector SelectionsResult); + + // Drag and drop + int64_t ItemUnderMouse = 0; + int SceneNodeDragAndDropTargetIndex = -1; + std::unordered_map SceneNodeDragAndDropTargets; + DragAndDropTarget* GetSceneNodeDragAndDropTarget(FENaiveSceneEntity* NodeToFind); + + bool bSceneNodeTargetsDirty = true; + static bool SceneNodeDragAndDropCallback(FEObject* Object, void** SceneNodeTarget) + { + if (Object == nullptr || SceneNodeTarget == nullptr || Object->GetType() != FE_SCENE_ENTITY) + return false; + + FENaiveSceneEntity* NodeTarget = reinterpret_cast(SceneNodeTarget); + FENaiveSceneEntity* SceneEntity = reinterpret_cast(Object); + + return SCENE.SceneGraph.MoveEntity(SceneEntity->GetObjectID(), NodeTarget->GetObjectID()); + } + + void UpdateSceneNodeDragAndDropTargets(); + + // Rendering and initialization + void Render(); + void RenderNewSceneGraph(); + void RenderSubTree(FENaiveSceneEntity* SubTreeRoot); + void Clear(); + void InitializeResources(); + +public: + SINGLETON_PUBLIC_PART(FEEditorSceneGraphWindow) +}; + +#define SCENE_GRAPH_WINDOW FEEditorSceneGraphWindow::getInstance() \ No newline at end of file diff --git a/FEEditorSubWindows/selectPopups.cpp b/EditorWindows/SelectPopups.cpp similarity index 88% rename from FEEditorSubWindows/selectPopups.cpp rename to EditorWindows/SelectPopups.cpp index eaa4bd2..d009e2f 100644 --- a/FEEditorSubWindows/selectPopups.cpp +++ b/EditorWindows/SelectPopups.cpp @@ -1,10 +1,10 @@ -#include "selectPopups.h" +#include "SelectPopups.h" -SelectFeObjectPopUp* SelectFeObjectPopUp::Instance = nullptr; -bool SelectFeObjectPopUp::ControlButtonPressed = false; -bool SelectFeObjectPopUp::bOneObjectSelectonMode = true; +SelectFEObjectPopUp* SelectFEObjectPopUp::Instance = nullptr; +bool SelectFEObjectPopUp::ControlButtonPressed = false; +bool SelectFEObjectPopUp::bOneObjectSelectonMode = true; -SelectFeObjectPopUp::SelectFeObjectPopUp() +SelectFEObjectPopUp::SelectFEObjectPopUp() { PopupCaption = "Select"; IconButton = new ImGuiImageButton(nullptr); @@ -20,17 +20,17 @@ SelectFeObjectPopUp::SelectFeObjectPopUp() CancelButton->SetSize(ImVec2(140, 24)); CancelButton->SetPosition(ImVec2(660, 35)); - ENGINE.AddKeyCallback(SelectFeObjectPopUp::KeyButtonCallback); + ENGINE.AddKeyCallback(SelectFEObjectPopUp::KeyButtonCallback); } -SelectFeObjectPopUp::~SelectFeObjectPopUp() +SelectFEObjectPopUp::~SelectFEObjectPopUp() { delete SelectButton; delete CancelButton; delete IconButton; } -void SelectFeObjectPopUp::Show(const FE_OBJECT_TYPE Type, void(*CallBack)(std::vector), FEObject* HighlightedObject, const std::vector CustomList) +void SelectFEObjectPopUp::Show(const FE_OBJECT_TYPE Type, void(*CallBack)(std::vector), FEObject* HighlightedObject, const std::vector CustomList) { CurrenType = Type; if (CurrenType == FE_NULL) @@ -118,7 +118,7 @@ void SelectFeObjectPopUp::Show(const FE_OBJECT_TYPE Type, void(*CallBack)(std::v } } -void SelectFeObjectPopUp::Render() +void SelectFEObjectPopUp::Render() { ImGuiModalPopup::Render(); @@ -228,7 +228,7 @@ void SelectFeObjectPopUp::Render() } } -void SelectFeObjectPopUp::OnSelectAction() +void SelectFEObjectPopUp::OnSelectAction() { if (CallBack != nullptr) { @@ -237,7 +237,7 @@ void SelectFeObjectPopUp::OnSelectAction() } } -void SelectFeObjectPopUp::Close() +void SelectFEObjectPopUp::Close() { ImGuiModalPopup::Close(); IndexUnderMouse = -1; @@ -245,7 +245,7 @@ void SelectFeObjectPopUp::Close() SelectedObjects.clear(); } -void SelectFeObjectPopUp::KeyButtonCallback(const int Key, int Scancode, const int Action, int Mods) +void SelectFEObjectPopUp::KeyButtonCallback(const int Key, int Scancode, const int Action, int Mods) { if ((Key == GLFW_KEY_LEFT_CONTROL || Action == GLFW_KEY_RIGHT_CONTROL) && Action == GLFW_RELEASE) { @@ -257,7 +257,7 @@ void SelectFeObjectPopUp::KeyButtonCallback(const int Key, int Scancode, const i } } -bool SelectFeObjectPopUp::IsSelected(const FEObject* Object) const +bool SelectFEObjectPopUp::IsSelected(const FEObject* Object) const { for (size_t i = 0; i < SelectedObjects.size(); i++) { @@ -268,19 +268,19 @@ bool SelectFeObjectPopUp::IsSelected(const FEObject* Object) const return false; } -bool SelectFeObjectPopUp::IsOneObjectSelectonMode() +bool SelectFEObjectPopUp::IsOneObjectSelectonMode() { return bOneObjectSelectonMode; } -void SelectFeObjectPopUp::SetOneObjectSelectonMode(const bool NewValue) +void SelectFEObjectPopUp::SetOneObjectSelectonMode(const bool NewValue) { bOneObjectSelectonMode = NewValue; if (bOneObjectSelectonMode && SelectedObjects.size() > 1) SelectedObjects.resize(1); } -void SelectFeObjectPopUp::AddToSelected(FEObject* Object) +void SelectFEObjectPopUp::AddToSelected(FEObject* Object) { if (IsSelected(Object)) return; diff --git a/FEEditorSubWindows/selectPopups.h b/EditorWindows/SelectPopups.h similarity index 85% rename from FEEditorSubWindows/selectPopups.h rename to EditorWindows/SelectPopups.h index e3e99d9..b8c4ccf 100644 --- a/FEEditorSubWindows/selectPopups.h +++ b/EditorWindows/SelectPopups.h @@ -1,10 +1,10 @@ #pragma once -#include "resizeTexturePopup.h" +#include "ResizeTexturePopup.h" -class SelectFeObjectPopUp : public ImGuiModalPopup +class SelectFEObjectPopUp : public ImGuiModalPopup { - SINGLETON_PRIVATE_PART(SelectFeObjectPopUp) + SINGLETON_PRIVATE_PART(SelectFEObjectPopUp) int IndexUnderMouse = -1; FEObject* HighlightedObject = nullptr; @@ -29,7 +29,7 @@ class SelectFeObjectPopUp : public ImGuiModalPopup bool IsSelected(const FEObject* Object) const; void AddToSelected(FEObject* Object); public: - SINGLETON_PUBLIC_PART(SelectFeObjectPopUp) + SINGLETON_PUBLIC_PART(SelectFEObjectPopUp) void Show(FE_OBJECT_TYPE Type, void(*CallBack)(std::vector), FEObject* HighlightedObject = nullptr, std::vector CustomList = std::vector()); void Close() override; diff --git a/FEEditorSubWindows/shaderEditorWindow.cpp b/EditorWindows/ShaderEditorWindow.cpp similarity index 95% rename from FEEditorSubWindows/shaderEditorWindow.cpp rename to EditorWindows/ShaderEditorWindow.cpp index ef3e0be..ab29058 100644 --- a/FEEditorSubWindows/shaderEditorWindow.cpp +++ b/EditorWindows/ShaderEditorWindow.cpp @@ -1,8 +1,8 @@ -#include "shaderEditorWindow.h" +#include "ShaderEditorWindow.h" -shaderDebugWindow* shaderDebugWindow::Instance = nullptr; +ShaderDebugWindow* ShaderDebugWindow::Instance = nullptr; -shaderDebugWindow::shaderDebugWindow() +ShaderDebugWindow::ShaderDebugWindow() { Flags = ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar; Editor.SetShowWhitespaces(false); @@ -14,7 +14,7 @@ shaderDebugWindow::shaderDebugWindow() Editor.SetColorizerEnable(false); } -shaderDebugWindow::~shaderDebugWindow() +ShaderDebugWindow::~ShaderDebugWindow() { delete CloseButton; delete UpdateButton; @@ -22,7 +22,7 @@ shaderDebugWindow::~shaderDebugWindow() ShaderToWorkWith = nullptr; } -void shaderDebugWindow::Show(FEShader* Shader, std::string Caption) +void ShaderDebugWindow::Show(FEShader* Shader, std::string Caption) { bUpdateNeeded = true; ShaderToWorkWith = Shader; @@ -39,7 +39,7 @@ void shaderDebugWindow::Show(FEShader* Shader, std::string Caption) FEImGuiWindow::Show(); } -void shaderDebugWindow::Render() +void ShaderDebugWindow::Render() { FEImGuiWindow::Render(); @@ -135,9 +135,9 @@ void shaderDebugWindow::Render() FEImGuiWindow::OnRenderEnd(); } -shaderEditorWindow* shaderEditorWindow::Instance = nullptr; +ShaderEditorWindow* ShaderEditorWindow::Instance = nullptr; -shaderEditorWindow::shaderEditorWindow() +ShaderEditorWindow::ShaderEditorWindow() { Flags = ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar; CurrentEditor = &VertexShaderEditor; @@ -163,12 +163,12 @@ shaderEditorWindow::shaderEditorWindow() CloseButton->SetHoveredColor((ImVec4)ImColor(0.8f, 0.16f, 0.16f)); } -shaderEditorWindow::~shaderEditorWindow() +ShaderEditorWindow::~ShaderEditorWindow() { delete CompileButton; } -void shaderEditorWindow::Show(FEShader* Shader) +void ShaderEditorWindow::Show(FEShader* Shader) { ShaderToEdit = Shader; std::string TempCaption = "Edit shader: "; @@ -257,7 +257,7 @@ void shaderEditorWindow::Show(FEShader* Shader) } } -void shaderEditorWindow::Render() +void ShaderEditorWindow::Render() { FEImGuiWindow::Render(); @@ -429,7 +429,7 @@ void shaderEditorWindow::Render() if (ShaderToEdit->IsDebugRequest()) { - shaderDebugWindow::getInstance().Show(ShaderToEdit, "Shader debug info"); + ShaderDebugWindow::getInstance().Show(ShaderToEdit, "Shader debug info"); } } } @@ -444,7 +444,7 @@ void shaderEditorWindow::Render() FEImGuiWindow::OnRenderEnd(); } -void shaderEditorWindow::ReplaceShader(FEShader* OldShader, FEShader* NewShader) +void ShaderEditorWindow::ReplaceShader(FEShader* OldShader, FEShader* NewShader) { std::vector MaterialList = RESOURCE_MANAGER.GetMaterialList(); for (size_t i = 0; i < MaterialList.size(); i++) diff --git a/FEEditorSubWindows/shaderEditorWindow.h b/EditorWindows/ShaderEditorWindow.h similarity index 80% rename from FEEditorSubWindows/shaderEditorWindow.h rename to EditorWindows/ShaderEditorWindow.h index 4d2f17d..82a1c85 100644 --- a/FEEditorSubWindows/shaderEditorWindow.h +++ b/EditorWindows/ShaderEditorWindow.h @@ -1,11 +1,11 @@ #pragma once -#include "editPopups.h" +#include "EditPopups.h" #pragma warning (disable: 4724) -class shaderDebugWindow : public FEImGuiWindow +class ShaderDebugWindow : public FEImGuiWindow { - SINGLETON_PRIVATE_PART(shaderDebugWindow) + SINGLETON_PRIVATE_PART(ShaderDebugWindow) TextEditor Editor; ImGuiButton* CloseButton = nullptr; @@ -17,15 +17,15 @@ class shaderDebugWindow : public FEImGuiWindow std::vector>* Data = nullptr; std::vector> DataDump; public: - SINGLETON_PUBLIC_PART(shaderDebugWindow) + SINGLETON_PUBLIC_PART(ShaderDebugWindow) void Show(FEShader* Shader, std::string Caption); void Render() override; }; -class shaderEditorWindow : public FEImGuiWindow +class ShaderEditorWindow : public FEImGuiWindow { - SINGLETON_PRIVATE_PART(shaderEditorWindow) + SINGLETON_PRIVATE_PART(ShaderEditorWindow) FEShader* ShaderToEdit = nullptr; FEShader* DummyShader = nullptr; @@ -50,7 +50,7 @@ class shaderEditorWindow : public FEImGuiWindow void ReplaceShader(FEShader* OldShader, FEShader* NewShader); public: - SINGLETON_PUBLIC_PART(shaderEditorWindow) + SINGLETON_PUBLIC_PART(ShaderEditorWindow) void Show(FEShader* Shader); diff --git a/FEEditor.cpp b/FEEditor.cpp index 7fa8001..0d7d671 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -3,7 +3,6 @@ FEEditor* FEEditor::Instance = nullptr; ImGuiWindow* FEEditor::SceneWindow = nullptr; FEEntity* FEEditor::EntityToModify = nullptr; -FEObject* FEEditor::ItemInFocus = nullptr; bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) { @@ -20,53 +19,6 @@ bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) return false; } -static void CreateNewInstancedEntityCallBack(const std::vector SelectionsResult) -{ - if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) - { - FEPrefab* SelectedPrefab = RESOURCE_MANAGER.GetPrefab(SelectionsResult[0]->GetObjectID()); - if (SelectedPrefab == nullptr) - return; - - FEEntityInstanced* NewEntity = SCENE.AddEntityInstanced(SelectedPrefab); - NewEntity->Transform.SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - SELECTED.SetSelected(NewEntity); - - PROJECT_MANAGER.GetCurrent()->SetModified(true); - } -} - -static void CreateNewEntityCallBack(const std::vector SelectionsResult) -{ - if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) - { - FEPrefab* SelectedPrefab = RESOURCE_MANAGER.GetPrefab(SelectionsResult[0]->GetObjectID()); - if (SelectedPrefab == nullptr) - return; - - FEEntity* NewEntity = SCENE.AddEntity(SelectedPrefab); - NewEntity->Transform.SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - SELECTED.SetSelected(NewEntity); - - PROJECT_MANAGER.GetCurrent()->SetModified(true); - } -} - -void FEEditor::ChangePrefabOfEntityCallBack(const std::vector SelectionsResult) -{ - if (EntityToModify == nullptr) - return; - - if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) - { - FEPrefab* SelectedPrefab = RESOURCE_MANAGER.GetPrefab(SelectionsResult[0]->GetObjectID()); - if (SelectedPrefab == nullptr) - return; - - EntityToModify->Prefab = SelectedPrefab; - } -} - FEEditor::FEEditor() { ENGINE.SetRenderTargetMode(FE_CUSTOM_MODE); @@ -75,9 +27,6 @@ FEEditor::FEEditor() if (ENGINE.GetCamera()->GetCameraType() == 1) ENGINE.RenderTargetCenterForCamera(reinterpret_cast(ENGINE.GetCamera())); - - strcpy_s(FilterForResourcesContentBrowser, ""); - strcpy_s(FilterForSceneEntities, ""); } FEEditor::~FEEditor() {} @@ -134,8 +83,6 @@ void FEEditor::SetObjectNameInClipboard(const std::string NewValue) void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) { - ItemInFocus = nullptr; - if (ImGui::GetCurrentContext()->HoveredWindow != nullptr && FEEditor::SceneWindow != nullptr) { EDITOR.bSceneWindowHovered = ImGui::GetCurrentContext()->HoveredWindow->Name == EDITOR.SceneWindow->Name; @@ -205,7 +152,7 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) { if (PROJECT_MANAGER.GetCurrent() == nullptr) ENGINE.Terminate(); - projectWasModifiedPopUp::getInstance().Show(PROJECT_MANAGER.GetCurrent(), true); + ProjectWasModifiedPopUp::getInstance().Show(PROJECT_MANAGER.GetCurrent(), true); } } @@ -564,421 +511,19 @@ void FEEditor::DisplayLightsProperties() const } } -void FEEditor::DrawCorrectSceneBrowserIcon(const FEObject* SceneObject) const -{ - ImGui::SetCursorPosX(20); - - if (SceneObject->GetType() == FE_ENTITY || SceneObject->GetType() == FE_ENTITY_INSTANCED) - { - const FEEntity* entity = SCENE.GetEntity(SceneObject->GetObjectID()); - - if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(entity)) - return; - - if (entity->GetType() == FE_ENTITY_INSTANCED) - { - - ImGui::Image((void*)(intptr_t)InstancedEntitySceneBrowserIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); - } - else - { - ImGui::Image((void*)(intptr_t)EntitySceneBrowserIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); - } - } - - if (SceneObject->GetType() == FE_DIRECTIONAL_LIGHT) - { - ImGui::Image((void*)(intptr_t)DirectionalLightSceneBrowserIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); - - } - - if (SceneObject->GetType() == FE_SPOT_LIGHT) - { - ImGui::Image((void*)(intptr_t)SpotLightSceneBrowserIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); - - } - - if (SceneObject->GetType() == FE_POINT_LIGHT) - { - ImGui::Image((void*)(intptr_t)PointLightSceneBrowserIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); - - } - - if (SceneObject->GetType() == FE_TERRAIN) - { - ImGui::Image((void*)(intptr_t)TerrainSceneBrowserIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); - } - - if (SceneObject->GetType() == FE_CAMERA) - { - ImGui::Image((void*)(intptr_t)CameraSceneBrowserIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); - } - - ImGui::SameLine(); - return; -} - -void FEEditor::DisplaySceneBrowser() +void FEEditor::ChangePrefabOfEntityCallBack(const std::vector SelectionsResult) { - if (!bSceneBrowserVisible) + if (EntityToModify == nullptr) return; - static int SceneObjectHoveredIndex = -1; - - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); - ImGui::Begin("Scene Entities", nullptr, ImGuiWindowFlags_None); - - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::ImColor(0.6f, 0.24f, 0.24f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.7f, 0.21f, 0.21f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.8f, 0.16f, 0.16f)); - - if (ImGui::Button("Enter game mode", ImVec2(220, 0))) - { - FEEditor::getInstance().SetGameMode(true); - } - - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - - const std::vector EntityList = SCENE.GetEntityList(); - std::vector SceneObjectsList; - for (size_t i = 0; i < EntityList.size(); i++) - { - if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(SCENE.GetEntity(EntityList[i]))) - continue; - SceneObjectsList.push_back(EntityList[i]); - } - - const std::vector LightList = SCENE.GetLightsList(); - for (size_t i = 0; i < LightList.size(); i++) - { - SceneObjectsList.push_back(LightList[i]); - } - - const std::vector TerrainList = SCENE.GetTerrainList(); - for (size_t i = 0; i < TerrainList.size(); i++) - { - SceneObjectsList.push_back(TerrainList[i]); - } - - SceneObjectsList.push_back(ENGINE.GetCamera()->GetObjectID()); - - // Filtering. - ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5.0f); - ImGui::Text("Filter: "); - ImGui::SameLine(); - - ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 5.0f); - ImGui::InputText("##selectFEObjectPopUpFilter", FilterForSceneEntities, IM_ARRAYSIZE(FilterForSceneEntities)); - - std::vector FilteredSceneObjectsList; - if (strlen(FilterForSceneEntities) == 0) - { - FilteredSceneObjectsList = SceneObjectsList; - } - else - { - FilteredSceneObjectsList.clear(); - for (size_t i = 0; i < SceneObjectsList.size(); i++) - { - if (OBJECT_MANAGER.GetFEObject(SceneObjectsList[i])->GetName().find(FilterForSceneEntities) != -1) - { - FilteredSceneObjectsList.push_back(SceneObjectsList[i]); - } - } - } - - if (!bShouldOpenContextMenuInSceneEntities) - SceneObjectHoveredIndex = -1; - - for (size_t i = 0; i < FilteredSceneObjectsList.size(); i++) - { - DrawCorrectSceneBrowserIcon(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); - - ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; - if (SELECTED.GetSelected() != nullptr) - { - if (SELECTED.GetSelected()->GetObjectID() == FilteredSceneObjectsList[i]) - { - node_flags |= ImGuiTreeNodeFlags_Selected; - } - } - - SetCorrectSceneBrowserColor(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); - ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])->GetName().c_str(), i); - PopCorrectSceneBrowserColor(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); - - if (ImGui::IsItemClicked()) - { - SELECTED.SetSelected(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); - SELECTED.SetDirtyFlag(false); - } - - if (ImGui::IsItemHovered()) - { - SceneObjectHoveredIndex = int(i); - } - } - - bool open_context_menu = false; - if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(1)) - open_context_menu = true; - - if (open_context_menu) - ImGui::OpenPopup("##context_menu"); - - bShouldOpenContextMenuInSceneEntities = false; - - if (ImGui::BeginPopup("##context_menu")) - { - bShouldOpenContextMenuInSceneEntities = true; - - if (SceneObjectHoveredIndex == -1) - { - if (ImGui::BeginMenu("Add")) - { - if (ImGui::MenuItem("Entity")) - { - SelectFeObjectPopUp::getInstance().Show(FE_PREFAB, CreateNewEntityCallBack); - //selectGameModelPopUp::getInstance().show(nullptr, true); - } - - if (ImGui::MenuItem("Instanced entity")) - { - SelectFeObjectPopUp::getInstance().Show(FE_PREFAB, CreateNewInstancedEntityCallBack); - //selectGameModelPopUp::getInstance().show(nullptr, true, true); - } - - if (ImGui::MenuItem("Terrain")) - { - const std::vector TerrainList = SCENE.GetTerrainList(); - const size_t NextId = TerrainList.size(); - size_t index = 0; - std::string NewName = "terrain_" + std::to_string(NextId + index); - - while (true) - { - bool bCorrectName = true; - for (size_t i = 0; i < TerrainList.size(); i++) - { - if (TerrainList[i] == NewName) - { - bCorrectName = false; - break; - } - } - - if (bCorrectName) - break; - - index++; - NewName = "terrain_" + std::to_string(NextId + index); - } - - FETerrain* NewTerrain = RESOURCE_MANAGER.CreateTerrain(true, NewName); - SCENE.AddTerrain(NewTerrain); - NewTerrain->HeightMap->SetDirtyFlag(true); - PROJECT_MANAGER.GetCurrent()->SetModified(true); - } - - if (ImGui::BeginMenu("Light")) - { - if (ImGui::MenuItem("Directional")) - { - SCENE.AddLight(FE_DIRECTIONAL_LIGHT, ""); - } - - if (ImGui::MenuItem("Spot")) - { - SCENE.AddLight(FE_SPOT_LIGHT, ""); - } - - if (ImGui::MenuItem("Point")) - { - SCENE.AddLight(FE_POINT_LIGHT, ""); - } - - ImGui::EndMenu(); - } - - ImGui::EndMenu(); - } - } - else - { - if (ImGui::MenuItem("Rename")) - { - if (SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - renamePopUp::getInstance().Show(SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex])); - } - else if (SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - renamePopUp::getInstance().Show(SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex])); - } - else if (SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - renamePopUp::getInstance().Show(SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex])); - //renameLightWindow.show(SCENE.getLight(filteredSceneObjectsList[sceneObjectHoveredIndex])); - } - } - - if (ImGui::MenuItem("Delete")) - { - if (SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - const FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); - if (SELECTED.GetEntity() == Entity) - SELECTED.Clear(); - - SCENE.DeleteEntity(Entity->GetObjectID()); - } - else if (SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - const FETerrain* Terrain = SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex]); - if (SELECTED.GetTerrain() == Terrain) - SELECTED.Clear(); - - SCENE.DeleteTerrain(Terrain->GetObjectID()); - } - else if (SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - const FELight* Light = SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]); - if (SELECTED.GetLight() == Light) - SELECTED.Clear(); - - SCENE.DeleteLight(Light->GetObjectID()); - } - } - - if (ImGui::MenuItem("*DEBUG* Test model camera on this")) - { - FEModelViewCamera* NewCamera = new FEModelViewCamera("New ModelViewCamera"); - NewCamera->SetAspectRatio(static_cast(ENGINE.GetRenderTargetWidth()) / static_cast(ENGINE.GetRenderTargetHeight())); - - glm::vec3 Position = glm::vec3(0.0f); - if (SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - const FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); - Position = Entity->Transform.GetPosition(); - } - else if (SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - const FETerrain* Terrain = SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex]); - Position = Terrain->Transform.GetPosition(); - } - else if (SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - const FELight* Light = SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]); - Position = Light->Transform.GetPosition(); - } - - NewCamera->SetTrackingObjectPosition(Position); - NewCamera->SetOnUpdate(OnCameraUpdate); - ENGINE.SetCamera(NewCamera); - } - } - - ImGui::EndPopup(); - } - - static bool bDisplayGrid = true; - ImGui::Checkbox("Display grid", &bDisplayGrid); - - static glm::vec3 color = glm::vec3(0.2f, 0.3f, 0.4f); - - const float BasicW = 0.1f; - float width = BasicW * 4.0f; - if (bDisplayGrid) - { - const int GridSize = 200; - for (int i = -GridSize / 2; i < GridSize / 2; i++) - { - color = glm::vec3(0.4f, 0.65f, 0.73f); - width = BasicW * 4.0f; - if (i % 2 != 0 && i != 0) - { - color = color / 4.0f; - width = width / 4.0f; - } - else if (i == 0) - { - color = glm::vec3(0.9f, 0.9f, 0.9f); - width = BasicW * 4.0f; - } - - RENDERER.DrawLine(glm::vec3(i, 0.0f, -GridSize / 2), glm::vec3(i, 0.0f, GridSize / 2), color, width); - RENDERER.DrawLine(glm::vec3(-GridSize / 2, 0.0f, i), glm::vec3(GridSize / 2, 0.0f, i), color, width); - } - } - - static float FavgTime = 0.0f; - static std::vector AvgTime; - static int counter = 0; - - ImGui::Text((std::string("Time : ") + std::to_string(RENDERER.LastTestTime)).c_str()); - - if (AvgTime.size() < 100) - { - AvgTime.push_back(RENDERER.LastTestTime); - } - else if (AvgTime.size() >= 100) - { - AvgTime[counter++ % 100] = RENDERER.LastTestTime; - } - - for (size_t i = 0; i < AvgTime.size(); i++) - { - FavgTime += AvgTime[i]; - } - FavgTime /= AvgTime.size(); - - - if (counter > 1000000) - counter = 0; - - ImGui::Text((std::string("avg Time : ") + std::to_string(FavgTime)).c_str()); - - bool bFreezeCulling = RENDERER.bFreezeCulling; - ImGui::Checkbox("bFreezeCulling", &bFreezeCulling); - RENDERER.bFreezeCulling = bFreezeCulling; - - bool bFreezeOcclusionCulling = !RENDERER.IsOcclusionCullingEnabled(); - ImGui::Checkbox("freezeOcclusionCulling", &bFreezeOcclusionCulling); - RENDERER.SetOcclusionCullingEnabled(!bFreezeOcclusionCulling); - - static bool bDisplaySelectedObjAABB = false; - ImGui::Checkbox("Display AABB of selected object", &bDisplaySelectedObjAABB); - - // draw AABB - if (SELECTED.GetSelected() != nullptr && - (SELECTED.GetSelected()->GetType() == FE_ENTITY || SELECTED.GetSelected()->GetType() == FE_ENTITY_INSTANCED || SELECTED.GetSelected()->GetType() == FE_TERRAIN) && - bDisplaySelectedObjAABB) + if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) { - const FEAABB SelectedAabb = SELECTED.GetEntity() != nullptr ? SELECTED.GetEntity()->GetAABB() : SELECTED.GetTerrain()->GetAABB(); - RENDERER.DrawAABB(SelectedAabb); - - if (SELECTED.GetSelected()->GetType() == FE_ENTITY_INSTANCED) - { - static bool bDisplaySubObjAABB = false; - ImGui::Checkbox("Display AABB of instanced entity subobjects", &bDisplaySubObjAABB); - - if (bDisplaySubObjAABB) - { - const FEEntityInstanced* EntityInstanced = reinterpret_cast (SELECTED.GetSelected()); - const int MaxIterations = EntityInstanced->InstancedAABB.size() * 8 >= FE_MAX_LINES ? FE_MAX_LINES : int(EntityInstanced->InstancedAABB.size()); + FEPrefab* SelectedPrefab = RESOURCE_MANAGER.GetPrefab(SelectionsResult[0]->GetObjectID()); + if (SelectedPrefab == nullptr) + return; - for (size_t j = 0; j < MaxIterations; j++) - { - RENDERER.DrawAABB(EntityInstanced->InstancedAABB[j]); - } - } - } + EntityToModify->Prefab = SelectedPrefab; } - - ImGui::PopStyleVar(); - ImGui::End(); } void FEEditor::InitializeResources() @@ -1038,47 +583,9 @@ void FEEditor::InitializeResources() ArrowToGroundIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/arrowToGroundIcon.png", "arrowToGroundIcon"); RESOURCE_MANAGER.MakeTextureStandard(ArrowToGroundIcon); - EntitySceneBrowserIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/entitySceneBrowserIcon.png", "entitySceneBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(EntitySceneBrowserIcon); - InstancedEntitySceneBrowserIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/instancedEntitySceneBrowserIcon.png", "instancedEntitySceneBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(InstancedEntitySceneBrowserIcon); - - DirectionalLightSceneBrowserIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/directionalLightSceneBrowserIcon.png", "directionalLightSceneBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(DirectionalLightSceneBrowserIcon); - SpotLightSceneBrowserIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/spotLightSceneBrowserIcon.png", "spotLightSceneBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(SpotLightSceneBrowserIcon); - PointLightSceneBrowserIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/pointLightSceneBrowserIcon.png", "pointLightSceneBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(PointLightSceneBrowserIcon); - - TerrainSceneBrowserIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/terrainSceneBrowserIcon.png", "terrainSceneBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(TerrainSceneBrowserIcon); - - CameraSceneBrowserIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/cameraSceneBrowserIcon.png", "cameraSceneBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(CameraSceneBrowserIcon); - - FolderIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/folderIcon.png", "folderIcon"); - RESOURCE_MANAGER.MakeTextureStandard(FolderIcon); - - ShaderIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/shaderIcon.png", "shaderIcon"); - RESOURCE_MANAGER.MakeTextureStandard(ShaderIcon); - - VFSBackIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/VFSBackIcon.png", "VFSBackIcon"); - RESOURCE_MANAGER.MakeTextureStandard(VFSBackIcon); - - TextureContentBrowserIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/textureContentBrowserIcon.png", "textureContentBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(TextureContentBrowserIcon); - - MeshContentBrowserIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/meshContentBrowserIcon.png", "meshContentBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(MeshContentBrowserIcon); - - MaterialContentBrowserIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/materialContentBrowserIcon.png", "materialContentBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(MaterialContentBrowserIcon); + SCENE_GRAPH_WINDOW.InitializeResources(); - GameModelContentBrowserIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/gameModelContentBrowserIcon.png", "gameModelContentBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(GameModelContentBrowserIcon); - - PrefabContentBrowserIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/prefabContentBrowserIcon.png", "prefabContentBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(PrefabContentBrowserIcon); + CONTENT_BROWSER_WINDOW.InitializeResources(); // ************** Terrain Settings ************** ExportHeightMapButton = new ImGuiButton("Export HeightMap"); @@ -1109,26 +616,6 @@ void FEEditor::InitializeResources() EntityChangePrefabTarget = DRAG_AND_DROP_MANAGER.AddTarget(FE_PREFAB, EntityChangePrefabTargetCallBack, nullptr, "Drop to assign prefab"); // ************** Terrain Settings END ************** - - AllContentBrowserIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/allContentBrowserIcon.png", "allIcon"); - FilterAllTypesButton = new ImGuiImageButton(AllContentBrowserIcon); - RESOURCE_MANAGER.MakeTextureStandard(AllContentBrowserIcon); - FilterAllTypesButton->SetSize(ImVec2(32, 32)); - - FilterTextureTypeButton = new ImGuiImageButton(TextureContentBrowserIcon); - FilterTextureTypeButton->SetSize(ImVec2(32, 32)); - - FilterMeshTypeButton = new ImGuiImageButton(MeshContentBrowserIcon); - FilterMeshTypeButton->SetSize(ImVec2(32, 32)); - - FilterMaterialTypeButton = new ImGuiImageButton(MaterialContentBrowserIcon); - FilterMaterialTypeButton->SetSize(ImVec2(32, 32)); - - FilterGameModelTypeButton = new ImGuiImageButton(GameModelContentBrowserIcon); - FilterGameModelTypeButton->SetSize(ImVec2(32, 32)); - - FilterPrefabTypeButton = new ImGuiImageButton(PrefabContentBrowserIcon); - FilterPrefabTypeButton->SetSize(ImVec2(32, 32)); ENGINE.GetCamera()->SetOnUpdate(OnCameraUpdate); ENGINE.AddWindowCloseCallback(CloseWindowCallBack); @@ -1200,13 +687,13 @@ void FEEditor::Render() { if (PROJECT_MANAGER.GetCurrent()->IsModified()) { - projectWasModifiedPopUp::getInstance().Show(PROJECT_MANAGER.GetCurrent(), false); + ProjectWasModifiedPopUp::getInstance().Show(PROJECT_MANAGER.GetCurrent(), false); } else { PROJECT_MANAGER.CloseCurrentProject(); - strcpy_s(FilterForResourcesContentBrowser, ""); - strcpy_s(FilterForSceneEntities, ""); + CONTENT_BROWSER_WINDOW.Clear(); + SCENE_GRAPH_WINDOW.Clear(); ImGui::PopStyleVar(); ImGui::EndMenu(); @@ -1221,7 +708,7 @@ void FEEditor::Render() if (PROJECT_MANAGER.GetCurrent()->IsModified()) { APPLICATION.GetMainWindow()->CancelClose(); - projectWasModifiedPopUp::getInstance().Show(PROJECT_MANAGER.GetCurrent(), true); + ProjectWasModifiedPopUp::getInstance().Show(PROJECT_MANAGER.GetCurrent(), true); } else { @@ -1236,9 +723,9 @@ void FEEditor::Render() if (ImGui::BeginMenu("Window")) { - if (ImGui::MenuItem("Scene Entities", nullptr, bSceneBrowserVisible)) + if (ImGui::MenuItem("Scene Entities", nullptr, SCENE_GRAPH_WINDOW.bVisible)) { - bSceneBrowserVisible = !bSceneBrowserVisible; + SCENE_GRAPH_WINDOW.bVisible = !SCENE_GRAPH_WINDOW.bVisible; } if (ImGui::MenuItem("Inspector", nullptr, bInspectorVisible)) @@ -1246,9 +733,9 @@ void FEEditor::Render() bInspectorVisible = !bInspectorVisible; } - if (ImGui::MenuItem("Content Browser", nullptr, bContentBrowserVisible)) + if (ImGui::MenuItem("Content Browser", nullptr, CONTENT_BROWSER_WINDOW.bVisible)) { - bContentBrowserVisible = !bContentBrowserVisible; + CONTENT_BROWSER_WINDOW.bVisible = !CONTENT_BROWSER_WINDOW.bVisible; } if (ImGui::MenuItem("Effects", nullptr, bEffectsWindowVisible)) @@ -1283,7 +770,7 @@ void FEEditor::Render() { if (CurrentWindow == nullptr) { - CurrentWindow = new debugTextureViewWindow(iterator->second); + CurrentWindow = new DebugTextureViewWindow(iterator->second); CurrentWindow->SetCaption(iterator->first); CurrentWindow->Show(); } @@ -1311,7 +798,6 @@ void FEEditor::Render() ImGui::EndMainMenuBar(); } ImGui::PopStyleVar(); - //ImGui::PopStyleVar(); ImGui::Begin("Scene", nullptr, ImGuiWindowFlags_None | ImGuiWindowFlags_NoScrollbar); @@ -1346,8 +832,8 @@ void FEEditor::Render() ImGui::End(); - DisplaySceneBrowser(); - DisplayContentBrowser(); + SCENE_GRAPH_WINDOW.Render(); + CONTENT_BROWSER_WINDOW.Render(); DisplayInspector(); DisplayEffectsWindow(); DisplayLogWindow(); @@ -1383,7 +869,7 @@ void FEEditor::CloseWindowCallBack() if (PROJECT_MANAGER.GetCurrent()->IsModified()) { APPLICATION.GetMainWindow()->CancelClose(); - projectWasModifiedPopUp::getInstance().Show(PROJECT_MANAGER.GetCurrent(), true); + ProjectWasModifiedPopUp::getInstance().Show(PROJECT_MANAGER.GetCurrent(), true); } else { @@ -1484,36 +970,6 @@ bool FEEditor::TerrainChangeMaterialTargetCallBack(FEObject* Object, void** Laye return true; } -void FEEditor::ShowInFolderItem(FEObject* Object) -{ - VIRTUAL_FILE_SYSTEM.SetCurrentPath(VIRTUAL_FILE_SYSTEM.LocateFile(Object)); - ImGui::SetWindowFocus("Content Browser"); - strcpy_s(FilterForResourcesContentBrowser, ""); - ItemInFocus = Object; - - const auto Content = VIRTUAL_FILE_SYSTEM.GetDirectoryContent(VIRTUAL_FILE_SYSTEM.GetCurrentPath()); - size_t TotalItemCount = Content.size(); - - size_t ItemIndex = 0; - for (size_t i = 0; i < Content.size(); i++) - { - if (Content[i]->GetObjectID() == Object->GetObjectID()) - { - ItemIndex = i; - break; - } - } - - ImGuiWindow* ContentBrowserWindow = ImGui::FindWindowByName("Content Browser"); - const int IconsPerWindowWidth = (int)(ContentBrowserWindow->Rect().GetWidth() / (ContentBrowserItemIconSize + 8 + 32)); - const size_t ItemRow = ItemIndex / IconsPerWindowWidth; - - if (ContentBrowserWindow != nullptr) - { - ContentBrowserWindow->Scroll.y = float(ItemRow * (ContentBrowserItemIconSize + 8 + 8 + 32)); - } -} - void FEEditor::DisplayInspector() { if (!bInspectorVisible) @@ -1531,48 +987,48 @@ void FEEditor::DisplayInspector() if (SELECTED.GetEntity() != nullptr) { - FEEntity* entity = SELECTED.GetEntity(); + FEEntity* Entity = SELECTED.GetEntity(); - if (entity->GetType() == FE_ENTITY) + if (Entity->GetType() == FE_ENTITY) { - ShowTransformConfiguration(entity, &entity->Transform); + ShowTransformConfiguration(Entity, &Entity->Transform); ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f)); - bool bActive = entity->IsWireframeMode(); + bool bActive = Entity->IsWireframeMode(); ImGui::Checkbox("WireframeMode", &bActive); - entity->SetWireframeMode(bActive); + Entity->SetWireframeMode(bActive); ImGui::Separator(); ImGui::Text("Prefab : "); - FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(entity->Prefab->GetObjectID()); + FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Entity->Prefab->GetObjectID()); if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) { - EntityToModify = entity; - SelectFeObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, entity->Prefab); + EntityToModify = Entity; + SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); } EntityChangePrefabTarget->StickToItem(); - bool open_context_menu = false; + bool bOpenContextMenu = false; if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) - open_context_menu = true; + bOpenContextMenu = true; - if (open_context_menu) + if (bOpenContextMenu) ImGui::OpenPopup("##Inspector_context_menu"); - bShouldOpenContextMenuInContentBrowser = false; + CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = false; ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); if (ImGui::BeginPopup("##Inspector_context_menu")) { - bShouldOpenContextMenuInContentBrowser = true; + CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = true; if (ImGui::MenuItem("Show in folder")) { - ShowInFolderItem(entity->Prefab); + CONTENT_BROWSER_WINDOW.OpenItemParentFolder(Entity->Prefab); } ImGui::EndPopup(); @@ -1585,9 +1041,9 @@ void FEEditor::DisplayInspector() ImGui::PopStyleColor(); ImGui::PopStyleColor(); } - else if (entity->GetType() == FE_ENTITY_INSTANCED) + else if (Entity->GetType() == FE_ENTITY_INSTANCED) { - FEEntityInstanced* InstancedEntity = reinterpret_cast(entity); + FEEntityInstanced* InstancedEntity = reinterpret_cast(Entity); if (SELECTED.InstancedSubObjectIndexSelected != -1) { @@ -1617,7 +1073,7 @@ void FEEditor::DisplayInspector() } else { - ShowTransformConfiguration(entity, &entity->Transform); + ShowTransformConfiguration(Entity, &Entity->Transform); ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); @@ -1626,30 +1082,30 @@ void FEEditor::DisplayInspector() ImGui::Separator(); ImGui::Text("Prefab : "); - FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(entity->Prefab->GetObjectID()); + FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Entity->Prefab->GetObjectID()); if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) { - EntityToModify = entity; - SelectFeObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, entity->Prefab); + EntityToModify = Entity; + SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); } EntityChangePrefabTarget->StickToItem(); - bool open_context_menu = false; + bool bOpenContextMenu = false; if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) - open_context_menu = true; + bOpenContextMenu = true; - if (open_context_menu) + if (bOpenContextMenu) ImGui::OpenPopup("##Inspector_context_menu"); - bShouldOpenContextMenuInContentBrowser = false; + CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = false; ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); if (ImGui::BeginPopup("##Inspector_context_menu")) { - bShouldOpenContextMenuInContentBrowser = true; + CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = true; if (ImGui::MenuItem("Show in folder")) { - ShowInFolderItem(entity->Prefab); + CONTENT_BROWSER_WINDOW.OpenItemParentFolder(Entity->Prefab); } ImGui::EndPopup(); @@ -2972,7 +2428,7 @@ void FEEditor::DisplayTerrainSettings(FETerrain* Terrain) else { TerrainToWorkWith = Terrain; - SelectFeObjectPopUp::getInstance().Show(FE_MATERIAL, CreateNewTerrainLayerWithMaterialCallBack, nullptr, FinalMaterialList); + SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, CreateNewTerrainLayerWithMaterialCallBack, nullptr, FinalMaterialList); } } @@ -3034,7 +2490,7 @@ void FEEditor::DisplayTerrainSettings(FETerrain* Terrain) { TerrainToWorkWith = Terrain; TempLayerIndex = HoveredTerrainLayerItem; - SelectFeObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialInTerrainLayerCallBack, Terrain->GetLayerInSlot(HoveredTerrainLayerItem)->GetMaterial(), FinalMaterialList); + SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialInTerrainLayerCallBack, Terrain->GetLayerInSlot(HoveredTerrainLayerItem)->GetMaterial(), FinalMaterialList); } } @@ -3077,7 +2533,7 @@ void FEEditor::DisplayTerrainSettings(FETerrain* Terrain) void FEEditor::RenderAllSubWindows() { - SelectFeObjectPopUp::getInstance().Render(); + SelectFEObjectPopUp::getInstance().Render(); DeleteTexturePopup::getInstance().Render(); DeleteMeshPopup::getInstance().Render(); @@ -3086,58 +2542,18 @@ void FEEditor::RenderAllSubWindows() DeletePrefabPopup::getInstance().Render(); DeleteDirectoryPopup::getInstance().Render(); - resizeTexturePopup::getInstance().Render(); + ResizeTexturePopup::getInstance().Render(); JustTextWindowObj.Render(); - renamePopUp::getInstance().Render(); - renameFailedPopUp::getInstance().Render(); + RenamePopUp::getInstance().Render(); + RenameFailedPopUp::getInstance().Render(); MessagePopUp::getInstance().Render(); - projectWasModifiedPopUp::getInstance().Render(); + ProjectWasModifiedPopUp::getInstance().Render(); FE_IMGUI_WINDOW_MANAGER.RenderAllWindows(); } -void FEEditor::SetCorrectSceneBrowserColor(FEObject* SceneObject) const -{ - if (SceneObject->GetType() == FE_DIRECTIONAL_LIGHT || - SceneObject->GetType() == FE_SPOT_LIGHT || - SceneObject->GetType() == FE_POINT_LIGHT) - { - ImGui::PushStyleColor(ImGuiCol_Text, LightColorSceneBrowser); - } - else if (SceneObject->GetType() == FE_CAMERA) - { - ImGui::PushStyleColor(ImGuiCol_Text, CameraColorSceneBrowser); - } - else if (SceneObject->GetType() == FE_TERRAIN) - { - ImGui::PushStyleColor(ImGuiCol_Text, TerrainColorSceneBrowser); - } - else if (SceneObject->GetType() == FE_ENTITY) - { - ImGui::PushStyleColor(ImGuiCol_Text, EntityColorSceneBrowser); - } - else if (SceneObject->GetType() == FE_ENTITY_INSTANCED) - { - ImGui::PushStyleColor(ImGuiCol_Text, InstancedEntityColorSceneBrowser); - } -} - -void FEEditor::PopCorrectSceneBrowserColor(FEObject* SceneObject) -{ - if (SceneObject->GetType() == FE_DIRECTIONAL_LIGHT || - SceneObject->GetType() == FE_SPOT_LIGHT || - SceneObject->GetType() == FE_POINT_LIGHT || - SceneObject->GetType() == FE_CAMERA || - SceneObject->GetType() == FE_TERRAIN || - SceneObject->GetType() == FE_ENTITY || - SceneObject->GetType() == FE_ENTITY_INSTANCED) - { - ImGui::PopStyleColor(); - } -} - void FEEditor::SetImguiStyle() { ImGuiStyle* style = &ImGui::GetStyle(); diff --git a/FEEditor.h b/FEEditor.h index d265a06..58d8eb3 100644 --- a/FEEditor.h +++ b/FEEditor.h @@ -1,233 +1,125 @@ #pragma once -#include "FEEditorSubWindows/projectWasModifiedPopUp.h" +#include "EditorWindows/ContentBrowserWindow.h" #include -using namespace FocalEngine; - -#ifdef FE_WIN_32 -const COMDLG_FILTERSPEC OBJ_LOAD_FILTER[] = -{ - { L"Wavefront OBJ files (*.obj)", L"*.obj" } -}; - -const COMDLG_FILTERSPEC TEXTURE_LOAD_FILTER[] = -{ - { L"Image files (*.png; *.jpg; *.bmp)", L"*.png;*.jpg;*.bmp" } -}; - -const COMDLG_FILTERSPEC ALL_IMPORT_LOAD_FILTER[] = -{ - { L"All files (*.png; *.jpg; *.bmp; *.obj)", L"*.png;*.jpg;*.bmp;*.obj" }, - { L"Image files (*.png; *.jpg; *.bmp)", L"*.png;*.jpg;*.bmp" }, - { L"Wavefront OBJ files (*.obj)", L"*.obj" } -}; -#endif class DragAndDropTarget; class FEEditor { public: - SINGLETON_PUBLIC_PART(FEEditor) - - void InitializeResources(); - - double GetLastMouseX() const; - void SetLastMouseX(double NewValue); - double GetLastMouseY() const; - void SetLastMouseY(double NewValue); - - double GetMouseX() const; - void SetMouseX(double NewValue); - double GetMouseY() const; - void SetMouseY(double NewValue); - - std::string GetObjectNameInClipboard(); - void SetObjectNameInClipboard(std::string NewValue); - - void Render(); - bool bLeftMousePressed = false; - bool bShiftPressed = false; + SINGLETON_PUBLIC_PART(FEEditor) + + // Initialization and rendering + void InitializeResources(); + void Render(); + + // Mouse and input + double GetLastMouseX() const; + void SetLastMouseX(double NewValue); + double GetLastMouseY() const; + void SetLastMouseY(double NewValue); + double GetMouseX() const; + void SetMouseX(double NewValue); + double GetMouseY() const; + void SetMouseY(double NewValue); + bool bLeftMousePressed = false; + bool bShiftPressed = false; + + // Clipboard + std::string GetObjectNameInClipboard(); + void SetObjectNameInClipboard(std::string NewValue); private: - SINGLETON_PRIVATE_PART(FEEditor) - - double LastMouseX, LastMouseY; - double MouseX, MouseY; - std::string ObjectNameInClipboard; - static ImGuiWindow* SceneWindow; - bool bSceneWindowHovered; - - bool bIsCameraInputActive = false; - - FETexture* SculptBrushIcon = nullptr; - FETexture* LevelBrushIcon = nullptr; - FETexture* SmoothBrushIcon = nullptr; - FETexture* MouseCursorIcon = nullptr; - FETexture* ArrowToGroundIcon = nullptr; - FETexture* DrawBrushIcon = nullptr; - - void SetCorrectSceneBrowserColor(FEObject* SceneObject) const; - void PopCorrectSceneBrowserColor(FEObject* SceneObject); - ImVec4 TerrainColorSceneBrowser = ImVec4(67.0f / 255.0f, 155.0f / 255.0f, 60.0f / 255.0f, 1.0f); - ImVec4 EntityColorSceneBrowser = ImVec4(141.0f / 255.0f, 141.0f / 255.0f, 233.0f / 255.0f, 1.0f); - ImVec4 InstancedEntityColorSceneBrowser = ImVec4(80.0f / 255.0f, 72.0f / 255.0f, 1.0f, 1.0f); - ImVec4 CameraColorSceneBrowser = ImVec4(0.0f, 215.0f / 255.0f, 201.0f / 255.0f, 1.0f); - ImVec4 LightColorSceneBrowser = ImVec4(243.0f / 255.0f, 230.0f / 255.0f, 31.0f / 255.0f, 1.0f); - - void DrawCorrectSceneBrowserIcon(const FEObject* SceneObject) const; - FETexture* EntitySceneBrowserIcon = nullptr; - FETexture* InstancedEntitySceneBrowserIcon = nullptr; - FETexture* DirectionalLightSceneBrowserIcon = nullptr; - FETexture* SpotLightSceneBrowserIcon = nullptr; - FETexture* PointLightSceneBrowserIcon = nullptr; - FETexture* TerrainSceneBrowserIcon = nullptr; - FETexture* CameraSceneBrowserIcon = nullptr; - - DragAndDropTarget* SceneWindowTarget = nullptr; - - static void OnCameraUpdate(FEBasicCamera* Camera); - static void MouseButtonCallback(int Button, int Action, int Mods); - static void MouseMoveCallback(double Xpos, double Ypos); - static void KeyButtonCallback(int Key, int Scancode, int Action, int Mods); - static void RenderTargetResizeCallback(int NewW, int NewH); - static void DropCallback(int Count, const char** Paths); - - void DisplaySceneBrowser(); - bool bSceneBrowserVisible = true; - void DisplayInspector(); - bool bInspectorVisible = true; - bool bEffectsWindowVisible = true; - void DisplayEffectsWindow() const; - bool bLogWindowVisible = true; - void DisplayLogWindow() const; - - static void CloseWindowCallBack(); - - void ShowTransformConfiguration(FEObject* Object, FETransformComponent* Transform) const; - void ShowTransformConfiguration(std::string Name, FETransformComponent* Transform) const; - - void DisplayLightProperties(FELight* Light) const; - void DisplayLightsProperties() const; - - void ShowInFolderItem(FEObject* Object); - - // ************** Terrain Settings ************** - ImGuiButton* ExportHeightMapButton = nullptr; - ImGuiButton* ImportHeightMapButton = nullptr; - ImGuiImageButton* SculptBrushButton = nullptr; - ImGuiImageButton* LevelBrushButton = nullptr; - ImGuiImageButton* SmoothBrushButton = nullptr; - - ImGuiImageButton* LayerBrushButton = nullptr; - - static bool EntityChangePrefabTargetCallBack(FEObject* Object, void** EntityPointer); - static bool TerrainChangeMaterialTargetCallBack(FEObject* Object, void** LayerIndex); - - static FEEntity* EntityToModify; - static void ChangePrefabOfEntityCallBack(std::vector SelectionsResult); - - DragAndDropTarget* EntityChangePrefabTarget = nullptr; - std::vector TerrainChangeMaterialIndecies; - std::vector TerrainChangeLayerMaterialTargets; - - int HoveredTerrainLayerItem = -1; - void DisplayTerrainSettings(FETerrain* Terrain); - - int TerrainLayerRenameIndex = -1; - char TerrainLayerRename[1024]; - bool bLastFrameTerrainLayerRenameEditWasVisiable = false; - // ************** Terrain Settings END ************** - // - // ************** Content Browser ************** - - FETexture* FolderIcon = nullptr; - FETexture* ShaderIcon = nullptr; - FETexture* VFSBackIcon = nullptr; - - FETexture* TextureContentBrowserIcon = nullptr; - FETexture* MeshContentBrowserIcon = nullptr; - FETexture* MaterialContentBrowserIcon = nullptr; - FETexture* GameModelContentBrowserIcon = nullptr; - FETexture* PrefabContentBrowserIcon = nullptr; - - void DisplayContentBrowser(); - bool bContentBrowserVisible = true; - void ChooseTexturesForContentBrowserItem(FETexture*& PreviewTexture, FETexture*& SmallAdditionTypeIcon, ImVec2& UV0, ImVec2& UV1, FEObject* Item); - void DisplayContentBrowserItems(); - - float ContentBrowserItemIconSize = 128.0; - int ContentBrowserItemUnderMouse = -1; - int ContentBrowserRenameIndex = -1; - char ContentBrowserRename[1024]; - bool bLastFrameRenameEditWasVisiable = false; - - std::vector AllResourcesContentBrowser; - std::vector FilteredResourcesContentBrowser; - char FilterForResourcesContentBrowser[512]; - static FEObject* ItemInFocus; - std::string ObjTypeFilterForResourcesContentBrowser; - void UpdateFilterForResourcesContentBrowser(); - FETexture* AllContentBrowserIcon = nullptr; - ImGuiImageButton* FilterAllTypesButton = nullptr; - ImGuiImageButton* FilterTextureTypeButton = nullptr; - ImGuiImageButton* FilterMeshTypeButton = nullptr; - ImGuiImageButton* FilterMaterialTypeButton = nullptr; - ImGuiImageButton* FilterGameModelTypeButton = nullptr; - ImGuiImageButton* FilterPrefabTypeButton = nullptr; - - char FilterForSceneEntities[512]; - bool bShouldOpenContextMenuInContentBrowser = false; - bool bShouldOpenContextMenuInSceneEntities = false; - - // ************** Drag&Drop ************** - struct DirectoryDragAndDropCallbackInfo - { - std::string DirectoryPath; - }; - std::vector DirectoryDragAndDropInfo; - std::vector ContentBrowserDirectoriesTargets; - DragAndDropTarget* VFSBackButtonTarget = nullptr; - DirectoryDragAndDropCallbackInfo VFSBackButtoninfo; - - static bool DirectoryDragAndDropCallback(FEObject* Object, void** Directory) - { - const DirectoryDragAndDropCallbackInfo* info = reinterpret_cast(Directory); - if (Object->GetType() == FE_NULL) - { - std::string OldPath = VIRTUAL_FILE_SYSTEM.GetCurrentPath(); - if (OldPath.back() != '/') - OldPath += "/"; - - VIRTUAL_FILE_SYSTEM.MoveDirectory(OldPath + Object->GetName(), info->DirectoryPath); - } - else - { - VIRTUAL_FILE_SYSTEM.MoveFile(Object, VIRTUAL_FILE_SYSTEM.GetCurrentPath(), info->DirectoryPath); - } - - return true; - } - - void UpdateDirectoryDragAndDropTargets(); - - // ************** Drag&Drop END ************** - - // ************** Content Browser END ************** - - int TextureUnderMouse = -1; - int MeshUnderMouse = -1; - std::string ShaderIdUnderMouse; - int MaterialUnderMouse = -1; - int GameModelUnderMouse = -1; - int EntityUnderMouse = -1; - - bool bGameMode = false; - bool IsInGameMode() const; - void SetGameMode(bool GameMode); - - void RenderAllSubWindows(); - - void SetUpImgui(); - void SetImguiStyle(); + SINGLETON_PRIVATE_PART(FEEditor) + + // Mouse and input + double LastMouseX, LastMouseY; + double MouseX, MouseY; + bool bSceneWindowHovered; + bool bIsCameraInputActive = false; + + // Clipboard + std::string ObjectNameInClipboard; + + // Scene window + static ImGuiWindow* SceneWindow; + + // Brush icons + FETexture* SculptBrushIcon = nullptr; + FETexture* LevelBrushIcon = nullptr; + FETexture* SmoothBrushIcon = nullptr; + FETexture* MouseCursorIcon = nullptr; + FETexture* ArrowToGroundIcon = nullptr; + FETexture* DrawBrushIcon = nullptr; + + // Drag and drop + DragAndDropTarget* SceneWindowTarget = nullptr; + + // Callbacks + static void OnCameraUpdate(FEBasicCamera* Camera); + static void MouseButtonCallback(int Button, int Action, int Mods); + static void MouseMoveCallback(double Xpos, double Ypos); + static void KeyButtonCallback(int Key, int Scancode, int Action, int Mods); + static void RenderTargetResizeCallback(int NewW, int NewH); + static void DropCallback(int Count, const char** Paths); + static void CloseWindowCallBack(); + + // Inspector + void DisplayInspector(); + bool bInspectorVisible = true; + void ShowTransformConfiguration(FEObject* Object, FETransformComponent* Transform) const; + void ShowTransformConfiguration(std::string Name, FETransformComponent* Transform) const; + + // Effects window + bool bEffectsWindowVisible = true; + void DisplayEffectsWindow() const; + + // Log window + bool bLogWindowVisible = true; + void DisplayLogWindow() const; + + // Light properties + void DisplayLightProperties(FELight* Light) const; + void DisplayLightsProperties() const; + + // Terrain settings + ImGuiButton* ExportHeightMapButton = nullptr; + ImGuiButton* ImportHeightMapButton = nullptr; + ImGuiImageButton* SculptBrushButton = nullptr; + ImGuiImageButton* LevelBrushButton = nullptr; + ImGuiImageButton* SmoothBrushButton = nullptr; + ImGuiImageButton* LayerBrushButton = nullptr; + static bool EntityChangePrefabTargetCallBack(FEObject* Object, void** EntityPointer); + static bool TerrainChangeMaterialTargetCallBack(FEObject* Object, void** LayerIndex); + static FEEntity* EntityToModify; + static void ChangePrefabOfEntityCallBack(std::vector SelectionsResult); + DragAndDropTarget* EntityChangePrefabTarget = nullptr; + std::vector TerrainChangeMaterialIndecies; + std::vector TerrainChangeLayerMaterialTargets; + int HoveredTerrainLayerItem = -1; + void DisplayTerrainSettings(FETerrain* Terrain); + int TerrainLayerRenameIndex = -1; + char TerrainLayerRename[1024]; + bool bLastFrameTerrainLayerRenameEditWasVisiable = false; + + // Resource under mouse + int TextureUnderMouse = -1; + int MeshUnderMouse = -1; + std::string ShaderIdUnderMouse; + int MaterialUnderMouse = -1; + int GameModelUnderMouse = -1; + int EntityUnderMouse = -1; + + // Game mode + bool bGameMode = false; + bool IsInGameMode() const; + void SetGameMode(bool GameMode); + + // Sub-windows + void RenderAllSubWindows(); + + // ImGui setup + void SetUpImgui(); + void SetImguiStyle(); }; #define EDITOR FEEditor::getInstance() \ No newline at end of file diff --git a/FEEditorDragAndDropManager.cpp b/FEEditorDragAndDropManager.cpp index a846c43..5f86ab3 100644 --- a/FEEditorDragAndDropManager.cpp +++ b/FEEditorDragAndDropManager.cpp @@ -165,9 +165,9 @@ void DragAndDropManager::MouseMove() } } -void DragAndDropManager::SetObject(FEObject* Obj, FETexture* Texture, ImVec2 UV0, ImVec2 UV1) +void DragAndDropManager::SetObjectToDrag(FEObject* Object, FETexture* Texture, ImVec2 UV0, ImVec2 UV1) { - Object = Obj; + this->Object = Object; PreviewTexture = Texture; this->UV0 = UV0; this->UV1 = UV1; diff --git a/FEEditorDragAndDropManager.h b/FEEditorDragAndDropManager.h index 28b48d2..56d4571 100644 --- a/FEEditorDragAndDropManager.h +++ b/FEEditorDragAndDropManager.h @@ -1,13 +1,12 @@ #pragma once #include "../FEngine.h" +#include using namespace FocalEngine; -class DragAndDropManager; - class DragAndDropTarget { - friend DragAndDropManager; + friend class DragAndDropManager; private: std::vector AcceptedTypes; std::vector ToolTipTexts; @@ -18,7 +17,6 @@ class DragAndDropTarget DragAndDropTarget(); DragAndDropTarget(FE_OBJECT_TYPE AcceptedType, bool (*Callback)(FEObject*, void**), void** UserData = nullptr, std::string ToolTipText = ""); DragAndDropTarget(std::vector& AcceptedTypes, bool (*Callback)(FEObject*, void**), void** UserData, std::vector& ToolTipTexts); - ~DragAndDropTarget(); void SetActive(bool Active); @@ -48,7 +46,7 @@ class DragAndDropManager void DropAction(); void MouseMove(); - void SetObject(FEObject* Obj, FETexture* Texture = nullptr, ImVec2 UV0 = ImVec2(0.0f, 1.0f), ImVec2 UV1 = ImVec2(0.0f, 1.0f)); + void SetObjectToDrag(FEObject* Object, FETexture* Texture = nullptr, ImVec2 UV0 = ImVec2(0.0f, 1.0f), ImVec2 UV1 = ImVec2(0.0f, 1.0f)); bool ObjectIsDraged() const; FETexture* GetToolTipTexture() const; diff --git a/FEEditorPreviewManager.h b/FEEditorPreviewManager.h index 3896bb5..8adec94 100644 --- a/FEEditorPreviewManager.h +++ b/FEEditorPreviewManager.h @@ -3,86 +3,77 @@ #include "../FEngine.h" using namespace FocalEngine; -class FEEditor; -class FEProjectManager; -class DeleteTexturePopup; -class RenameMeshPopUp; -class DeleteMeshPopup; -class SelectMeshPopUp; -class SelectMaterialPopUp; -class SelectGameModelPopUp; -class EditGameModelPopup; -class EditMaterialPopup; -class DeleteMaterialPopup; -class SelectFeObjectPopUp; -class PrefabEditorWindow; - -class FEEditorPreviewManager -{ - friend FEEditor; - friend FEProjectManager; - friend DeleteTexturePopup; - friend RenameMeshPopUp; - friend DeleteMeshPopup; - friend SelectMeshPopUp; - friend SelectMaterialPopUp; - friend SelectGameModelPopUp; - friend EditGameModelPopup; - friend EditMaterialPopup; - friend DeleteMaterialPopup; - friend SelectFeObjectPopUp; - friend PrefabEditorWindow; - -private: - SINGLETON_PUBLIC_PART(FEEditorPreviewManager) - SINGLETON_PRIVATE_PART(FEEditorPreviewManager) - - void InitializeResources(); - void ReInitializeEntities(); - void UpdateAll(); - - FEFramebuffer* PreviewFB; - FEEntity* PreviewEntity; - FEPrefab* PreviewPrefab; - FEGameModel* PreviewGameModel; - FEMaterial* MeshPreviewMaterial; - - std::unordered_map MeshPreviewTextures; - std::unordered_map MaterialPreviewTextures; - std::unordered_map GameModelPreviewTextures; - std::unordered_map PrefabPreviewTextures; - - static glm::vec4 OriginalClearColor; - static FETransformComponent OriginalMeshTransform; - static glm::vec3 OriginalCameraPosition; - static float OriginalAspectRation; - static float OriginalCameraPitch; - static float OriginalCameraRoll; - static float OriginalCameraYaw; - static float OriginalExposure; - - void BeforePreviewActions(); - void AfterPreviewActions(); - - void CreateMeshPreview(std::string MeshID); - FETexture* GetMeshPreview(std::string MeshID); - - void CreateMaterialPreview(std::string MaterialID); - FETexture* GetMaterialPreview(std::string MaterialID); - - void CreateGameModelPreview(std::string GameModelID); - void CreateGameModelPreview(const FEGameModel* GameModel, FETexture** ResultingTexture); - FETexture* GetGameModelPreview(std::string GameModelID); - void UpdateAllGameModelPreviews(); - - void CreatePrefabPreview(std::string PrefabID); - void CreatePrefabPreview(FEPrefab* Prefab, FETexture** ResultingTexture); - FETexture* GetPrefabPreview(std::string PrefabID); - - FETexture* GetPreview(FEObject* Object); - FETexture* GetPreview(std::string ObjectID); - - void Clear(); -}; - -#define PREVIEW_MANAGER FEEditorPreviewManager::getInstance() \ No newline at end of file +//namespace FocalEngine +//{ + + class FEEditorPreviewManager + { + friend class FEEditor; + friend class FEEditorContentBrowserWindow; + friend class FEProjectManager; + friend class DeleteTexturePopup; + friend class RenameMeshPopUp; + friend class DeleteMeshPopup; + friend class SelectMeshPopUp; + friend class SelectMaterialPopUp; + friend class SelectGameModelPopUp; + friend class EditGameModelPopup; + friend class EditMaterialPopup; + friend class DeleteMaterialPopup; + friend class SelectFEObjectPopUp; + friend class PrefabEditorWindow; + + private: + SINGLETON_PUBLIC_PART(FEEditorPreviewManager) + SINGLETON_PRIVATE_PART(FEEditorPreviewManager) + + void InitializeResources(); + void ReInitializeEntities(); + void UpdateAll(); + + FEFramebuffer* PreviewFB; + FEEntity* PreviewEntity; + FEPrefab* PreviewPrefab; + FEGameModel* PreviewGameModel; + FEMaterial* MeshPreviewMaterial; + + std::unordered_map MeshPreviewTextures; + std::unordered_map MaterialPreviewTextures; + std::unordered_map GameModelPreviewTextures; + std::unordered_map PrefabPreviewTextures; + + static glm::vec4 OriginalClearColor; + static FETransformComponent OriginalMeshTransform; + static glm::vec3 OriginalCameraPosition; + static float OriginalAspectRation; + static float OriginalCameraPitch; + static float OriginalCameraRoll; + static float OriginalCameraYaw; + static float OriginalExposure; + + void BeforePreviewActions(); + void AfterPreviewActions(); + + void CreateMeshPreview(std::string MeshID); + FETexture* GetMeshPreview(std::string MeshID); + + void CreateMaterialPreview(std::string MaterialID); + FETexture* GetMaterialPreview(std::string MaterialID); + + void CreateGameModelPreview(std::string GameModelID); + void CreateGameModelPreview(const FEGameModel* GameModel, FETexture** ResultingTexture); + FETexture* GetGameModelPreview(std::string GameModelID); + void UpdateAllGameModelPreviews(); + + void CreatePrefabPreview(std::string PrefabID); + void CreatePrefabPreview(FEPrefab* Prefab, FETexture** ResultingTexture); + FETexture* GetPrefabPreview(std::string PrefabID); + + FETexture* GetPreview(FEObject* Object); + FETexture* GetPreview(std::string ObjectID); + + void Clear(); + }; + +#define PREVIEW_MANAGER FEEditorPreviewManager::getInstance() +//} \ No newline at end of file diff --git a/FEEditorSubWindows/debugTextureViewWindow.h b/FEEditorSubWindows/debugTextureViewWindow.h deleted file mode 100644 index b142be5..0000000 --- a/FEEditorSubWindows/debugTextureViewWindow.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "prefabEditorWindow.h" - -class debugTextureViewWindow : public FEImGuiWindow -{ - ImGuiButton* CloseButton = nullptr; - std::function TextureToView; -public: - debugTextureViewWindow(std::function Func); - ~debugTextureViewWindow(); - - void Render() override; -}; \ No newline at end of file diff --git a/FEEditorSubWindows/projectWasModifiedPopUp.h b/FEEditorSubWindows/projectWasModifiedPopUp.h deleted file mode 100644 index 2147968..0000000 --- a/FEEditorSubWindows/projectWasModifiedPopUp.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "debugTextureViewWindow.h" - -class projectWasModifiedPopUp : public ImGuiModalPopup -{ - FEProject* ObjToWorkWith; - bool bShouldTerminate = false; -public: - SINGLETON_PUBLIC_PART(projectWasModifiedPopUp) - - void Show(FEProject* Project, bool FullyCloseApplication); - void Render() override; - -private: - SINGLETON_PRIVATE_PART(projectWasModifiedPopUp) -}; \ No newline at end of file diff --git a/FEEditorSubWindows/renamePopups.h b/FEEditorSubWindows/renamePopups.h deleted file mode 100644 index 0e9efd6..0000000 --- a/FEEditorSubWindows/renamePopups.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "deletePopups.h" - -class renameFailedPopUp : public ImGuiModalPopup -{ - ImGuiButton* OkButton = nullptr; -public: - SINGLETON_PUBLIC_PART(renameFailedPopUp) - void Render() override; -private: - SINGLETON_PRIVATE_PART(renameFailedPopUp) -}; - -class renamePopUp : public ImGuiModalPopup -{ - FEObject* ObjToWorkWith; - char NewName[512]; -public: - SINGLETON_PUBLIC_PART(renamePopUp) - - void Show(FEObject* ObjToWorkWith); - void Render() override; -private: - SINGLETON_PRIVATE_PART(renamePopUp) -}; \ No newline at end of file diff --git a/FEProject.h b/FEProject.h index 33bd8b1..ae0d8af 100644 --- a/FEProject.h +++ b/FEProject.h @@ -8,8 +8,6 @@ #include "FEEditorInternalResources.h" #include "FEEditorVirtualFileSystem.h" -using namespace FocalEngine; - class FEProject { public: diff --git a/Resources/imgui.ini b/Resources/imgui.ini index d781fa9..963cba5 100644 --- a/Resources/imgui.ini +++ b/Resources/imgui.ini @@ -5,57 +5,57 @@ Collapsed=0 [Window][Scene Entities] Pos=0,28 -Size=504,954 +Size=504,1604 Collapsed=0 DockId=0x00000001,0 [Window][Content Browser] -Pos=0,984 -Size=2564,437 +Pos=0,1634 +Size=3840,437 Collapsed=0 DockId=0x00000003,0 [Window][Scene] Pos=506,28 -Size=1590,954 +Size=2866,1604 Collapsed=0 DockId=0x0000000B,0 [Window][Inspector] -Pos=2098,28 -Size=466,954 +Pos=3374,28 +Size=466,1604 Collapsed=0 DockId=0x00000008,0 [Window][Effects settings] -Pos=0,984 -Size=2564,437 +Pos=0,1634 +Size=3840,437 Collapsed=0 DockId=0x00000003,1 [Window][Log] -Pos=0,984 -Size=2564,437 +Pos=0,1634 +Size=3840,437 Collapsed=0 DockId=0x00000003,2 [Window][DockSpaceViewport_11111111] Pos=0,28 -Size=2564,1393 +Size=3840,2043 Collapsed=0 [Window][##create project] -Pos=0,1331 -Size=2564,90 +Pos=0,1981 +Size=3840,90 Collapsed=0 [Window][Project Browser] Pos=0,0 -Size=2564,1331 +Size=3840,1981 Collapsed=0 [Window][##GizmosSettingsWindow] -Pos=1207,10 +Pos=1845,10 Size=146,48 Collapsed=0 @@ -74,8 +74,8 @@ Pos=2271,895 Collapsed=0 [Window][dragAndDrop info] -Pos=1688,1268 -Size=313,212 +Pos=119,511 +Size=271,80 Collapsed=0 [Window][Edit material: tree_stump] @@ -943,7 +943,7 @@ Column 0 Weight=1.0000 Column 1 Weight=1.0000 [Docking][Data] -DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,28 Size=2564,1393 Split=Y +DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,28 Size=3840,2043 Split=Y DockNode ID=0x00000005 Parent=0x8B93E3BD SizeRef=2524,1357 Split=Y Selected=0x18B8C0DE DockNode ID=0x00000002 Parent=0x00000005 SizeRef=3319,1604 Split=Y DockNode ID=0x00000009 Parent=0x00000002 SizeRef=2691,835 Split=X Selected=0x18B8C0DE diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 8090483..76afe1b 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 80904837b1f47b77c04a9855901234f25ac3f120 +Subproject commit 76afe1bd797a7186da4811f4738bee2a0d89c614 From 6ded99b5e35957993341af68dfa2878960ea8650 Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Sun, 16 Jun 2024 15:05:46 -0400 Subject: [PATCH 02/46] Updated FEBasicApplication and Visual Node System; Made changes to accommodate these updates. --- EditorWindows/EditPopups.cpp | 2 +- SubSystems/FocalEngine | 2 +- SubSystems/NodeSystem/VisualNodeSystem | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/EditorWindows/EditPopups.cpp b/EditorWindows/EditPopups.cpp index ec2c57b..3547a78 100644 --- a/EditorWindows/EditPopups.cpp +++ b/EditorWindows/EditPopups.cpp @@ -773,7 +773,7 @@ void EditMaterialPopup::Show(FEMaterial* Material) #ifdef USE_NODES MaterialNodeArea = NODE_SYSTEM.CreateNodeArea(); MaterialNodeArea->SetMainContextMenuFunc(NodeSystemMainContextMenu); - MaterialNodeArea->SetNodeEventCallback(TextureNodeCallback); + MaterialNodeArea->AddNodeEventCallback(TextureNodeCallback); FEEditorMaterialNode* NewNode = new FEEditorMaterialNode(Material); diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 76afe1b..a58330e 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 76afe1bd797a7186da4811f4738bee2a0d89c614 +Subproject commit a58330ec4dcbd3dd1299e7c90c24882366cce240 diff --git a/SubSystems/NodeSystem/VisualNodeSystem b/SubSystems/NodeSystem/VisualNodeSystem index ff367bd..252484d 160000 --- a/SubSystems/NodeSystem/VisualNodeSystem +++ b/SubSystems/NodeSystem/VisualNodeSystem @@ -1 +1 @@ -Subproject commit ff367bda047c6583089c5698a091086fac4c924c +Subproject commit 252484de4a10e773802475250535df3e3fb53b0d From 272fd908ceb67e880a550302004b279643ddc137 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Tue, 18 Jun 2024 14:22:19 -0400 Subject: [PATCH 03/46] Updated FocalEngine; Made adjustments to incorporate the engine update. --- CMakeLists.txt | 2 +- EditorWindows/ContentBrowserWindow.cpp | 2 +- FEEditor.cpp | 4 ++-- SubSystems/FocalEngine | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4c963c..05524ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_FLAGS_DEBUG "/MP /ZI /W3 /Od /MDd /JMC /sdl /FC /D IMGUI_IMPL_OPENGL_LOADER_GLEW /D WIN32 /D _WINDOWS /D _DEBUG /D FE_DEBUG_ENABLED") -set(CMAKE_CXX_FLAGS_RELEASE "/MP /W3 /O2 /Oi /Gy /sdl /FC /GL /OPT:REF /OPT:ICF /D IMGUI_IMPL_OPENGL_LOADER_GLEW /D NDEBUG /D WIN32 /D _WINDOWS") +set(CMAKE_CXX_FLAGS_RELEASE "/MP /W3 /O2 /Oi /MD /Gy /sdl /FC /GL /OPT:REF /OPT:ICF /D IMGUI_IMPL_OPENGL_LOADER_GLEW /D NDEBUG /D WIN32 /D _WINDOWS") # Turn on the ability to create folders to organize projects (.vcproj) # It creates "CMakePredefinedTargets" folder by default and adds CMake diff --git a/EditorWindows/ContentBrowserWindow.cpp b/EditorWindows/ContentBrowserWindow.cpp index c375dd1..86152d3 100644 --- a/EditorWindows/ContentBrowserWindow.cpp +++ b/EditorWindows/ContentBrowserWindow.cpp @@ -132,7 +132,7 @@ void FEEditorContentBrowserWindow::Render() FILE_SYSTEM.ShowFileOpenDialog(FilePath, ALL_IMPORT_LOAD_FILTER, 3); if (!FilePath.empty()) { - const std::vector LoadedObjects = RESOURCE_MANAGER.ImportAsset(FilePath.c_str()); + const std::vector LoadedObjects = SCENE.ImportAsset(FilePath.c_str()); for (size_t i = 0; i < LoadedObjects.size(); i++) { if (LoadedObjects[i] != nullptr) diff --git a/FEEditor.cpp b/FEEditor.cpp index 0d7d671..bcd8c33 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -900,14 +900,14 @@ void FEEditor::DropCallback(const int Count, const char** Paths) if (PROJECT_MANAGER.GetCurrent() != nullptr) { - std::vector LoadedObjects = RESOURCE_MANAGER.ImportAsset(Paths[i]); + std::vector LoadedObjects = SCENE.ImportAsset(Paths[i]); for (size_t j = 0; j < LoadedObjects.size(); j++) { if (LoadedObjects[j] != nullptr) { if (LoadedObjects[j]->GetType() == FE_ENTITY) { - SCENE.AddEntity(reinterpret_cast(LoadedObjects[j])); + //SCENE.AddEntity(reinterpret_cast(LoadedObjects[j])); } else { diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index a58330e..37a8571 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit a58330ec4dcbd3dd1299e7c90c24882366cce240 +Subproject commit 37a857112957be5765f13c5e5ab977341d32fab0 From 05e471e179a8f828c0b97f81d78aa1f0d0f6691d Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Tue, 18 Jun 2024 22:09:23 -0400 Subject: [PATCH 04/46] Added temporary code to facilitate performance profiling; Moved log rendering code to a separate file; Rendering the log window using TextEditor is taking too much time (up to several ms) even with a small amount of text, disabling SetColorizerEnable helps but still takes too long for the log, so switched to ImGui::InputTextMultiline. --- CMakeLists.txt | 1 + EditorWindows/LogWindow.cpp | 115 ++++++++++++++++++++++++++++++++++++ FEEditor.cpp | 111 ---------------------------------- main.cpp | 16 +++++ 4 files changed, 132 insertions(+), 111 deletions(-) create mode 100644 EditorWindows/LogWindow.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 05524ff..35f0d81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,7 @@ file(GLOB EditorWindows_SRC "EditorWindows/SceneGraphWindow.h" "EditorWindows/ContentBrowserWindow.cpp" "EditorWindows/ContentBrowserWindow.h" + "EditorWindows/LogWindow.cpp" ) file(GLOB Editor_Materials_SRC diff --git a/EditorWindows/LogWindow.cpp b/EditorWindows/LogWindow.cpp new file mode 100644 index 0000000..91e6650 --- /dev/null +++ b/EditorWindows/LogWindow.cpp @@ -0,0 +1,115 @@ +#include "../FEEditor.h" + +void FEEditor::DisplayLogWindow() const +{ + if (!bLogWindowVisible) + return; + + const auto TopicList = LOG.GetTopicList(); + + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); + ImGui::Begin("Log", nullptr, ImGuiWindowFlags_None); + + static std::string SelectedChannel = "FE_LOG_GENERAL"; + ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 3); + ImGui::Text("Channel:"); + ImGui::SameLine(); + ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 5); + if (ImGui::BeginCombo("##Channel", (SelectedChannel == "" ? "ALL" : SelectedChannel).c_str(), ImGuiWindowFlags_None)) + { + for (int i = -1; i < int(TopicList.size()); i++) + { + ImGui::PushID(i); + + if (i == -1) + { + const bool is_selected = (SelectedChannel == ""); + + if (ImGui::Selectable("ALL", is_selected)) + { + SelectedChannel = ""; + } + + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + else + { + const bool is_selected = (SelectedChannel == TopicList[i]); + if (ImGui::Selectable(TopicList[i].c_str(), is_selected)) + { + SelectedChannel = TopicList[i]; + } + + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + + ImGui::PopID(); + } + ImGui::EndCombo(); + } + + std::string LogMessages; + std::vector LogItems; + + if (SelectedChannel == "") + { + std::vector TempItems; + for (int i = 0; i < int(TopicList.size()); i++) + { + TempItems = LOG.GetLogItems(TopicList[i]); + for (size_t j = 0; j < TempItems.size(); j++) + { + LogItems.push_back(TempItems[j]); + } + } + } + else + { + LogItems = LOG.GetLogItems(SelectedChannel); + } + + std::sort(LogItems.begin(), LogItems.end(), + [](const LogItem& A, const LogItem& B) -> bool + { + return A.TimeStamp < B.TimeStamp; + }); + + for (size_t i = 0; i < LogItems.size(); i++) + { + LogMessages += LogItems[i].Text; + + if (LogItems[i].Count < 1000) + { + LogMessages += " | COUNT: " + std::to_string(LogItems[i].Count); + } + else + { + LogMessages += " | COUNT: 1000+(Suppressed)"; + } + + LogMessages += " | SEVERITY: " + LOG.SeverityLevelToString(LogItems[i].Severity); + + if (SelectedChannel == "") + { + LogMessages += " | CHANNEL: " + LogItems[i].Topic; + } + + if (i < LogItems.size() - 1) + LogMessages += "\n"; + } + + /*static TextEditor LogEditor; + LogEditor.SetReadOnly(true); + LogEditor.SetShowWhitespaces(false); + LogEditor.SetText(LogMessages); + LogEditor.Render("Log messages");*/ + + static char LogMessages_[1000000]; + strcpy_s(LogMessages_, LogMessages.c_str()); + ImGui::InputTextMultiline("Log messages", LogMessages_, 1000000, ImVec2(ImGui::GetWindowWidth() - 30, ImGui::GetWindowHeight() - 100), ImGuiInputTextFlags_ReadOnly); + + ImGui::PopStyleVar(); + ImGui::End(); +} \ No newline at end of file diff --git a/FEEditor.cpp b/FEEditor.cpp index bcd8c33..f83dbfe 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -1950,117 +1950,6 @@ void FEEditor::DisplayEffectsWindow() const ImGui::End(); } -void FEEditor::DisplayLogWindow() const -{ - if (!bLogWindowVisible) - return; - - const auto TopicList = LOG.GetTopicList(); - - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); - ImGui::Begin("Log", nullptr, ImGuiWindowFlags_None); - - static std::string SelectedChannel = "FE_LOG_GENERAL"; - ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 3); - ImGui::Text("Channel:"); - ImGui::SameLine(); - ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 5); - if (ImGui::BeginCombo("##Channel", (SelectedChannel == "" ? "ALL" : SelectedChannel).c_str(), ImGuiWindowFlags_None)) - { - for (int i = -1; i < int(TopicList.size()); i++) - { - ImGui::PushID(i); - - if (i == -1) - { - const bool is_selected = (SelectedChannel == ""); - - if (ImGui::Selectable("ALL", is_selected)) - { - SelectedChannel = ""; - } - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - else - { - const bool is_selected = (SelectedChannel == TopicList[i]); - if (ImGui::Selectable(TopicList[i].c_str(), is_selected)) - { - SelectedChannel = TopicList[i]; - } - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - - ImGui::PopID(); - } - ImGui::EndCombo(); - } - - std::string LogMessages; - std::vector LogItems; - - if (SelectedChannel == "") - { - std::vector TempItems; - for (int i = 0; i < int(TopicList.size()); i++) - { - TempItems = LOG.GetLogItems(TopicList[i]); - for (size_t j = 0; j < TempItems.size(); j++) - { - LogItems.push_back(TempItems[j]); - } - } - } - else - { - LogItems = LOG.GetLogItems(SelectedChannel); - } - - std::sort(LogItems.begin(), LogItems.end(), - [](const LogItem& A, const LogItem& B) -> bool - { - return A.TimeStamp < B.TimeStamp; - }); - - for (size_t i = 0; i < LogItems.size(); i++) - { - LogMessages += LogItems[i].Text; - - if (LogItems[i].Count < 1000) - { - LogMessages += " | COUNT: " + std::to_string(LogItems[i].Count); - } - else - { - LogMessages += " | COUNT: 1000+(Suppressed)"; - } - - LogMessages += " | SEVERITY: " + LOG.SeverityLevelToString(LogItems[i].Severity); - - if (SelectedChannel == "") - { - LogMessages += " | CHANNEL: " + LogItems[i].Topic; - } - - if (i < LogItems.size() - 1) - LogMessages += "\n"; - } - - static TextEditor LogEditor; - LogEditor.SetReadOnly(true); - LogEditor.SetShowWhitespaces(false); - LogEditor.SetText(LogMessages); - LogEditor.Render("Log messages"); - - ImGui::PopStyleVar(); - ImGui::End(); -} - -//static FEMaterial* tempMaterial = nullptr; static FETerrain* TerrainToWorkWith = nullptr; static void CreateNewTerrainLayerWithMaterialCallBack(std::vector SelectionsResult) { diff --git a/main.cpp b/main.cpp index 457dadf..0f239d3 100644 --- a/main.cpp +++ b/main.cpp @@ -15,8 +15,12 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine double AverageCpuFrameDuration = 0.0; double AverageGpuFrameDuration = 0.0; + bool bPutThisFrameToTimeline = false; + while (ENGINE.IsNotTerminated()) { + PROFILING.StartProfiling(); + ENGINE.BeginFrame(); ENGINE.Render(); @@ -30,6 +34,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine ImGui::Image((void*)(intptr_t)SELECTED.PixelAccurateSelectionFB->GetColorAttachment()->GetTextureID(), ImVec2(256 * 4, 256 * 4), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); #endif + if (ImGui::Button("Put This Frame To Timeline")) + { + bPutThisFrameToTimeline = true; + } + //ImGui::ShowDemoWindow(); EDITOR.Render(); ENGINE.EndFrame(); @@ -74,6 +83,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine caption += " ms"; ENGINE.SetWindowCaption(caption.c_str()); + + PROFILING.StopProfiling(); + if (bPutThisFrameToTimeline) + { + PROFILING.SaveTimelineToJSON("timeline.json"); + bPutThisFrameToTimeline = false; + } } return 0; From d9ceba82c508ec9198c938c32c914e4a22df2471 Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Wed, 19 Jun 2024 20:58:14 -0400 Subject: [PATCH 05/46] Engine update. --- SubSystems/FocalEngine | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 37a8571..16bc99c 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 37a857112957be5765f13c5e5ab977341d32fab0 +Subproject commit 16bc99cd867b5b9b40d7d755a5e9cbc558ab1839 From bf5997e3b15f0f003addbfff26fed936c2d21676 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Thu, 20 Jun 2024 15:11:20 -0400 Subject: [PATCH 06/46] Engine update; In FEEditor::ShowTransformConfiguration, the transform will not be updated if there is nothing to change; Added a test function void TransformUpdate(FENaiveSceneEntity* SubTreeRoot) which will be deleted later. --- EditorWindows/SceneGraphWindow.cpp | 48 +++++++++++++++++++ FEEditor.cpp | 76 +++++++++++++++++++----------- SubSystems/FocalEngine | 2 +- 3 files changed, 98 insertions(+), 28 deletions(-) diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index f8fee2a..615aa7b 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -198,8 +198,54 @@ DragAndDropTarget* FEEditorSceneGraphWindow::GetSceneNodeDragAndDropTarget(FENai return SceneNodeDragAndDropTargets[UniqueID]; } +#include "glm/gtx/matrix_decompose.hpp" + +void TransformUpdate(FENaiveSceneEntity* SubTreeRoot) +{ + FEEntity* Entity = reinterpret_cast(SubTreeRoot->GetOldStyleEntity()); + if (Entity == nullptr) + return; + + FETransformComponent& ParentTransform = Entity->Transform; + + auto Children = SubTreeRoot->GetChildren(); + for (size_t i = 0; i < Children.size(); i++) + { + /*FEEntity* ChildEntity = reinterpret_cast(Children[i]->GetOldStyleEntity()); + FETransformComponent& ChildTransform = ChildEntity->Transform; + + ChildTransform.SetPosition(ParentTransform.GetPosition() + ChildTransform.GetPosition()); + ChildTransform.SetQuaternion(ParentTransform.GetQuaternion() * ChildTransform.GetQuaternion()); + ChildTransform.SetScale(ParentTransform.GetScale() * ChildTransform.GetScale()); + + TransformUpdate(Children[i]);*/ + + if (SubTreeRoot->GetName() == "BistroExterior") + { + int y = 0; + y++; + } + + + FEEntity* ChildEntity = reinterpret_cast(Children[i]->GetOldStyleEntity()); + FETransformComponent& ChildTransform = ChildEntity->Transform; + + ParentTransform.Update(); + ChildTransform.Update(); + ChildTransform.ForceSetTransformMatrix(ParentTransform.GetTransformMatrix() * ChildTransform.GetTransformMatrix()); + + glm::vec3 Position, Scale; + glm::quat Rotation; + glm::decompose(ParentTransform.GetTransformMatrix(), Scale, Rotation, Position, glm::vec3(), glm::vec4()); + + int y = 0; + y++; + } +} + void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneEntity* SubTreeRoot) { + TransformUpdate(SubTreeRoot); SceneNodeDragAndDropTargetIndex++; int64_t UniqueID = 0; @@ -269,6 +315,8 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneEntity* SubTreeRoot) } } + + void FEEditorSceneGraphWindow::RenderNewSceneGraph() { FENaiveSceneEntity* Root = SCENE.SceneGraph.GetRoot(); diff --git a/FEEditor.cpp b/FEEditor.cpp index f83dbfe..20c99a7 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -221,82 +221,104 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) void FEEditor::ShowTransformConfiguration(FEObject* Object, FETransformComponent* Transform) const { // ********************* POSITION ********************* - glm::vec3 position = Transform->GetPosition(); + glm::vec3 TemporaryPosition = Transform->GetPosition(); + bool bModified = false; + ImGui::Text("Position : "); ImGui::SameLine(); ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##X pos : ") + Object->GetName()).c_str(), &position[0], 0.1f); + if (ImGui::DragFloat((std::string("##X pos : ") + Object->GetName()).c_str(), &TemporaryPosition[0], 0.1f)) + bModified = true; ShowToolTip("X position"); ImGui::SameLine(); ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Y pos : ") + Object->GetName()).c_str(), &position[1], 0.1f); + if (ImGui::DragFloat((std::string("##Y pos : ") + Object->GetName()).c_str(), &TemporaryPosition[1], 0.1f)) + bModified = true; ShowToolTip("Y position"); ImGui::SameLine(); ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Z pos : ") + Object->GetName()).c_str(), &position[2], 0.1f); + if (ImGui::DragFloat((std::string("##Z pos : ") + Object->GetName()).c_str(), &TemporaryPosition[2], 0.1f)) + bModified = true; ShowToolTip("Z position"); - Transform->SetPosition(position); + + if (bModified) + Transform->SetPosition(TemporaryPosition); // ********************* ROTATION ********************* - glm::vec3 rotation = Transform->GetRotation(); + glm::vec3 TemporaryRotation = Transform->GetRotation(); + bModified = false; + ImGui::Text("Rotation : "); ImGui::SameLine(); ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##X rot : ") + Object->GetName()).c_str(), &rotation[0], 0.1f, -360.0f, 360.0f); + if (ImGui::DragFloat((std::string("##X rot : ") + Object->GetName()).c_str(), &TemporaryRotation[0], 0.1f, -360.0f, 360.0f)) + bModified = true; ShowToolTip("X rotation"); ImGui::SameLine(); ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Y rot : ") + Object->GetName()).c_str(), &rotation[1], 0.1f, -360.0f, 360.0f); + if (ImGui::DragFloat((std::string("##Y rot : ") + Object->GetName()).c_str(), &TemporaryRotation[1], 0.1f, -360.0f, 360.0f)) + bModified = true; ShowToolTip("Y rotation"); ImGui::SameLine(); ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Z rot : ") + Object->GetName()).c_str(), &rotation[2], 0.1f, -360.0f, 360.0f); + if (ImGui::DragFloat((std::string("##Z rot : ") + Object->GetName()).c_str(), &TemporaryRotation[2], 0.1f, -360.0f, 360.0f)) + bModified = true; ShowToolTip("Z rotation"); - Transform->SetRotation(rotation); + + if (bModified) + Transform->SetRotation(TemporaryRotation); // ********************* SCALE ********************* bool bUniformScaling = Transform->IsUniformScalingSet(); - ImGui::Checkbox("Uniform scaling", &bUniformScaling); - Transform->SetUniformScaling(bUniformScaling); + bModified = false; - glm::vec3 scale = Transform->GetScale(); + if (ImGui::Checkbox("Uniform scaling", &bUniformScaling)) + Transform->SetUniformScaling(bUniformScaling); + + glm::vec3 TemporaryScale = Transform->GetScale(); ImGui::Text("Scale : "); ImGui::SameLine(); ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##X scale : ") + Object->GetName()).c_str(), &scale[0], 0.01f, 0.01f, 1000.0f); + if (ImGui::DragFloat((std::string("##X scale : ") + Object->GetName()).c_str(), &TemporaryScale[0], 0.01f, 0.01f, 1000.0f)) + bModified = true; ShowToolTip("X scale"); ImGui::SameLine(); ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Y scale : ") + Object->GetName()).c_str(), &scale[1], 0.01f, 0.01f, 1000.0f); + if (ImGui::DragFloat((std::string("##Y scale : ") + Object->GetName()).c_str(), &TemporaryScale[1], 0.01f, 0.01f, 1000.0f)) + bModified = true; ShowToolTip("Y scale"); ImGui::SameLine(); ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Z scale : ") + Object->GetName()).c_str(), &scale[2], 0.01f, 0.01f, 1000.0f); + if (ImGui::DragFloat((std::string("##Z scale : ") + Object->GetName()).c_str(), &TemporaryScale[2], 0.01f, 0.01f, 1000.0f)) + bModified = true; ShowToolTip("Z scale"); - glm::vec3 OldScale = Transform->GetScale(); - Transform->ChangeXScaleBy(scale[0] - OldScale[0]); - Transform->ChangeYScaleBy(scale[1] - OldScale[1]); - Transform->ChangeZScaleBy(scale[2] - OldScale[2]); + if (bModified) + { + glm::vec3 OldScale = Transform->GetScale(); + Transform->ChangeXScaleBy(TemporaryScale[0] - OldScale[0]); + Transform->ChangeYScaleBy(TemporaryScale[1] - OldScale[1]); + Transform->ChangeZScaleBy(TemporaryScale[2] - OldScale[2]); + } // ********************* REAL WORLD COMPARISON SCALE ********************* if (Object->GetType() == FE_ENTITY || Object->GetType() == FE_ENTITY_INSTANCED) { - FEEntity* entity = SCENE.GetEntity(Object->GetObjectID()); + FEEntity* Entity = SCENE.GetEntity(Object->GetObjectID()); - FEAABB RealAabb = entity->GetAABB(); - const glm::vec3 min = RealAabb.GetMin(); - const glm::vec3 max = RealAabb.GetMax(); + FEAABB RealAabb = Entity->GetAABB(); + const glm::vec3 Min = RealAabb.GetMin(); + const glm::vec3 Max = RealAabb.GetMax(); - const float XSize = sqrt((max.x - min.x) * (max.x - min.x)); - const float YSize = sqrt((max.y - min.y) * (max.y - min.y)); - const float ZSize = sqrt((max.z - min.z) * (max.z - min.z)); + const float XSize = sqrt((Max.x - Min.x) * (Max.x - Min.x)); + const float YSize = sqrt((Max.y - Min.y) * (Max.y - Min.y)); + const float ZSize = sqrt((Max.z - Min.z) * (Max.z - Min.z)); std::string SizeInM = "Approximate object size: "; SizeInM += std::to_string(std::max(XSize, std::max(YSize, ZSize))); diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 16bc99c..830ec76 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 16bc99cd867b5b9b40d7d755a5e9cbc558ab1839 +Subproject commit 830ec763049aa59bee1dc95504079aa6c37f0624 From 1a7324ef69df3d11c6877967cff84669b3d66660 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Fri, 21 Jun 2024 13:54:43 -0400 Subject: [PATCH 07/46] Engine update; Added support for the engine scene transform hierarchy; Moved editor inspector-related code to a separate file. --- CMakeLists.txt | 2 + EditorWindows/ContentBrowserWindow.h | 8 +- EditorWindows/InspectorWindow.cpp | 1369 ++++++++++++++++++++++++++ EditorWindows/InspectorWindow.h | 63 ++ EditorWindows/SceneGraphWindow.cpp | 39 +- EditorWindows/SceneGraphWindow.h | 1 - FEEditor.cpp | 1366 +------------------------ FEEditor.h | 42 +- FEEditorPreviewManager.h | 145 ++- FEEditorSelectedObject.cpp | 14 +- FEEditorVirtualFileSystem.cpp | 36 +- FEProject.cpp | 6 +- SubSystems/FocalEngine | 2 +- 13 files changed, 1576 insertions(+), 1517 deletions(-) create mode 100644 EditorWindows/InspectorWindow.cpp create mode 100644 EditorWindows/InspectorWindow.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 35f0d81..075008b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,6 +91,8 @@ file(GLOB EditorWindows_SRC "EditorWindows/DebugTextureViewWindow.h" "EditorWindows/SceneGraphWindow.cpp" "EditorWindows/SceneGraphWindow.h" + "EditorWindows/InspectorWindow.cpp" + "EditorWindows/InspectorWindow.h" "EditorWindows/ContentBrowserWindow.cpp" "EditorWindows/ContentBrowserWindow.h" "EditorWindows/LogWindow.cpp" diff --git a/EditorWindows/ContentBrowserWindow.h b/EditorWindows/ContentBrowserWindow.h index 7e2a8bd..a6a4d1f 100644 --- a/EditorWindows/ContentBrowserWindow.h +++ b/EditorWindows/ContentBrowserWindow.h @@ -1,10 +1,7 @@ #pragma once #include "SceneGraphWindow.h" -//using namespace FocalEngine; -//namespace FocalEngine -//{ #ifdef FE_WIN_32 const COMDLG_FILTERSPEC OBJ_LOAD_FILTER[] = { @@ -27,6 +24,8 @@ class FEEditorContentBrowserWindow { friend class FEEditor; + friend class FEEditorInspectorWindow; + SINGLETON_PRIVATE_PART(FEEditorContentBrowserWindow) // Visibility and state @@ -111,5 +110,4 @@ SINGLETON_PUBLIC_PART(FEEditorContentBrowserWindow) }; -#define CONTENT_BROWSER_WINDOW FEEditorContentBrowserWindow::getInstance() -//} \ No newline at end of file +#define CONTENT_BROWSER_WINDOW FEEditorContentBrowserWindow::getInstance() \ No newline at end of file diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp new file mode 100644 index 0000000..992dcde --- /dev/null +++ b/EditorWindows/InspectorWindow.cpp @@ -0,0 +1,1369 @@ +#include "InspectorWindow.h" + +FEEditorInspectorWindow* FEEditorInspectorWindow::Instance = nullptr; +FEEntity* FEEditorInspectorWindow::EntityToModify = nullptr; + +FEEditorInspectorWindow::FEEditorInspectorWindow() +{ + +} + +void FEEditorInspectorWindow::InitializeResources() +{ + // ************** Terrain Settings ************** + ExportHeightMapButton = new ImGuiButton("Export HeightMap"); + ExportHeightMapButton->SetSize(ImVec2(200, 0)); + + ImportHeightMapButton = new ImGuiButton("Import HeightMap"); + ImportHeightMapButton->SetSize(ImVec2(200, 0)); + + SculptBrushIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/sculptBrush.png", "sculptBrushIcon"); + RESOURCE_MANAGER.MakeTextureStandard(SculptBrushIcon); + SculptBrushButton = new ImGuiImageButton(SculptBrushIcon); + SculptBrushButton->SetSize(ImVec2(24, 24)); + + LevelBrushIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/levelBrush.png", "levelBrushIcon"); + RESOURCE_MANAGER.MakeTextureStandard(LevelBrushIcon); + LevelBrushButton = new ImGuiImageButton(LevelBrushIcon); + LevelBrushButton->SetSize(ImVec2(24, 24)); + + SmoothBrushIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/smoothBrush.png", "smoothBrushIcon"); + RESOURCE_MANAGER.MakeTextureStandard(SmoothBrushIcon); + SmoothBrushButton = new ImGuiImageButton(SmoothBrushIcon); + SmoothBrushButton->SetSize(ImVec2(24, 24)); + + DrawBrushIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/paintbrush.png", "drawBrushIcon"); + RESOURCE_MANAGER.MakeTextureStandard(DrawBrushIcon); + LayerBrushButton = new ImGuiImageButton(DrawBrushIcon); + LayerBrushButton->SetSize(ImVec2(48, 48)); + + EntityChangePrefabTarget = DRAG_AND_DROP_MANAGER.AddTarget(FE_PREFAB, EntityChangePrefabTargetCallBack, nullptr, "Drop to assign prefab"); + // ************** Terrain Settings END ************** + + MouseCursorIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/mouseCursorIcon.png", "mouseCursorIcon"); + RESOURCE_MANAGER.MakeTextureStandard(MouseCursorIcon); + ArrowToGroundIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/arrowToGroundIcon.png", "arrowToGroundIcon"); + RESOURCE_MANAGER.MakeTextureStandard(ArrowToGroundIcon); +} + +void FEEditorInspectorWindow::Clear() +{ + +} + +void FEEditorInspectorWindow::ShowTransformConfiguration(FEObject* Object, FETransformComponent* Transform) const +{ + // ********************* POSITION ********************* + glm::vec3 TemporaryPosition = Transform->GetPosition(); + bool bModified = false; + + ImGui::Text("Position : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + if (ImGui::DragFloat((std::string("##X pos : ") + Object->GetName()).c_str(), &TemporaryPosition[0], 0.1f)) + bModified = true; + ShowToolTip("X position"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + if (ImGui::DragFloat((std::string("##Y pos : ") + Object->GetName()).c_str(), &TemporaryPosition[1], 0.1f)) + bModified = true; + ShowToolTip("Y position"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + if (ImGui::DragFloat((std::string("##Z pos : ") + Object->GetName()).c_str(), &TemporaryPosition[2], 0.1f)) + bModified = true; + ShowToolTip("Z position"); + + if (bModified) + Transform->SetPosition(TemporaryPosition); + + // ********************* ROTATION ********************* + glm::vec3 TemporaryRotation = Transform->GetRotation(); + bModified = false; + + ImGui::Text("Rotation : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + if (ImGui::DragFloat((std::string("##X rot : ") + Object->GetName()).c_str(), &TemporaryRotation[0], 0.1f, -360.0f, 360.0f)) + bModified = true; + ShowToolTip("X rotation"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + if (ImGui::DragFloat((std::string("##Y rot : ") + Object->GetName()).c_str(), &TemporaryRotation[1], 0.1f, -360.0f, 360.0f)) + bModified = true; + ShowToolTip("Y rotation"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + if (ImGui::DragFloat((std::string("##Z rot : ") + Object->GetName()).c_str(), &TemporaryRotation[2], 0.1f, -360.0f, 360.0f)) + bModified = true; + ShowToolTip("Z rotation"); + + if (bModified) + Transform->SetRotation(TemporaryRotation); + + // ********************* SCALE ********************* + bool bUniformScaling = Transform->IsUniformScalingSet(); + bModified = false; + + if (ImGui::Checkbox("Uniform scaling", &bUniformScaling)) + Transform->SetUniformScaling(bUniformScaling); + + glm::vec3 TemporaryScale = Transform->GetScale(); + ImGui::Text("Scale : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + if (ImGui::DragFloat((std::string("##X scale : ") + Object->GetName()).c_str(), &TemporaryScale[0], 0.01f, 0.01f, 1000.0f)) + bModified = true; + ShowToolTip("X scale"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + if (ImGui::DragFloat((std::string("##Y scale : ") + Object->GetName()).c_str(), &TemporaryScale[1], 0.01f, 0.01f, 1000.0f)) + bModified = true; + ShowToolTip("Y scale"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + if (ImGui::DragFloat((std::string("##Z scale : ") + Object->GetName()).c_str(), &TemporaryScale[2], 0.01f, 0.01f, 1000.0f)) + bModified = true; + ShowToolTip("Z scale"); + + if (bModified) + { + glm::vec3 OldScale = Transform->GetScale(); + Transform->ChangeXScaleBy(TemporaryScale[0] - OldScale[0]); + Transform->ChangeYScaleBy(TemporaryScale[1] - OldScale[1]); + Transform->ChangeZScaleBy(TemporaryScale[2] - OldScale[2]); + } + + // ********************* REAL WORLD COMPARISON SCALE ********************* + if (Object->GetType() == FE_ENTITY || Object->GetType() == FE_ENTITY_INSTANCED) + { + FEEntity* Entity = SCENE.GetEntity(Object->GetObjectID()); + + FEAABB RealAabb = Entity->GetAABB(); + const glm::vec3 Min = RealAabb.GetMin(); + const glm::vec3 Max = RealAabb.GetMax(); + + const float XSize = sqrt((Max.x - Min.x) * (Max.x - Min.x)); + const float YSize = sqrt((Max.y - Min.y) * (Max.y - Min.y)); + const float ZSize = sqrt((Max.z - Min.z) * (Max.z - Min.z)); + + std::string SizeInM = "Approximate object size: "; + SizeInM += std::to_string(std::max(XSize, std::max(YSize, ZSize))); + SizeInM += " m"; + + /*std::string dementionsInM = "Xlength: "; + dementionsInM += std::to_string(xSize); + dementionsInM += " m Ylength: "; + dementionsInM += std::to_string(ySize); + dementionsInM += " m Zlength: "; + dementionsInM += std::to_string(zSize); + dementionsInM += " m";*/ + + ImGui::Text(SizeInM.c_str()); + } +} + +bool FEEditorInspectorWindow::EntityChangePrefabTargetCallBack(FEObject* Object, void** EntityPointer) +{ + FEEntity* Entity = SELECTED.GetEntity(); + if (Entity == nullptr) + return false; + + Entity->Prefab = (RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())); + return true; +} + +bool FEEditorInspectorWindow::TerrainChangeMaterialTargetCallBack(FEObject* Object, void** LayerIndex) +{ + FETerrain* Terrain = SELECTED.GetTerrain(); + if (Terrain == nullptr) + return false; + + FEMaterial* MaterialToAssign = RESOURCE_MANAGER.GetMaterial(Object->GetObjectID()); + if (!MaterialToAssign->IsCompackPacking()) + return false; + + const int TempLayerIndex = *(int*)LayerIndex; + if (TempLayerIndex >= 0 && TempLayerIndex < FE_TERRAIN_MAX_LAYERS) + Terrain->GetLayerInSlot(TempLayerIndex)->SetMaterial(MaterialToAssign); + + return true; +} + +void FEEditorInspectorWindow::ShowTransformConfiguration(const std::string Name, FETransformComponent* Transform) const +{ + // ********************* POSITION ********************* + glm::vec3 position = Transform->GetPosition(); + ImGui::Text("Position : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + ImGui::DragFloat((std::string("##X pos : ") + Name).c_str(), &position[0], 0.1f); + ShowToolTip("X position"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + ImGui::DragFloat((std::string("##Y pos : ") + Name).c_str(), &position[1], 0.1f); + ShowToolTip("Y position"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + ImGui::DragFloat((std::string("##Z pos : ") + Name).c_str(), &position[2], 0.1f); + ShowToolTip("Z position"); + Transform->SetPosition(position); + + // ********************* ROTATION ********************* + glm::vec3 rotation = Transform->GetRotation(); + ImGui::Text("Rotation : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + ImGui::DragFloat((std::string("##X rot : ") + Name).c_str(), &rotation[0], 0.1f, -360.0f, 360.0f); + ShowToolTip("X rotation"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + ImGui::DragFloat((std::string("##Y rot : ") + Name).c_str(), &rotation[1], 0.1f, -360.0f, 360.0f); + ShowToolTip("Y rotation"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + ImGui::DragFloat((std::string("##Z rot : ") + Name).c_str(), &rotation[2], 0.1f, -360.0f, 360.0f); + ShowToolTip("Z rotation"); + Transform->SetRotation(rotation); + + // ********************* SCALE ********************* + bool bUniformScaling = Transform->IsUniformScalingSet(); + ImGui::Checkbox("Uniform scaling", &bUniformScaling); + Transform->SetUniformScaling(bUniformScaling); + + glm::vec3 scale = Transform->GetScale(); + ImGui::Text("Scale : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + ImGui::DragFloat((std::string("##X scale : ") + Name).c_str(), &scale[0], 0.01f, 0.01f, 1000.0f); + ShowToolTip("X scale"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + ImGui::DragFloat((std::string("##Y scale : ") + Name).c_str(), &scale[1], 0.01f, 0.01f, 1000.0f); + ShowToolTip("Y scale"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(50); + ImGui::DragFloat((std::string("##Z scale : ") + Name).c_str(), &scale[2], 0.01f, 0.01f, 1000.0f); + ShowToolTip("Z scale"); + + glm::vec3 OldScale = Transform->GetScale(); + Transform->ChangeXScaleBy(scale[0] - OldScale[0]); + Transform->ChangeYScaleBy(scale[1] - OldScale[1]); + Transform->ChangeZScaleBy(scale[2] - OldScale[2]); +} + +void FEEditorInspectorWindow::DisplayLightProperties(FELight* Light) const +{ + ShowTransformConfiguration(Light, &Light->Transform); + + if (Light->GetType() == FE_DIRECTIONAL_LIGHT) + { + FEDirectionalLight* DirectionalLight = reinterpret_cast(Light); + ImGui::Separator(); + ImGui::Text("-------------Shadow settings--------------"); + + ImGui::Text("Cast shadows:"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + bool bCastShadows = DirectionalLight->IsCastShadows(); + ImGui::Checkbox("##Cast shadows", &bCastShadows); + DirectionalLight->SetCastShadows(bCastShadows); + ShowToolTip("Will this light cast shadows."); + + if (!DirectionalLight->IsCastShadows()) + ImGui::BeginDisabled(); + + ImGui::Text("Number of cascades :"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + int cascades = DirectionalLight->GetActiveCascades(); + ImGui::SliderInt("##cascades", &cascades, 1, 4); + DirectionalLight->SetActiveCascades(cascades); + ShowToolTip("How much steps of shadow quality will be used."); + + ImGui::Text("Shadow coverage in M :"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + float FirstCascadeSize = DirectionalLight->GetShadowCoverage(); + ImGui::DragFloat("##shadowCoverage", &FirstCascadeSize, 0.1f, 0.1f, 500.0f); + DirectionalLight->SetShadowCoverage(FirstCascadeSize); + ShowToolTip("Distance from camera at which shadows would be present."); + + ImGui::Text("Z depth of shadow map :"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + float CSMZDepth = DirectionalLight->GetCSMZDepth(); + ImGui::DragFloat("##CSMZDepth", &CSMZDepth, 0.01f, 0.1f, 100.0f); + DirectionalLight->SetCSMZDepth(CSMZDepth); + ShowToolTip("If you have problems with shadow disapearing when camera is at close distance to shadow reciver, tweaking this parameter could help. Otherwise this parameter should be as small as possible."); + + ImGui::Text("XY depth of shadow map :"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + float CSMXYDepth = DirectionalLight->GetCSMXYDepth(); + ImGui::DragFloat("##CSMXYDepth", &CSMXYDepth, 0.01f, 0.0f, 100.0f); + DirectionalLight->SetCSMXYDepth(CSMXYDepth); + ShowToolTip("If you have problems with shadow on edges of screen, tweaking this parameter could help. Otherwise this parameter should be as small as possible."); + + ImGui::Text("Shadows blur factor:"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(200.0f); + float ShadowsBlurFactor = DirectionalLight->GetShadowBlurFactor(); + ImGui::DragFloat("##Shadows blur factor", &ShadowsBlurFactor, 0.001f, 0.0f, 10.0f); + DirectionalLight->SetShadowBlurFactor(ShadowsBlurFactor); + + bool bStaticShadowBias = DirectionalLight->IsStaticShadowBias(); + ImGui::Checkbox("Static shadow bias :", &bStaticShadowBias); + DirectionalLight->SetIsStaticShadowBias(bStaticShadowBias); + + if (DirectionalLight->IsStaticShadowBias()) + { + ImGui::Text("Static shadow bias value :"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + float ShadowBias = DirectionalLight->GetShadowBias(); + ImGui::DragFloat("##shadowBias", &ShadowBias, 0.0001f, 0.00001f, 0.1f); + DirectionalLight->SetShadowBias(ShadowBias); + } + else + { + ImGui::Text("Intensity of variable shadow bias :"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + float ShadowBiasIntensity = DirectionalLight->GetShadowBiasVariableIntensity(); + ImGui::DragFloat("##shadowBiasIntensity", &ShadowBiasIntensity, 0.01f, 0.01f, 10.0f); + DirectionalLight->SetShadowBiasVariableIntensity(ShadowBiasIntensity); + } + + if (!DirectionalLight->IsCastShadows()) + ImGui::EndDisabled(); + } + else if (Light->GetType() == FE_POINT_LIGHT) + { + } + else if (Light->GetType() == FE_SPOT_LIGHT) + { + FESpotLight* SpotLight = reinterpret_cast(Light); + glm::vec3 direction = SpotLight->GetDirection(); + ImGui::DragFloat("##x", &direction[0], 0.01f, 0.0f, 1.0f); + ImGui::DragFloat("##y", &direction[1], 0.01f, 0.0f, 1.0f); + ImGui::DragFloat("##z", &direction[2], 0.01f, 0.0f, 1.0f); + + float SpotAngle = SpotLight->GetSpotAngle(); + ImGui::SliderFloat((std::string("Inner angle##") + SpotLight->GetName()).c_str(), &SpotAngle, 0.0f, 90.0f); + SpotLight->SetSpotAngle(SpotAngle); + + float SpotAngleOuter = SpotLight->GetSpotAngleOuter(); + ImGui::SliderFloat((std::string("Outer angle ##") + SpotLight->GetName()).c_str(), &SpotAngleOuter, 0.0f, 90.0f); + SpotLight->SetSpotAngleOuter(SpotAngleOuter); + } + + glm::vec3 color = Light->GetColor(); + ImGui::ColorEdit3((std::string("Color##") + Light->GetName()).c_str(), &color.x); + Light->SetColor(color); + + float intensity = Light->GetIntensity(); + ImGui::SliderFloat((std::string("Intensity##") + Light->GetName()).c_str(), &intensity, 0.0f, 100.0f); + Light->SetIntensity(intensity); +} + +void FEEditorInspectorWindow::ChangePrefabOfEntityCallBack(const std::vector SelectionsResult) +{ + if (EntityToModify == nullptr) + return; + + if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) + { + FEPrefab* SelectedPrefab = RESOURCE_MANAGER.GetPrefab(SelectionsResult[0]->GetObjectID()); + if (SelectedPrefab == nullptr) + return; + + EntityToModify->Prefab = SelectedPrefab; + } +} + +void FEEditorInspectorWindow::DisplayLightsProperties() const +{ + const std::vector LightList = SCENE.GetLightsList(); + + for (size_t i = 0; i < LightList.size(); i++) + { + if (ImGui::TreeNode(LightList[i].c_str())) + { + DisplayLightProperties(SCENE.GetLight(LightList[i])); + ImGui::TreePop(); + } + } +} + +void FEEditorInspectorWindow::Render() +{ + if (!bVisible) + return; + + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); + ImGui::Begin("Inspector", nullptr, ImGuiWindowFlags_None); + + if (SELECTED.GetSelected() == nullptr) + { + ImGui::PopStyleVar(); + ImGui::End(); + return; + } + + if (SELECTED.GetEntity() != nullptr) + { + FEEntity* Entity = SELECTED.GetEntity(); + + if (Entity->GetType() == FE_ENTITY) + { + ShowTransformConfiguration(Entity, &Entity->Transform); + + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f)); + + ImGui::InputInt("Force old matrix order", &Entity->Transform.OldWayForce); + ImGui::Checkbox("Use old matrix order globaly", &Entity->Transform.OldWayGlobal); + + bool bActive = Entity->IsWireframeMode(); + ImGui::Checkbox("WireframeMode", &bActive); + Entity->SetWireframeMode(bActive); + + ImGui::Separator(); + ImGui::Text("Prefab : "); + FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Entity->Prefab->GetObjectID()); + + if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + { + EntityToModify = Entity; + SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); + + } + EntityChangePrefabTarget->StickToItem(); + + bool bOpenContextMenu = false; + if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) + bOpenContextMenu = true; + + if (bOpenContextMenu) + ImGui::OpenPopup("##Inspector_context_menu"); + + CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = false; + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); + if (ImGui::BeginPopup("##Inspector_context_menu")) + { + CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = true; + + if (ImGui::MenuItem("Show in folder")) + { + CONTENT_BROWSER_WINDOW.OpenItemParentFolder(Entity->Prefab); + } + + ImGui::EndPopup(); + } + ImGui::PopStyleVar(); + + ImGui::Separator(); + + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + } + else if (Entity->GetType() == FE_ENTITY_INSTANCED) + { + FEEntityInstanced* InstancedEntity = reinterpret_cast(Entity); + + if (SELECTED.InstancedSubObjectIndexSelected != -1) + { + std::string InstancedSubObjectInfo = "index: "; + + ImGui::Text("Selected instance info:"); + InstancedSubObjectInfo = "index: " + std::to_string(SELECTED.InstancedSubObjectIndexSelected); + ImGui::Text(InstancedSubObjectInfo.c_str()); + + FETransformComponent TempTransform = FETransformComponent(InstancedEntity->GetTransformedInstancedMatrix(SELECTED.InstancedSubObjectIndexSelected)); + ShowTransformConfiguration("selected instance", &TempTransform); + InstancedEntity->ModifyInstance(SELECTED.InstancedSubObjectIndexSelected, TempTransform.GetTransformMatrix()); + + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + + if (ImGui::ImageButton((void*)(intptr_t)ArrowToGroundIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + { + InstancedEntity->TryToSnapInstance(SELECTED.InstancedSubObjectIndexSelected); + } + ShowToolTip("Selected instance will attempt to snap to the terrain."); + + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + } + else + { + ShowTransformConfiguration(Entity, &Entity->Transform); + + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f)); + + ImGui::Separator(); + + ImGui::Text("Prefab : "); + FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Entity->Prefab->GetObjectID()); + if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + { + EntityToModify = Entity; + SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); + } + EntityChangePrefabTarget->StickToItem(); + + bool bOpenContextMenu = false; + if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) + bOpenContextMenu = true; + + if (bOpenContextMenu) + ImGui::OpenPopup("##Inspector_context_menu"); + + CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = false; + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); + if (ImGui::BeginPopup("##Inspector_context_menu")) + { + CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = true; + + if (ImGui::MenuItem("Show in folder")) + { + CONTENT_BROWSER_WINDOW.OpenItemParentFolder(Entity->Prefab); + } + + ImGui::EndPopup(); + } + ImGui::PopStyleVar(); + ImGui::Separator(); + + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + + ImGui::Text("Snapped to: "); + ImGui::SameLine(); + + const std::vector TerrainList = SCENE.GetTerrainList(); + static std::string CurrentTerrain = "none"; + + if (InstancedEntity->GetSnappedToTerrain() == nullptr) + { + CurrentTerrain = "none"; + } + else + { + CurrentTerrain = InstancedEntity->GetSnappedToTerrain()->GetName(); + } + + ImGui::SetNextItemWidth(220); + if (ImGui::BeginCombo("##Terrain", CurrentTerrain.c_str(), ImGuiWindowFlags_None)) + { + const bool is_selected = (CurrentTerrain == "none"); + if (ImGui::Selectable("none", is_selected)) + { + if (InstancedEntity->GetSnappedToTerrain() != nullptr) + InstancedEntity->GetSnappedToTerrain()->UnSnapInstancedEntity(InstancedEntity); + } + + if (is_selected) + ImGui::SetItemDefaultFocus(); + + for (size_t i = 0; i < TerrainList.size(); i++) + { + const bool is_selected = (CurrentTerrain == TerrainList[i]); + if (ImGui::Selectable(SCENE.GetTerrain(TerrainList[i])->GetName().c_str(), is_selected)) + { + SCENE.GetTerrain(TerrainList[i])->SnapInstancedEntity(InstancedEntity); + } + + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } + + if (InstancedEntity->GetSnappedToTerrain() != nullptr) + { + ImGui::Text("Terrain layer: "); + ImGui::SameLine(); + + const int CurrentLayer = InstancedEntity->GetTerrainLayer(); + FETerrain* CurrentTerrain = InstancedEntity->GetSnappedToTerrain(); + + std::string caption = "none"; + const auto layer = CurrentTerrain->GetLayerInSlot(CurrentLayer); + if (layer != nullptr) + caption = layer->GetName(); + + ImGui::SetNextItemWidth(220); + if (ImGui::BeginCombo("##TerrainLayers", caption.c_str(), ImGuiWindowFlags_None)) + { + const bool is_selected = (CurrentLayer == -1); + ImGui::PushID("none_TerrainLayers_entity"); + if (ImGui::Selectable("none", is_selected)) + { + if (CurrentTerrain != nullptr) + CurrentTerrain->UnConnectInstancedEntityFromLayer(InstancedEntity); + } + ImGui::PopID(); + + if (is_selected) + ImGui::SetItemDefaultFocus(); + + for (size_t i = 0; i < FE_TERRAIN_MAX_LAYERS; i++) + { + FETerrainLayer* layer = CurrentTerrain->GetLayerInSlot(i); + if (layer == nullptr) + break; + + const bool is_selected = (CurrentLayer == i); + ImGui::PushID(layer->GetObjectID().c_str()); + if (ImGui::Selectable(layer->GetName().c_str(), is_selected)) + { + CurrentTerrain->ConnectInstancedEntityToLayer(InstancedEntity, int(i)); + } + ImGui::PopID(); + + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } + + if (CurrentLayer != -1) + { + ImGui::Text("Minimal layer intensity:"); + float MinLevel = InstancedEntity->GetMinimalLayerIntensity(); + ImGui::SameLine(); + ImGui::SetNextItemWidth(80); + ImGui::DragFloat("##minLevel", &MinLevel); + InstancedEntity->SetMinimalLayerIntensity(MinLevel); + } + } + + ImGui::Separator(); + + ImGui::Text("Seed:"); + int seed = InstancedEntity->SpawnInfo.Seed; + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + ImGui::DragInt("##Seed", &seed); + InstancedEntity->SpawnInfo.Seed = seed; + + ImGui::Text("Object count:"); + int ObjectCount = InstancedEntity->SpawnInfo.ObjectCount; + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + ImGui::DragInt("##Object count", &ObjectCount); + if (ObjectCount <= 0) + ObjectCount = 1; + InstancedEntity->SpawnInfo.ObjectCount = ObjectCount; + + ImGui::Text("Radius:"); + float radius = InstancedEntity->SpawnInfo.Radius; + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + ImGui::DragFloat("##Radius", &radius); + if (radius < 0.0f) + radius = 0.1f; + InstancedEntity->SpawnInfo.Radius = radius; + + // Scale deviation. + ImGui::Text("Scale: "); + + ImGui::SameLine(); + ImGui::Text("min "); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(100); + float MinScale = InstancedEntity->SpawnInfo.GetMinScale(); + ImGui::DragFloat("##minScale", &MinScale, 0.01f); + InstancedEntity->SpawnInfo.SetMinScale(MinScale); + + ImGui::SameLine(); + ImGui::Text("max "); + + ImGui::SameLine(); + float MaxScale = InstancedEntity->SpawnInfo.GetMaxScale(); + ImGui::SetNextItemWidth(100); + ImGui::DragFloat("##maxScale", &MaxScale, 0.01f); + InstancedEntity->SpawnInfo.SetMaxScale(MaxScale); + + ImGui::Text("Rotation deviation:"); + float RotationDeviationX = InstancedEntity->SpawnInfo.RotationDeviation.x; + ImGui::Text("X:"); + ImGui::SameLine(); + ImGui::DragFloat("##Rotation deviation X", &RotationDeviationX, 0.01f); + if (RotationDeviationX < 0.01f) + RotationDeviationX = 0.01f; + if (RotationDeviationX > 1.0f) + RotationDeviationX = 1.0f; + InstancedEntity->SpawnInfo.RotationDeviation.x = RotationDeviationX; + + float RotationDeviationY = InstancedEntity->SpawnInfo.RotationDeviation.y; + ImGui::Text("Y:"); + ImGui::SameLine(); + ImGui::DragFloat("##Rotation deviation Y", &RotationDeviationY, 0.01f); + if (RotationDeviationY < 0.01f) + RotationDeviationY = 0.01f; + if (RotationDeviationY > 1.0f) + RotationDeviationY = 1.0f; + InstancedEntity->SpawnInfo.RotationDeviation.y = RotationDeviationY; + + float RotationDeviationZ = InstancedEntity->SpawnInfo.RotationDeviation.z; + ImGui::Text("Z:"); + ImGui::SameLine(); + ImGui::DragFloat("##Rotation deviation z", &RotationDeviationZ, 0.01f); + if (RotationDeviationZ < 0.01f) + RotationDeviationZ = 0.01f; + if (RotationDeviationZ > 1.0f) + RotationDeviationZ = 1.0f; + InstancedEntity->SpawnInfo.RotationDeviation.z = RotationDeviationZ; + + if (ImGui::Button("Spawn/Re-Spawn")) + { + InstancedEntity->Clear(); + InstancedEntity->Populate(InstancedEntity->SpawnInfo); + } + + if (ImGui::Button("Add instance")) + { + glm::mat4 NewInstanceMatrix = glm::identity(); + NewInstanceMatrix = glm::translate(NewInstanceMatrix, ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + InstancedEntity->AddInstance(NewInstanceMatrix); + + PROJECT_MANAGER.GetCurrent()->SetModified(true); + } + + if (InstancedEntity->IsSelectMode()) + { + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.0f, 0.75f, 0.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); + } + else + { + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + } + + ImGui::Separator(); + if (ImGui::ImageButton((void*)(intptr_t)MouseCursorIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + { + SCENE.SetSelectMode(InstancedEntity, !InstancedEntity->IsSelectMode()); + if (!InstancedEntity->IsSelectMode()) + { + SELECTED.Clear(); + SELECTED.SetSelected(InstancedEntity); + } + } + ShowToolTip("Individual selection mode - Used to select individual instances."); + + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + } + } + } + else if (SELECTED.GetTerrain() != nullptr) + { + FETerrain* CurrentTerrain = SELECTED.GetTerrain(); + DisplayTerrainSettings(CurrentTerrain); + + if (CurrentTerrain->GetBrushMode() != FE_TERRAIN_BRUSH_NONE) + { + // to hide gizmos + if (SELECTED.GetTerrain() != nullptr) + SELECTED.SetSelected(SELECTED.GetTerrain()); + + CurrentTerrain->SetBrushActive(bLeftMousePressed); + + if (bShiftPressed) + { + if (CurrentTerrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW) + CurrentTerrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED); + } + else + { + if (CurrentTerrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) + CurrentTerrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); + } + + /*if (EDITOR.bLeftMousePressed) + { + if (EDITOR.bShiftPressed) + { + currentTerrain->setBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED); + } + else + { + currentTerrain->setBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); + } + } + else + { + currentTerrain->setBrushMode(FE_TERRAIN_BRUSH_NONE); + }*/ + + //currentTerrain->setBrushActive(EDITOR.bLeftMousePressed); + //currentTerrain->setBrushInversed(EDITOR.bShiftPressed); + } + else + { + // to show gizmos + if (SELECTED.GetTerrain() != nullptr) + SELECTED.SetSelected(SELECTED.GetTerrain()); + } + } + else if (SELECTED.GetLight() != nullptr) + { + DisplayLightProperties(SELECTED.GetLight()); + } + else if (SELECTED.GetSelected()->GetType() == FE_CAMERA) + { + FEBasicCamera* Camera = ENGINE.GetCamera(); + + // ********* POSITION ********* + glm::vec3 CameraPosition = Camera->GetPosition(); + + ImGui::Text("Position : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(90); + ImGui::DragFloat("##X pos", &CameraPosition[0], 0.1f); + ShowToolTip("X position"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(90); + ImGui::DragFloat("##Y pos", &CameraPosition[1], 0.1f); + ShowToolTip("Y position"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(90); + ImGui::DragFloat("##Z pos", &CameraPosition[2], 0.1f); + ShowToolTip("Z position"); + + Camera->SetPosition(CameraPosition); + + // ********* ROTATION ********* + glm::vec3 CameraRotation = glm::vec3(Camera->GetYaw(), Camera->GetPitch(), Camera->GetRoll()); + + ImGui::Text("Rotation : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(90); + ImGui::DragFloat("##X rot", &CameraRotation[0], 0.1f); + ShowToolTip("X rotation"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(90); + ImGui::DragFloat("##Y rot", &CameraRotation[1], 0.1f); + ShowToolTip("Y rotation"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(90); + ImGui::DragFloat("##Z rot", &CameraRotation[2], 0.1f); + ShowToolTip("Z rotation"); + + Camera->SetYaw(CameraRotation[0]); + Camera->SetPitch(CameraRotation[1]); + Camera->SetRoll(CameraRotation[2]); + + float CameraSpeed = Camera->GetMovementSpeed(); + ImGui::Text("Camera speed in m/s : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(70); + ImGui::DragFloat("##Camera_speed", &CameraSpeed, 0.01f, 0.01f, 100.0f); + Camera->SetMovementSpeed(CameraSpeed); + } + + ImGui::PopStyleVar(); + ImGui::End(); +} + +static FETerrain* TerrainToWorkWith = nullptr; +static void CreateNewTerrainLayerWithMaterialCallBack(std::vector SelectionsResult) +{ + if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_MATERIAL) + { + if (TerrainToWorkWith == nullptr) + return; + + FEMaterial* SelectedMaterial = RESOURCE_MANAGER.GetMaterial(SelectionsResult[0]->GetObjectID()); + if (SelectedMaterial == nullptr) + return; + + RESOURCE_MANAGER.ActivateTerrainVacantLayerSlot(TerrainToWorkWith, SelectedMaterial); + } + + TerrainToWorkWith = nullptr; +} + +static size_t TempLayerIndex = -1; +static void ChangeMaterialInTerrainLayerCallBack(std::vector SelectionsResult) +{ + if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_MATERIAL) + { + if (TempLayerIndex == -1) + return; + + FEMaterial* SelectedMaterial = RESOURCE_MANAGER.GetMaterial(SelectionsResult[0]->GetObjectID()); + if (SelectedMaterial == nullptr) + return; + + TerrainToWorkWith->GetLayerInSlot(TempLayerIndex)->SetMaterial(SelectedMaterial); + } + + TerrainToWorkWith = nullptr; + TempLayerIndex = -1; +} + +void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) +{ + if (TerrainChangeLayerMaterialTargets.size() != Terrain->LayersUsed()) + { + for (size_t i = 0; i < TerrainChangeLayerMaterialTargets.size(); i++) + { + delete TerrainChangeLayerMaterialTargets[i]; + } + + TerrainChangeLayerMaterialTargets.resize(Terrain->LayersUsed()); + TerrainChangeMaterialIndecies.resize(Terrain->LayersUsed()); + for (size_t i = 0; i < size_t(Terrain->LayersUsed()); i++) + { + TerrainChangeMaterialIndecies[i] = int(i); + TerrainChangeLayerMaterialTargets[i] = DRAG_AND_DROP_MANAGER.AddTarget(FE_MATERIAL, TerrainChangeMaterialTargetCallBack, (void**)&TerrainChangeMaterialIndecies[i], "Drop to assing material to " + Terrain->GetLayerInSlot(i)->GetName()); + } + } + + if (ImGui::BeginTabBar("##terrainSettings", ImGuiTabBarFlags_None)) + { + if (ImGui::BeginTabItem("General")) + { + bool bActive = Terrain->IsWireframeMode(); + ImGui::Checkbox("WireframeMode", &bActive); + Terrain->SetWireframeMode(bActive); + + int IData = *(int*)RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/)->GetParameterData("debugFlag"); + ImGui::SliderInt("debugFlag", &IData, 0, 10); + RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/)->UpdateParameterData("debugFlag", IData); + + float DisplacementScale = Terrain->GetDisplacementScale(); + ImGui::DragFloat("displacementScale", &DisplacementScale, 0.02f, -10.0f, 10.0f); + Terrain->SetDisplacementScale(DisplacementScale); + + float LODLevel = Terrain->GetLODLevel(); + ImGui::DragFloat("LODlevel", &LODLevel, 2.0f, 2.0f, 128.0f); + Terrain->SetLODLevel(LODLevel); + ShowToolTip("Bigger LODlevel more details terraine will have and less performance you will get."); + + float ChunkPerSide = Terrain->GetChunkPerSide(); + ImGui::DragFloat("chunkPerSide", &ChunkPerSide, 2.0f, 1.0f, 16.0f); + Terrain->SetChunkPerSide(ChunkPerSide); + + // ********************* REAL WORLD COMPARISON SCALE ********************* + FEAABB RealAABB = Terrain->GetAABB(); + glm::vec3 min = RealAABB.GetMin(); + glm::vec3 max = RealAABB.GetMax(); + + float XSize = sqrt((max.x - min.x) * (max.x - min.x)); + float YSize = sqrt((max.y - min.y) * (max.y - min.y)); + float ZSize = sqrt((max.z - min.z) * (max.z - min.z)); + + std::string SizeInM = "Approximate terrain size: "; + SizeInM += std::to_string(std::max(XSize, std::max(YSize, ZSize))); + SizeInM += " m"; + ImGui::Text(SizeInM.c_str()); + // ********************* REAL WORLD COMPARISON SCALE END ********************* + + ShowTransformConfiguration(Terrain, &Terrain->Transform); + + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("Sculpt")) + { + ExportHeightMapButton->Render(); + if (ExportHeightMapButton->IsClicked()) + { + std::string filePath = ""; + FILE_SYSTEM.ShowFileSaveDialog(filePath, TEXTURE_LOAD_FILTER, 1); + + if (!filePath.empty()) + { + filePath += ".png"; + RESOURCE_MANAGER.ExportFETextureToPNG(Terrain->HeightMap, filePath.c_str()); + } + } + + ImGui::SameLine(); + ImportHeightMapButton->Render(); + if (ImportHeightMapButton->IsClicked()) + { + std::string FilePath; + FILE_SYSTEM.ShowFileOpenDialog(FilePath, TEXTURE_LOAD_FILTER, 1); + + if (!FilePath.empty()) + { + FETexture* LoadedTexture = RESOURCE_MANAGER.LoadPNGHeightmap(FilePath.c_str(), Terrain); + if (LoadedTexture == RESOURCE_MANAGER.NoTexture) + { + LOG.Add(std::string("can't load height map: ") + FilePath, "FE_LOG_LOADING", FE_LOG_ERROR); + } + else + { + LoadedTexture->SetDirtyFlag(true); + PROJECT_MANAGER.GetCurrent()->SetModified(true); + } + } + } + + float HighScale = Terrain->GetHightScale(); + ImGui::DragFloat("hight range in m", &HighScale); + Terrain->SetHightScale(HighScale); + + float CurrentBrushSize = Terrain->GetBrushSize(); + ImGui::DragFloat("brushSize", &CurrentBrushSize, 0.1f, 0.01f, 100.0f); + Terrain->SetBrushSize(CurrentBrushSize); + + float CurrentBrushIntensity = Terrain->GetBrushIntensity(); + ImGui::DragFloat("brushIntensity", &CurrentBrushIntensity, 0.0001f, 0.0001f, 10.0f); + Terrain->SetBrushIntensity(CurrentBrushIntensity); + + SetDefaultStyle(SculptBrushButton); + if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW || + Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) + SetSelectedStyle(SculptBrushButton); + + SculptBrushButton->Render(); + ShowToolTip("Sculpt Brush. Left mouse to increase height, hold shift to decrease height."); + + if (SculptBrushButton->IsClicked()) + { + if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW || + Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) + { + Terrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); + } + else + { + Terrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); + } + } + + SetDefaultStyle(LevelBrushButton); + if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_LEVEL) + SetSelectedStyle(LevelBrushButton); + + ImGui::SameLine(); + LevelBrushButton->Render(); + ShowToolTip("Level Brush."); + + if (LevelBrushButton->IsClicked()) + { + if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_LEVEL) + { + Terrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); + } + else + { + Terrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_LEVEL); + } + } + + SetDefaultStyle(SmoothBrushButton); + if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_SMOOTH) + SetSelectedStyle(SmoothBrushButton); + + ImGui::SameLine(); + SmoothBrushButton->Render(); + ShowToolTip("Smooth Brush."); + + if (SmoothBrushButton->IsClicked()) + { + if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_SMOOTH) + { + Terrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); + } + else + { + Terrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_SMOOTH); + } + } + + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("Paint")) + { + glm::vec2 TileMult = Terrain->GetTileMult(); + ImGui::DragFloat2("all layers tile factors", &TileMult[0], 0.1f, 1.0f, 100.0f); + Terrain->SetTileMult(TileMult); + + float CurrentBrushSize = Terrain->GetBrushSize(); + ImGui::DragFloat("brushSize", &CurrentBrushSize, 0.1f, 0.01f, 100.0f); + Terrain->SetBrushSize(CurrentBrushSize); + + float CurrentBrushIntensity = Terrain->GetBrushIntensity(); + ImGui::DragFloat("brushIntensity", &CurrentBrushIntensity, 0.0001f, 0.0001f, 10.0f); + Terrain->SetBrushIntensity(CurrentBrushIntensity); + + SetDefaultStyle(LayerBrushButton); + if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_LAYER_DRAW) + SetSelectedStyle(LayerBrushButton); + + LayerBrushButton->Render(); + ShowToolTip("Layer draw brush. Left mouse to paint currently selected layer, hold shift to decrease layer influence."); + static int SelectedLayer = -1; + if (SelectedLayer != -1 && Terrain->GetLayerInSlot(SelectedLayer) == nullptr) + SelectedLayer = -1; + + if (LayerBrushButton->IsClicked()) + { + if (SelectedLayer != -1) + { + if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_LAYER_DRAW) + { + Terrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); + } + else + { + Terrain->SetBrushMode(FE_TERRAIN_BRUSH_LAYER_DRAW); + } + } + + } + + ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); + static bool bContextMenuOpened = false; + + ImGui::Text("Layers:"); + + ImGui::BeginChildFrame(ImGui::GetID("Layers ListBox Child"), ImVec2(ImGui::GetContentRegionAvail().x - 10.0f, 500.0f), ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse); + bool bListBoxHovered = false; + if (ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows)) + bListBoxHovered = true; + + static bool bShouldOpenContextMenu = false; + if (ImGui::IsMouseClicked(1)) + { + if (bListBoxHovered) + { + bShouldOpenContextMenu = true; + } + } + + ImGui::BeginListBox("##Layers ListBox", ImVec2(ImGui::GetContentRegionAvail().x - 10.0f, 500.0f)); + + for (size_t i = 0; i < FE_TERRAIN_MAX_LAYERS; i++) + { + FETerrainLayer* layer = Terrain->GetLayerInSlot(i); + if (layer == nullptr) + break; + + ImVec2 PostionBeforeDraw = ImGui::GetCursorPos(); + + ImVec2 TextSize = ImGui::CalcTextSize(layer->GetName().c_str()); + ImGui::SetCursorPos(PostionBeforeDraw + ImVec2(ImGui::GetContentRegionAvail().x / 2.0f - TextSize.x / 2.0f, 16)); + + if (TerrainLayerRenameIndex == i) + { + if (!bLastFrameTerrainLayerRenameEditWasVisiable) + { + ImGui::SetKeyboardFocusHere(0); + ImGui::SetFocusID(ImGui::GetID("##newNameTerrainLayerEditor"), ImGui::GetCurrentWindow()); + ImGui::SetItemDefaultFocus(); + bLastFrameTerrainLayerRenameEditWasVisiable = true; + } + + ImGui::SetNextItemWidth(350.0f); + ImGui::SetCursorPos(ImVec2(PostionBeforeDraw.x + 64.0f + (ImGui::GetContentRegionAvail().x - 64.0f) / 2.0f - 350.0f / 2.0f, PostionBeforeDraw.y + 12)); + if (ImGui::InputText("##newNameTerrainLayerEditor", TerrainLayerRename, IM_ARRAYSIZE(TerrainLayerRename), ImGuiInputTextFlags_EnterReturnsTrue) || + ImGui::IsMouseClicked(0) && !ImGui::IsItemHovered() || ImGui::GetFocusID() != ImGui::GetID("##newNameTerrainLayerEditor")) + { + PROJECT_MANAGER.GetCurrent()->SetModified(true); + layer->SetName(TerrainLayerRename); + + TerrainLayerRenameIndex = -1; + } + } + else + { + ImGui::Text(layer->GetName().c_str()); + } + ImGui::SetCursorPos(PostionBeforeDraw); + + ImGui::PushID(int(i)); + if (ImGui::Selectable("##item", SelectedLayer == i ? true : false, ImGuiSelectableFlags_None, ImVec2(ImGui::GetContentRegionAvail().x - 0, 64))) + { + SelectedLayer = int(i); + Terrain->SetBrushLayerIndex(SelectedLayer); + } + TerrainChangeLayerMaterialTargets[i]->StickToItem(); + ImGui::PopID(); + + if (ImGui::IsItemHovered()) + HoveredTerrainLayerItem = int(i); + + ImGui::SetCursorPos(PostionBeforeDraw); + ImColor ImageTint = ImGui::IsItemHovered() ? ImColor(1.0f, 1.0f, 1.0f, 0.5f) : ImColor(1.0f, 1.0f, 1.0f, 1.0f); + FETexture* PreviewTexture = PREVIEW_MANAGER.GetMaterialPreview(layer->GetMaterial()->GetObjectID()); + ImGui::Image((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), ImageTint); + } + + ImGui::EndListBox(); + ImGui::PopFont(); + + ImGui::EndChildFrame(); + ImGui::EndTabItem(); + + if (bShouldOpenContextMenu) + { + bShouldOpenContextMenu = false; + ImGui::OpenPopup("##layers_listBox_context_menu"); + } + + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); + if (ImGui::BeginPopup("##layers_listBox_context_menu")) + { + bContextMenuOpened = true; + + if (Terrain->GetLayerInSlot(FE_TERRAIN_MAX_LAYERS - 1) != nullptr) + ImGui::BeginDisabled(); + + if (ImGui::MenuItem("Add layer...")) + { + std::vector TempMaterialList = RESOURCE_MANAGER.GetMaterialList(); + std::vector FinalMaterialList; + for (size_t i = 0; i < TempMaterialList.size(); i++) + { + if (RESOURCE_MANAGER.GetMaterial(TempMaterialList[i])->IsCompackPacking()) + { + FinalMaterialList.push_back(RESOURCE_MANAGER.GetMaterial(TempMaterialList[i])); + } + } + + if (FinalMaterialList.empty()) + { + MessagePopUp::getInstance().Show("No suitable material", "There are no materials with compack packing."); + } + else + { + TerrainToWorkWith = Terrain; + SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, CreateNewTerrainLayerWithMaterialCallBack, nullptr, FinalMaterialList); + } + } + + if (Terrain->GetLayerInSlot(FE_TERRAIN_MAX_LAYERS - 1) != nullptr) + ImGui::EndDisabled(); + + if (HoveredTerrainLayerItem != -1) + { + FETerrainLayer* layer = Terrain->GetLayerInSlot(HoveredTerrainLayerItem); + if (layer != nullptr) + { + ImGui::Separator(); + std::string LayerName = layer->GetName(); + ImGui::Text((std::string("Actions with ") + LayerName).c_str()); + ImGui::Separator(); + + if (ImGui::MenuItem("Rename")) + { + TerrainLayerRenameIndex = HoveredTerrainLayerItem; + + strcpy_s(TerrainLayerRename, layer->GetName().size() + 1, layer->GetName().c_str()); + bLastFrameTerrainLayerRenameEditWasVisiable = false; + } + + if (ImGui::MenuItem("Fill")) + { + RESOURCE_MANAGER.FillTerrainLayerMask(Terrain, HoveredTerrainLayerItem); + } + + if (ImGui::MenuItem("Clear")) + { + RESOURCE_MANAGER.ClearTerrainLayerMask(Terrain, HoveredTerrainLayerItem); + } + + if (ImGui::MenuItem("Delete")) + { + RESOURCE_MANAGER.DeleteTerrainLayerMask(Terrain, HoveredTerrainLayerItem); + } + + ImGui::Separator(); + + if (ImGui::MenuItem("Change material...")) + { + std::vector TempMaterialList = RESOURCE_MANAGER.GetMaterialList(); + std::vector FinalMaterialList; + for (size_t i = 0; i < TempMaterialList.size(); i++) + { + if (RESOURCE_MANAGER.GetMaterial(TempMaterialList[i])->IsCompackPacking()) + { + FinalMaterialList.push_back(RESOURCE_MANAGER.GetMaterial(TempMaterialList[i])); + } + } + + if (FinalMaterialList.empty()) + { + MessagePopUp::getInstance().Show("No suitable material", "There are no materials with compack packing."); + } + else + { + TerrainToWorkWith = Terrain; + TempLayerIndex = HoveredTerrainLayerItem; + SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialInTerrainLayerCallBack, Terrain->GetLayerInSlot(HoveredTerrainLayerItem)->GetMaterial(), FinalMaterialList); + } + } + + if (ImGui::MenuItem("Export mask...")) + { + std::string filePath = ""; + FILE_SYSTEM.ShowFileSaveDialog(filePath, TEXTURE_LOAD_FILTER, 1); + if (!filePath.empty()) + { + filePath += ".png"; + RESOURCE_MANAGER.SaveTerrainLayerMask(filePath.c_str(), Terrain, HoveredTerrainLayerItem); + } + } + + if (ImGui::MenuItem("Import mask...")) + { + std::string filePath = ""; + FILE_SYSTEM.ShowFileOpenDialog(filePath, TEXTURE_LOAD_FILTER, 1); + if (!filePath.empty()) + { + RESOURCE_MANAGER.LoadTerrainLayerMask(filePath.c_str(), Terrain, HoveredTerrainLayerItem); + PROJECT_MANAGER.GetCurrent()->SetModified(true); + } + } + } + } + + ImGui::EndPopup(); + } + ImGui::PopStyleVar(); + + if (!bContextMenuOpened) + HoveredTerrainLayerItem = -1; + + bContextMenuOpened = false; + } + ImGui::EndTabBar(); + } +} \ No newline at end of file diff --git a/EditorWindows/InspectorWindow.h b/EditorWindows/InspectorWindow.h new file mode 100644 index 0000000..dd3a29d --- /dev/null +++ b/EditorWindows/InspectorWindow.h @@ -0,0 +1,63 @@ +#pragma once + +#include "ContentBrowserWindow.h" + +class FEEditorInspectorWindow +{ + friend class FEEditor; + SINGLETON_PRIVATE_PART(FEEditorInspectorWindow) + + // Visibility + bool bVisible = true; + static FEEntity* EntityToModify; + + // Light properties + void DisplayLightProperties(FELight* Light) const; + void DisplayLightsProperties() const; + + // Terrain settings + ImGuiButton* ExportHeightMapButton = nullptr; + ImGuiButton* ImportHeightMapButton = nullptr; + ImGuiImageButton* SculptBrushButton = nullptr; + ImGuiImageButton* LevelBrushButton = nullptr; + ImGuiImageButton* SmoothBrushButton = nullptr; + ImGuiImageButton* LayerBrushButton = nullptr; + static bool EntityChangePrefabTargetCallBack(FEObject* Object, void** EntityPointer); + static bool TerrainChangeMaterialTargetCallBack(FEObject* Object, void** LayerIndex); + static void ChangePrefabOfEntityCallBack(std::vector SelectionsResult); + DragAndDropTarget* EntityChangePrefabTarget = nullptr; + std::vector TerrainChangeMaterialIndecies; + std::vector TerrainChangeLayerMaterialTargets; + int HoveredTerrainLayerItem = -1; + void DisplayTerrainSettings(FETerrain* Terrain); + int TerrainLayerRenameIndex = -1; + char TerrainLayerRename[1024]; + bool bLastFrameTerrainLayerRenameEditWasVisiable = false; + + // Brush icons + FETexture* SculptBrushIcon = nullptr; + FETexture* LevelBrushIcon = nullptr; + FETexture* SmoothBrushIcon = nullptr; + FETexture* MouseCursorIcon = nullptr; + FETexture* ArrowToGroundIcon = nullptr; + FETexture* DrawBrushIcon = nullptr; + + // Context menu + bool bShouldOpenContextMenu = false; + + bool bLeftMousePressed = false; + bool bShiftPressed = false; + + void ShowTransformConfiguration(FEObject* Object, FETransformComponent* Transform) const; + void ShowTransformConfiguration(std::string Name, FETransformComponent* Transform) const; + + // Rendering and initialization + void Render(); + void Clear(); + void InitializeResources(); + +public: + SINGLETON_PUBLIC_PART(FEEditorInspectorWindow) +}; + +#define INSPECTOR_WINDOW FEEditorInspectorWindow::getInstance() \ No newline at end of file diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 615aa7b..9079e14 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -204,7 +204,22 @@ void TransformUpdate(FENaiveSceneEntity* SubTreeRoot) { FEEntity* Entity = reinterpret_cast(SubTreeRoot->GetOldStyleEntity()); if (Entity == nullptr) + { + auto Children = SubTreeRoot->GetChildren(); + for (size_t i = 0; i < Children.size(); i++) + { + TransformUpdate(Children[i]); + } return; + } + + Entity->Transform.bIsInSceneGraph = true; + + if (SubTreeRoot->GetParent() == nullptr || SubTreeRoot->GetParent() == SCENE.SceneGraph.GetRoot()) + { + Entity->Transform.Update(); + Entity->Transform.WorldSpaceMatrix = Entity->Transform.LocalSpaceMatrix; + } FETransformComponent& ParentTransform = Entity->Transform; @@ -220,26 +235,33 @@ void TransformUpdate(FENaiveSceneEntity* SubTreeRoot) TransformUpdate(Children[i]);*/ - if (SubTreeRoot->GetName() == "BistroExterior") + /*if (SubTreeRoot->GetName() == "BistroExterior") { int y = 0; y++; - } - + }*/ FEEntity* ChildEntity = reinterpret_cast(Children[i]->GetOldStyleEntity()); FETransformComponent& ChildTransform = ChildEntity->Transform; - ParentTransform.Update(); - ChildTransform.Update(); - ChildTransform.ForceSetTransformMatrix(ParentTransform.GetTransformMatrix() * ChildTransform.GetTransformMatrix()); - glm::vec3 Position, Scale; + //glm::mat4 CurrentParentTransform = ParentTransform.GetTransformMatrix(); + + //ParentTransform.Update(); + //ChildTransform.Update(); + + //ChildTransform.LocalSpaceMatrix = ChildTransform.GetTransformMatrix(); + ChildTransform.WorldSpaceMatrix = ParentTransform.WorldSpaceMatrix * ChildTransform.LocalSpaceMatrix; + //ChildTransform.ForceSetTransformMatrix(ChildTransform.WorldSpaceMatrix); + + TransformUpdate(Children[i]); + + /*glm::vec3 Position, Scale; glm::quat Rotation; glm::decompose(ParentTransform.GetTransformMatrix(), Scale, Rotation, Position, glm::vec3(), glm::vec4()); int y = 0; - y++; + y++;*/ } } @@ -326,6 +348,7 @@ void FEEditorSceneGraphWindow::RenderNewSceneGraph() SceneNodeDragAndDropTargetIndex = -1; RenderSubTree(Root); + TransformUpdate(Root); if (bSceneNodeTargetsDirty) bSceneNodeTargetsDirty = false; diff --git a/EditorWindows/SceneGraphWindow.h b/EditorWindows/SceneGraphWindow.h index 27b19fc..1985c0a 100644 --- a/EditorWindows/SceneGraphWindow.h +++ b/EditorWindows/SceneGraphWindow.h @@ -1,7 +1,6 @@ #pragma once #include "ProjectWasModifiedPopUp.h" -//using namespace FocalEngine; class FEEditorSceneGraphWindow { diff --git a/FEEditor.cpp b/FEEditor.cpp index 20c99a7..aafbcee 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -2,7 +2,6 @@ FEEditor* FEEditor::Instance = nullptr; ImGuiWindow* FEEditor::SceneWindow = nullptr; -FEEntity* FEEditor::EntityToModify = nullptr; bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) { @@ -120,11 +119,11 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) SELECTED.CheckForSelectionisNeeded = true; } - EDITOR.bLeftMousePressed = true; + INSPECTOR_WINDOW.bLeftMousePressed = true; } else if (Button == GLFW_MOUSE_BUTTON_1 && Action == GLFW_RELEASE) { - EDITOR.bLeftMousePressed = false; + INSPECTOR_WINDOW.bLeftMousePressed = false; GIZMO_MANAGER.DeactivateAllGizmo(); } @@ -210,341 +209,11 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) if (!ImGui::GetIO().WantCaptureKeyboard && (Key == GLFW_KEY_RIGHT_SHIFT || Key == GLFW_KEY_LEFT_SHIFT) && Action == GLFW_RELEASE) { - EDITOR.bShiftPressed = false; + INSPECTOR_WINDOW.bShiftPressed = false; } else if (!ImGui::GetIO().WantCaptureKeyboard && (Key == GLFW_KEY_RIGHT_SHIFT || Key == GLFW_KEY_LEFT_SHIFT) && Action == GLFW_PRESS) { - EDITOR.bShiftPressed = true; - } -} - -void FEEditor::ShowTransformConfiguration(FEObject* Object, FETransformComponent* Transform) const -{ - // ********************* POSITION ********************* - glm::vec3 TemporaryPosition = Transform->GetPosition(); - bool bModified = false; - - ImGui::Text("Position : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##X pos : ") + Object->GetName()).c_str(), &TemporaryPosition[0], 0.1f)) - bModified = true; - ShowToolTip("X position"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##Y pos : ") + Object->GetName()).c_str(), &TemporaryPosition[1], 0.1f)) - bModified = true; - ShowToolTip("Y position"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##Z pos : ") + Object->GetName()).c_str(), &TemporaryPosition[2], 0.1f)) - bModified = true; - ShowToolTip("Z position"); - - if (bModified) - Transform->SetPosition(TemporaryPosition); - - // ********************* ROTATION ********************* - glm::vec3 TemporaryRotation = Transform->GetRotation(); - bModified = false; - - ImGui::Text("Rotation : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##X rot : ") + Object->GetName()).c_str(), &TemporaryRotation[0], 0.1f, -360.0f, 360.0f)) - bModified = true; - ShowToolTip("X rotation"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##Y rot : ") + Object->GetName()).c_str(), &TemporaryRotation[1], 0.1f, -360.0f, 360.0f)) - bModified = true; - ShowToolTip("Y rotation"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##Z rot : ") + Object->GetName()).c_str(), &TemporaryRotation[2], 0.1f, -360.0f, 360.0f)) - bModified = true; - ShowToolTip("Z rotation"); - - if (bModified) - Transform->SetRotation(TemporaryRotation); - - // ********************* SCALE ********************* - bool bUniformScaling = Transform->IsUniformScalingSet(); - bModified = false; - - if (ImGui::Checkbox("Uniform scaling", &bUniformScaling)) - Transform->SetUniformScaling(bUniformScaling); - - glm::vec3 TemporaryScale = Transform->GetScale(); - ImGui::Text("Scale : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##X scale : ") + Object->GetName()).c_str(), &TemporaryScale[0], 0.01f, 0.01f, 1000.0f)) - bModified = true; - ShowToolTip("X scale"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##Y scale : ") + Object->GetName()).c_str(), &TemporaryScale[1], 0.01f, 0.01f, 1000.0f)) - bModified = true; - ShowToolTip("Y scale"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##Z scale : ") + Object->GetName()).c_str(), &TemporaryScale[2], 0.01f, 0.01f, 1000.0f)) - bModified = true; - ShowToolTip("Z scale"); - - if (bModified) - { - glm::vec3 OldScale = Transform->GetScale(); - Transform->ChangeXScaleBy(TemporaryScale[0] - OldScale[0]); - Transform->ChangeYScaleBy(TemporaryScale[1] - OldScale[1]); - Transform->ChangeZScaleBy(TemporaryScale[2] - OldScale[2]); - } - - // ********************* REAL WORLD COMPARISON SCALE ********************* - if (Object->GetType() == FE_ENTITY || Object->GetType() == FE_ENTITY_INSTANCED) - { - FEEntity* Entity = SCENE.GetEntity(Object->GetObjectID()); - - FEAABB RealAabb = Entity->GetAABB(); - const glm::vec3 Min = RealAabb.GetMin(); - const glm::vec3 Max = RealAabb.GetMax(); - - const float XSize = sqrt((Max.x - Min.x) * (Max.x - Min.x)); - const float YSize = sqrt((Max.y - Min.y) * (Max.y - Min.y)); - const float ZSize = sqrt((Max.z - Min.z) * (Max.z - Min.z)); - - std::string SizeInM = "Approximate object size: "; - SizeInM += std::to_string(std::max(XSize, std::max(YSize, ZSize))); - SizeInM += " m"; - - /*std::string dementionsInM = "Xlength: "; - dementionsInM += std::to_string(xSize); - dementionsInM += " m Ylength: "; - dementionsInM += std::to_string(ySize); - dementionsInM += " m Zlength: "; - dementionsInM += std::to_string(zSize); - dementionsInM += " m";*/ - - ImGui::Text(SizeInM.c_str()); - } -} - -void FEEditor::ShowTransformConfiguration(const std::string Name, FETransformComponent* Transform) const -{ - // ********************* POSITION ********************* - glm::vec3 position = Transform->GetPosition(); - ImGui::Text("Position : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##X pos : ") + Name).c_str(), &position[0], 0.1f); - ShowToolTip("X position"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Y pos : ") + Name).c_str(), &position[1], 0.1f); - ShowToolTip("Y position"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Z pos : ") + Name).c_str(), &position[2], 0.1f); - ShowToolTip("Z position"); - Transform->SetPosition(position); - - // ********************* ROTATION ********************* - glm::vec3 rotation = Transform->GetRotation(); - ImGui::Text("Rotation : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##X rot : ") + Name).c_str(), &rotation[0], 0.1f, -360.0f, 360.0f); - ShowToolTip("X rotation"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Y rot : ") + Name).c_str(), &rotation[1], 0.1f, -360.0f, 360.0f); - ShowToolTip("Y rotation"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Z rot : ") + Name).c_str(), &rotation[2], 0.1f, -360.0f, 360.0f); - ShowToolTip("Z rotation"); - Transform->SetRotation(rotation); - - // ********************* SCALE ********************* - bool bUniformScaling = Transform->IsUniformScalingSet(); - ImGui::Checkbox("Uniform scaling", &bUniformScaling); - Transform->SetUniformScaling(bUniformScaling); - - glm::vec3 scale = Transform->GetScale(); - ImGui::Text("Scale : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##X scale : ") + Name).c_str(), &scale[0], 0.01f, 0.01f, 1000.0f); - ShowToolTip("X scale"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Y scale : ") + Name).c_str(), &scale[1], 0.01f, 0.01f, 1000.0f); - ShowToolTip("Y scale"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Z scale : ") + Name).c_str(), &scale[2], 0.01f, 0.01f, 1000.0f); - ShowToolTip("Z scale"); - - glm::vec3 OldScale = Transform->GetScale(); - Transform->ChangeXScaleBy(scale[0] - OldScale[0]); - Transform->ChangeYScaleBy(scale[1] - OldScale[1]); - Transform->ChangeZScaleBy(scale[2] - OldScale[2]); -} - -void FEEditor::DisplayLightProperties(FELight* Light) const -{ - ShowTransformConfiguration(Light, &Light->Transform); - - if (Light->GetType() == FE_DIRECTIONAL_LIGHT) - { - FEDirectionalLight* DirectionalLight = reinterpret_cast(Light); - ImGui::Separator(); - ImGui::Text("-------------Shadow settings--------------"); - - ImGui::Text("Cast shadows:"); - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - bool bCastShadows = DirectionalLight->IsCastShadows(); - ImGui::Checkbox("##Cast shadows", &bCastShadows); - DirectionalLight->SetCastShadows(bCastShadows); - ShowToolTip("Will this light cast shadows."); - - if (!DirectionalLight->IsCastShadows()) - ImGui::BeginDisabled(); - - ImGui::Text("Number of cascades :"); - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - int cascades = DirectionalLight->GetActiveCascades(); - ImGui::SliderInt("##cascades", &cascades, 1, 4); - DirectionalLight->SetActiveCascades(cascades); - ShowToolTip("How much steps of shadow quality will be used."); - - ImGui::Text("Shadow coverage in M :"); - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - float FirstCascadeSize = DirectionalLight->GetShadowCoverage(); - ImGui::DragFloat("##shadowCoverage", &FirstCascadeSize, 0.1f, 0.1f, 500.0f); - DirectionalLight->SetShadowCoverage(FirstCascadeSize); - ShowToolTip("Distance from camera at which shadows would be present."); - - ImGui::Text("Z depth of shadow map :"); - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - float CSMZDepth = DirectionalLight->GetCSMZDepth(); - ImGui::DragFloat("##CSMZDepth", &CSMZDepth, 0.01f, 0.1f, 100.0f); - DirectionalLight->SetCSMZDepth(CSMZDepth); - ShowToolTip("If you have problems with shadow disapearing when camera is at close distance to shadow reciver, tweaking this parameter could help. Otherwise this parameter should be as small as possible."); - - ImGui::Text("XY depth of shadow map :"); - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - float CSMXYDepth = DirectionalLight->GetCSMXYDepth(); - ImGui::DragFloat("##CSMXYDepth", &CSMXYDepth, 0.01f, 0.0f, 100.0f); - DirectionalLight->SetCSMXYDepth(CSMXYDepth); - ShowToolTip("If you have problems with shadow on edges of screen, tweaking this parameter could help. Otherwise this parameter should be as small as possible."); - - ImGui::Text("Shadows blur factor:"); - ImGui::SameLine(); - ImGui::SetNextItemWidth(200.0f); - float ShadowsBlurFactor = DirectionalLight->GetShadowBlurFactor(); - ImGui::DragFloat("##Shadows blur factor", &ShadowsBlurFactor, 0.001f, 0.0f, 10.0f); - DirectionalLight->SetShadowBlurFactor(ShadowsBlurFactor); - - bool bStaticShadowBias = DirectionalLight->IsStaticShadowBias(); - ImGui::Checkbox("Static shadow bias :", &bStaticShadowBias); - DirectionalLight->SetIsStaticShadowBias(bStaticShadowBias); - - if (DirectionalLight->IsStaticShadowBias()) - { - ImGui::Text("Static shadow bias value :"); - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - float ShadowBias = DirectionalLight->GetShadowBias(); - ImGui::DragFloat("##shadowBias", &ShadowBias, 0.0001f, 0.00001f, 0.1f); - DirectionalLight->SetShadowBias(ShadowBias); - } - else - { - ImGui::Text("Intensity of variable shadow bias :"); - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - float ShadowBiasIntensity = DirectionalLight->GetShadowBiasVariableIntensity(); - ImGui::DragFloat("##shadowBiasIntensity", &ShadowBiasIntensity, 0.01f, 0.01f, 10.0f); - DirectionalLight->SetShadowBiasVariableIntensity(ShadowBiasIntensity); - } - - if (!DirectionalLight->IsCastShadows()) - ImGui::EndDisabled(); - } - else if (Light->GetType() == FE_POINT_LIGHT) - { - } - else if (Light->GetType() == FE_SPOT_LIGHT) - { - FESpotLight* SpotLight = reinterpret_cast(Light); - glm::vec3 direction = SpotLight->GetDirection(); - ImGui::DragFloat("##x", &direction[0], 0.01f, 0.0f, 1.0f); - ImGui::DragFloat("##y", &direction[1], 0.01f, 0.0f, 1.0f); - ImGui::DragFloat("##z", &direction[2], 0.01f, 0.0f, 1.0f); - - float SpotAngle = SpotLight->GetSpotAngle(); - ImGui::SliderFloat((std::string("Inner angle##") + SpotLight->GetName()).c_str(), &SpotAngle, 0.0f, 90.0f); - SpotLight->SetSpotAngle(SpotAngle); - - float SpotAngleOuter = SpotLight->GetSpotAngleOuter(); - ImGui::SliderFloat((std::string("Outer angle ##") + SpotLight->GetName()).c_str(), &SpotAngleOuter, 0.0f, 90.0f); - SpotLight->SetSpotAngleOuter(SpotAngleOuter); - } - - glm::vec3 color = Light->GetColor(); - ImGui::ColorEdit3((std::string("Color##") + Light->GetName()).c_str(), &color.x); - Light->SetColor(color); - - float intensity = Light->GetIntensity(); - ImGui::SliderFloat((std::string("Intensity##") + Light->GetName()).c_str(), &intensity, 0.0f, 100.0f); - Light->SetIntensity(intensity); -} - -void FEEditor::DisplayLightsProperties() const -{ - const std::vector LightList = SCENE.GetLightsList(); - - for (size_t i = 0; i < LightList.size(); i++) - { - if (ImGui::TreeNode(LightList[i].c_str())) - { - DisplayLightProperties(SCENE.GetLight(LightList[i])); - ImGui::TreePop(); - } - } -} - -void FEEditor::ChangePrefabOfEntityCallBack(const std::vector SelectionsResult) -{ - if (EntityToModify == nullptr) - return; - - if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) - { - FEPrefab* SelectedPrefab = RESOURCE_MANAGER.GetPrefab(SelectionsResult[0]->GetObjectID()); - if (SelectedPrefab == nullptr) - return; - - EntityToModify->Prefab = SelectedPrefab; + INSPECTOR_WINDOW.bShiftPressed = true; } } @@ -600,44 +269,9 @@ void FEEditor::InitializeResources() EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(PREVIEW_MANAGER.PreviewEntity); - MouseCursorIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/mouseCursorIcon.png", "mouseCursorIcon"); - RESOURCE_MANAGER.MakeTextureStandard(MouseCursorIcon); - ArrowToGroundIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/arrowToGroundIcon.png", "arrowToGroundIcon"); - RESOURCE_MANAGER.MakeTextureStandard(ArrowToGroundIcon); - SCENE_GRAPH_WINDOW.InitializeResources(); - CONTENT_BROWSER_WINDOW.InitializeResources(); - - // ************** Terrain Settings ************** - ExportHeightMapButton = new ImGuiButton("Export HeightMap"); - ExportHeightMapButton->SetSize(ImVec2(200, 0)); - - ImportHeightMapButton = new ImGuiButton("Import HeightMap"); - ImportHeightMapButton->SetSize(ImVec2(200, 0)); - - SculptBrushIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/sculptBrush.png", "sculptBrushIcon"); - RESOURCE_MANAGER.MakeTextureStandard(SculptBrushIcon); - SculptBrushButton = new ImGuiImageButton(SculptBrushIcon); - SculptBrushButton->SetSize(ImVec2(24, 24)); - - LevelBrushIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/levelBrush.png", "levelBrushIcon"); - RESOURCE_MANAGER.MakeTextureStandard(LevelBrushIcon); - LevelBrushButton = new ImGuiImageButton(LevelBrushIcon); - LevelBrushButton->SetSize(ImVec2(24, 24)); - - SmoothBrushIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/smoothBrush.png", "smoothBrushIcon"); - RESOURCE_MANAGER.MakeTextureStandard(SmoothBrushIcon); - SmoothBrushButton = new ImGuiImageButton(SmoothBrushIcon); - SmoothBrushButton->SetSize(ImVec2(24, 24)); - - DrawBrushIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/paintbrush.png", "drawBrushIcon"); - RESOURCE_MANAGER.MakeTextureStandard(DrawBrushIcon); - LayerBrushButton = new ImGuiImageButton(DrawBrushIcon); - LayerBrushButton->SetSize(ImVec2(48, 48)); - - EntityChangePrefabTarget = DRAG_AND_DROP_MANAGER.AddTarget(FE_PREFAB, EntityChangePrefabTargetCallBack, nullptr, "Drop to assign prefab"); - // ************** Terrain Settings END ************** + INSPECTOR_WINDOW.InitializeResources(); ENGINE.GetCamera()->SetOnUpdate(OnCameraUpdate); ENGINE.AddWindowCloseCallback(CloseWindowCallBack); @@ -750,9 +384,9 @@ void FEEditor::Render() SCENE_GRAPH_WINDOW.bVisible = !SCENE_GRAPH_WINDOW.bVisible; } - if (ImGui::MenuItem("Inspector", nullptr, bInspectorVisible)) + if (ImGui::MenuItem("Inspector", nullptr, INSPECTOR_WINDOW.bVisible)) { - bInspectorVisible = !bInspectorVisible; + INSPECTOR_WINDOW.bVisible = !INSPECTOR_WINDOW.bVisible; } if (ImGui::MenuItem("Content Browser", nullptr, CONTENT_BROWSER_WINDOW.bVisible)) @@ -856,7 +490,7 @@ void FEEditor::Render() SCENE_GRAPH_WINDOW.Render(); CONTENT_BROWSER_WINDOW.Render(); - DisplayInspector(); + INSPECTOR_WINDOW.Render(); DisplayEffectsWindow(); DisplayLogWindow(); if (!GyzmosSettingsWindowObject.IsVisible()) @@ -965,520 +599,6 @@ void FEEditor::SetGameMode(const bool GameMode) } } -bool FEEditor::EntityChangePrefabTargetCallBack(FEObject* Object, void** EntityPointer) -{ - FEEntity* entity = SELECTED.GetEntity(); - if (entity == nullptr) - return false; - - entity->Prefab = (RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())); - return true; -} - -bool FEEditor::TerrainChangeMaterialTargetCallBack(FEObject* Object, void** LayerIndex) -{ - FETerrain* terrain = SELECTED.GetTerrain(); - if (terrain == nullptr) - return false; - - FEMaterial* MaterialToAssign = RESOURCE_MANAGER.GetMaterial(Object->GetObjectID()); - if (!MaterialToAssign->IsCompackPacking()) - return false; - - const int TempLayerIndex = *(int*)LayerIndex; - if (TempLayerIndex >= 0 && TempLayerIndex < FE_TERRAIN_MAX_LAYERS) - terrain->GetLayerInSlot(TempLayerIndex)->SetMaterial(MaterialToAssign); - - return true; -} - -void FEEditor::DisplayInspector() -{ - if (!bInspectorVisible) - return; - - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); - ImGui::Begin("Inspector", nullptr, ImGuiWindowFlags_None); - - if (SELECTED.GetSelected() == nullptr) - { - ImGui::PopStyleVar(); - ImGui::End(); - return; - } - - if (SELECTED.GetEntity() != nullptr) - { - FEEntity* Entity = SELECTED.GetEntity(); - - if (Entity->GetType() == FE_ENTITY) - { - ShowTransformConfiguration(Entity, &Entity->Transform); - - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f)); - - bool bActive = Entity->IsWireframeMode(); - ImGui::Checkbox("WireframeMode", &bActive); - Entity->SetWireframeMode(bActive); - - ImGui::Separator(); - ImGui::Text("Prefab : "); - FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Entity->Prefab->GetObjectID()); - - if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - { - EntityToModify = Entity; - SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); - - } - EntityChangePrefabTarget->StickToItem(); - - bool bOpenContextMenu = false; - if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) - bOpenContextMenu = true; - - if (bOpenContextMenu) - ImGui::OpenPopup("##Inspector_context_menu"); - - CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = false; - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); - if (ImGui::BeginPopup("##Inspector_context_menu")) - { - CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = true; - - if (ImGui::MenuItem("Show in folder")) - { - CONTENT_BROWSER_WINDOW.OpenItemParentFolder(Entity->Prefab); - } - - ImGui::EndPopup(); - } - ImGui::PopStyleVar(); - - ImGui::Separator(); - - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - } - else if (Entity->GetType() == FE_ENTITY_INSTANCED) - { - FEEntityInstanced* InstancedEntity = reinterpret_cast(Entity); - - if (SELECTED.InstancedSubObjectIndexSelected != -1) - { - std::string InstancedSubObjectInfo = "index: "; - - ImGui::Text("Selected instance info:"); - InstancedSubObjectInfo = "index: " + std::to_string(SELECTED.InstancedSubObjectIndexSelected); - ImGui::Text(InstancedSubObjectInfo.c_str()); - - FETransformComponent TempTransform = FETransformComponent(InstancedEntity->GetTransformedInstancedMatrix(SELECTED.InstancedSubObjectIndexSelected)); - ShowTransformConfiguration("selected instance", &TempTransform); - InstancedEntity->ModifyInstance(SELECTED.InstancedSubObjectIndexSelected, TempTransform.GetTransformMatrix()); - - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - - if (ImGui::ImageButton((void*)(intptr_t)ArrowToGroundIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - { - InstancedEntity->TryToSnapInstance(SELECTED.InstancedSubObjectIndexSelected); - } - ShowToolTip("Selected instance will attempt to snap to the terrain."); - - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - } - else - { - ShowTransformConfiguration(Entity, &Entity->Transform); - - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f)); - - ImGui::Separator(); - - ImGui::Text("Prefab : "); - FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Entity->Prefab->GetObjectID()); - if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - { - EntityToModify = Entity; - SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); - } - EntityChangePrefabTarget->StickToItem(); - - bool bOpenContextMenu = false; - if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) - bOpenContextMenu = true; - - if (bOpenContextMenu) - ImGui::OpenPopup("##Inspector_context_menu"); - - CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = false; - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); - if (ImGui::BeginPopup("##Inspector_context_menu")) - { - CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = true; - - if (ImGui::MenuItem("Show in folder")) - { - CONTENT_BROWSER_WINDOW.OpenItemParentFolder(Entity->Prefab); - } - - ImGui::EndPopup(); - } - ImGui::PopStyleVar(); - ImGui::Separator(); - - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - - ImGui::Text("Snapped to: "); - ImGui::SameLine(); - - const std::vector TerrainList = SCENE.GetTerrainList(); - static std::string CurrentTerrain = "none"; - - if (InstancedEntity->GetSnappedToTerrain() == nullptr) - { - CurrentTerrain = "none"; - } - else - { - CurrentTerrain = InstancedEntity->GetSnappedToTerrain()->GetName(); - } - - ImGui::SetNextItemWidth(220); - if (ImGui::BeginCombo("##Terrain", CurrentTerrain.c_str(), ImGuiWindowFlags_None)) - { - const bool is_selected = (CurrentTerrain == "none"); - if (ImGui::Selectable("none", is_selected)) - { - if (InstancedEntity->GetSnappedToTerrain() != nullptr) - InstancedEntity->GetSnappedToTerrain()->UnSnapInstancedEntity(InstancedEntity); - } - - if (is_selected) - ImGui::SetItemDefaultFocus(); - - for (size_t i = 0; i < TerrainList.size(); i++) - { - const bool is_selected = (CurrentTerrain == TerrainList[i]); - if (ImGui::Selectable(SCENE.GetTerrain(TerrainList[i])->GetName().c_str(), is_selected)) - { - SCENE.GetTerrain(TerrainList[i])->SnapInstancedEntity(InstancedEntity); - } - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - ImGui::EndCombo(); - } - - if (InstancedEntity->GetSnappedToTerrain() != nullptr) - { - ImGui::Text("Terrain layer: "); - ImGui::SameLine(); - - const int CurrentLayer = InstancedEntity->GetTerrainLayer(); - FETerrain* CurrentTerrain = InstancedEntity->GetSnappedToTerrain(); - - std::string caption = "none"; - const auto layer = CurrentTerrain->GetLayerInSlot(CurrentLayer); - if (layer != nullptr) - caption = layer->GetName(); - - ImGui::SetNextItemWidth(220); - if (ImGui::BeginCombo("##TerrainLayers", caption.c_str(), ImGuiWindowFlags_None)) - { - const bool is_selected = (CurrentLayer == -1); - ImGui::PushID("none_TerrainLayers_entity"); - if (ImGui::Selectable("none", is_selected)) - { - if (CurrentTerrain != nullptr) - CurrentTerrain->UnConnectInstancedEntityFromLayer(InstancedEntity); - } - ImGui::PopID(); - - if (is_selected) - ImGui::SetItemDefaultFocus(); - - for (size_t i = 0; i < FE_TERRAIN_MAX_LAYERS; i++) - { - FETerrainLayer* layer = CurrentTerrain->GetLayerInSlot(i); - if (layer == nullptr) - break; - - const bool is_selected = (CurrentLayer == i); - ImGui::PushID(layer->GetObjectID().c_str()); - if (ImGui::Selectable(layer->GetName().c_str(), is_selected)) - { - CurrentTerrain->ConnectInstancedEntityToLayer(InstancedEntity, int(i)); - } - ImGui::PopID(); - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - ImGui::EndCombo(); - } - - if (CurrentLayer != -1) - { - ImGui::Text("Minimal layer intensity:"); - float MinLevel = InstancedEntity->GetMinimalLayerIntensity(); - ImGui::SameLine(); - ImGui::SetNextItemWidth(80); - ImGui::DragFloat("##minLevel", &MinLevel); - InstancedEntity->SetMinimalLayerIntensity(MinLevel); - } - } - - ImGui::Separator(); - - ImGui::Text("Seed:"); - int seed = InstancedEntity->SpawnInfo.Seed; - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - ImGui::DragInt("##Seed", &seed); - InstancedEntity->SpawnInfo.Seed = seed; - - ImGui::Text("Object count:"); - int ObjectCount = InstancedEntity->SpawnInfo.ObjectCount; - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - ImGui::DragInt("##Object count", &ObjectCount); - if (ObjectCount <= 0) - ObjectCount = 1; - InstancedEntity->SpawnInfo.ObjectCount = ObjectCount; - - ImGui::Text("Radius:"); - float radius = InstancedEntity->SpawnInfo.Radius; - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - ImGui::DragFloat("##Radius", &radius); - if (radius < 0.0f) - radius = 0.1f; - InstancedEntity->SpawnInfo.Radius = radius; - - // Scale deviation. - ImGui::Text("Scale: "); - - ImGui::SameLine(); - ImGui::Text("min "); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(100); - float MinScale = InstancedEntity->SpawnInfo.GetMinScale(); - ImGui::DragFloat("##minScale", &MinScale, 0.01f); - InstancedEntity->SpawnInfo.SetMinScale(MinScale); - - ImGui::SameLine(); - ImGui::Text("max "); - - ImGui::SameLine(); - float MaxScale = InstancedEntity->SpawnInfo.GetMaxScale(); - ImGui::SetNextItemWidth(100); - ImGui::DragFloat("##maxScale", &MaxScale, 0.01f); - InstancedEntity->SpawnInfo.SetMaxScale(MaxScale); - - ImGui::Text("Rotation deviation:"); - float RotationDeviationX = InstancedEntity->SpawnInfo.RotationDeviation.x; - ImGui::Text("X:"); - ImGui::SameLine(); - ImGui::DragFloat("##Rotation deviation X", &RotationDeviationX, 0.01f); - if (RotationDeviationX < 0.01f) - RotationDeviationX = 0.01f; - if (RotationDeviationX > 1.0f) - RotationDeviationX = 1.0f; - InstancedEntity->SpawnInfo.RotationDeviation.x = RotationDeviationX; - - float RotationDeviationY = InstancedEntity->SpawnInfo.RotationDeviation.y; - ImGui::Text("Y:"); - ImGui::SameLine(); - ImGui::DragFloat("##Rotation deviation Y", &RotationDeviationY, 0.01f); - if (RotationDeviationY < 0.01f) - RotationDeviationY = 0.01f; - if (RotationDeviationY > 1.0f) - RotationDeviationY = 1.0f; - InstancedEntity->SpawnInfo.RotationDeviation.y = RotationDeviationY; - - float RotationDeviationZ = InstancedEntity->SpawnInfo.RotationDeviation.z; - ImGui::Text("Z:"); - ImGui::SameLine(); - ImGui::DragFloat("##Rotation deviation z", &RotationDeviationZ, 0.01f); - if (RotationDeviationZ < 0.01f) - RotationDeviationZ = 0.01f; - if (RotationDeviationZ > 1.0f) - RotationDeviationZ = 1.0f; - InstancedEntity->SpawnInfo.RotationDeviation.z = RotationDeviationZ; - - if (ImGui::Button("Spawn/Re-Spawn")) - { - InstancedEntity->Clear(); - InstancedEntity->Populate(InstancedEntity->SpawnInfo); - } - - if (ImGui::Button("Add instance")) - { - glm::mat4 NewInstanceMatrix = glm::identity(); - NewInstanceMatrix = glm::translate(NewInstanceMatrix, ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - InstancedEntity->AddInstance(NewInstanceMatrix); - - PROJECT_MANAGER.GetCurrent()->SetModified(true); - } - - if (InstancedEntity->IsSelectMode()) - { - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.0f, 0.75f, 0.0f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); - } - else - { - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - } - - ImGui::Separator(); - if (ImGui::ImageButton((void*)(intptr_t)MouseCursorIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - { - SCENE.SetSelectMode(InstancedEntity, !InstancedEntity->IsSelectMode()); - if (!InstancedEntity->IsSelectMode()) - { - SELECTED.Clear(); - SELECTED.SetSelected(InstancedEntity); - } - } - ShowToolTip("Individual selection mode - Used to select individual instances."); - - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - } - } - } - else if (SELECTED.GetTerrain() != nullptr) - { - FETerrain* CurrentTerrain = SELECTED.GetTerrain(); - DisplayTerrainSettings(CurrentTerrain); - - if (CurrentTerrain->GetBrushMode() != FE_TERRAIN_BRUSH_NONE) - { - // to hide gizmos - if (SELECTED.GetTerrain() != nullptr) - SELECTED.SetSelected(SELECTED.GetTerrain()); - - CurrentTerrain->SetBrushActive(EDITOR.bLeftMousePressed); - - if (EDITOR.bShiftPressed) - { - if (CurrentTerrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW) - CurrentTerrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED); - } - else - { - if (CurrentTerrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) - CurrentTerrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); - } - - /*if (EDITOR.bLeftMousePressed) - { - if (EDITOR.bShiftPressed) - { - currentTerrain->setBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED); - } - else - { - currentTerrain->setBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); - } - } - else - { - currentTerrain->setBrushMode(FE_TERRAIN_BRUSH_NONE); - }*/ - - //currentTerrain->setBrushActive(EDITOR.bLeftMousePressed); - //currentTerrain->setBrushInversed(EDITOR.bShiftPressed); - } - else - { - // to show gizmos - if (SELECTED.GetTerrain() != nullptr) - SELECTED.SetSelected(SELECTED.GetTerrain()); - } - } - else if (SELECTED.GetLight() != nullptr) - { - DisplayLightProperties(SELECTED.GetLight()); - } - else if (SELECTED.GetSelected()->GetType() == FE_CAMERA) - { - FEBasicCamera* camera = ENGINE.GetCamera(); - - // ********* POSITION ********* - glm::vec3 CameraPosition = camera->GetPosition(); - - ImGui::Text("Position : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(90); - ImGui::DragFloat("##X pos", &CameraPosition[0], 0.1f); - ShowToolTip("X position"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(90); - ImGui::DragFloat("##Y pos", &CameraPosition[1], 0.1f); - ShowToolTip("Y position"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(90); - ImGui::DragFloat("##Z pos", &CameraPosition[2], 0.1f); - ShowToolTip("Z position"); - - camera->SetPosition(CameraPosition); - - // ********* ROTATION ********* - glm::vec3 CameraRotation = glm::vec3(camera->GetYaw(), camera->GetPitch(), camera->GetRoll()); - - ImGui::Text("Rotation : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(90); - ImGui::DragFloat("##X rot", &CameraRotation[0], 0.1f); - ShowToolTip("X rotation"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(90); - ImGui::DragFloat("##Y rot", &CameraRotation[1], 0.1f); - ShowToolTip("Y rotation"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(90); - ImGui::DragFloat("##Z rot", &CameraRotation[2], 0.1f); - ShowToolTip("Z rotation"); - - camera->SetYaw(CameraRotation[0]); - camera->SetPitch(CameraRotation[1]); - camera->SetRoll(CameraRotation[2]); - - float CameraSpeed = camera->GetMovementSpeed(); - ImGui::Text("Camera speed in m/s : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(70); - ImGui::DragFloat("##Camera_speed", &CameraSpeed, 0.01f, 0.01f, 100.0f); - camera->SetMovementSpeed(CameraSpeed); - } - - ImGui::PopStyleVar(); - ImGui::End(); -} - void FEEditor::DisplayEffectsWindow() const { if (!bEffectsWindowVisible) @@ -1972,476 +1092,6 @@ void FEEditor::DisplayEffectsWindow() const ImGui::End(); } -static FETerrain* TerrainToWorkWith = nullptr; -static void CreateNewTerrainLayerWithMaterialCallBack(std::vector SelectionsResult) -{ - if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_MATERIAL) - { - if (TerrainToWorkWith == nullptr) - return; - - FEMaterial* SelectedMaterial = RESOURCE_MANAGER.GetMaterial(SelectionsResult[0]->GetObjectID()); - if (SelectedMaterial == nullptr) - return; - - RESOURCE_MANAGER.ActivateTerrainVacantLayerSlot(TerrainToWorkWith, SelectedMaterial); - } - - TerrainToWorkWith = nullptr; -} - -static size_t TempLayerIndex = -1; -static void ChangeMaterialInTerrainLayerCallBack(std::vector SelectionsResult) -{ - if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_MATERIAL) - { - if (TempLayerIndex == -1) - return; - - FEMaterial* SelectedMaterial = RESOURCE_MANAGER.GetMaterial(SelectionsResult[0]->GetObjectID()); - if (SelectedMaterial == nullptr) - return; - - TerrainToWorkWith->GetLayerInSlot(TempLayerIndex)->SetMaterial(SelectedMaterial); - } - - TerrainToWorkWith = nullptr; - TempLayerIndex = -1; -} - -void FEEditor::DisplayTerrainSettings(FETerrain* Terrain) -{ - if (TerrainChangeLayerMaterialTargets.size() != Terrain->LayersUsed()) - { - for (size_t i = 0; i < TerrainChangeLayerMaterialTargets.size(); i++) - { - delete TerrainChangeLayerMaterialTargets[i]; - } - - TerrainChangeLayerMaterialTargets.resize(Terrain->LayersUsed()); - TerrainChangeMaterialIndecies.resize(Terrain->LayersUsed()); - for (size_t i = 0; i < size_t(Terrain->LayersUsed()); i++) - { - TerrainChangeMaterialIndecies[i] = int(i); - TerrainChangeLayerMaterialTargets[i] = DRAG_AND_DROP_MANAGER.AddTarget(FE_MATERIAL, TerrainChangeMaterialTargetCallBack, (void**)&TerrainChangeMaterialIndecies[i], "Drop to assing material to " + Terrain->GetLayerInSlot(i)->GetName()); - } - } - - if (ImGui::BeginTabBar("##terrainSettings", ImGuiTabBarFlags_None)) - { - if (ImGui::BeginTabItem("General")) - { - bool bActive = Terrain->IsWireframeMode(); - ImGui::Checkbox("WireframeMode", &bActive); - Terrain->SetWireframeMode(bActive); - - int IData = *(int*)RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/)->GetParameterData("debugFlag"); - ImGui::SliderInt("debugFlag", &IData, 0, 10); - RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/)->UpdateParameterData("debugFlag", IData); - - float DisplacementScale = Terrain->GetDisplacementScale(); - ImGui::DragFloat("displacementScale", &DisplacementScale, 0.02f, -10.0f, 10.0f); - Terrain->SetDisplacementScale(DisplacementScale); - - float LODLevel = Terrain->GetLODLevel(); - ImGui::DragFloat("LODlevel", &LODLevel, 2.0f, 2.0f, 128.0f); - Terrain->SetLODLevel(LODLevel); - ShowToolTip("Bigger LODlevel more details terraine will have and less performance you will get."); - - float ChunkPerSide = Terrain->GetChunkPerSide(); - ImGui::DragFloat("chunkPerSide", &ChunkPerSide, 2.0f, 1.0f, 16.0f); - Terrain->SetChunkPerSide(ChunkPerSide); - - // ********************* REAL WORLD COMPARISON SCALE ********************* - FEAABB RealAABB = Terrain->GetAABB(); - glm::vec3 min = RealAABB.GetMin(); - glm::vec3 max = RealAABB.GetMax(); - - float XSize = sqrt((max.x - min.x) * (max.x - min.x)); - float YSize = sqrt((max.y - min.y) * (max.y - min.y)); - float ZSize = sqrt((max.z - min.z) * (max.z - min.z)); - - std::string SizeInM = "Approximate terrain size: "; - SizeInM += std::to_string(std::max(XSize, std::max(YSize, ZSize))); - SizeInM += " m"; - ImGui::Text(SizeInM.c_str()); - // ********************* REAL WORLD COMPARISON SCALE END ********************* - - ShowTransformConfiguration(Terrain, &Terrain->Transform); - - ImGui::EndTabItem(); - } - if (ImGui::BeginTabItem("Sculpt")) - { - ExportHeightMapButton->Render(); - if (ExportHeightMapButton->IsClicked()) - { - std::string filePath = ""; - FILE_SYSTEM.ShowFileSaveDialog(filePath, TEXTURE_LOAD_FILTER, 1); - - if (!filePath.empty()) - { - filePath += ".png"; - RESOURCE_MANAGER.ExportFETextureToPNG(Terrain->HeightMap, filePath.c_str()); - } - } - - ImGui::SameLine(); - ImportHeightMapButton->Render(); - if (ImportHeightMapButton->IsClicked()) - { - std::string FilePath; - FILE_SYSTEM.ShowFileOpenDialog(FilePath, TEXTURE_LOAD_FILTER, 1); - - if (!FilePath.empty()) - { - FETexture* LoadedTexture = RESOURCE_MANAGER.LoadPNGHeightmap(FilePath.c_str(), Terrain); - if (LoadedTexture == RESOURCE_MANAGER.NoTexture) - { - LOG.Add(std::string("can't load height map: ") + FilePath, "FE_LOG_LOADING", FE_LOG_ERROR); - } - else - { - LoadedTexture->SetDirtyFlag(true); - PROJECT_MANAGER.GetCurrent()->SetModified(true); - } - } - } - - float HighScale = Terrain->GetHightScale(); - ImGui::DragFloat("hight range in m", &HighScale); - Terrain->SetHightScale(HighScale); - - float CurrentBrushSize = Terrain->GetBrushSize(); - ImGui::DragFloat("brushSize", &CurrentBrushSize, 0.1f, 0.01f, 100.0f); - Terrain->SetBrushSize(CurrentBrushSize); - - float CurrentBrushIntensity = Terrain->GetBrushIntensity(); - ImGui::DragFloat("brushIntensity", &CurrentBrushIntensity, 0.0001f, 0.0001f, 10.0f); - Terrain->SetBrushIntensity(CurrentBrushIntensity); - - SetDefaultStyle(SculptBrushButton); - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW || - Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) - SetSelectedStyle(SculptBrushButton); - - SculptBrushButton->Render(); - ShowToolTip("Sculpt Brush. Left mouse to increase height, hold shift to decrease height."); - - if (SculptBrushButton->IsClicked()) - { - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW || - Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) - { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); - } - else - { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); - } - } - - SetDefaultStyle(LevelBrushButton); - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_LEVEL) - SetSelectedStyle(LevelBrushButton); - - ImGui::SameLine(); - LevelBrushButton->Render(); - ShowToolTip("Level Brush."); - - if (LevelBrushButton->IsClicked()) - { - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_LEVEL) - { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); - } - else - { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_LEVEL); - } - } - - SetDefaultStyle(SmoothBrushButton); - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_SMOOTH) - SetSelectedStyle(SmoothBrushButton); - - ImGui::SameLine(); - SmoothBrushButton->Render(); - ShowToolTip("Smooth Brush."); - - if (SmoothBrushButton->IsClicked()) - { - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_SMOOTH) - { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); - } - else - { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_SMOOTH); - } - } - - ImGui::EndTabItem(); - } - if (ImGui::BeginTabItem("Paint")) - { - glm::vec2 TileMult = Terrain->GetTileMult(); - ImGui::DragFloat2("all layers tile factors", &TileMult[0], 0.1f, 1.0f, 100.0f); - Terrain->SetTileMult(TileMult); - - float CurrentBrushSize = Terrain->GetBrushSize(); - ImGui::DragFloat("brushSize", &CurrentBrushSize, 0.1f, 0.01f, 100.0f); - Terrain->SetBrushSize(CurrentBrushSize); - - float CurrentBrushIntensity = Terrain->GetBrushIntensity(); - ImGui::DragFloat("brushIntensity", &CurrentBrushIntensity, 0.0001f, 0.0001f, 10.0f); - Terrain->SetBrushIntensity(CurrentBrushIntensity); - - SetDefaultStyle(LayerBrushButton); - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_LAYER_DRAW) - SetSelectedStyle(LayerBrushButton); - - LayerBrushButton->Render(); - ShowToolTip("Layer draw brush. Left mouse to paint currently selected layer, hold shift to decrease layer influence."); - static int SelectedLayer = -1; - if (SelectedLayer != -1 && Terrain->GetLayerInSlot(SelectedLayer) == nullptr) - SelectedLayer = -1; - - if (LayerBrushButton->IsClicked()) - { - if (SelectedLayer != -1) - { - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_LAYER_DRAW) - { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); - } - else - { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_LAYER_DRAW); - } - } - - } - - ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); - static bool bContextMenuOpened = false; - - ImGui::Text("Layers:"); - - ImGui::BeginChildFrame(ImGui::GetID("Layers ListBox Child"), ImVec2(ImGui::GetContentRegionAvail().x - 10.0f, 500.0f), ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse); - bool bListBoxHovered = false; - if (ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows)) - bListBoxHovered = true; - - static bool bShouldOpenContextMenu = false; - if (ImGui::IsMouseClicked(1)) - { - if (bListBoxHovered) - { - bShouldOpenContextMenu = true; - } - } - - ImGui::BeginListBox("##Layers ListBox", ImVec2(ImGui::GetContentRegionAvail().x - 10.0f, 500.0f)); - - for (size_t i = 0; i < FE_TERRAIN_MAX_LAYERS; i++) - { - FETerrainLayer* layer = Terrain->GetLayerInSlot(i); - if (layer == nullptr) - break; - - ImVec2 PostionBeforeDraw = ImGui::GetCursorPos(); - - ImVec2 TextSize = ImGui::CalcTextSize(layer->GetName().c_str()); - ImGui::SetCursorPos(PostionBeforeDraw + ImVec2(ImGui::GetContentRegionAvail().x / 2.0f - TextSize.x / 2.0f, 16)); - - if (TerrainLayerRenameIndex == i) - { - if (!bLastFrameTerrainLayerRenameEditWasVisiable) - { - ImGui::SetKeyboardFocusHere(0); - ImGui::SetFocusID(ImGui::GetID("##newNameTerrainLayerEditor"), ImGui::GetCurrentWindow()); - ImGui::SetItemDefaultFocus(); - bLastFrameTerrainLayerRenameEditWasVisiable = true; - } - - ImGui::SetNextItemWidth(350.0f); - ImGui::SetCursorPos(ImVec2(PostionBeforeDraw.x + 64.0f + (ImGui::GetContentRegionAvail().x- 64.0f) / 2.0f - 350.0f / 2.0f, PostionBeforeDraw.y + 12)); - if (ImGui::InputText("##newNameTerrainLayerEditor", TerrainLayerRename, IM_ARRAYSIZE(TerrainLayerRename), ImGuiInputTextFlags_EnterReturnsTrue) || - ImGui::IsMouseClicked(0) && !ImGui::IsItemHovered() || ImGui::GetFocusID() != ImGui::GetID("##newNameTerrainLayerEditor")) - { - PROJECT_MANAGER.GetCurrent()->SetModified(true); - layer->SetName(TerrainLayerRename); - - TerrainLayerRenameIndex = -1; - } - } - else - { - ImGui::Text(layer->GetName().c_str()); - } - ImGui::SetCursorPos(PostionBeforeDraw); - - ImGui::PushID(int(i)); - if (ImGui::Selectable("##item", SelectedLayer == i ? true : false, ImGuiSelectableFlags_None, ImVec2(ImGui::GetContentRegionAvail().x - 0, 64))) - { - SelectedLayer = int(i); - Terrain->SetBrushLayerIndex(SelectedLayer); - } - TerrainChangeLayerMaterialTargets[i]->StickToItem(); - ImGui::PopID(); - - if (ImGui::IsItemHovered()) - HoveredTerrainLayerItem = int(i); - - ImGui::SetCursorPos(PostionBeforeDraw); - ImColor ImageTint = ImGui::IsItemHovered() ? ImColor(1.0f, 1.0f, 1.0f, 0.5f) : ImColor(1.0f, 1.0f, 1.0f, 1.0f); - FETexture* PreviewTexture = PREVIEW_MANAGER.GetMaterialPreview(layer->GetMaterial()->GetObjectID()); - ImGui::Image((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), ImageTint); - } - - ImGui::EndListBox(); - ImGui::PopFont(); - - ImGui::EndChildFrame(); - ImGui::EndTabItem(); - - if (bShouldOpenContextMenu) - { - bShouldOpenContextMenu = false; - ImGui::OpenPopup("##layers_listBox_context_menu"); - } - - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); - if (ImGui::BeginPopup("##layers_listBox_context_menu")) - { - bContextMenuOpened = true; - - if (Terrain->GetLayerInSlot(FE_TERRAIN_MAX_LAYERS - 1) != nullptr) - ImGui::BeginDisabled(); - - if (ImGui::MenuItem("Add layer...")) - { - std::vector TempMaterialList = RESOURCE_MANAGER.GetMaterialList(); - std::vector FinalMaterialList; - for (size_t i = 0; i < TempMaterialList.size(); i++) - { - if (RESOURCE_MANAGER.GetMaterial(TempMaterialList[i])->IsCompackPacking()) - { - FinalMaterialList.push_back(RESOURCE_MANAGER.GetMaterial(TempMaterialList[i])); - } - } - - if (FinalMaterialList.empty()) - { - MessagePopUp::getInstance().Show("No suitable material", "There are no materials with compack packing."); - } - else - { - TerrainToWorkWith = Terrain; - SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, CreateNewTerrainLayerWithMaterialCallBack, nullptr, FinalMaterialList); - } - } - - if (Terrain->GetLayerInSlot(FE_TERRAIN_MAX_LAYERS - 1) != nullptr) - ImGui::EndDisabled(); - - if (HoveredTerrainLayerItem != -1) - { - FETerrainLayer* layer = Terrain->GetLayerInSlot(HoveredTerrainLayerItem); - if (layer != nullptr) - { - ImGui::Separator(); - std::string LayerName = layer->GetName(); - ImGui::Text((std::string("Actions with ") + LayerName).c_str()); - ImGui::Separator(); - - if (ImGui::MenuItem("Rename")) - { - TerrainLayerRenameIndex = HoveredTerrainLayerItem; - - strcpy_s(TerrainLayerRename, layer->GetName().size() + 1, layer->GetName().c_str()); - bLastFrameTerrainLayerRenameEditWasVisiable = false; - } - - if (ImGui::MenuItem("Fill")) - { - RESOURCE_MANAGER.FillTerrainLayerMask(Terrain, HoveredTerrainLayerItem); - } - - if (ImGui::MenuItem("Clear")) - { - RESOURCE_MANAGER.ClearTerrainLayerMask(Terrain, HoveredTerrainLayerItem); - } - - if (ImGui::MenuItem("Delete")) - { - RESOURCE_MANAGER.DeleteTerrainLayerMask(Terrain, HoveredTerrainLayerItem); - } - - ImGui::Separator(); - - if (ImGui::MenuItem("Change material...")) - { - std::vector TempMaterialList = RESOURCE_MANAGER.GetMaterialList(); - std::vector FinalMaterialList; - for (size_t i = 0; i < TempMaterialList.size(); i++) - { - if (RESOURCE_MANAGER.GetMaterial(TempMaterialList[i])->IsCompackPacking()) - { - FinalMaterialList.push_back(RESOURCE_MANAGER.GetMaterial(TempMaterialList[i])); - } - } - - if (FinalMaterialList.empty()) - { - MessagePopUp::getInstance().Show("No suitable material", "There are no materials with compack packing."); - } - else - { - TerrainToWorkWith = Terrain; - TempLayerIndex = HoveredTerrainLayerItem; - SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialInTerrainLayerCallBack, Terrain->GetLayerInSlot(HoveredTerrainLayerItem)->GetMaterial(), FinalMaterialList); - } - } - - if (ImGui::MenuItem("Export mask...")) - { - std::string filePath = ""; - FILE_SYSTEM.ShowFileSaveDialog(filePath, TEXTURE_LOAD_FILTER, 1); - if (!filePath.empty()) - { - filePath += ".png"; - RESOURCE_MANAGER.SaveTerrainLayerMask(filePath.c_str(), Terrain, HoveredTerrainLayerItem); - } - } - - if (ImGui::MenuItem("Import mask...")) - { - std::string filePath = ""; - FILE_SYSTEM.ShowFileOpenDialog(filePath, TEXTURE_LOAD_FILTER, 1); - if (!filePath.empty()) - { - RESOURCE_MANAGER.LoadTerrainLayerMask(filePath.c_str(), Terrain, HoveredTerrainLayerItem); - PROJECT_MANAGER.GetCurrent()->SetModified(true); - } - } - } - } - - ImGui::EndPopup(); - } - ImGui::PopStyleVar(); - - if (!bContextMenuOpened) - HoveredTerrainLayerItem = -1; - - bContextMenuOpened = false; - } - ImGui::EndTabBar(); - } -} - void FEEditor::RenderAllSubWindows() { SelectFEObjectPopUp::getInstance().Render(); diff --git a/FEEditor.h b/FEEditor.h index 58d8eb3..3d73891 100644 --- a/FEEditor.h +++ b/FEEditor.h @@ -1,6 +1,6 @@ #pragma once -#include "EditorWindows/ContentBrowserWindow.h" +#include "EditorWindows/InspectorWindow.h" #include class DragAndDropTarget; @@ -22,8 +22,6 @@ class FEEditor void SetMouseX(double NewValue); double GetMouseY() const; void SetMouseY(double NewValue); - bool bLeftMousePressed = false; - bool bShiftPressed = false; // Clipboard std::string GetObjectNameInClipboard(); @@ -43,14 +41,6 @@ class FEEditor // Scene window static ImGuiWindow* SceneWindow; - // Brush icons - FETexture* SculptBrushIcon = nullptr; - FETexture* LevelBrushIcon = nullptr; - FETexture* SmoothBrushIcon = nullptr; - FETexture* MouseCursorIcon = nullptr; - FETexture* ArrowToGroundIcon = nullptr; - FETexture* DrawBrushIcon = nullptr; - // Drag and drop DragAndDropTarget* SceneWindowTarget = nullptr; @@ -63,12 +53,6 @@ class FEEditor static void DropCallback(int Count, const char** Paths); static void CloseWindowCallBack(); - // Inspector - void DisplayInspector(); - bool bInspectorVisible = true; - void ShowTransformConfiguration(FEObject* Object, FETransformComponent* Transform) const; - void ShowTransformConfiguration(std::string Name, FETransformComponent* Transform) const; - // Effects window bool bEffectsWindowVisible = true; void DisplayEffectsWindow() const; @@ -77,30 +61,6 @@ class FEEditor bool bLogWindowVisible = true; void DisplayLogWindow() const; - // Light properties - void DisplayLightProperties(FELight* Light) const; - void DisplayLightsProperties() const; - - // Terrain settings - ImGuiButton* ExportHeightMapButton = nullptr; - ImGuiButton* ImportHeightMapButton = nullptr; - ImGuiImageButton* SculptBrushButton = nullptr; - ImGuiImageButton* LevelBrushButton = nullptr; - ImGuiImageButton* SmoothBrushButton = nullptr; - ImGuiImageButton* LayerBrushButton = nullptr; - static bool EntityChangePrefabTargetCallBack(FEObject* Object, void** EntityPointer); - static bool TerrainChangeMaterialTargetCallBack(FEObject* Object, void** LayerIndex); - static FEEntity* EntityToModify; - static void ChangePrefabOfEntityCallBack(std::vector SelectionsResult); - DragAndDropTarget* EntityChangePrefabTarget = nullptr; - std::vector TerrainChangeMaterialIndecies; - std::vector TerrainChangeLayerMaterialTargets; - int HoveredTerrainLayerItem = -1; - void DisplayTerrainSettings(FETerrain* Terrain); - int TerrainLayerRenameIndex = -1; - char TerrainLayerRename[1024]; - bool bLastFrameTerrainLayerRenameEditWasVisiable = false; - // Resource under mouse int TextureUnderMouse = -1; int MeshUnderMouse = -1; diff --git a/FEEditorPreviewManager.h b/FEEditorPreviewManager.h index 8adec94..dfed7de 100644 --- a/FEEditorPreviewManager.h +++ b/FEEditorPreviewManager.h @@ -3,77 +3,74 @@ #include "../FEngine.h" using namespace FocalEngine; -//namespace FocalEngine -//{ - - class FEEditorPreviewManager - { - friend class FEEditor; - friend class FEEditorContentBrowserWindow; - friend class FEProjectManager; - friend class DeleteTexturePopup; - friend class RenameMeshPopUp; - friend class DeleteMeshPopup; - friend class SelectMeshPopUp; - friend class SelectMaterialPopUp; - friend class SelectGameModelPopUp; - friend class EditGameModelPopup; - friend class EditMaterialPopup; - friend class DeleteMaterialPopup; - friend class SelectFEObjectPopUp; - friend class PrefabEditorWindow; - - private: - SINGLETON_PUBLIC_PART(FEEditorPreviewManager) - SINGLETON_PRIVATE_PART(FEEditorPreviewManager) - - void InitializeResources(); - void ReInitializeEntities(); - void UpdateAll(); - - FEFramebuffer* PreviewFB; - FEEntity* PreviewEntity; - FEPrefab* PreviewPrefab; - FEGameModel* PreviewGameModel; - FEMaterial* MeshPreviewMaterial; - - std::unordered_map MeshPreviewTextures; - std::unordered_map MaterialPreviewTextures; - std::unordered_map GameModelPreviewTextures; - std::unordered_map PrefabPreviewTextures; - - static glm::vec4 OriginalClearColor; - static FETransformComponent OriginalMeshTransform; - static glm::vec3 OriginalCameraPosition; - static float OriginalAspectRation; - static float OriginalCameraPitch; - static float OriginalCameraRoll; - static float OriginalCameraYaw; - static float OriginalExposure; - - void BeforePreviewActions(); - void AfterPreviewActions(); - - void CreateMeshPreview(std::string MeshID); - FETexture* GetMeshPreview(std::string MeshID); - - void CreateMaterialPreview(std::string MaterialID); - FETexture* GetMaterialPreview(std::string MaterialID); - - void CreateGameModelPreview(std::string GameModelID); - void CreateGameModelPreview(const FEGameModel* GameModel, FETexture** ResultingTexture); - FETexture* GetGameModelPreview(std::string GameModelID); - void UpdateAllGameModelPreviews(); - - void CreatePrefabPreview(std::string PrefabID); - void CreatePrefabPreview(FEPrefab* Prefab, FETexture** ResultingTexture); - FETexture* GetPrefabPreview(std::string PrefabID); - - FETexture* GetPreview(FEObject* Object); - FETexture* GetPreview(std::string ObjectID); - - void Clear(); - }; - -#define PREVIEW_MANAGER FEEditorPreviewManager::getInstance() -//} \ No newline at end of file +class FEEditorPreviewManager +{ + friend class FEEditor; + friend class FEEditorInspectorWindow; + friend class FEEditorContentBrowserWindow; + friend class FEProjectManager; + friend class DeleteTexturePopup; + friend class RenameMeshPopUp; + friend class DeleteMeshPopup; + friend class SelectMeshPopUp; + friend class SelectMaterialPopUp; + friend class SelectGameModelPopUp; + friend class EditGameModelPopup; + friend class EditMaterialPopup; + friend class DeleteMaterialPopup; + friend class SelectFEObjectPopUp; + friend class PrefabEditorWindow; + +private: + SINGLETON_PUBLIC_PART(FEEditorPreviewManager) + SINGLETON_PRIVATE_PART(FEEditorPreviewManager) + + void InitializeResources(); + void ReInitializeEntities(); + void UpdateAll(); + + FEFramebuffer* PreviewFB; + FEEntity* PreviewEntity; + FEPrefab* PreviewPrefab; + FEGameModel* PreviewGameModel; + FEMaterial* MeshPreviewMaterial; + + std::unordered_map MeshPreviewTextures; + std::unordered_map MaterialPreviewTextures; + std::unordered_map GameModelPreviewTextures; + std::unordered_map PrefabPreviewTextures; + + static glm::vec4 OriginalClearColor; + static FETransformComponent OriginalMeshTransform; + static glm::vec3 OriginalCameraPosition; + static float OriginalAspectRation; + static float OriginalCameraPitch; + static float OriginalCameraRoll; + static float OriginalCameraYaw; + static float OriginalExposure; + + void BeforePreviewActions(); + void AfterPreviewActions(); + + void CreateMeshPreview(std::string MeshID); + FETexture* GetMeshPreview(std::string MeshID); + + void CreateMaterialPreview(std::string MaterialID); + FETexture* GetMaterialPreview(std::string MaterialID); + + void CreateGameModelPreview(std::string GameModelID); + void CreateGameModelPreview(const FEGameModel* GameModel, FETexture** ResultingTexture); + FETexture* GetGameModelPreview(std::string GameModelID); + void UpdateAllGameModelPreviews(); + + void CreatePrefabPreview(std::string PrefabID); + void CreatePrefabPreview(FEPrefab* Prefab, FETexture** ResultingTexture); + FETexture* GetPrefabPreview(std::string PrefabID); + + FETexture* GetPreview(FEObject* Object); + FETexture* GetPreview(std::string ObjectID); + + void Clear(); +}; + +#define PREVIEW_MANAGER FEEditorPreviewManager::getInstance() \ No newline at end of file diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index 2674f70..cebfb34 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -128,9 +128,9 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons const std::vector EntityList = SCENE.GetEntityList(); for (size_t i = 0; i < EntityList.size(); i++) { - float dis = 0; - FEAABB box = SCENE.GetEntity(EntityList[i])->GetAABB(); - if (box.RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, dis)) + float Distance = 0; + FEAABB Box = SCENE.GetEntity(EntityList[i])->GetAABB(); + if (Box.RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) { if (SCENE.GetEntity(EntityList[i])->GetType() == FE_ENTITY_INSTANCED) { @@ -140,7 +140,7 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons InstancedSubObjectsInfo[InstancedEntity] = std::vector(); for (size_t j = 0; j < InstancedEntity->InstancedAABB.size(); j++) { - if(InstancedEntity->InstancedAABB[j].RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, dis)) + if(InstancedEntity->InstancedAABB[j].RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) { InstancedSubObjectsInfo[InstancedEntity].push_back(static_cast(j)); } @@ -159,9 +159,9 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons const std::vector TerrainList = SCENE.GetTerrainList(); for (size_t i = 0; i < TerrainList.size(); i++) { - float dis = 0; - FEAABB box = SCENE.GetTerrain(TerrainList[i])->GetAABB(); - if (box.RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, dis)) + float Distance = 0; + FEAABB Box = SCENE.GetTerrain(TerrainList[i])->GetAABB(); + if (Box.RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) { SELECTED.ObjectsUnderMouse.push_back(SCENE.GetTerrain(TerrainList[i])); } diff --git a/FEEditorVirtualFileSystem.cpp b/FEEditorVirtualFileSystem.cpp index a23e1d4..a2aabbf 100644 --- a/FEEditorVirtualFileSystem.cpp +++ b/FEEditorVirtualFileSystem.cpp @@ -43,7 +43,7 @@ bool FEVFSDirectory::HasFile(const FEObject* File) { if (File == nullptr) { - LOG.Add("file is nullptr in function FEVFSDirectory::hasFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("File is nullptr in function FEVFSDirectory::HasFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); return false; } @@ -258,7 +258,7 @@ bool FEVirtualFileSystem::CreateFile(FEObject* Data, const std::string Path) { if (Data == nullptr) { - LOG.Add("data is nullptr in function FEVirtualFileSystem::createFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("Data is nullptr in function FEVirtualFileSystem::CreateFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); return false; } @@ -269,7 +269,7 @@ bool FEVirtualFileSystem::CreateFile(FEObject* Data, const std::string Path) Data->GetType() != FE_GAMEMODEL && Data->GetType() != FE_PREFAB) { - LOG.Add("data type is not supported in function FEVirtualFileSystem::createFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("Data type is not supported in function FEVirtualFileSystem::CreateFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); return false; } @@ -398,7 +398,7 @@ bool FEVirtualFileSystem::MoveFile(FEObject* Data, const std::string OldPath, co { if (Data == nullptr) { - LOG.Add("data is nullptr in function FEVirtualFileSystem::moveFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("Data is nullptr in function FEVirtualFileSystem::MoveFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); return false; } @@ -467,7 +467,7 @@ void FEVirtualFileSystem::DeleteDirectory(FEVFSDirectory* Directory) { if (Directory == nullptr) { - LOG.Add("directory is nullptr in function FEVirtualFileSystem::deleteDirectory.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("Directory is nullptr in function FEVirtualFileSystem::DeleteDirectory.", "FE_LOG_GENERAL", FE_LOG_ERROR); return; } @@ -523,32 +523,32 @@ std::string FEVirtualFileSystem::DirectoryToPath(FEVFSDirectory* Directory) std::string FEVirtualFileSystem::GetDirectoryParent(const std::string Path) { - const FEVFSDirectory* directory = PathToDirectory(Path); - if (directory == nullptr) + const FEVFSDirectory* Directory = PathToDirectory(Path); + if (Directory == nullptr) return "/"; - return DirectoryToPath(directory->Parent); + return DirectoryToPath(Directory->Parent); } bool FEVirtualFileSystem::DeleteFile(const FEObject* Data, const std::string Path) { if (Data == nullptr) { - LOG.Add("data is nullptr in function FEVirtualFileSystem::deleteFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("Data is nullptr in function FEVirtualFileSystem::DeleteFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); return false; } - FEVFSDirectory* directory = PathToDirectory(Path); - if (directory == nullptr) + FEVFSDirectory* Directory = PathToDirectory(Path); + if (Directory == nullptr) return false; - if (!directory->HasFile(Data)) + if (!Directory->HasFile(Data)) return false; - if (directory->IsReadOnly()) + if (Directory->IsReadOnly()) return false; - directory->DeleteFile(Data); + Directory->DeleteFile(Data); return true; } @@ -621,12 +621,12 @@ void FEVirtualFileSystem::SaveStateRecursive(Json::Value* LocalRoot, FEVFSDirect { LocalRoot->operator[](Directory->GetObjectID())["name"] = Directory->GetName(); - Json::Value files; + Json::Value Files; for (size_t i = 0; i < Directory->Files.size(); i++) { - files[Directory->Files[i].Data->GetObjectID()]; + Files[Directory->Files[i].Data->GetObjectID()]; } - LocalRoot->operator[](Directory->GetObjectID())["files"] = files; + LocalRoot->operator[](Directory->GetObjectID())["files"] = Files; Json::Value SubDirectories; for (size_t i = 0; i < Directory->SubDirectories.size(); i++) @@ -744,7 +744,6 @@ bool FEVirtualFileSystem::IsReadOnly(const FEObject* Data, const std::string Pat void FEVirtualFileSystem::SetDirectoryReadOnly(const bool NewValue, const std::string Path) { FEVFSDirectory* Directory = PathToDirectory(Path); - if (Directory == nullptr) return; @@ -754,7 +753,6 @@ void FEVirtualFileSystem::SetDirectoryReadOnly(const bool NewValue, const std::s void FEVirtualFileSystem::SetFileReadOnly(const bool NewValue, const FEObject* Data, const std::string Path) { FEVFSDirectory* Directory = PathToDirectory(Path); - if (Directory == nullptr) return; diff --git a/FEProject.cpp b/FEProject.cpp index 67ffe9e..d65daa0 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -236,9 +236,9 @@ void FEProjectManager::DisplayProjectSelection() ImGui::SetCursorPos(ImVec2(ImGui::GetContentRegionAvail().x + 280.0f + 64.0f, ImGui::GetCursorPos().y)); if (ImGui::Button("Choose projects directory", ImVec2(280.0f, 64.0f))) { - std::string path; - FILE_SYSTEM.ShowFolderOpenDialog(path); - SetProjectsFolder(path); + std::string Path; + FILE_SYSTEM.ShowFolderOpenDialog(Path); + SetProjectsFolder(Path); } ImGui::PopStyleColor(); diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 830ec76..ef29227 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 830ec763049aa59bee1dc95504079aa6c37f0624 +Subproject commit ef292270d705d9f67a04735128cf1e8922402c0f From 8e48e4a82108b5660b4ef131b5bea17f681bbfdc Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Sun, 23 Jun 2024 19:37:32 -0400 Subject: [PATCH 08/46] Moved the RaysIntersection function from GizmoManager to the engine's GEOMETRY class as it is a general geometry-related function; Attempted to make entity scaling less aggressive in some edge cases; Moved the temporary TransformUpdate function to the engine; Reworked the editor gizmo to have a parent and work with all gizmo entities through it. --- EditorWindows/SceneGraphWindow.cpp | 72 ----- FEEditor.cpp | 12 +- FEEditorGizmoManager.cpp | 442 ++++++++++++++++------------- FEEditorGizmoManager.h | 19 +- FEProject.cpp | 6 +- SubSystems/FocalEngine | 2 +- 6 files changed, 265 insertions(+), 288 deletions(-) diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 9079e14..8e85bc3 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -198,77 +198,8 @@ DragAndDropTarget* FEEditorSceneGraphWindow::GetSceneNodeDragAndDropTarget(FENai return SceneNodeDragAndDropTargets[UniqueID]; } -#include "glm/gtx/matrix_decompose.hpp" - -void TransformUpdate(FENaiveSceneEntity* SubTreeRoot) -{ - FEEntity* Entity = reinterpret_cast(SubTreeRoot->GetOldStyleEntity()); - if (Entity == nullptr) - { - auto Children = SubTreeRoot->GetChildren(); - for (size_t i = 0; i < Children.size(); i++) - { - TransformUpdate(Children[i]); - } - return; - } - - Entity->Transform.bIsInSceneGraph = true; - - if (SubTreeRoot->GetParent() == nullptr || SubTreeRoot->GetParent() == SCENE.SceneGraph.GetRoot()) - { - Entity->Transform.Update(); - Entity->Transform.WorldSpaceMatrix = Entity->Transform.LocalSpaceMatrix; - } - - FETransformComponent& ParentTransform = Entity->Transform; - - auto Children = SubTreeRoot->GetChildren(); - for (size_t i = 0; i < Children.size(); i++) - { - /*FEEntity* ChildEntity = reinterpret_cast(Children[i]->GetOldStyleEntity()); - FETransformComponent& ChildTransform = ChildEntity->Transform; - - ChildTransform.SetPosition(ParentTransform.GetPosition() + ChildTransform.GetPosition()); - ChildTransform.SetQuaternion(ParentTransform.GetQuaternion() * ChildTransform.GetQuaternion()); - ChildTransform.SetScale(ParentTransform.GetScale() * ChildTransform.GetScale()); - - TransformUpdate(Children[i]);*/ - - /*if (SubTreeRoot->GetName() == "BistroExterior") - { - int y = 0; - y++; - }*/ - - FEEntity* ChildEntity = reinterpret_cast(Children[i]->GetOldStyleEntity()); - FETransformComponent& ChildTransform = ChildEntity->Transform; - - - //glm::mat4 CurrentParentTransform = ParentTransform.GetTransformMatrix(); - - //ParentTransform.Update(); - //ChildTransform.Update(); - - //ChildTransform.LocalSpaceMatrix = ChildTransform.GetTransformMatrix(); - ChildTransform.WorldSpaceMatrix = ParentTransform.WorldSpaceMatrix * ChildTransform.LocalSpaceMatrix; - //ChildTransform.ForceSetTransformMatrix(ChildTransform.WorldSpaceMatrix); - - TransformUpdate(Children[i]); - - /*glm::vec3 Position, Scale; - glm::quat Rotation; - glm::decompose(ParentTransform.GetTransformMatrix(), Scale, Rotation, Position, glm::vec3(), glm::vec4()); - - int y = 0; - y++;*/ - } -} - void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneEntity* SubTreeRoot) { - TransformUpdate(SubTreeRoot); - SceneNodeDragAndDropTargetIndex++; int64_t UniqueID = 0; bool bIsLeaf = SubTreeRoot->GetChildren().size() == 0; @@ -337,8 +268,6 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneEntity* SubTreeRoot) } } - - void FEEditorSceneGraphWindow::RenderNewSceneGraph() { FENaiveSceneEntity* Root = SCENE.SceneGraph.GetRoot(); @@ -348,7 +277,6 @@ void FEEditorSceneGraphWindow::RenderNewSceneGraph() SceneNodeDragAndDropTargetIndex = -1; RenderSubTree(Root); - TransformUpdate(Root); if (bSceneNodeTargetsDirty) bSceneNodeTargetsDirty = false; diff --git a/FEEditor.cpp b/FEEditor.cpp index aafbcee..c18295c 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -246,12 +246,12 @@ void FEEditor::InitializeResources() EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity->Prefab->GetComponent(0)->GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXyGizmoEntity->Prefab->GetComponent(0)->GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXyGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYzGizmoEntity->Prefab->GetComponent(0)->GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYzGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXzGizmoEntity->Prefab->GetComponent(0)->GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXzGizmoEntity); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity->Prefab->GetComponent(0)->GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity); diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index a2b2bfd..2046e22 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -12,7 +12,10 @@ void GizmoManager::InitializeResources() FEMesh* TransformationGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "45191B6F172E3B531978692E.model").c_str(), "transformationGizmoMesh"); RESOURCE_MANAGER.MakeMeshStandard(TransformationGizmoMesh); - // transformationXGizmo + ParentGizmoEntity = SCENE.AddEmptyEntity("ParentGizmoEntity"); + FENaiveSceneEntity* ParentGizmoGraphEntity = SCENE.SceneGraph.GetEntityByOldEntityID(ParentGizmoEntity->GetObjectID()); + + // TransformationXGizmo FEMaterial* CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); @@ -25,8 +28,10 @@ void GizmoManager::InitializeResources() TransformationXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); TransformationXGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); TransformationXGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - // transformationYGizmo + // TransformationYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); @@ -39,8 +44,10 @@ void GizmoManager::InitializeResources() TransformationYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); TransformationYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); TransformationYGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - // transformationZGizmo + // TransformationZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); @@ -53,52 +60,63 @@ void GizmoManager::InitializeResources() TransformationZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); TransformationZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); TransformationZGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - // plane gizmos + // Plane gizmos CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXYGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationXyGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"), "transformationXYGizmoEntity"); - RESOURCE_MANAGER.MakePrefabStandard(TransformationXyGizmoEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationXyGizmoEntity->Prefab->GetComponent(0)->GameModel); - TransformationXyGizmoEntity->SetCastShadows(false); - TransformationXyGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); - TransformationXyGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - TransformationXyGizmoEntity->SetIsPostprocessApplied(false); + TransformationXYGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"), "transformationXYGizmoEntity"); + RESOURCE_MANAGER.MakePrefabStandard(TransformationXYGizmoEntity->Prefab); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationXYGizmoEntity->Prefab->GetComponent(0)->GameModel); + TransformationXYGizmoEntity->SetCastShadows(false); + TransformationXYGizmoEntity->Transform.SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); + TransformationXYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); + TransformationXYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + TransformationXYGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationYzGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"), "transformationYZGizmoEntity"); - RESOURCE_MANAGER.MakePrefabStandard(TransformationYzGizmoEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationYzGizmoEntity->Prefab->GetComponent(0)->GameModel); - TransformationYzGizmoEntity->SetCastShadows(false); - TransformationYzGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); - TransformationYzGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - TransformationYzGizmoEntity->SetIsPostprocessApplied(false); + TransformationYZGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"), "transformationYZGizmoEntity"); + RESOURCE_MANAGER.MakePrefabStandard(TransformationYZGizmoEntity->Prefab); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationYZGizmoEntity->Prefab->GetComponent(0)->GameModel); + TransformationYZGizmoEntity->SetCastShadows(false); + TransformationYZGizmoEntity->Transform.SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); + TransformationYZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); + TransformationYZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + TransformationYZGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationXzGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"), "transformationXZGizmoEntity"); - RESOURCE_MANAGER.MakePrefabStandard(TransformationXzGizmoEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationXzGizmoEntity->Prefab->GetComponent(0)->GameModel); - TransformationXzGizmoEntity->SetCastShadows(false); - TransformationXzGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); - TransformationXzGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - TransformationXzGizmoEntity->SetIsPostprocessApplied(false); - - // scale gizmos + TransformationXZGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"), "transformationXZGizmoEntity"); + RESOURCE_MANAGER.MakePrefabStandard(TransformationXZGizmoEntity->Prefab); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationXZGizmoEntity->Prefab->GetComponent(0)->GameModel); + TransformationXZGizmoEntity->SetCastShadows(false); + TransformationXZGizmoEntity->Transform.SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); + TransformationXZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); + TransformationXZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + TransformationXZGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + + // Scale gizmos. FEMesh* ScaleGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "637C784B2E5E5C6548190E1B.model").c_str(), "scaleGizmoMesh"); RESOURCE_MANAGER.MakeMeshStandard(ScaleGizmoMesh); - // scaleXGizmo + // ScaleXGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleXGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); @@ -111,8 +129,10 @@ void GizmoManager::InitializeResources() ScaleXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); ScaleXGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); ScaleXGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - // scaleYGizmo + // ScaleYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleYGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); @@ -125,8 +145,10 @@ void GizmoManager::InitializeResources() ScaleYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); ScaleYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); ScaleYGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - // scaleZGizmo + // ScaleZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); @@ -139,12 +161,14 @@ void GizmoManager::InitializeResources() ScaleZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); ScaleZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); ScaleZGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - // rotate gizmos + // Rotate gizmos FEMesh* RotateGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "19622421516E5B317E1B5360.model").c_str(), "rotateGizmoMesh"); RESOURCE_MANAGER.MakeMeshStandard(RotateGizmoMesh); - // rotateXGizmo + // RotateXGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateXGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); @@ -157,8 +181,10 @@ void GizmoManager::InitializeResources() RotateXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); RotateXGizmoEntity->Transform.SetRotation(RotateXStandardRotation); RotateXGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - // rotateYGizmo + // RotateYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateYGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); @@ -171,8 +197,10 @@ void GizmoManager::InitializeResources() RotateYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); RotateYGizmoEntity->Transform.SetRotation(RotateYStandardRotation); RotateYGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - // rotateZGizmo + // RotateZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); @@ -185,6 +213,8 @@ void GizmoManager::InitializeResources() RotateZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); RotateZGizmoEntity->Transform.SetRotation(RotateZStandardRotation); RotateZGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); TransformationGizmoIcon = RESOURCE_MANAGER.LoadFETexture((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "456A31026A1C3152181A6064.texture").c_str(), "transformationGizmoIcon"); RESOURCE_MANAGER.MakeTextureStandard(TransformationGizmoIcon); @@ -200,9 +230,9 @@ void GizmoManager::HideAllGizmo() TransformationYGizmoEntity->SetVisibility(false); TransformationZGizmoEntity->SetVisibility(false); - TransformationXyGizmoEntity->SetVisibility(false); - TransformationYzGizmoEntity->SetVisibility(false); - TransformationXzGizmoEntity->SetVisibility(false); + TransformationXYGizmoEntity->SetVisibility(false); + TransformationYZGizmoEntity->SetVisibility(false); + TransformationXZGizmoEntity->SetVisibility(false); bTransformationXGizmoActive = false; bTransformationYGizmoActive = false; @@ -254,9 +284,9 @@ void GizmoManager::UpdateGizmoState(int NewState) TransformationYGizmoEntity->SetVisibility(true); TransformationZGizmoEntity->SetVisibility(true); - TransformationXyGizmoEntity->SetVisibility(true); - TransformationYzGizmoEntity->SetVisibility(true); - TransformationXzGizmoEntity->SetVisibility(true); + TransformationXYGizmoEntity->SetVisibility(true); + TransformationYZGizmoEntity->SetVisibility(true); + TransformationXZGizmoEntity->SetVisibility(true); break; } @@ -306,7 +336,7 @@ void GizmoManager::Render() { HideAllGizmo(); return; - } + } FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); const glm::vec3 ObjectSpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); @@ -321,25 +351,9 @@ void GizmoManager::Render() toObject = glm::normalize(center - ENGINE.getCamera()->getPosition()); }*/ + ParentGizmoEntity->Transform.SetPosition((ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f)); if (GIZMO_MANAGER.GizmosState == TRANSFORM_GIZMOS) { - GIZMO_MANAGER.TransformationXGizmoEntity->Transform.SetPosition((ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f)); - GIZMO_MANAGER.TransformationYGizmoEntity->Transform.SetPosition((ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f)); - GIZMO_MANAGER.TransformationZGizmoEntity->Transform.SetPosition((ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f)); - - glm::vec3 NewP = ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f; - NewP.x += 0.005f; - NewP.y += 0.005f; - GIZMO_MANAGER.TransformationXyGizmoEntity->Transform.SetPosition(NewP); - NewP = ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f; - NewP.z += 0.005f; - NewP.y += 0.005f; - GIZMO_MANAGER.TransformationYzGizmoEntity->Transform.SetPosition(NewP); - NewP = ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f; - NewP.x += 0.005f; - NewP.z += 0.005f; - GIZMO_MANAGER.TransformationXzGizmoEntity->Transform.SetPosition(NewP); - // X Gizmos GIZMO_MANAGER.TransformationXGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); if (GIZMO_MANAGER.bTransformationXZGizmoActive || GIZMO_MANAGER.bTransformationXYGizmoActive || GIZMO_MANAGER.bTransformationXGizmoActive) @@ -356,26 +370,22 @@ void GizmoManager::Render() GIZMO_MANAGER.TransformationZGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // XY Gizmos - GIZMO_MANAGER.TransformationXyGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); + GIZMO_MANAGER.TransformationXYGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); if (GIZMO_MANAGER.bTransformationXYGizmoActive) - GIZMO_MANAGER.TransformationXyGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.TransformationXYGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // YZ Gizmos - GIZMO_MANAGER.TransformationYzGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); + GIZMO_MANAGER.TransformationYZGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); if (GIZMO_MANAGER.bTransformationYZGizmoActive) - GIZMO_MANAGER.TransformationYzGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.TransformationYZGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // XZ Gizmos - GIZMO_MANAGER.TransformationXzGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); + GIZMO_MANAGER.TransformationXZGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); if (GIZMO_MANAGER.bTransformationXZGizmoActive) - GIZMO_MANAGER.TransformationXzGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.TransformationXZGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); } else if (GIZMO_MANAGER.GizmosState == SCALE_GIZMOS) { - GIZMO_MANAGER.ScaleXGizmoEntity->Transform.SetPosition((ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f)); - GIZMO_MANAGER.ScaleYGizmoEntity->Transform.SetPosition((ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f)); - GIZMO_MANAGER.ScaleZGizmoEntity->Transform.SetPosition((ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f)); - // X Gizmos GIZMO_MANAGER.ScaleXGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); if (GIZMO_MANAGER.bScaleXGizmoActive) @@ -393,10 +403,6 @@ void GizmoManager::Render() } else if (GIZMO_MANAGER.GizmosState == ROTATE_GIZMOS) { - GIZMO_MANAGER.RotateXGizmoEntity->Transform.SetPosition((ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f)); - GIZMO_MANAGER.RotateYGizmoEntity->Transform.SetPosition((ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f)); - GIZMO_MANAGER.RotateZGizmoEntity->Transform.SetPosition((ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f)); - if (SELECTED.SELECTED.GetSelected() != nullptr) { GIZMO_MANAGER.RotateXGizmoEntity->SetVisibility(true); @@ -457,15 +463,15 @@ bool GizmoManager::WasSelected(int Index) { bTransformationZGizmoActive = true; } - else if (GizmosState == TRANSFORM_GIZMOS && EntityNameHash == TransformationXyGizmoEntity->GetNameHash()) + else if (GizmosState == TRANSFORM_GIZMOS && EntityNameHash == TransformationXYGizmoEntity->GetNameHash()) { bTransformationXYGizmoActive = true; } - else if (GizmosState == TRANSFORM_GIZMOS && EntityNameHash == TransformationYzGizmoEntity->GetNameHash()) + else if (GizmosState == TRANSFORM_GIZMOS && EntityNameHash == TransformationYZGizmoEntity->GetNameHash()) { bTransformationYZGizmoActive = true; } - else if (GizmosState == TRANSFORM_GIZMOS && EntityNameHash == TransformationXzGizmoEntity->GetNameHash()) + else if (GizmosState == TRANSFORM_GIZMOS && EntityNameHash == TransformationXZGizmoEntity->GetNameHash()) { bTransformationXZGizmoActive = true; } @@ -579,113 +585,136 @@ glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, return PointOnPlane; } -bool GizmoManager::RaysIntersection(const glm::vec3& FRayOrigin, const glm::vec3& FRayDirection, - const glm::vec3& SRayOrigin, const glm::vec3& SRayDirection, - float& Ft, float& St) const +void GizmoManager::MoveSelectedEntityAlongAxis(const glm::vec3& AxisOfMovement, FETransformComponent& ObjectTransform) { - const glm::vec3 DirectionsCross = glm::cross(FRayDirection, SRayDirection); - // two rays are parallel - if (DirectionsCross == glm::vec3(0.0f)) - return false; + glm::vec3 NewPosition = ObjectTransform.GetPosition(); + glm::vec3 LocalAlternativeAxis = AxisOfMovement; + + FENaiveSceneEntity* SceneGraphParentEntity = SCENE.SceneGraph.GetEntityByOldEntityID(SELECTED.GetSelected()->GetObjectID()); + if (SceneGraphParentEntity != nullptr) + { + if (SceneGraphParentEntity->GetParent() != SCENE.SceneGraph.GetRoot()) + { + FEEntity* ParentEntity = reinterpret_cast(SceneGraphParentEntity->GetParent()->GetOldStyleEntity()); + LocalAlternativeAxis = glm::inverse(ParentEntity->Transform.WorldSpaceMatrix) * glm::vec4(AxisOfMovement, 0.0f); + } + + NewPosition += LocalAlternativeAxis; + ObjectTransform.SetPosition(NewPosition); + } +} - Ft = glm::dot(glm::cross((SRayOrigin - FRayOrigin), SRayDirection), DirectionsCross); - Ft /= glm::length(DirectionsCross) * glm::length(DirectionsCross); +#include +void GizmoManager::RotateSelectedEntity(const glm::vec3& AxisOfRotation, FETransformComponent& ObjectTransform, const float& RotationAmount) +{ + glm::vec3 LocalAlternativeAxis = AxisOfRotation; - St = glm::dot(glm::cross((SRayOrigin - FRayOrigin), FRayDirection), DirectionsCross); - St /= glm::length(DirectionsCross) * glm::length(DirectionsCross); + FENaiveSceneEntity* SceneGraphParentEntity = SCENE.SceneGraph.GetEntityByOldEntityID(SELECTED.GetSelected()->GetObjectID()); + if (SceneGraphParentEntity != nullptr) + { + if (SceneGraphParentEntity->GetParent() != SCENE.SceneGraph.GetRoot()) + { + FEEntity* ParentEntity = reinterpret_cast(SceneGraphParentEntity->GetParent()->GetOldStyleEntity()); + //LocalAlternativeAxis = glm::inverse(ParentEntity->Transform.GetQuaternion()) * glm::vec3(AxisOfRotation); + + glm::dvec3 DoubleScale; + glm::dquat DoubleRotation; + glm::dvec3 DoubleTranslation; + glm::dvec3 DoubleSkew; + glm::dvec4 DoublePerspective; + glm::dmat4 DoubleNewChildLocalMatrix = ParentEntity->Transform.WorldSpaceMatrix; + bool Success = glm::decompose(DoubleNewChildLocalMatrix, DoubleScale, DoubleRotation, DoubleTranslation, DoubleSkew, DoublePerspective); + if (Success) + { + LocalAlternativeAxis = glm::inverse(glm::quat(DoubleRotation)) * glm::vec3(AxisOfRotation); + } - return true; + //LocalAlternativeAxis = glm::quat(glm::inverse(ParentEntity->Transform.WorldSpaceMatrix)) * glm::vec4(AxisOfRotation, 1.0f); + } + + glm::quat RotationQuaternion = glm::quat(cos(RotationAmount * ANGLE_TORADIANS_COF / 2), + LocalAlternativeAxis.x * sin(RotationAmount * ANGLE_TORADIANS_COF / 2), + LocalAlternativeAxis.y * sin(RotationAmount * ANGLE_TORADIANS_COF / 2), + LocalAlternativeAxis.z * sin(RotationAmount * ANGLE_TORADIANS_COF / 2)); + + ObjectTransform.RotateByQuaternion(RotationQuaternion); + } } void GizmoManager::MouseMoveTransformationGizmos() { FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); - float Ft = 0.0f; - float St = 0.0f; + float MouseRayParametricIntersection = 0.0f; + float GizmoRayParametricIntersection = 0.0f; - float LastFt = 0.0f; - float LastSt = 0.0f; + float LastFrameMouseRayParametricIntersection = 0.0f; + float LastFrameGizmoRayParametricIntersection = 0.0f; if (GIZMO_MANAGER.bTransformationXGizmoActive) { const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); - RaysIntersection(ENGINE.GetCamera()->GetPosition(), LastMouseRayVector, - glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f), - LastFt, LastSt); + GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), LastMouseRayVector, + glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f), + LastFrameMouseRayParametricIntersection, LastFrameGizmoRayParametricIntersection); const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); - RaysIntersection(ENGINE.GetCamera()->GetPosition(), MouseRayVector, - glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f), - Ft, St); + GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), MouseRayVector, + glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f), + MouseRayParametricIntersection, GizmoRayParametricIntersection); - const float TDifference = St - LastSt; - glm::vec3 NewPosition = ObjTransform.GetPosition(); - NewPosition.x += TDifference; - ObjTransform.SetPosition(NewPosition); + const float Difference = GizmoRayParametricIntersection - LastFrameGizmoRayParametricIntersection; + MoveSelectedEntityAlongAxis(glm::vec3(Difference, 0.0f, 0.0f), ObjTransform); } if (GIZMO_MANAGER.bTransformationYGizmoActive) { const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); - RaysIntersection(ENGINE.GetCamera()->GetPosition(), LastMouseRayVector, - glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 1.0f, 0.0f), - LastFt, LastSt); + GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), LastMouseRayVector, + glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 1.0f, 0.0f), + LastFrameMouseRayParametricIntersection, LastFrameGizmoRayParametricIntersection); const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); - RaysIntersection(ENGINE.GetCamera()->GetPosition(), MouseRayVector, - glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 1.0f, 0.0f), - Ft, St); + GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), MouseRayVector, + glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 1.0f, 0.0f), + MouseRayParametricIntersection, GizmoRayParametricIntersection); - const float TDifference = St - LastSt; - glm::vec3 NewPosition = ObjTransform.GetPosition(); - NewPosition.y += TDifference; - ObjTransform.SetPosition(NewPosition); + const float Difference = GizmoRayParametricIntersection - LastFrameGizmoRayParametricIntersection; + MoveSelectedEntityAlongAxis(glm::vec3(0.0f, Difference, 0.0f), ObjTransform); } if (GIZMO_MANAGER.bTransformationZGizmoActive) { const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); - RaysIntersection(ENGINE.GetCamera()->GetPosition(), LastMouseRayVector, - glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 0.0f, 1.0f), - LastFt, LastSt); + GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), LastMouseRayVector, + glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 0.0f, 1.0f), + LastFrameMouseRayParametricIntersection, LastFrameGizmoRayParametricIntersection); const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); - RaysIntersection(ENGINE.GetCamera()->GetPosition(), MouseRayVector, - glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 0.0f, 1.0f), - Ft, St); + GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), MouseRayVector, + glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 0.0f, 1.0f), + MouseRayParametricIntersection, GizmoRayParametricIntersection); - const float TDifference = St - LastSt; - glm::vec3 NewPosition = ObjTransform.GetPosition(); - NewPosition.z += TDifference; - ObjTransform.SetPosition(NewPosition); + const float Difference = GizmoRayParametricIntersection - LastFrameGizmoRayParametricIntersection; + MoveSelectedEntityAlongAxis(glm::vec3(0.0f, 0.0f, Difference), ObjTransform); } if (GIZMO_MANAGER.bTransformationXYGizmoActive) { const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(0.0f, 0.0f, 1.0f)); - glm::vec3 NewPosition = ObjTransform.GetPosition(); - NewPosition.x += Difference.x; - NewPosition.y += Difference.y; - ObjTransform.SetPosition(NewPosition); + MoveSelectedEntityAlongAxis(Difference, ObjTransform); } if (GIZMO_MANAGER.bTransformationYZGizmoActive) { const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(1.0f, 0.0f, 0.0f)); - glm::vec3 NewPosition = ObjTransform.GetPosition(); - NewPosition.y += Difference.y; - NewPosition.z += Difference.z; - ObjTransform.SetPosition(NewPosition); + MoveSelectedEntityAlongAxis(Difference, ObjTransform); } if (GIZMO_MANAGER.bTransformationXZGizmoActive) { const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(0.0f, 1.0f, 0.0f)); - glm::vec3 NewPosition = ObjTransform.GetPosition(); - NewPosition.x += Difference.x; - NewPosition.z += Difference.z; - ObjTransform.SetPosition(NewPosition); + MoveSelectedEntityAlongAxis(Difference, ObjTransform); } ApplyChangesToSelectedObject(ObjTransform); @@ -698,9 +727,16 @@ void GizmoManager::MouseMoveScaleGizmos() if (GIZMO_MANAGER.bScaleXGizmoActive && GIZMO_MANAGER.bScaleYGizmoActive && GIZMO_MANAGER.bScaleZGizmoActive) { const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(-ENGINE.GetCamera()->GetForward()); - const float Magnitude = Difference.x + Difference.y + Difference.z; - + float Magnitude = Difference.x + Difference.y + Difference.z; + glm::vec3 EntityScale = ObjTransform.GetScale(); + // Calculate the average current scale + float AverageScale = (EntityScale.x + EntityScale.y + EntityScale.z) / 3.0f; + + // Adjust the magnitude based on the current scale + // to prevent the object from scaling too fast or too slow + float ScaleFactor = glm::clamp(1.0f / AverageScale, 0.001f, 1000.0f); + Magnitude /= ScaleFactor; EntityScale += Magnitude; ObjTransform.SetScale(EntityScale); } @@ -736,6 +772,11 @@ void GizmoManager::MouseMoveScaleGizmos() void GizmoManager::MouseMoveRotateGizmos() { + if (!GIZMO_MANAGER.bRotateXGizmoActive && + !GIZMO_MANAGER.bRotateYGizmoActive && + !GIZMO_MANAGER.bRotateZGizmoActive) + return; + FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); const float DifferenceX = static_cast(MouseX - LastMouseX); @@ -743,42 +784,18 @@ void GizmoManager::MouseMoveRotateGizmos() const float Difference = (DifferenceX + DifferenceY) / 2.0f; - if (GIZMO_MANAGER.bRotateXGizmoActive) - { - const glm::vec3 XVector = glm::vec3(1.0f, 0.0f, 0.0f); - - const glm::quat RotationQuaternion1 = glm::quat(cos(Difference * ANGLE_TORADIANS_COF / 2), - XVector.x * sin(Difference * ANGLE_TORADIANS_COF / 2), - XVector.y * sin(Difference * ANGLE_TORADIANS_COF / 2), - XVector.z * sin(Difference * ANGLE_TORADIANS_COF / 2)); + glm::vec3 AxisOfRotation = glm::vec3(0.0f, 0.0f, 0.0f); - ObjTransform.RotateByQuaternion(RotationQuaternion1); - } + if (GIZMO_MANAGER.bRotateXGizmoActive) + AxisOfRotation = glm::vec3(1.0f, 0.0f, 0.0f); if (GIZMO_MANAGER.bRotateYGizmoActive) - { - const glm::vec3 YVector = glm::vec3(0.0f, 1.0f, 0.0f); - - const glm::quat RotationQuaternion1 = glm::quat(cos(Difference * ANGLE_TORADIANS_COF / 2), - YVector.x * sin(Difference * ANGLE_TORADIANS_COF / 2), - YVector.y * sin(Difference * ANGLE_TORADIANS_COF / 2), - YVector.z * sin(Difference * ANGLE_TORADIANS_COF / 2)); - - ObjTransform.RotateByQuaternion(RotationQuaternion1); - } + AxisOfRotation = glm::vec3(0.0f, 1.0f, 0.0f); if (GIZMO_MANAGER.bRotateZGizmoActive) - { - const glm::vec3 ZVector = glm::vec3(0.0f, 0.0f, 1.0f); - - const glm::quat RotationQuaternion1 = glm::quat(cos(Difference * ANGLE_TORADIANS_COF / 2), - ZVector.x * sin(Difference * ANGLE_TORADIANS_COF / 2), - ZVector.y * sin(Difference * ANGLE_TORADIANS_COF / 2), - ZVector.z * sin(Difference * ANGLE_TORADIANS_COF / 2)); - - ObjTransform.RotateByQuaternion(RotationQuaternion1); - } + AxisOfRotation = glm::vec3(0.0f, 0.0f, 1.0f); + RotateSelectedEntity(AxisOfRotation, ObjTransform, Difference); ApplyChangesToSelectedObject(ObjTransform); } @@ -825,9 +842,9 @@ void GizmoManager::OnSelectedObjectUpdate() GIZMO_MANAGER.TransformationXGizmoEntity->SetVisibility(true); GIZMO_MANAGER.TransformationYGizmoEntity->SetVisibility(true); GIZMO_MANAGER.TransformationZGizmoEntity->SetVisibility(true); - GIZMO_MANAGER.TransformationXyGizmoEntity->SetVisibility(true); - GIZMO_MANAGER.TransformationYzGizmoEntity->SetVisibility(true); - GIZMO_MANAGER.TransformationXzGizmoEntity->SetVisibility(true); + GIZMO_MANAGER.TransformationXYGizmoEntity->SetVisibility(true); + GIZMO_MANAGER.TransformationYZGizmoEntity->SetVisibility(true); + GIZMO_MANAGER.TransformationXZGizmoEntity->SetVisibility(true); } else if (GIZMO_MANAGER.GizmosState == SCALE_GIZMOS) { @@ -908,86 +925,115 @@ void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent Changes) void GizmoManager::ReInitializeEntities() { - // transformationXGizmo + ParentGizmoEntity = SCENE.AddEmptyEntity("ParentGizmoEntity"); + ParentGizmoGraphEntity = SCENE.SceneGraph.GetEntityByOldEntityID(ParentGizmoEntity->GetObjectID()); + + // TransformationXGizmo TransformationXGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXGizmoGM")[0], "transformationXGizmoEntity"); TransformationXGizmoEntity->SetCastShadows(false); TransformationXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); TransformationXGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); TransformationXGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - // transformationYGizmo + // TransformationYGizmo TransformationYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationYGizmoGM")[0], "transformationYGizmoEntity"); TransformationYGizmoEntity->SetCastShadows(false); TransformationYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); TransformationYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); TransformationYGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - // transformationZGizmo + // TransformationZGizmo TransformationZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationZGizmoGM")[0], "transformationZGizmoEntity"); TransformationZGizmoEntity->SetCastShadows(false); TransformationZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); TransformationZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); TransformationZGizmoEntity->SetIsPostprocessApplied(false); - - // plane gizmos - TransformationXyGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXYGizmoGM")[0], "transformationXYGizmoEntity"); - TransformationXyGizmoEntity->SetCastShadows(false); - TransformationXyGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); - TransformationXyGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - TransformationXyGizmoEntity->SetIsPostprocessApplied(false); - - - TransformationYzGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationYZGizmoGM")[0], "transformationYZGizmoEntity"); - TransformationYzGizmoEntity->SetCastShadows(false); - TransformationYzGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); - TransformationYzGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - TransformationYzGizmoEntity->SetIsPostprocessApplied(false); - - TransformationXzGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXZGizmoGM")[0], "transformationXZGizmoEntity"); - TransformationXzGizmoEntity->SetCastShadows(false); - TransformationXzGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); - TransformationXzGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - TransformationXzGizmoEntity->SetIsPostprocessApplied(false); - - // scaleXGizmo + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + + // Plane gizmos + TransformationXYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXYGizmoGM")[0], "transformationXYGizmoEntity"); + TransformationXYGizmoEntity->SetCastShadows(false); + TransformationXYGizmoEntity->Transform.SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); + TransformationXYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); + TransformationXYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + TransformationXYGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + + TransformationYZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationYZGizmoGM")[0], "transformationYZGizmoEntity"); + TransformationYZGizmoEntity->SetCastShadows(false); + TransformationYZGizmoEntity->Transform.SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); + TransformationYZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); + TransformationYZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + TransformationYZGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + + TransformationXZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXZGizmoGM")[0], "transformationXZGizmoEntity"); + TransformationXZGizmoEntity->SetCastShadows(false); + TransformationXZGizmoEntity->Transform.SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); + TransformationXZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); + TransformationXZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + TransformationXZGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + + // ScaleXGizmo ScaleXGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("scaleXGizmoGM")[0], "scaleXGizmoEntity"); ScaleXGizmoEntity->SetCastShadows(false); ScaleXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); ScaleXGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); ScaleXGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - // scaleYGizmo + // ScaleYGizmo ScaleYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("scaleYGizmoGM")[0], "scaleYGizmoEntity"); ScaleYGizmoEntity->SetCastShadows(false); ScaleYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); ScaleYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); ScaleYGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - // scaleZGizmo + // ScaleZGizmo ScaleZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("scaleZGizmoGM")[0], "scaleZGizmoEntity"); ScaleZGizmoEntity->SetCastShadows(false); ScaleZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); ScaleZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); ScaleZGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - // rotateXGizmo + // RotateXGizmo RotateXGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("rotateXGizmoGM")[0], "rotateXGizmoEntity"); RotateXGizmoEntity->SetCastShadows(false); RotateXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); RotateXGizmoEntity->Transform.SetRotation(RotateXStandardRotation); RotateXGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - // rotateYGizmo + // RotateYGizmo RotateYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("rotateYGizmoGM")[0], "rotateYGizmoEntity"); RotateYGizmoEntity->SetCastShadows(false); RotateYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); RotateYGizmoEntity->Transform.SetRotation(RotateYStandardRotation); RotateYGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - // rotateZGizmo + // RotateZGizmo RotateZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("rotateZGizmoGM")[0], "rotateZGizmoEntity"); RotateZGizmoEntity->SetCastShadows(false); RotateZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); RotateZGizmoEntity->Transform.SetRotation(RotateZStandardRotation); RotateZGizmoEntity->SetIsPostprocessApplied(false); + // Temporary overly complicated solution, because of new and old entity system. + SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); } \ No newline at end of file diff --git a/FEEditorGizmoManager.h b/FEEditorGizmoManager.h index 9b72216..b35532c 100644 --- a/FEEditorGizmoManager.h +++ b/FEEditorGizmoManager.h @@ -21,6 +21,10 @@ class GizmoManager float GizmosScale = 0.00175f; int GizmosState = TRANSFORM_GIZMOS; + // Parent Gizmo Entity + FEEntity* ParentGizmoEntity = nullptr; + FENaiveSceneEntity* ParentGizmoGraphEntity = nullptr; + FEEntity* TransformationXGizmoEntity = nullptr; FEEntity* TransformationYGizmoEntity = nullptr; FEEntity* TransformationZGizmoEntity = nullptr; @@ -29,15 +33,15 @@ class GizmoManager bool bTransformationYGizmoActive = false; bool bTransformationZGizmoActive = false; - FEEntity* TransformationXyGizmoEntity = nullptr; - FEEntity* TransformationYzGizmoEntity = nullptr; - FEEntity* TransformationXzGizmoEntity = nullptr; + FEEntity* TransformationXYGizmoEntity = nullptr; + FEEntity* TransformationYZGizmoEntity = nullptr; + FEEntity* TransformationXZGizmoEntity = nullptr; bool bTransformationXYGizmoActive = false; bool bTransformationYZGizmoActive = false; bool bTransformationXZGizmoActive = false; - // scale part + // Scale part. FEEntity* ScaleXGizmoEntity = nullptr; FEEntity* ScaleYGizmoEntity = nullptr; FEEntity* ScaleZGizmoEntity = nullptr; @@ -46,7 +50,7 @@ class GizmoManager bool bScaleYGizmoActive = false; bool bScaleZGizmoActive = false; - // rotate part + // Rotate part. FEEntity* RotateXGizmoEntity = nullptr; FEEntity* RotateYGizmoEntity = nullptr; FEEntity* RotateZGizmoEntity = nullptr; @@ -80,9 +84,6 @@ class GizmoManager glm::vec3 GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal); glm::vec3 GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, glm::vec3& LastMousePointOnPlane); - bool RaysIntersection(const glm::vec3& FRayOrigin, const glm::vec3& FRayDirection, - const glm::vec3& SRayOrigin, const glm::vec3& SRayDirection, - float& Ft, float& St) const; void MouseMoveTransformationGizmos(); void MouseMoveScaleGizmos(); @@ -91,6 +92,8 @@ class GizmoManager static void OnSelectedObjectUpdate(); FETransformComponent GetTransformComponentOfSelectedObject(); + void MoveSelectedEntityAlongAxis(const glm::vec3& AxisOfMovement, FETransformComponent& ObjectTransform); + void RotateSelectedEntity(const glm::vec3& AxisOfRotation, FETransformComponent& ObjectTransform, const float& RotationAmount); void ApplyChangesToSelectedObject(FETransformComponent Changes); }; diff --git a/FEProject.cpp b/FEProject.cpp index d65daa0..5055269 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -70,9 +70,9 @@ void FEProjectManager::OpenProject(const int ProjectIndex) EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoEntity); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXyGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYzGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXzGizmoEntity); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoEntity); diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index ef29227..834ddbf 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit ef292270d705d9f67a04735128cf1e8922402c0f +Subproject commit 834ddbf611ca71d7f946054f948edba8a364ff7b From be1eca482e0b7c9b1fd98729200520602bfcd628 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Mon, 24 Jun 2024 15:05:31 -0400 Subject: [PATCH 09/46] Updated FocalEngine; Made adjustments due to the engine update. --- EditorWindows/SceneGraphWindow.cpp | 6 ++-- EditorWindows/SceneGraphWindow.h | 10 +++--- FEEditorGizmoManager.cpp | 56 +++++++++++++++--------------- FEEditorGizmoManager.h | 2 +- SubSystems/FocalEngine | 2 +- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 8e85bc3..a57793f 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -175,7 +175,7 @@ void FEEditorSceneGraphWindow::DrawCorrectIcon(const FEObject* SceneObject) cons return; } -DragAndDropTarget* FEEditorSceneGraphWindow::GetSceneNodeDragAndDropTarget(FENaiveSceneEntity* NodeToFind) +DragAndDropTarget* FEEditorSceneGraphWindow::GetSceneNodeDragAndDropTarget(FENaiveSceneGraphNode* NodeToFind) { int64_t UniqueID = 0; // If it is Root. @@ -198,7 +198,7 @@ DragAndDropTarget* FEEditorSceneGraphWindow::GetSceneNodeDragAndDropTarget(FENai return SceneNodeDragAndDropTargets[UniqueID]; } -void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneEntity* SubTreeRoot) +void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) { SceneNodeDragAndDropTargetIndex++; int64_t UniqueID = 0; @@ -270,7 +270,7 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneEntity* SubTreeRoot) void FEEditorSceneGraphWindow::RenderNewSceneGraph() { - FENaiveSceneEntity* Root = SCENE.SceneGraph.GetRoot(); + FENaiveSceneGraphNode* Root = SCENE.SceneGraph.GetRoot(); if (bSceneNodeTargetsDirty) SceneNodeDragAndDropTargets.clear(); diff --git a/EditorWindows/SceneGraphWindow.h b/EditorWindows/SceneGraphWindow.h index 1985c0a..89457b9 100644 --- a/EditorWindows/SceneGraphWindow.h +++ b/EditorWindows/SceneGraphWindow.h @@ -43,7 +43,7 @@ class FEEditorSceneGraphWindow int64_t ItemUnderMouse = 0; int SceneNodeDragAndDropTargetIndex = -1; std::unordered_map SceneNodeDragAndDropTargets; - DragAndDropTarget* GetSceneNodeDragAndDropTarget(FENaiveSceneEntity* NodeToFind); + DragAndDropTarget* GetSceneNodeDragAndDropTarget(FENaiveSceneGraphNode* NodeToFind); bool bSceneNodeTargetsDirty = true; static bool SceneNodeDragAndDropCallback(FEObject* Object, void** SceneNodeTarget) @@ -51,10 +51,10 @@ class FEEditorSceneGraphWindow if (Object == nullptr || SceneNodeTarget == nullptr || Object->GetType() != FE_SCENE_ENTITY) return false; - FENaiveSceneEntity* NodeTarget = reinterpret_cast(SceneNodeTarget); - FENaiveSceneEntity* SceneEntity = reinterpret_cast(Object); + FENaiveSceneGraphNode* NodeTarget = reinterpret_cast(SceneNodeTarget); + FENaiveSceneGraphNode* SceneEntity = reinterpret_cast(Object); - return SCENE.SceneGraph.MoveEntity(SceneEntity->GetObjectID(), NodeTarget->GetObjectID()); + return SCENE.SceneGraph.MoveNode(SceneEntity->GetObjectID(), NodeTarget->GetObjectID()); } void UpdateSceneNodeDragAndDropTargets(); @@ -62,7 +62,7 @@ class FEEditorSceneGraphWindow // Rendering and initialization void Render(); void RenderNewSceneGraph(); - void RenderSubTree(FENaiveSceneEntity* SubTreeRoot); + void RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot); void Clear(); void InitializeResources(); diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index 2046e22..afff323 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -13,7 +13,7 @@ void GizmoManager::InitializeResources() RESOURCE_MANAGER.MakeMeshStandard(TransformationGizmoMesh); ParentGizmoEntity = SCENE.AddEmptyEntity("ParentGizmoEntity"); - FENaiveSceneEntity* ParentGizmoGraphEntity = SCENE.SceneGraph.GetEntityByOldEntityID(ParentGizmoEntity->GetObjectID()); + FENaiveSceneGraphNode* ParentGizmoGraphEntity = SCENE.SceneGraph.GetNodeByOldEntityID(ParentGizmoEntity->GetObjectID()); // TransformationXGizmo FEMaterial* CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXGizmoMaterial"); @@ -29,7 +29,7 @@ void GizmoManager::InitializeResources() TransformationXGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); TransformationXGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // TransformationYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYGizmoMaterial"); @@ -45,7 +45,7 @@ void GizmoManager::InitializeResources() TransformationYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); TransformationYGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // TransformationZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationZGizmoMaterial"); @@ -61,7 +61,7 @@ void GizmoManager::InitializeResources() TransformationZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); TransformationZGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // Plane gizmos CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXYGizmoMaterial"); @@ -78,7 +78,7 @@ void GizmoManager::InitializeResources() TransformationXYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); TransformationXYGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); @@ -94,7 +94,7 @@ void GizmoManager::InitializeResources() TransformationYZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); TransformationYZGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); @@ -110,7 +110,7 @@ void GizmoManager::InitializeResources() TransformationXZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); TransformationXZGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // Scale gizmos. FEMesh* ScaleGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "637C784B2E5E5C6548190E1B.model").c_str(), "scaleGizmoMesh"); @@ -130,7 +130,7 @@ void GizmoManager::InitializeResources() ScaleXGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); ScaleXGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // ScaleYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleYGizmoMaterial"); @@ -146,7 +146,7 @@ void GizmoManager::InitializeResources() ScaleYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); ScaleYGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // ScaleZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleZGizmoMaterial"); @@ -162,7 +162,7 @@ void GizmoManager::InitializeResources() ScaleZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); ScaleZGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // Rotate gizmos FEMesh* RotateGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "19622421516E5B317E1B5360.model").c_str(), "rotateGizmoMesh"); @@ -182,7 +182,7 @@ void GizmoManager::InitializeResources() RotateXGizmoEntity->Transform.SetRotation(RotateXStandardRotation); RotateXGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // RotateYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateYGizmoMaterial"); @@ -198,7 +198,7 @@ void GizmoManager::InitializeResources() RotateYGizmoEntity->Transform.SetRotation(RotateYStandardRotation); RotateYGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // RotateZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateZGizmoMaterial"); @@ -214,7 +214,7 @@ void GizmoManager::InitializeResources() RotateZGizmoEntity->Transform.SetRotation(RotateZStandardRotation); RotateZGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); TransformationGizmoIcon = RESOURCE_MANAGER.LoadFETexture((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "456A31026A1C3152181A6064.texture").c_str(), "transformationGizmoIcon"); RESOURCE_MANAGER.MakeTextureStandard(TransformationGizmoIcon); @@ -590,7 +590,7 @@ void GizmoManager::MoveSelectedEntityAlongAxis(const glm::vec3& AxisOfMovement, glm::vec3 NewPosition = ObjectTransform.GetPosition(); glm::vec3 LocalAlternativeAxis = AxisOfMovement; - FENaiveSceneEntity* SceneGraphParentEntity = SCENE.SceneGraph.GetEntityByOldEntityID(SELECTED.GetSelected()->GetObjectID()); + FENaiveSceneGraphNode* SceneGraphParentEntity = SCENE.SceneGraph.GetNodeByOldEntityID(SELECTED.GetSelected()->GetObjectID()); if (SceneGraphParentEntity != nullptr) { if (SceneGraphParentEntity->GetParent() != SCENE.SceneGraph.GetRoot()) @@ -609,7 +609,7 @@ void GizmoManager::RotateSelectedEntity(const glm::vec3& AxisOfRotation, FETrans { glm::vec3 LocalAlternativeAxis = AxisOfRotation; - FENaiveSceneEntity* SceneGraphParentEntity = SCENE.SceneGraph.GetEntityByOldEntityID(SELECTED.GetSelected()->GetObjectID()); + FENaiveSceneGraphNode* SceneGraphParentEntity = SCENE.SceneGraph.GetNodeByOldEntityID(SELECTED.GetSelected()->GetObjectID()); if (SceneGraphParentEntity != nullptr) { if (SceneGraphParentEntity->GetParent() != SCENE.SceneGraph.GetRoot()) @@ -926,7 +926,7 @@ void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent Changes) void GizmoManager::ReInitializeEntities() { ParentGizmoEntity = SCENE.AddEmptyEntity("ParentGizmoEntity"); - ParentGizmoGraphEntity = SCENE.SceneGraph.GetEntityByOldEntityID(ParentGizmoEntity->GetObjectID()); + ParentGizmoGraphEntity = SCENE.SceneGraph.GetNodeByOldEntityID(ParentGizmoEntity->GetObjectID()); // TransformationXGizmo TransformationXGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXGizmoGM")[0], "transformationXGizmoEntity"); @@ -935,7 +935,7 @@ void GizmoManager::ReInitializeEntities() TransformationXGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); TransformationXGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // TransformationYGizmo TransformationYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationYGizmoGM")[0], "transformationYGizmoEntity"); @@ -944,7 +944,7 @@ void GizmoManager::ReInitializeEntities() TransformationYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); TransformationYGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // TransformationZGizmo TransformationZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationZGizmoGM")[0], "transformationZGizmoEntity"); @@ -953,7 +953,7 @@ void GizmoManager::ReInitializeEntities() TransformationZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); TransformationZGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // Plane gizmos TransformationXYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXYGizmoGM")[0], "transformationXYGizmoEntity"); @@ -963,7 +963,7 @@ void GizmoManager::ReInitializeEntities() TransformationXYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); TransformationXYGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); TransformationYZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationYZGizmoGM")[0], "transformationYZGizmoEntity"); TransformationYZGizmoEntity->SetCastShadows(false); @@ -972,7 +972,7 @@ void GizmoManager::ReInitializeEntities() TransformationYZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); TransformationYZGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); TransformationXZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXZGizmoGM")[0], "transformationXZGizmoEntity"); TransformationXZGizmoEntity->SetCastShadows(false); @@ -981,7 +981,7 @@ void GizmoManager::ReInitializeEntities() TransformationXZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); TransformationXZGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // ScaleXGizmo ScaleXGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("scaleXGizmoGM")[0], "scaleXGizmoEntity"); @@ -990,7 +990,7 @@ void GizmoManager::ReInitializeEntities() ScaleXGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); ScaleXGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // ScaleYGizmo ScaleYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("scaleYGizmoGM")[0], "scaleYGizmoEntity"); @@ -999,7 +999,7 @@ void GizmoManager::ReInitializeEntities() ScaleYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); ScaleYGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // ScaleZGizmo ScaleZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("scaleZGizmoGM")[0], "scaleZGizmoEntity"); @@ -1008,7 +1008,7 @@ void GizmoManager::ReInitializeEntities() ScaleZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); ScaleZGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // RotateXGizmo RotateXGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("rotateXGizmoGM")[0], "rotateXGizmoEntity"); @@ -1017,7 +1017,7 @@ void GizmoManager::ReInitializeEntities() RotateXGizmoEntity->Transform.SetRotation(RotateXStandardRotation); RotateXGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // RotateYGizmo RotateYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("rotateYGizmoGM")[0], "rotateYGizmoEntity"); @@ -1026,7 +1026,7 @@ void GizmoManager::ReInitializeEntities() RotateYGizmoEntity->Transform.SetRotation(RotateYStandardRotation); RotateYGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); // RotateZGizmo RotateZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("rotateZGizmoGM")[0], "rotateZGizmoEntity"); @@ -1035,5 +1035,5 @@ void GizmoManager::ReInitializeEntities() RotateZGizmoEntity->Transform.SetRotation(RotateZStandardRotation); RotateZGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveEntity(SCENE.SceneGraph.GetEntityByOldEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); } \ No newline at end of file diff --git a/FEEditorGizmoManager.h b/FEEditorGizmoManager.h index b35532c..9a0be25 100644 --- a/FEEditorGizmoManager.h +++ b/FEEditorGizmoManager.h @@ -23,7 +23,7 @@ class GizmoManager // Parent Gizmo Entity FEEntity* ParentGizmoEntity = nullptr; - FENaiveSceneEntity* ParentGizmoGraphEntity = nullptr; + FENaiveSceneGraphNode* ParentGizmoGraphEntity = nullptr; FEEntity* TransformationXGizmoEntity = nullptr; FEEntity* TransformationYGizmoEntity = nullptr; diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 834ddbf..b1123c9 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 834ddbf611ca71d7f946054f948edba8a364ff7b +Subproject commit b1123c92b2c0ef90403e64b2fcfe39915898cc1a From 9ce177d53f45d080cd103eec879b4315031ec3db Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Tue, 25 Jun 2024 15:10:55 -0400 Subject: [PATCH 10/46] Engine update. --- SubSystems/FocalEngine | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index b1123c9..0139ca6 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit b1123c92b2c0ef90403e64b2fcfe39915898cc1a +Subproject commit 0139ca6697abd43e5660bf0c7a05ee578c9e8baa From 41d2d16b1165894ad6799ca2a44b052333087e01 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Fri, 28 Jun 2024 14:03:49 -0400 Subject: [PATCH 11/46] Engine update; Implemented a temporary hack to allow selection of scene nodes with dummy entities for transformation control through the new scene graph; The visibility of entities is now saved along with other information. --- EditorWindows/InspectorWindow.cpp | 26 ++++++-- EditorWindows/SceneGraphWindow.cpp | 9 +++ FEEditorSelectedObject.cpp | 22 ++++++ FEProject.cpp | 103 +++++++++++++++++++++++------ FEProject.h | 5 +- SubSystems/FocalEngine | 2 +- 6 files changed, 137 insertions(+), 30 deletions(-) diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index 992dcde..bbd3894 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -145,6 +145,12 @@ void FEEditorInspectorWindow::ShowTransformConfiguration(FEObject* Object, FETra { FEEntity* Entity = SCENE.GetEntity(Object->GetObjectID()); + // Temporary solution, becuase of the lack of proper ECS system + if (Object->GetType() == FE_ENTITY) + { + Entity = reinterpret_cast(Object); + } + FEAABB RealAabb = Entity->GetAABB(); const glm::vec3 Min = RealAabb.GetMin(); const glm::vec3 Max = RealAabb.GetMax(); @@ -444,15 +450,23 @@ void FEEditorInspectorWindow::Render() ImGui::Separator(); ImGui::Text("Prefab : "); - FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Entity->Prefab->GetObjectID()); - - if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + // Temporary solution, becuase of the lack of proper ECS system + if (Entity->Prefab != nullptr) { - EntityToModify = Entity; - SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); + FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Entity->Prefab->GetObjectID()); + if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + { + EntityToModify = Entity; + SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); + + } + EntityChangePrefabTarget->StickToItem(); + } + else + { + ImGui::Text("No prefab assigned."); } - EntityChangePrefabTarget->StickToItem(); bool bOpenContextMenu = false; if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index a57793f..95365ae 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -227,6 +227,15 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) bool bOpened = ImGui::TreeNodeEx((void*)UniqueID, NodeFlags, Name.c_str(), 0); GetSceneNodeDragAndDropTarget(SubTreeRoot)->StickToItem(); + if (ImGui::IsItemClicked()) + { + if (SubTreeRoot->GetOldStyleEntity() != nullptr) + { + SELECTED.SetSelected(OBJECT_MANAGER.GetFEObject(SubTreeRoot->GetOldStyleEntity()->GetObjectID())); + SELECTED.SetDirtyFlag(false); + } + } + if (ImGui::IsItemHovered()) { if (!bShouldOpenContextMenu && !DRAG_AND_DROP_MANAGER.ObjectIsDraged()) diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index cebfb34..4cada01 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -382,12 +382,27 @@ void FEEditorSelectedObject::OnCameraUpdate() const //FE_GL_ERROR(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT)); + // Temporary solution, becuase of the lack of proper ECS system + if (Container != nullptr && Container->GetType() == FE_ENTITY) + { + FEEntity* SelectedEntity = reinterpret_cast(Container); + if (SelectedEntity->Prefab == nullptr) + { + HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); + ENGINE.SetClearColor(OriginalClearColor); + HALO_SELECTION_EFFECT.PostProcess->bActive = true; + + return; + } + } + if (Container == nullptr) { HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); ENGINE.SetClearColor(OriginalClearColor); //FE_GL_ERROR(glClearColor(FE_CLEAR_COLOR.x, FE_CLEAR_COLOR.y, FE_CLEAR_COLOR.z, FE_CLEAR_COLOR.w)); HALO_SELECTION_EFFECT.PostProcess->bActive = true; + return; } @@ -508,6 +523,13 @@ FEEntity* FEEditorSelectedObject::GetEntity() const if (Container == nullptr) return nullptr; + // Temporary solution, becuase of the lack of proper ECS system + if (Container->GetType() == FE_ENTITY) + { + FEEntity* SelectedEntity = reinterpret_cast(Container); + if (SelectedEntity->Prefab == nullptr) + return SelectedEntity; + } if (Container->GetType() == FE_ENTITY || Container->GetType() == FE_ENTITY_INSTANCED) { diff --git a/FEProject.cpp b/FEProject.cpp index 5055269..049a421 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -396,9 +396,38 @@ void FEProject::SaveScene(bool bFullSave) Root["version"] = PROJECTS_FILE_VER; + // Saving scene hierarchy. + Json::Value SceneHierarchy = SCENE.SceneGraph.ToJson(); + + std::vector KeysToDelete; + Json::Value& SceneNodes = SceneHierarchy["Nodes"]; + + std::vector ListOfOmitedObjects = { "gizmo", "Gizmo", "editorPreviewEntity" }; + // Parsing scene hierarchy to delete all internal editor objects. + for (auto it = SceneNodes.begin(); it != SceneNodes.end(); it++) + { + auto test = it.key().asString(); + auto Name = SceneNodes[it.key().asString()]["Name"].asString(); + + for (size_t j = 0; j < ListOfOmitedObjects.size(); j++) + { + if (Name.find(ListOfOmitedObjects[j]) != std::string::npos) + { + KeysToDelete.push_back(it.key().asString()); + break; + } + } + } + + for (size_t i = 0; i < KeysToDelete.size(); i++) + { + SceneNodes.removeMember(KeysToDelete[i]); + } + Root["sceneHierarchy"] = SceneHierarchy; + if (!bFullSave) { - // saving all unSaved objects + // Saving all unsaved objects. for (size_t i = 0; i < UnSavedObjects.size(); i++) { switch (UnSavedObjects[i]->GetType()) @@ -422,7 +451,7 @@ void FEProject::SaveScene(bool bFullSave) } } - // saving Meshes + // Saving Meshes. std::vector MeshList = RESOURCE_MANAGER.GetMeshList(); Json::Value MeshData; for (size_t i = 0; i < MeshList.size(); i++) @@ -439,7 +468,7 @@ void FEProject::SaveScene(bool bFullSave) } Root["meshes"] = MeshData; - // saving Textures + // Saving Textures. std::vector TexturesList = RESOURCE_MANAGER.GetTextureList(); Json::Value TexturesData; for (size_t i = 0; i < TexturesList.size(); i++) @@ -460,7 +489,7 @@ void FEProject::SaveScene(bool bFullSave) } Root["textures"] = TexturesData; - // saving Materials + // Saving Materials. std::vector MaterialList = RESOURCE_MANAGER.GetMaterialList(); Json::Value MaterialData; for (size_t i = 0; i < MaterialList.size(); i++) @@ -495,7 +524,7 @@ void FEProject::SaveScene(bool bFullSave) } Root["materials"] = MaterialData; - // saving gameModels + // Saving GameModels. std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); Json::Value GameModelData; for (size_t i = 0; i < GameModelList.size(); i++) @@ -527,7 +556,7 @@ void FEProject::SaveScene(bool bFullSave) } Root["gameModels"] = GameModelData; - // saving prefabs + // Saving Prefabs. std::vector PrefabList = RESOURCE_MANAGER.GetPrefabList(); Json::Value PrefabData; for (size_t i = 0; i < PrefabList.size(); i++) @@ -547,7 +576,7 @@ void FEProject::SaveScene(bool bFullSave) } Root["prefabs"] = PrefabData; - // saving Entities + // Saving Entities. std::vector EntityList = SCENE.GetEntityList(); Json::Value EntityData; for (size_t i = 0; i < EntityList.size(); i++) @@ -556,10 +585,32 @@ void FEProject::SaveScene(bool bFullSave) if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(Entity)) continue; + // Temporary solution, becuase of the lack of proper ECS system + bool bOmit = false; + for (size_t j = 0; j < ListOfOmitedObjects.size(); j++) + { + if (Entity->GetName().find(ListOfOmitedObjects[j]) != std::string::npos) + { + bOmit = true; + break; + } + } + if (bOmit) + continue; + EntityData[Entity->GetObjectID()]["ID"] = Entity->GetObjectID(); EntityData[Entity->GetObjectID()]["type"] = FEObjectTypeToString(Entity->GetType()); EntityData[Entity->GetObjectID()]["name"] = Entity->GetName(); - EntityData[Entity->GetObjectID()]["prefab"] = Entity->Prefab->GetObjectID(); + EntityData[Entity->GetObjectID()]["visible"] = Entity->IsVisible(); + // Temporary solution, becuase of the lack of proper ECS system + if (Entity->Prefab != nullptr) + { + EntityData[Entity->GetObjectID()]["prefab"] = Entity->Prefab->GetObjectID(); + } + else + { + EntityData[Entity->GetObjectID()]["prefab"] = "none"; + } WriteTransformToJson(EntityData[Entity->GetObjectID()]["transformation"], &Entity->Transform); if (Entity->GetType() == FE_ENTITY_INSTANCED) @@ -619,7 +670,7 @@ void FEProject::SaveScene(bool bFullSave) } Root["entities"] = EntityData; - // saving Terrains + // Saving Terrains. std::vector TerrainList = SCENE.GetTerrainList(); Json::Value TerrainData; for (size_t i = 0; i < TerrainList.size(); i++) @@ -673,7 +724,7 @@ void FEProject::SaveScene(bool bFullSave) } Root["terrains"] = TerrainData; - // saving Lights + // Saving Lights. std::vector LightList = SCENE.GetLightsList(); Json::Value LightData; for (size_t i = 0; i < LightList.size(); i++) @@ -696,7 +747,7 @@ void FEProject::SaveScene(bool bFullSave) LightData[Light->GetObjectID()]["shadowBiasVariableIntensity"] = Light->GetShadowBiasVariableIntensity(); LightData[Light->GetObjectID()]["shadowBlurFactor"] = Light->GetShadowBlurFactor(); - // type specific information + // Type specific information. if (Light->GetType() == FE_DIRECTIONAL_LIGHT) { FEDirectionalLight* DirectionalLight = reinterpret_cast(Light); @@ -728,7 +779,7 @@ void FEProject::SaveScene(bool bFullSave) } Root["lights"] = LightData; - // saving Effects settings + // Saving Effects settings. Json::Value EffectsData; // *********** Gamma Correction & Exposure *********** EffectsData["Gamma Correction & Exposure"]["Gamma"] = ENGINE.GetCamera()->GetGamma(); @@ -757,7 +808,7 @@ void FEProject::SaveScene(bool bFullSave) Root["effects"] = EffectsData; - // saving Camera settings + // Saving Camera settings. Json::Value CameraData; CameraData["position"]["X"] = ENGINE.GetCamera()->GetPosition()[0]; @@ -778,7 +829,7 @@ void FEProject::SaveScene(bool bFullSave) Root["camera"] = CameraData; - // saving into file + // Saving into file. Json::StreamWriterBuilder Builder; const std::string JsonFile = Json::writeString(Builder, Root); @@ -830,10 +881,10 @@ void FEProject::LoadScene() if (!Reader->parse(FileData.c_str(), FileData.c_str() + FileData.size(), &Root, &Err)) return; - // read project file version + // Read project file version. float ProjectVersion = Root["version"].asFloat(); - // project file was created before any version was written to project files. + // Project file was created before any version was written to project files. if (ProjectVersion != PROJECTS_FILE_VER) { if (ProjectVersion == 0.0f) @@ -849,7 +900,7 @@ void FEProject::LoadScene() } } - // loading Meshes + // Loading Meshes std::vector MeshList = Root["meshes"].getMemberNames(); for (size_t i = 0; i < MeshList.size(); i++) { @@ -1045,6 +1096,9 @@ void FEProject::LoadScene() Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) + InstancedEntity->SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); + ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(EntityList[i])->Transform); InstancedEntity->SpawnInfo.Seed = Root["entities"][EntityList[i]]["spawnInfo"]["seed"].asInt(); @@ -1135,9 +1189,12 @@ void FEProject::LoadScene() else { SCENE.AddEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), - Root["entities"][EntityList[i]]["name"].asString(), - Root["entities"][EntityList[i]]["ID"].asString()); + Root["entities"][EntityList[i]]["name"].asString(), + Root["entities"][EntityList[i]]["ID"].asString()); } + + if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) + SCENE.GetEntity(EntityList[i])->SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(EntityList[i])->Transform); } @@ -1151,6 +1208,14 @@ void FEProject::LoadScene() } } + if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) + { + int y = 0; + y++; + // Loading scene hierarchy. + SCENE.SceneGraph.FromJson(Root["sceneHierarchy"]); + } + // loading Lights std::vector LightList = Root["lights"].getMemberNames(); for (size_t i = 0; i < LightList.size(); i++) diff --git a/FEProject.h b/FEProject.h index ae0d8af..7635bcf 100644 --- a/FEProject.h +++ b/FEProject.h @@ -47,10 +47,7 @@ class FEProject void SetProjectFolder(std::string NewValue); }; -//#define PROJECTS_FOLDER "../FocalEngineProjects" -//#define PROJECTS_FOLDER "C:/Users/Kindr/Downloads/FocalEngineProjects-master" -//#define PROJECTS_FOLDER "C:/Users/Anastasiia/Desktop/FocalEngine/FEProjects" -#define PROJECTS_FILE_VER 0.02f +#define PROJECTS_FILE_VER 0.025f class FEProjectManager { diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 0139ca6..b169fbf 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 0139ca6697abd43e5660bf0c7a05ee578c9e8baa +Subproject commit b169fbf3e918652b9e5244945015ac346a3a4a94 From 5081e1afaa84da50d37756c4296751834bb9f77e Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Mon, 1 Jul 2024 18:27:22 -0400 Subject: [PATCH 12/46] Engine update and first changes to incorporate EnTT as Entity component system. --- CMakeLists.txt | 2 +- EditorWindows/InspectorWindow.cpp | 79 +++- EditorWindows/SceneGraphWindow.cpp | 80 ++-- FEEditor.cpp | 51 ++- FEEditorGizmoManager.cpp | 595 +++++++++++++++++++---------- FEEditorGizmoManager.h | 28 +- FEEditorPreviewManager.cpp | 17 +- FEEditorSelectedObject.cpp | 289 +++++++++----- FEEditorSelectedObject.h | 11 +- FEProject.cpp | 25 +- SubSystems/FocalEngine | 2 +- 11 files changed, 787 insertions(+), 392 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 075008b..f44c462 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -167,6 +167,6 @@ include_directories( ${BASICAPP_THIRDPARTY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/imgui ${BASICAPP_DIR} - ${FOCAL_ENGINE_THIRD_PARTY_DIR} + ${FOCAL_ENGINE_INCLUDES} ${VISUAL_NODE_SYSTEM_DIR} ) \ No newline at end of file diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index bbd3894..d6b3461 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -144,16 +144,17 @@ void FEEditorInspectorWindow::ShowTransformConfiguration(FEObject* Object, FETra if (Object->GetType() == FE_ENTITY || Object->GetType() == FE_ENTITY_INSTANCED) { FEEntity* Entity = SCENE.GetEntity(Object->GetObjectID()); + FENewEntity* NewStyleEntity = SCENE.GetNewStyleEntityByOldStyleID(Object->GetObjectID()); - // Temporary solution, becuase of the lack of proper ECS system - if (Object->GetType() == FE_ENTITY) - { - Entity = reinterpret_cast(Object); - } + //// Temporary solution, becuase of the lack of proper ECS system + //if (Object->GetType() == FE_ENTITY) + //{ + // Entity = reinterpret_cast(Object); + //} - FEAABB RealAabb = Entity->GetAABB(); - const glm::vec3 Min = RealAabb.GetMin(); - const glm::vec3 Max = RealAabb.GetMax(); + FEAABB RealAABB = Entity->GetAABB().Transform(NewStyleEntity->GetComponent().GetTransformMatrix()); + const glm::vec3 Min = RealAABB.GetMin(); + const glm::vec3 Max = RealAABB.GetMax(); const float XSize = sqrt((Max.x - Min.x) * (Max.x - Min.x)); const float YSize = sqrt((Max.y - Min.y) * (Max.y - Min.y)); @@ -422,6 +423,51 @@ void FEEditorInspectorWindow::Render() ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); ImGui::Begin("Inspector", nullptr, ImGuiWindowFlags_None); + // Test new ECS. + if (SELECTED.GetSelected() == nullptr) + { + ImGui::PopStyleVar(); + ImGui::End(); + return; + } + else + { + FENewEntity* NewStyleEntity = SELECTED.GetSelected(); + if (NewStyleEntity->HasComponent()) + { + FETagComponent& Tag = NewStyleEntity->GetComponent(); + char Buffer[256]; + memset(Buffer, 0, 256); + strcpy_s(Buffer, Tag.Tag.c_str()); + if (ImGui::InputText("Tag", Buffer, 256)) + { + Tag.Tag = std::string(Buffer); + } + } + + if (NewStyleEntity->HasComponent()) + { + FETransformComponent& Transform = NewStyleEntity->GetComponent(); + ShowTransformConfiguration(NewStyleEntity->GetName(), &Transform); + } + + /*if (NewStyleEntity->HasComponent()) + { + FERenderableComponent& Renderable = NewStyleEntity->GetComponent(); + if (Renderable.OldStyleEntity != nullptr) + { + FEEntity* OldStyleEntity = Renderable.OldStyleEntity; + ShowTransformConfiguration(OldStyleEntity, &OldStyleEntity->Transform); + } + }*/ + + + ImGui::PopStyleVar(); + ImGui::End(); + return; + } + + if (SELECTED.GetSelected() == nullptr) { ImGui::PopStyleVar(); @@ -787,7 +833,8 @@ void FEEditorInspectorWindow::Render() if (!InstancedEntity->IsSelectMode()) { SELECTED.Clear(); - SELECTED.SetSelected(InstancedEntity); + // FIX ME! + //SELECTED.SetSelected(InstancedEntity); } } ShowToolTip("Individual selection mode - Used to select individual instances."); @@ -805,9 +852,10 @@ void FEEditorInspectorWindow::Render() if (CurrentTerrain->GetBrushMode() != FE_TERRAIN_BRUSH_NONE) { - // to hide gizmos - if (SELECTED.GetTerrain() != nullptr) - SELECTED.SetSelected(SELECTED.GetTerrain()); + // FIX ME! + // To hide gizmos. + /*if (SELECTED.GetTerrain() != nullptr) + SELECTED.SetSelected(SELECTED.GetTerrain());*/ CurrentTerrain->SetBrushActive(bLeftMousePressed); @@ -843,9 +891,10 @@ void FEEditorInspectorWindow::Render() } else { - // to show gizmos - if (SELECTED.GetTerrain() != nullptr) - SELECTED.SetSelected(SELECTED.GetTerrain()); + // FIX ME! + // To show gizmos. + /*if (SELECTED.GetTerrain() != nullptr) + SELECTED.SetSelected(SELECTED.GetTerrain());*/ } } else if (SELECTED.GetLight() != nullptr) diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 95365ae..b666885 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -84,7 +84,8 @@ static void CreateNewInstancedEntityCallBack(const std::vector Select FEEntityInstanced* NewEntity = SCENE.AddEntityInstanced(SelectedPrefab); NewEntity->Transform.SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - SELECTED.SetSelected(NewEntity); + // FIX ME! + //SELECTED.SetSelected(NewEntity); PROJECT_MANAGER.GetCurrent()->SetModified(true); } @@ -98,9 +99,12 @@ static void CreateNewEntityCallBack(const std::vector SelectionsResul if (SelectedPrefab == nullptr) return; + // FIX ME! FEEntity* NewEntity = SCENE.AddEntity(SelectedPrefab); - NewEntity->Transform.SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - SELECTED.SetSelected(NewEntity); + FENewEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(NewEntity->GetObjectID()); + NewNewEntity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + //NewEntity->Transform.SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + SELECTED.SetSelected(NewNewEntity); PROJECT_MANAGER.GetCurrent()->SetModified(true); } @@ -178,15 +182,15 @@ void FEEditorSceneGraphWindow::DrawCorrectIcon(const FEObject* SceneObject) cons DragAndDropTarget* FEEditorSceneGraphWindow::GetSceneNodeDragAndDropTarget(FENaiveSceneGraphNode* NodeToFind) { int64_t UniqueID = 0; - // If it is Root. - if (NodeToFind->GetOldStyleEntity() == nullptr) - { - UniqueID = 1; - } - else - { - UniqueID = static_cast(std::hash{}(NodeToFind->GetOldStyleEntity()->GetObjectID().c_str())); - } + //// If it is Root. + //if (NodeToFind->GetOldStyleEntity() == nullptr) + //{ + // UniqueID = 1; + //} + //else + //{ + UniqueID = static_cast(std::hash{}(NodeToFind->GetNewStyleEntity()->GetObjectID().c_str())); + //} if (SceneNodeDragAndDropTargets.find(UniqueID) == SceneNodeDragAndDropTargets.end()) { @@ -204,34 +208,34 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) int64_t UniqueID = 0; bool bIsLeaf = SubTreeRoot->GetChildren().size() == 0; ImGuiTreeNodeFlags NodeFlags = bIsLeaf ? ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen : ImGuiTreeNodeFlags_OpenOnArrow; - std::string Name = SubTreeRoot->GetOldStyleEntity() == nullptr ? PROJECT_MANAGER.GetCurrent()->GetName() : SubTreeRoot->GetName(); + std::string Name = SubTreeRoot->GetParent() == nullptr ? PROJECT_MANAGER.GetCurrent()->GetName() : SubTreeRoot->GetName(); - if (SELECTED.GetSelected() != nullptr && SubTreeRoot->GetOldStyleEntity() != nullptr) + if (SELECTED.GetSelected() != nullptr && SubTreeRoot->GetNewStyleEntity() != nullptr) { - if (SELECTED.GetSelected()->GetObjectID() == SubTreeRoot->GetOldStyleEntity()->GetObjectID()) + if (SELECTED.GetSelected()->GetObjectID() == SubTreeRoot->GetNewStyleEntity()->GetObjectID()) { NodeFlags |= ImGuiTreeNodeFlags_Selected; } } // If it is Root. - if (SubTreeRoot->GetOldStyleEntity() == nullptr) + /*if (SubTreeRoot->GetOldStyleEntity() == nullptr) { UniqueID = 1; } else - { - UniqueID = static_cast(std::hash{}(SubTreeRoot->GetOldStyleEntity()->GetObjectID().c_str())); - } + {*/ + UniqueID = static_cast(std::hash{}(SubTreeRoot->GetNewStyleEntity()->GetObjectID().c_str())); + //} bool bOpened = ImGui::TreeNodeEx((void*)UniqueID, NodeFlags, Name.c_str(), 0); GetSceneNodeDragAndDropTarget(SubTreeRoot)->StickToItem(); if (ImGui::IsItemClicked()) { - if (SubTreeRoot->GetOldStyleEntity() != nullptr) + if (SubTreeRoot->GetParent() != nullptr) { - SELECTED.SetSelected(OBJECT_MANAGER.GetFEObject(SubTreeRoot->GetOldStyleEntity()->GetObjectID())); + SELECTED.SetSelected(SubTreeRoot->GetNewStyleEntity()); SELECTED.SetDirtyFlag(false); } } @@ -386,7 +390,9 @@ void FEEditorSceneGraphWindow::Render() if (ImGui::IsItemClicked()) { - SELECTED.SetSelected(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); + // FIX ME! + FENewEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])->GetObjectID()); + SELECTED.SetSelected(NewNewEntity); SELECTED.SetDirtyFlag(false); } @@ -627,27 +633,33 @@ void FEEditorSceneGraphWindow::Render() static bool bDisplaySelectedObjAABB = false; ImGui::Checkbox("Display AABB of selected object", &bDisplaySelectedObjAABB); - // draw AABB + // Draw AABB if (SELECTED.GetSelected() != nullptr && (SELECTED.GetSelected()->GetType() == FE_ENTITY || SELECTED.GetSelected()->GetType() == FE_ENTITY_INSTANCED || SELECTED.GetSelected()->GetType() == FE_TERRAIN) && bDisplaySelectedObjAABB) { - const FEAABB SelectedAabb = SELECTED.GetEntity() != nullptr ? SELECTED.GetEntity()->GetAABB() : SELECTED.GetTerrain()->GetAABB(); - RENDERER.DrawAABB(SelectedAabb); - - if (SELECTED.GetSelected()->GetType() == FE_ENTITY_INSTANCED) + if (SELECTED.GetSelected()->HasComponent()) { - static bool bDisplaySubObjAABB = false; - ImGui::Checkbox("Display AABB of instanced entity subobjects", &bDisplaySubObjAABB); + FEEntity* OldStyleEntity = SELECTED.GetSelected()->GetComponent().OldStyleEntity; + FEAABB SelectedAABB = OldStyleEntity->GetAABB().Transform(SELECTED.GetSelected()->GetComponent().GetTransformMatrix()); + //const FEAABB SelectedAABB = SELECTED.GetEntity() != nullptr ? SELECTED.GetEntity()->GetAABB() : SELECTED.GetTerrain()->GetAABB(); + + RENDERER.DrawAABB(SelectedAABB); - if (bDisplaySubObjAABB) + if (SELECTED.GetSelected()->GetType() == FE_ENTITY_INSTANCED) { - const FEEntityInstanced* EntityInstanced = reinterpret_cast (SELECTED.GetSelected()); - const int MaxIterations = EntityInstanced->InstancedAABB.size() * 8 >= FE_MAX_LINES ? FE_MAX_LINES : int(EntityInstanced->InstancedAABB.size()); + static bool bDisplaySubObjAABB = false; + ImGui::Checkbox("Display AABB of instanced entity subobjects", &bDisplaySubObjAABB); - for (size_t j = 0; j < MaxIterations; j++) + if (bDisplaySubObjAABB) { - RENDERER.DrawAABB(EntityInstanced->InstancedAABB[j]); + const FEEntityInstanced* EntityInstanced = reinterpret_cast (SELECTED.GetSelected()); + const int MaxIterations = EntityInstanced->InstancedAABB.size() * 8 >= FE_MAX_LINES ? FE_MAX_LINES : int(EntityInstanced->InstancedAABB.size()); + + for (size_t j = 0; j < MaxIterations; j++) + { + RENDERER.DrawAABB(EntityInstanced->InstancedAABB[j]); + } } } } diff --git a/FEEditor.cpp b/FEEditor.cpp index c18295c..ea8eeaa 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -7,9 +7,12 @@ bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) { if (Object->GetType() == FE_PREFAB) { + // FIX ME! FEEntity* NewEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())); - NewEntity->Transform.SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - SELECTED.SetSelected(NewEntity); + FENewEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(NewEntity->GetObjectID()); + NewNewEntity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + //NewEntity->Transform.SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + SELECTED.SetSelected(NewNewEntity); PROJECT_MANAGER.GetCurrent()->SetModified(true); return true; @@ -192,10 +195,16 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) { if (!EDITOR.GetObjectNameInClipboard().empty()) { + // FIX ME! FEEntity* NewEntity = SCENE.AddEntity(SCENE.GetEntity(EDITOR.GetObjectNameInClipboard())->Prefab, ""); - NewEntity->Transform = SCENE.GetEntity(EDITOR.GetObjectNameInClipboard())->Transform; - NewEntity->Transform.SetPosition(NewEntity->Transform.GetPosition() * 1.1f); - SELECTED.SetSelected(NewEntity); + FENewEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(NewEntity->GetObjectID()); + NewNewEntity->GetComponent() = SCENE.GetEntity(EDITOR.GetObjectNameInClipboard())->Transform; + NewNewEntity->GetComponent().SetPosition(NewEntity->Transform.GetPosition() * 1.1f); + + //NewEntity->Transform = SCENE.GetEntity(EDITOR.GetObjectNameInClipboard())->Transform; + //NewEntity->Transform.SetPosition(NewEntity->Transform.GetPosition() * 1.1f); + + SELECTED.SetSelected(NewNewEntity); } } @@ -240,31 +249,31 @@ void FEEditor::InitializeResources() EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("637C784B2E5E5C6548190E1B"/*"scaleGizmoMesh"*/)); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("19622421516E5B317E1B5360"/*"rotateGizmoMesh"*/)); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleZGizmoEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateXGizmoEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateXGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateYGizmoEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateZGizmoEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateZGizmoEntity); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(PREVIEW_MANAGER.PreviewEntity); @@ -497,12 +506,12 @@ void FEEditor::Render() GyzmosSettingsWindowObject.Show(); GyzmosSettingsWindowObject.Render(); - const int index = SELECTED.GetIndexOfObjectUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY()); - if (index >= 0) + const int ObjectIndex = SELECTED.GetIndexOfObjectUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY()); + if (ObjectIndex >= 0) { - if (!GIZMO_MANAGER.WasSelected(index)) + if (!GIZMO_MANAGER.WasSelected(ObjectIndex)) { - SELECTED.SetSelectedByIndex(index); + SELECTED.SetSelectedByIndex(ObjectIndex); } } diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index afff323..3be6441 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -12,8 +12,8 @@ void GizmoManager::InitializeResources() FEMesh* TransformationGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "45191B6F172E3B531978692E.model").c_str(), "transformationGizmoMesh"); RESOURCE_MANAGER.MakeMeshStandard(TransformationGizmoMesh); - ParentGizmoEntity = SCENE.AddEmptyEntity("ParentGizmoEntity"); - FENaiveSceneGraphNode* ParentGizmoGraphEntity = SCENE.SceneGraph.GetNodeByOldEntityID(ParentGizmoEntity->GetObjectID()); + ParentGizmoEntity = SCENE.AddNewStyleEntity("ParentGizmoEntity"); + FENaiveSceneGraphNode* ParentGizmoGraphNode = SCENE.SceneGraph.GetNodeByEntityID(ParentGizmoEntity->GetObjectID()); // TransformationXGizmo FEMaterial* CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXGizmoMaterial"); @@ -21,15 +21,17 @@ void GizmoManager::InitializeResources() CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationXGizmoEntity = SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM"), "transformationXGizmoEntity"); - RESOURCE_MANAGER.MakePrefabStandard(TransformationXGizmoEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationXGizmoEntity->Prefab->GetComponent(0)->GameModel); - TransformationXGizmoEntity->SetCastShadows(false); - TransformationXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); - TransformationXGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - TransformationXGizmoEntity->SetIsPostprocessApplied(false); + TransformationXGizmoEntity = SCENE.AddNewStyleEntity("TransformationXGizmoEntity"); + TransformationXGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM"), "TransformationXGizmoEntity")); + RESOURCE_MANAGER.MakePrefabStandard(TransformationXGizmoEntity->GetComponent().OldStyleEntity->Prefab); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + TransformationXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + TransformationXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // TransformationYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYGizmoMaterial"); @@ -37,15 +39,25 @@ void GizmoManager::InitializeResources() CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationYGizmoEntity = SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"), "transformationYGizmoEntity"); + + TransformationYGizmoEntity = SCENE.AddNewStyleEntity("TransformationYGizmoEntity"); + TransformationYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"), "TransformationYGizmoEntity")); + RESOURCE_MANAGER.MakePrefabStandard(TransformationYGizmoEntity->GetComponent().OldStyleEntity->Prefab); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + TransformationYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + TransformationYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); + TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + /*TransformationYGizmoEntity = SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"), "transformationYGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(TransformationYGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(TransformationYGizmoEntity->Prefab->GetComponent(0)->GameModel); TransformationYGizmoEntity->SetCastShadows(false); TransformationYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); TransformationYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); - TransformationYGizmoEntity->SetIsPostprocessApplied(false); + TransformationYGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // TransformationZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationZGizmoMaterial"); @@ -53,15 +65,25 @@ void GizmoManager::InitializeResources() CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationZGizmoEntity = SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"), "transformationZGizmoEntity"); + + TransformationZGizmoEntity = SCENE.AddNewStyleEntity("TransformationZGizmoEntity"); + TransformationZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"), "TransformationZGizmoEntity")); + RESOURCE_MANAGER.MakePrefabStandard(TransformationZGizmoEntity->GetComponent().OldStyleEntity->Prefab); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + TransformationZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + TransformationZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); + TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + /*TransformationZGizmoEntity = SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"), "transformationZGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(TransformationZGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(TransformationZGizmoEntity->Prefab->GetComponent(0)->GameModel); TransformationZGizmoEntity->SetCastShadows(false); TransformationZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); TransformationZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - TransformationZGizmoEntity->SetIsPostprocessApplied(false); + TransformationZGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // Plane gizmos CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXYGizmoMaterial"); @@ -69,48 +91,81 @@ void GizmoManager::InitializeResources() CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationXYGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"), "transformationXYGizmoEntity"); - RESOURCE_MANAGER.MakePrefabStandard(TransformationXYGizmoEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationXYGizmoEntity->Prefab->GetComponent(0)->GameModel); - TransformationXYGizmoEntity->SetCastShadows(false); - TransformationXYGizmoEntity->Transform.SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); - TransformationXYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); - TransformationXYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - TransformationXYGizmoEntity->SetIsPostprocessApplied(false); + + TransformationXYGizmoEntity = SCENE.AddNewStyleEntity("TransformationXYGizmoEntity"); + TransformationXYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"), "TransformationXYGizmoEntity")); + RESOURCE_MANAGER.MakePrefabStandard(TransformationXYGizmoEntity->GetComponent().OldStyleEntity->Prefab); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationXYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + TransformationXYGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); + TransformationXYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); + TransformationXYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + //TransformationXYGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"), "transformationXYGizmoEntity"); + //RESOURCE_MANAGER.MakePrefabStandard(TransformationXYGizmoEntity->Prefab); + //RESOURCE_MANAGER.MakeGameModelStandard(TransformationXYGizmoEntity->Prefab->GetComponent(0)->GameModel); + //TransformationXYGizmoEntity->SetCastShadows(false); + //TransformationXYGizmoEntity->Transform.SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); + //TransformationXYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); + //TransformationXYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + //TransformationXYGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationYZGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"), "transformationYZGizmoEntity"); - RESOURCE_MANAGER.MakePrefabStandard(TransformationYZGizmoEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationYZGizmoEntity->Prefab->GetComponent(0)->GameModel); - TransformationYZGizmoEntity->SetCastShadows(false); - TransformationYZGizmoEntity->Transform.SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); - TransformationYZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); - TransformationYZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - TransformationYZGizmoEntity->SetIsPostprocessApplied(false); + + TransformationYZGizmoEntity = SCENE.AddNewStyleEntity("TransformationYZGizmoEntity"); + TransformationYZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"), "TransformationYZGizmoEntity")); + RESOURCE_MANAGER.MakePrefabStandard(TransformationYZGizmoEntity->GetComponent().OldStyleEntity->Prefab); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationYZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + TransformationYZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); + TransformationYZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); + TransformationYZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + //TransformationYZGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"), "transformationYZGizmoEntity"); + //RESOURCE_MANAGER.MakePrefabStandard(TransformationYZGizmoEntity->Prefab); + //RESOURCE_MANAGER.MakeGameModelStandard(TransformationYZGizmoEntity->Prefab->GetComponent(0)->GameModel); + //TransformationYZGizmoEntity->SetCastShadows(false); + //TransformationYZGizmoEntity->Transform.SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); + //TransformationYZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); + //TransformationYZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + //TransformationYZGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationXZGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"), "transformationXZGizmoEntity"); - RESOURCE_MANAGER.MakePrefabStandard(TransformationXZGizmoEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationXZGizmoEntity->Prefab->GetComponent(0)->GameModel); - TransformationXZGizmoEntity->SetCastShadows(false); - TransformationXZGizmoEntity->Transform.SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); - TransformationXZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); - TransformationXZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - TransformationXZGizmoEntity->SetIsPostprocessApplied(false); + + TransformationXZGizmoEntity = SCENE.AddNewStyleEntity("TransformationXZGizmoEntity"); + TransformationXZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"), "TransformationXZGizmoEntity")); + RESOURCE_MANAGER.MakePrefabStandard(TransformationXZGizmoEntity->GetComponent().OldStyleEntity->Prefab); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationXZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + TransformationXZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); + TransformationXZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); + TransformationXZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + //TransformationXZGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"), "transformationXZGizmoEntity"); + //RESOURCE_MANAGER.MakePrefabStandard(TransformationXZGizmoEntity->Prefab); + //RESOURCE_MANAGER.MakeGameModelStandard(TransformationXZGizmoEntity->Prefab->GetComponent(0)->GameModel); + //TransformationXZGizmoEntity->SetCastShadows(false); + //TransformationXZGizmoEntity->Transform.SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); + //TransformationXZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); + //TransformationXZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + //TransformationXZGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // Scale gizmos. FEMesh* ScaleGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "637C784B2E5E5C6548190E1B.model").c_str(), "scaleGizmoMesh"); @@ -122,15 +177,25 @@ void GizmoManager::InitializeResources() CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - ScaleXGizmoEntity = SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "scaleXGizmoGM"), "scaleXGizmoEntity"); + + ScaleXGizmoEntity = SCENE.AddNewStyleEntity("ScaleXGizmoEntity"); + ScaleXGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM"), "ScaleXGizmoEntity")); + RESOURCE_MANAGER.MakePrefabStandard(ScaleXGizmoEntity->GetComponent().OldStyleEntity->Prefab); + RESOURCE_MANAGER.MakeGameModelStandard(ScaleXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + ScaleXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + ScaleXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + /*ScaleXGizmoEntity = SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "scaleXGizmoGM"), "scaleXGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(ScaleXGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(ScaleXGizmoEntity->Prefab->GetComponent(0)->GameModel); ScaleXGizmoEntity->SetCastShadows(false); ScaleXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); ScaleXGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - ScaleXGizmoEntity->SetIsPostprocessApplied(false); + ScaleXGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // ScaleYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleYGizmoMaterial"); @@ -138,15 +203,25 @@ void GizmoManager::InitializeResources() CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - ScaleYGizmoEntity = SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "scaleYGizmoGM"), "scaleYGizmoEntity"); + + ScaleYGizmoEntity = SCENE.AddNewStyleEntity("ScaleYGizmoEntity"); + ScaleYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM"), "ScaleYGizmoEntity")); + RESOURCE_MANAGER.MakePrefabStandard(ScaleYGizmoEntity->GetComponent().OldStyleEntity->Prefab); + RESOURCE_MANAGER.MakeGameModelStandard(ScaleYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + ScaleYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + ScaleYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); + ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + /*ScaleYGizmoEntity = SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "scaleYGizmoGM"), "scaleYGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(ScaleYGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(ScaleYGizmoEntity->Prefab->GetComponent(0)->GameModel); ScaleYGizmoEntity->SetCastShadows(false); ScaleYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); ScaleYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); - ScaleYGizmoEntity->SetIsPostprocessApplied(false); + ScaleYGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // ScaleZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleZGizmoMaterial"); @@ -154,15 +229,25 @@ void GizmoManager::InitializeResources() CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - ScaleZGizmoEntity = SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "scaleZGizmoGM"), "scaleZGizmoEntity"); + + ScaleZGizmoEntity = SCENE.AddNewStyleEntity("ScaleZGizmoEntity"); + ScaleZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM"), "ScaleZGizmoEntity")); + RESOURCE_MANAGER.MakePrefabStandard(ScaleZGizmoEntity->GetComponent().OldStyleEntity->Prefab); + RESOURCE_MANAGER.MakeGameModelStandard(ScaleZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + ScaleZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + ScaleZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); + ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + /*ScaleZGizmoEntity = SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "scaleZGizmoGM"), "scaleZGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(ScaleZGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(ScaleZGizmoEntity->Prefab->GetComponent(0)->GameModel); ScaleZGizmoEntity->SetCastShadows(false); ScaleZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); ScaleZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - ScaleZGizmoEntity->SetIsPostprocessApplied(false); + ScaleZGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // Rotate gizmos FEMesh* RotateGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "19622421516E5B317E1B5360.model").c_str(), "rotateGizmoMesh"); @@ -174,15 +259,25 @@ void GizmoManager::InitializeResources() CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - RotateXGizmoEntity = SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "rotateXGizmoGM"), "rotateXGizmoEntity"); + + RotateXGizmoEntity = SCENE.AddNewStyleEntity("RotateXGizmoEntity"); + RotateXGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM"), "RotateXGizmoEntity")); + RESOURCE_MANAGER.MakePrefabStandard(RotateXGizmoEntity->GetComponent().OldStyleEntity->Prefab); + RESOURCE_MANAGER.MakeGameModelStandard(RotateXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + RotateXGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + RotateXGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + RotateXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); + RotateXGizmoEntity->GetComponent().SetRotation(RotateXStandardRotation); + RotateXGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + /*RotateXGizmoEntity = SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "rotateXGizmoGM"), "rotateXGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(RotateXGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(RotateXGizmoEntity->Prefab->GetComponent(0)->GameModel); RotateXGizmoEntity->SetCastShadows(false); RotateXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); RotateXGizmoEntity->Transform.SetRotation(RotateXStandardRotation); - RotateXGizmoEntity->SetIsPostprocessApplied(false); + RotateXGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // RotateYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateYGizmoMaterial"); @@ -190,15 +285,25 @@ void GizmoManager::InitializeResources() CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - RotateYGizmoEntity = SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "rotateYGizmoGM"), "rotateYGizmoEntity"); + + RotateYGizmoEntity = SCENE.AddNewStyleEntity("RotateYGizmoEntity"); + RotateYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM"), "RotateYGizmoEntity")); + RESOURCE_MANAGER.MakePrefabStandard(RotateYGizmoEntity->GetComponent().OldStyleEntity->Prefab); + RESOURCE_MANAGER.MakeGameModelStandard(RotateYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + RotateYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + RotateYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + RotateYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); + RotateYGizmoEntity->GetComponent().SetRotation(RotateYStandardRotation); + RotateYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + /*RotateYGizmoEntity = SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "rotateYGizmoGM"), "rotateYGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(RotateYGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(RotateYGizmoEntity->Prefab->GetComponent(0)->GameModel); RotateYGizmoEntity->SetCastShadows(false); RotateYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); RotateYGizmoEntity->Transform.SetRotation(RotateYStandardRotation); - RotateYGizmoEntity->SetIsPostprocessApplied(false); + RotateYGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // RotateZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateZGizmoMaterial"); @@ -206,15 +311,25 @@ void GizmoManager::InitializeResources() CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - RotateZGizmoEntity = SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "rotateZGizmoGM"), "rotateZGizmoEntity"); + + RotateZGizmoEntity = SCENE.AddNewStyleEntity("RotateZGizmoEntity"); + RotateZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM"), "RotateZGizmoEntity")); + RESOURCE_MANAGER.MakePrefabStandard(RotateZGizmoEntity->GetComponent().OldStyleEntity->Prefab); + RESOURCE_MANAGER.MakeGameModelStandard(RotateZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + RotateZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + RotateZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + RotateZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); + RotateZGizmoEntity->GetComponent().SetRotation(RotateZStandardRotation); + RotateZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + /*RotateZGizmoEntity = SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "rotateZGizmoGM"), "rotateZGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(RotateZGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(RotateZGizmoEntity->Prefab->GetComponent(0)->GameModel); RotateZGizmoEntity->SetCastShadows(false); RotateZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); RotateZGizmoEntity->Transform.SetRotation(RotateZStandardRotation); - RotateZGizmoEntity->SetIsPostprocessApplied(false); + RotateZGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); TransformationGizmoIcon = RESOURCE_MANAGER.LoadFETexture((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "456A31026A1C3152181A6064.texture").c_str(), "transformationGizmoIcon"); RESOURCE_MANAGER.MakeTextureStandard(TransformationGizmoIcon); @@ -226,13 +341,13 @@ void GizmoManager::InitializeResources() void GizmoManager::HideAllGizmo() { - TransformationXGizmoEntity->SetVisibility(false); - TransformationYGizmoEntity->SetVisibility(false); - TransformationZGizmoEntity->SetVisibility(false); + TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); - TransformationXYGizmoEntity->SetVisibility(false); - TransformationYZGizmoEntity->SetVisibility(false); - TransformationXZGizmoEntity->SetVisibility(false); + TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); bTransformationXGizmoActive = false; bTransformationYGizmoActive = false; @@ -242,17 +357,17 @@ void GizmoManager::HideAllGizmo() bTransformationYZGizmoActive = false; bTransformationXZGizmoActive = false; - ScaleXGizmoEntity->SetVisibility(false); - ScaleYGizmoEntity->SetVisibility(false); - ScaleZGizmoEntity->SetVisibility(false); + ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); bScaleXGizmoActive = false; bScaleYGizmoActive = false; bScaleZGizmoActive = false; - RotateXGizmoEntity->SetVisibility(false); - RotateYGizmoEntity->SetVisibility(false); - RotateZGizmoEntity->SetVisibility(false); + RotateXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + RotateYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + RotateZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); bRotateXGizmoActive = false; bRotateYGizmoActive = false; @@ -280,29 +395,29 @@ void GizmoManager::UpdateGizmoState(int NewState) { case TRANSFORM_GIZMOS: { - TransformationXGizmoEntity->SetVisibility(true); - TransformationYGizmoEntity->SetVisibility(true); - TransformationZGizmoEntity->SetVisibility(true); + TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - TransformationXYGizmoEntity->SetVisibility(true); - TransformationYZGizmoEntity->SetVisibility(true); - TransformationXZGizmoEntity->SetVisibility(true); + TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); break; } case SCALE_GIZMOS: { - ScaleXGizmoEntity->SetVisibility(true); - ScaleYGizmoEntity->SetVisibility(true); - ScaleZGizmoEntity->SetVisibility(true); + ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); break; } case ROTATE_GIZMOS: { - RotateXGizmoEntity->SetVisibility(true); - RotateYGizmoEntity->SetVisibility(true); - RotateZGizmoEntity->SetVisibility(true); + RotateXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + RotateYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + RotateZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); break; } @@ -351,90 +466,90 @@ void GizmoManager::Render() toObject = glm::normalize(center - ENGINE.getCamera()->getPosition()); }*/ - ParentGizmoEntity->Transform.SetPosition((ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f)); + ParentGizmoEntity->GetComponent().SetPosition((ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f)); if (GIZMO_MANAGER.GizmosState == TRANSFORM_GIZMOS) { // X Gizmos - GIZMO_MANAGER.TransformationXGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); + GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); if (GIZMO_MANAGER.bTransformationXZGizmoActive || GIZMO_MANAGER.bTransformationXYGizmoActive || GIZMO_MANAGER.bTransformationXGizmoActive) - GIZMO_MANAGER.TransformationXGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // Y Gizmos - GIZMO_MANAGER.TransformationYGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); + GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); if (GIZMO_MANAGER.bTransformationYZGizmoActive || GIZMO_MANAGER.bTransformationXYGizmoActive || GIZMO_MANAGER.bTransformationYGizmoActive) - GIZMO_MANAGER.TransformationYGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // Z Gizmos - GIZMO_MANAGER.TransformationZGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); + GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); if (GIZMO_MANAGER.bTransformationYZGizmoActive || GIZMO_MANAGER.bTransformationXZGizmoActive || GIZMO_MANAGER.bTransformationZGizmoActive) - GIZMO_MANAGER.TransformationZGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); - // XY Gizmos - GIZMO_MANAGER.TransformationXYGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); + // XY Gizmos + GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); if (GIZMO_MANAGER.bTransformationXYGizmoActive) - GIZMO_MANAGER.TransformationXYGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // YZ Gizmos - GIZMO_MANAGER.TransformationYZGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); + GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); if (GIZMO_MANAGER.bTransformationYZGizmoActive) - GIZMO_MANAGER.TransformationYZGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // XZ Gizmos - GIZMO_MANAGER.TransformationXZGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); + GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); if (GIZMO_MANAGER.bTransformationXZGizmoActive) - GIZMO_MANAGER.TransformationXZGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); } else if (GIZMO_MANAGER.GizmosState == SCALE_GIZMOS) { // X Gizmos - GIZMO_MANAGER.ScaleXGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); + GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); if (GIZMO_MANAGER.bScaleXGizmoActive) - GIZMO_MANAGER.ScaleXGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // Y Gizmos - GIZMO_MANAGER.ScaleYGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); + GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); if (GIZMO_MANAGER.bScaleYGizmoActive) - GIZMO_MANAGER.ScaleYGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // Z Gizmos - GIZMO_MANAGER.ScaleZGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); + GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); if (GIZMO_MANAGER.bScaleZGizmoActive) - GIZMO_MANAGER.ScaleZGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); } else if (GIZMO_MANAGER.GizmosState == ROTATE_GIZMOS) { if (SELECTED.SELECTED.GetSelected() != nullptr) { - GIZMO_MANAGER.RotateXGizmoEntity->SetVisibility(true); - GIZMO_MANAGER.RotateYGizmoEntity->SetVisibility(true); - GIZMO_MANAGER.RotateZGizmoEntity->SetVisibility(true); + GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); } // X Gizmos - GIZMO_MANAGER.RotateXGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); + GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); if (GIZMO_MANAGER.bRotateXGizmoActive) { - GIZMO_MANAGER.RotateXGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); - GIZMO_MANAGER.RotateYGizmoEntity->SetVisibility(false); - GIZMO_MANAGER.RotateZGizmoEntity->SetVisibility(false); + GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); } // Y Gizmos - GIZMO_MANAGER.RotateYGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); + GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); if (GIZMO_MANAGER.bRotateYGizmoActive) { - GIZMO_MANAGER.RotateYGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); - GIZMO_MANAGER.RotateXGizmoEntity->SetVisibility(false); - GIZMO_MANAGER.RotateZGizmoEntity->SetVisibility(false); + GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); } // Z Gizmos - GIZMO_MANAGER.RotateZGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); + GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); if (GIZMO_MANAGER.bRotateZGizmoActive) { - GIZMO_MANAGER.RotateZGizmoEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); - GIZMO_MANAGER.RotateXGizmoEntity->SetVisibility(false); - GIZMO_MANAGER.RotateYGizmoEntity->SetVisibility(false); + GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); } } } @@ -590,13 +705,14 @@ void GizmoManager::MoveSelectedEntityAlongAxis(const glm::vec3& AxisOfMovement, glm::vec3 NewPosition = ObjectTransform.GetPosition(); glm::vec3 LocalAlternativeAxis = AxisOfMovement; - FENaiveSceneGraphNode* SceneGraphParentEntity = SCENE.SceneGraph.GetNodeByOldEntityID(SELECTED.GetSelected()->GetObjectID()); + FENaiveSceneGraphNode* SceneGraphParentEntity = SCENE.SceneGraph.GetNodeByEntityID(SELECTED.GetSelected()->GetObjectID()); if (SceneGraphParentEntity != nullptr) { if (SceneGraphParentEntity->GetParent() != SCENE.SceneGraph.GetRoot()) { - FEEntity* ParentEntity = reinterpret_cast(SceneGraphParentEntity->GetParent()->GetOldStyleEntity()); - LocalAlternativeAxis = glm::inverse(ParentEntity->Transform.WorldSpaceMatrix) * glm::vec4(AxisOfMovement, 0.0f); + FETransformComponent& ParentTransform = SceneGraphParentEntity->GetParent()->GetNewStyleEntity()->GetComponent(); + //FEEntity* ParentEntity = reinterpret_cast(SceneGraphParentEntity->GetParent()->GetOldStyleEntity()); + LocalAlternativeAxis = glm::inverse(ParentTransform.WorldSpaceMatrix) * glm::vec4(AxisOfMovement, 0.0f); } NewPosition += LocalAlternativeAxis; @@ -609,12 +725,13 @@ void GizmoManager::RotateSelectedEntity(const glm::vec3& AxisOfRotation, FETrans { glm::vec3 LocalAlternativeAxis = AxisOfRotation; - FENaiveSceneGraphNode* SceneGraphParentEntity = SCENE.SceneGraph.GetNodeByOldEntityID(SELECTED.GetSelected()->GetObjectID()); + FENaiveSceneGraphNode* SceneGraphParentEntity = SCENE.SceneGraph.GetNodeByEntityID(SELECTED.GetSelected()->GetObjectID()); if (SceneGraphParentEntity != nullptr) { if (SceneGraphParentEntity->GetParent() != SCENE.SceneGraph.GetRoot()) { - FEEntity* ParentEntity = reinterpret_cast(SceneGraphParentEntity->GetParent()->GetOldStyleEntity()); + FETransformComponent& ParentTransform = SceneGraphParentEntity->GetParent()->GetNewStyleEntity()->GetComponent(); + //FEEntity* ParentEntity = reinterpret_cast(SceneGraphParentEntity->GetParent()->GetOldStyleEntity()); //LocalAlternativeAxis = glm::inverse(ParentEntity->Transform.GetQuaternion()) * glm::vec3(AxisOfRotation); glm::dvec3 DoubleScale; @@ -622,7 +739,7 @@ void GizmoManager::RotateSelectedEntity(const glm::vec3& AxisOfRotation, FETrans glm::dvec3 DoubleTranslation; glm::dvec3 DoubleSkew; glm::dvec4 DoublePerspective; - glm::dmat4 DoubleNewChildLocalMatrix = ParentEntity->Transform.WorldSpaceMatrix; + glm::dmat4 DoubleNewChildLocalMatrix = ParentTransform.WorldSpaceMatrix; bool Success = glm::decompose(DoubleNewChildLocalMatrix, DoubleScale, DoubleRotation, DoubleTranslation, DoubleSkew, DoublePerspective); if (Success) { @@ -839,24 +956,24 @@ void GizmoManager::OnSelectedObjectUpdate() if (GIZMO_MANAGER.GizmosState == TRANSFORM_GIZMOS) { - GIZMO_MANAGER.TransformationXGizmoEntity->SetVisibility(true); - GIZMO_MANAGER.TransformationYGizmoEntity->SetVisibility(true); - GIZMO_MANAGER.TransformationZGizmoEntity->SetVisibility(true); - GIZMO_MANAGER.TransformationXYGizmoEntity->SetVisibility(true); - GIZMO_MANAGER.TransformationYZGizmoEntity->SetVisibility(true); - GIZMO_MANAGER.TransformationXZGizmoEntity->SetVisibility(true); + GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); } else if (GIZMO_MANAGER.GizmosState == SCALE_GIZMOS) { - GIZMO_MANAGER.ScaleXGizmoEntity->SetVisibility(true); - GIZMO_MANAGER.ScaleYGizmoEntity->SetVisibility(true); - GIZMO_MANAGER.ScaleZGizmoEntity->SetVisibility(true); + GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); } else if (GIZMO_MANAGER.GizmosState == ROTATE_GIZMOS) { - GIZMO_MANAGER.RotateXGizmoEntity->SetVisibility(true); - GIZMO_MANAGER.RotateYGizmoEntity->SetVisibility(true); - GIZMO_MANAGER.RotateZGizmoEntity->SetVisibility(true); + GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); } } } @@ -864,9 +981,11 @@ void GizmoManager::OnSelectedObjectUpdate() FETransformComponent GizmoManager::GetTransformComponentOfSelectedObject() { if (SELECTED.GetSelected() == nullptr) - FETransformComponent(); + return FETransformComponent(); - if (SELECTED.GetSelected()->GetType() == FE_ENTITY) + return SELECTED.GetSelected()->GetComponent(); + + /*if (SELECTED.GetSelected()->GetType() == FE_ENTITY) { return SELECTED.GetEntity()->Transform; } @@ -890,15 +1009,23 @@ FETransformComponent GizmoManager::GetTransformComponentOfSelectedObject() return SELECTED.GetLight()->Transform; } - return FETransformComponent(); + return FETransformComponent();*/ } void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent Changes) { if (SELECTED.GetSelected() == nullptr) - FETransformComponent(); + return; - if (SELECTED.GetSelected()->GetType() == FE_ENTITY) + if (SELECTED.InstancedSubObjectIndexSelected != -1) + { + //reinterpret_cast(SELECTED.GetEntity())->ModifyInstance(SELECTED.InstancedSubObjectIndexSelected, Changes.GetTransformMatrix()); + assert(false); + } + + SELECTED.GetSelected()->GetComponent() = Changes; + + /*if (SELECTED.GetSelected()->GetType() == FE_ENTITY) { SELECTED.GetEntity()->Transform = Changes; } @@ -920,120 +1047,202 @@ void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent Changes) else if (SELECTED.GetSelected()->GetType() == FE_DIRECTIONAL_LIGHT || SELECTED.GetSelected()->GetType() == FE_SPOT_LIGHT || SELECTED.GetSelected()->GetType() == FE_POINT_LIGHT) { SELECTED.GetLight()->Transform = Changes; - } + }*/ } void GizmoManager::ReInitializeEntities() { - ParentGizmoEntity = SCENE.AddEmptyEntity("ParentGizmoEntity"); - ParentGizmoGraphEntity = SCENE.SceneGraph.GetNodeByOldEntityID(ParentGizmoEntity->GetObjectID()); + ParentGizmoEntity = SCENE.AddNewStyleEntity("ParentGizmoEntity"); + ParentGizmoGraphNode = SCENE.SceneGraph.GetNodeByEntityID(ParentGizmoEntity->GetObjectID()); // TransformationXGizmo - TransformationXGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXGizmoGM")[0], "transformationXGizmoEntity"); - TransformationXGizmoEntity->SetCastShadows(false); - TransformationXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); - TransformationXGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - TransformationXGizmoEntity->SetIsPostprocessApplied(false); + TransformationXGizmoEntity = SCENE.AddNewStyleEntity("TransformationXGizmoEntity"); + TransformationXGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXGizmoGM")[0], "TransformationXGizmoEntity")); + TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + TransformationXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // TransformationYGizmo - TransformationYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationYGizmoGM")[0], "transformationYGizmoEntity"); - TransformationYGizmoEntity->SetCastShadows(false); - TransformationYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); - TransformationYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); - TransformationYGizmoEntity->SetIsPostprocessApplied(false); + TransformationYGizmoEntity = SCENE.AddNewStyleEntity("TransformationYGizmoEntity"); + TransformationYGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationYGizmoGM")[0], "TransformationYGizmoEntity")); + TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + TransformationYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); + //TransformationYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationYGizmoGM")[0], "transformationYGizmoEntity"); + //TransformationYGizmoEntity->SetCastShadows(false); + //TransformationYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); + //TransformationYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); + //TransformationYGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // TransformationZGizmo - TransformationZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationZGizmoGM")[0], "transformationZGizmoEntity"); - TransformationZGizmoEntity->SetCastShadows(false); - TransformationZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); - TransformationZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - TransformationZGizmoEntity->SetIsPostprocessApplied(false); + TransformationZGizmoEntity = SCENE.AddNewStyleEntity("TransformationZGizmoEntity"); + TransformationZGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationZGizmoGM")[0], "TransformationZGizmoEntity")); + TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + TransformationZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); + //TransformationZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationZGizmoGM")[0], "transformationZGizmoEntity"); + //TransformationZGizmoEntity->SetCastShadows(false); + //TransformationZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); + //TransformationZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); + //TransformationZGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // Plane gizmos - TransformationXYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXYGizmoGM")[0], "transformationXYGizmoEntity"); + TransformationXYGizmoEntity = SCENE.AddNewStyleEntity("TransformationXYGizmoEntity"); + TransformationXYGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXYGizmoGM")[0], "TransformationXYGizmoEntity")); + TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationXYGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); + TransformationXYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); + TransformationXYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + /*TransformationXYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXYGizmoGM")[0], "transformationXYGizmoEntity"); TransformationXYGizmoEntity->SetCastShadows(false); TransformationXYGizmoEntity->Transform.SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); TransformationXYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); TransformationXYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - TransformationXYGizmoEntity->SetIsPostprocessApplied(false); + TransformationXYGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - - TransformationYZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationYZGizmoGM")[0], "transformationYZGizmoEntity"); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + + TransformationYZGizmoEntity = SCENE.AddNewStyleEntity("TransformationYZGizmoEntity"); + TransformationYZGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationYZGizmoGM")[0], "TransformationYZGizmoEntity")); + TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationYZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); + TransformationYZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); + TransformationYZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + /*TransformationYZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationYZGizmoGM")[0], "transformationYZGizmoEntity"); TransformationYZGizmoEntity->SetCastShadows(false); TransformationYZGizmoEntity->Transform.SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); TransformationYZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); TransformationYZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - TransformationYZGizmoEntity->SetIsPostprocessApplied(false); + TransformationYZGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); - - TransformationXZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXZGizmoGM")[0], "transformationXZGizmoEntity"); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + + TransformationXZGizmoEntity = SCENE.AddNewStyleEntity("TransformationXZGizmoEntity"); + TransformationXZGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXZGizmoGM")[0], "TransformationXZGizmoEntity")); + TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationXZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); + TransformationXZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); + TransformationXZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + /*TransformationXZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXZGizmoGM")[0], "transformationXZGizmoEntity"); TransformationXZGizmoEntity->SetCastShadows(false); TransformationXZGizmoEntity->Transform.SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); TransformationXZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); TransformationXZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - TransformationXZGizmoEntity->SetIsPostprocessApplied(false); + TransformationXZGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // ScaleXGizmo - ScaleXGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("scaleXGizmoGM")[0], "scaleXGizmoEntity"); + ScaleXGizmoEntity = SCENE.AddNewStyleEntity("ScaleXGizmoEntity"); + ScaleXGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("ScaleXGizmoGM")[0], "ScaleXGizmoEntity")); + ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + ScaleXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + ScaleXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + /*ScaleXGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("scaleXGizmoGM")[0], "scaleXGizmoEntity"); ScaleXGizmoEntity->SetCastShadows(false); ScaleXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); ScaleXGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - ScaleXGizmoEntity->SetIsPostprocessApplied(false); + ScaleXGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // ScaleYGizmo - ScaleYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("scaleYGizmoGM")[0], "scaleYGizmoEntity"); + ScaleYGizmoEntity = SCENE.AddNewStyleEntity("ScaleYGizmoEntity"); + ScaleYGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("ScaleYGizmoGM")[0], "ScaleYGizmoEntity")); + ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + ScaleYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + ScaleYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); + /*ScaleYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("scaleYGizmoGM")[0], "scaleYGizmoEntity"); ScaleYGizmoEntity->SetCastShadows(false); ScaleYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); ScaleYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); - ScaleYGizmoEntity->SetIsPostprocessApplied(false); + ScaleYGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // ScaleZGizmo - ScaleZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("scaleZGizmoGM")[0], "scaleZGizmoEntity"); + ScaleZGizmoEntity = SCENE.AddNewStyleEntity("ScaleZGizmoEntity"); + ScaleZGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("ScaleZGizmoGM")[0], "ScaleZGizmoEntity")); + ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + ScaleZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + ScaleZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); + /*ScaleZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("scaleZGizmoGM")[0], "scaleZGizmoEntity"); ScaleZGizmoEntity->SetCastShadows(false); ScaleZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); ScaleZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - ScaleZGizmoEntity->SetIsPostprocessApplied(false); + ScaleZGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // RotateXGizmo - RotateXGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("rotateXGizmoGM")[0], "rotateXGizmoEntity"); + RotateXGizmoEntity = SCENE.AddNewStyleEntity("RotateXGizmoEntity"); + RotateXGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("RotateXGizmoGM")[0], "RotateXGizmoEntity")); + RotateXGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + RotateXGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + RotateXGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + RotateXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); + RotateXGizmoEntity->GetComponent().SetRotation(RotateXStandardRotation); + /*RotateXGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("rotateXGizmoGM")[0], "rotateXGizmoEntity"); RotateXGizmoEntity->SetCastShadows(false); RotateXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); RotateXGizmoEntity->Transform.SetRotation(RotateXStandardRotation); - RotateXGizmoEntity->SetIsPostprocessApplied(false); + RotateXGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // RotateYGizmo - RotateYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("rotateYGizmoGM")[0], "rotateYGizmoEntity"); + RotateYGizmoEntity = SCENE.AddNewStyleEntity("RotateYGizmoEntity"); + RotateYGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("RotateYGizmoGM")[0], "RotateYGizmoEntity")); + RotateYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + RotateYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + RotateYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + RotateYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); + RotateYGizmoEntity->GetComponent().SetRotation(RotateYStandardRotation); + /*RotateYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("rotateYGizmoGM")[0], "rotateYGizmoEntity"); RotateYGizmoEntity->SetCastShadows(false); RotateYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); RotateYGizmoEntity->Transform.SetRotation(RotateYStandardRotation); - RotateYGizmoEntity->SetIsPostprocessApplied(false); + RotateYGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // RotateZGizmo - RotateZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("rotateZGizmoGM")[0], "rotateZGizmoEntity"); + RotateZGizmoEntity = SCENE.AddNewStyleEntity("RotateZGizmoEntity"); + RotateZGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("RotateZGizmoGM")[0], "RotateZGizmoEntity")); + RotateZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); + RotateZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + RotateZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + RotateZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); + RotateZGizmoEntity->GetComponent().SetRotation(RotateZStandardRotation); + /*RotateZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("rotateZGizmoGM")[0], "rotateZGizmoEntity"); RotateZGizmoEntity->SetCastShadows(false); RotateZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); RotateZGizmoEntity->Transform.SetRotation(RotateZStandardRotation); - RotateZGizmoEntity->SetIsPostprocessApplied(false); + RotateZGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByOldEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphEntity->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); } \ No newline at end of file diff --git a/FEEditorGizmoManager.h b/FEEditorGizmoManager.h index 9a0be25..a4868e9 100644 --- a/FEEditorGizmoManager.h +++ b/FEEditorGizmoManager.h @@ -22,38 +22,38 @@ class GizmoManager int GizmosState = TRANSFORM_GIZMOS; // Parent Gizmo Entity - FEEntity* ParentGizmoEntity = nullptr; - FENaiveSceneGraphNode* ParentGizmoGraphEntity = nullptr; + FENewEntity* ParentGizmoEntity = nullptr; + FENaiveSceneGraphNode* ParentGizmoGraphNode = nullptr; - FEEntity* TransformationXGizmoEntity = nullptr; - FEEntity* TransformationYGizmoEntity = nullptr; - FEEntity* TransformationZGizmoEntity = nullptr; + FENewEntity* TransformationXGizmoEntity = nullptr; + FENewEntity* TransformationYGizmoEntity = nullptr; + FENewEntity* TransformationZGizmoEntity = nullptr; bool bTransformationXGizmoActive = false; bool bTransformationYGizmoActive = false; bool bTransformationZGizmoActive = false; - FEEntity* TransformationXYGizmoEntity = nullptr; - FEEntity* TransformationYZGizmoEntity = nullptr; - FEEntity* TransformationXZGizmoEntity = nullptr; + FENewEntity* TransformationXYGizmoEntity = nullptr; + FENewEntity* TransformationYZGizmoEntity = nullptr; + FENewEntity* TransformationXZGizmoEntity = nullptr; bool bTransformationXYGizmoActive = false; bool bTransformationYZGizmoActive = false; bool bTransformationXZGizmoActive = false; // Scale part. - FEEntity* ScaleXGizmoEntity = nullptr; - FEEntity* ScaleYGizmoEntity = nullptr; - FEEntity* ScaleZGizmoEntity = nullptr; + FENewEntity* ScaleXGizmoEntity = nullptr; + FENewEntity* ScaleYGizmoEntity = nullptr; + FENewEntity* ScaleZGizmoEntity = nullptr; bool bScaleXGizmoActive = false; bool bScaleYGizmoActive = false; bool bScaleZGizmoActive = false; // Rotate part. - FEEntity* RotateXGizmoEntity = nullptr; - FEEntity* RotateYGizmoEntity = nullptr; - FEEntity* RotateZGizmoEntity = nullptr; + FENewEntity* RotateXGizmoEntity = nullptr; + FENewEntity* RotateYGizmoEntity = nullptr; + FENewEntity* RotateZGizmoEntity = nullptr; bool bRotateXGizmoActive = false; bool bRotateYGizmoActive = false; diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index 19632f1..9814c2e 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -282,7 +282,7 @@ FETexture* FEEditorPreviewManager::GetMaterialPreview(const std::string Material { CreateGameModelPreview(CurrentGameModel->GetObjectID()); - // if some prefab uses this game model we should also update it's preview + // if some Prefab uses this game model we should also update it's preview std::vector PrefabList = RESOURCE_MANAGER.GetPrefabList(); for (size_t j = 0; j < PrefabList.size(); j++) { @@ -312,7 +312,6 @@ FETexture* FEEditorPreviewManager::GetMaterialPreview(const std::string Material void FEEditorPreviewManager::CreateGameModelPreview(const std::string GameModelID) { const FEGameModel* GameModel = RESOURCE_MANAGER.GetGameModel(GameModelID); - if (GameModel == nullptr) return; @@ -468,14 +467,14 @@ void FEEditorPreviewManager::UpdateAllGameModelPreviews() void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) { - FEPrefab* prefab = RESOURCE_MANAGER.GetPrefab(PrefabID); - if (prefab == nullptr) + FEPrefab* Prefab = RESOURCE_MANAGER.GetPrefab(PrefabID); + if (Prefab == nullptr) return; - if (prefab->ComponentsCount() < 1) + if (Prefab->ComponentsCount() < 1) return; - const FEGameModel* GameModel = prefab->GetComponent(0)->GameModel; + const FEGameModel* GameModel = Prefab->GetComponent(0)->GameModel; if (GameModel == nullptr) return; @@ -498,7 +497,7 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) const bool RegularFog = RENDERER.IsDistanceFogEnabled(); RENDERER.SetDistanceFogEnabled(false); - PreviewEntity->Prefab = prefab; + PreviewEntity->Prefab = Prefab; PreviewEntity->SetReceivingShadows(false); BeforePreviewActions(); @@ -550,7 +549,7 @@ FETexture* FEEditorPreviewManager::GetPrefabPreview(const std::string PrefabID) return RESOURCE_MANAGER.NoTexture; } - // if prefab's dirty flag is set we need to update preview + // if Prefab's dirty flag is set we need to update preview if (CurrentPrefab->IsDirty()) { CreatePrefabPreview(PrefabID); @@ -559,7 +558,7 @@ FETexture* FEEditorPreviewManager::GetPrefabPreview(const std::string PrefabID) for (int i = 0; i < CurrentPrefab->ComponentsCount(); i++) { - // if prefab's material dirty flag is set we need to update preview + // if Prefab's material dirty flag is set we need to update preview if (CurrentPrefab->GetComponent(i)->GameModel->GetMaterial() != nullptr && CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->IsDirty()) { CreateMaterialPreview(CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->GetObjectID()); diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index 4cada01..c406f18 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -55,7 +55,7 @@ void FEEditorSelectedObject::SetOnUpdateFunc(void(*Func)()) OnUpdateFunc = Func; } -FEObject* FEEditorSelectedObject::GetSelected() const +FENewEntity* FEEditorSelectedObject::GetSelected() const { return Container; } @@ -70,20 +70,53 @@ void FEEditorSelectedObject::SetDirtyFlag(const bool NewValue) bDirtyFlag = NewValue; } -void FEEditorSelectedObject::SetSelected(FEObject* SelectedObject) +//void FEEditorSelectedObject::SetSelected(FEObject* SelectedObject) +//{ +// if (SelectedObject == nullptr) +// return; +// +// if (Container != SelectedObject) +// bDirtyFlag = true; +// +// if (Container != nullptr && Container->GetType() == FE_TERRAIN && Container != SelectedObject) +// { +// FETerrain* DeselectedTerrain = reinterpret_cast(Container); +// DeselectedTerrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); +// } +// +// // Temporary solution, becuase of the lack of proper ECS system +// FENewEntity* NewEntity = SCENE.GetNewStyleEntityByOldStyleID(SelectedObject->GetObjectID()); +// if (NewEntity != nullptr) +// { +// NewContainer = NewEntity; +// Container = nullptr; +// } +// else +// { +// Container = SelectedObject; +// NewContainer = nullptr; +// } +// +// //Container = SelectedObject; +// if (OnUpdateFunc != nullptr) +// OnUpdateFunc(); +//} + +void FEEditorSelectedObject::SetSelected(FENewEntity* SelectedObject) { if (SelectedObject == nullptr) return; - + + // FIX ME! + //if (Container != nullptr && Container->GetType() == FE_TERRAIN && Container != SelectedObject) + //{ + // FETerrain* DeselectedTerrain = reinterpret_cast(Container); + // DeselectedTerrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); + //} + if (Container != SelectedObject) bDirtyFlag = true; - if (Container != nullptr && Container->GetType() == FE_TERRAIN && Container != SelectedObject) - { - FETerrain* DeselectedTerrain = reinterpret_cast(Container); - DeselectedTerrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); - } - Container = SelectedObject; if (OnUpdateFunc != nullptr) OnUpdateFunc(); @@ -91,10 +124,11 @@ void FEEditorSelectedObject::SetSelected(FEObject* SelectedObject) void FEEditorSelectedObject::Clear() { - if (InstancedSubObjectIndexSelected != -1 && SCENE.GetEntityInstanced(Container->GetObjectID()) != nullptr) + // FIX ME! + /*if (InstancedSubObjectIndexSelected != -1 && SCENE.GetEntityInstanced(Container->GetObjectID()) != nullptr) { SCENE.GetEntityInstanced(Container->GetObjectID())->SetSelectMode(false); - } + }*/ InstancedSubObjectIndexSelected = -1; Container = nullptr; @@ -129,29 +163,37 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons for (size_t i = 0; i < EntityList.size(); i++) { float Distance = 0; - FEAABB Box = SCENE.GetEntity(EntityList[i])->GetAABB(); - if (Box.RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) + + FEEntity* Entity = SCENE.GetEntity(EntityList[i]); + FENewEntity* NewStyleEntity = SCENE.GetNewStyleEntityByOldStyleID(Entity->GetObjectID()); + if (NewStyleEntity != nullptr && NewStyleEntity->HasComponent()) { - if (SCENE.GetEntity(EntityList[i])->GetType() == FE_ENTITY_INSTANCED) + FEAABB Box = Entity->GetAABB().Transform(NewStyleEntity->GetComponent().GetTransformMatrix()); + //FEAABB Box = SCENE.GetEntity(EntityList[i])->GetAABB(); + if (Box.RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) { - FEEntityInstanced* InstancedEntity = reinterpret_cast(SCENE.GetEntity(EntityList[i])); - if (InstancedEntity->IsSelectMode()) + // FIX ME! + /*if (SCENE.GetEntity(EntityList[i])->GetType() == FE_ENTITY_INSTANCED) { - InstancedSubObjectsInfo[InstancedEntity] = std::vector(); - for (size_t j = 0; j < InstancedEntity->InstancedAABB.size(); j++) + FEEntityInstanced* InstancedEntity = reinterpret_cast(SCENE.GetEntity(EntityList[i])); + if (InstancedEntity->IsSelectMode()) { - if(InstancedEntity->InstancedAABB[j].RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) + InstancedSubObjectsInfo[InstancedEntity] = std::vector(); + for (size_t j = 0; j < InstancedEntity->InstancedAABB.size(); j++) { - InstancedSubObjectsInfo[InstancedEntity].push_back(static_cast(j)); + if (InstancedEntity->InstancedAABB[j].RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) + { + InstancedSubObjectsInfo[InstancedEntity].push_back(static_cast(j)); + } } } - } - SELECTED.ObjectsUnderMouse.push_back(InstancedEntity); - } - else - { - SELECTED.ObjectsUnderMouse.push_back(SCENE.GetEntity(EntityList[i])); + SELECTED.ObjectsUnderMouse.push_back(InstancedEntity); + } + else + {*/ + SELECTED.ObjectsUnderMouse.push_back(SCENE.GetEntity(EntityList[i])); + //} } } } @@ -382,34 +424,20 @@ void FEEditorSelectedObject::OnCameraUpdate() const //FE_GL_ERROR(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT)); - // Temporary solution, becuase of the lack of proper ECS system - if (Container != nullptr && Container->GetType() == FE_ENTITY) - { - FEEntity* SelectedEntity = reinterpret_cast(Container); - if (SelectedEntity->Prefab == nullptr) - { - HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); - ENGINE.SetClearColor(OriginalClearColor); - HALO_SELECTION_EFFECT.PostProcess->bActive = true; - - return; - } - } - - if (Container == nullptr) + if (Container == nullptr || !Container->HasComponent()) { HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); ENGINE.SetClearColor(OriginalClearColor); - //FE_GL_ERROR(glClearColor(FE_CLEAR_COLOR.x, FE_CLEAR_COLOR.y, FE_CLEAR_COLOR.z, FE_CLEAR_COLOR.w)); HALO_SELECTION_EFFECT.PostProcess->bActive = true; return; } - - if (Container->GetType() == FE_ENTITY) - { - FEEntity* SelectedEntity = SCENE.GetEntity(Container->GetObjectID()); + FERenderableComponent& RenderableComponent = Container->GetComponent(); + FEEntity* SelectedEntity = RenderableComponent.OldStyleEntity; + + if (SelectedEntity->GetType() == FE_ENTITY) + { for (int i = 0; i < SelectedEntity->Prefab->ComponentsCount(); i++) { FEMaterial* RegularMaterial = SelectedEntity->Prefab->GetComponent(i)->GameModel->Material; @@ -423,16 +451,16 @@ void FEEditorSelectedObject::OnCameraUpdate() const SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; } } - else if (Container->GetType() == FE_ENTITY_INSTANCED) + else if (SelectedEntity->GetType() == FE_ENTITY_INSTANCED) { - FEEntityInstanced* SelectedEntity = reinterpret_cast(SCENE.GetEntity(Container->GetObjectID())); + FEEntityInstanced* SelectedInstancedEntity = reinterpret_cast(SelectedEntity); if (InstancedSubObjectIndexSelected != -1) { - static FEEntity* DummyEntity = SCENE.AddEntity(SelectedEntity->Prefab, "dummyEntity"); + static FEEntity* DummyEntity = SCENE.AddEntity(SelectedInstancedEntity->Prefab, "dummyEntity"); DummyEntity->SetVisibility(true); - DummyEntity->Prefab = SelectedEntity->Prefab; - DummyEntity->Transform = FETransformComponent(SelectedEntity->GetTransformedInstancedMatrix(InstancedSubObjectIndexSelected)); + DummyEntity->Prefab = SelectedInstancedEntity->Prefab; + DummyEntity->Transform = FETransformComponent(SelectedInstancedEntity->GetTransformedInstancedMatrix(InstancedSubObjectIndexSelected)); for (int i = 0; i < DummyEntity->Prefab->ComponentsCount(); i++) { @@ -446,45 +474,135 @@ void FEEditorSelectedObject::OnCameraUpdate() const RENDERER.RenderEntity(DummyEntity, ENGINE.GetCamera(), false, i); - SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; + SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; } DummyEntity->SetVisibility(false); } else { - for (int i = 0; i < SelectedEntity->Prefab->ComponentsCount(); i++) + for (int i = 0; i < SelectedInstancedEntity->Prefab->ComponentsCount(); i++) { - FEMaterial* RegularMaterial = SelectedEntity->Prefab->GetComponent(i)->GameModel->Material; - SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; + FEMaterial* RegularMaterial = SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->Material; + SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawInstancedObjectShader; - FEMaterial* RegularBillboardMaterial = SelectedEntity->Prefab->GetComponent(i)->GameModel->GetBillboardMaterial(); - SelectedEntity->Prefab->GetComponent(i)->GameModel->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); + FEMaterial* RegularBillboardMaterial = SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->GetBillboardMaterial(); + SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); - RENDERER.RenderEntityInstanced(SelectedEntity, ENGINE.GetCamera(), nullptr, false, false, i); + RENDERER.RenderEntityInstanced(SelectedInstancedEntity, ENGINE.GetCamera(), nullptr, false, false, i); HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; - SelectedEntity->Prefab->GetComponent(i)->GameModel->SetBillboardMaterial(RegularBillboardMaterial); - SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; + SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->SetBillboardMaterial(RegularBillboardMaterial); + SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; } } } - else if (Container->GetType() == FE_TERRAIN) - { - FETerrain* SelectedTerrain = SCENE.GetTerrain(Container->GetObjectID()); - - SelectedTerrain->Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); - SelectedTerrain->Shader->UpdateParameterData("baseColor", glm::vec3(1.0f, 0.25f, 0.0f)); - const float RegularLODLevel = SelectedTerrain->GetLODLevel(); - SelectedTerrain->SetLODLevel(0.0f); - RENDERER.RenderTerrain(SelectedTerrain, ENGINE.GetCamera()); - SelectedTerrain->SetLODLevel(RegularLODLevel); - SelectedTerrain->Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); - SelectedTerrain->Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); - } + + //// Temporary solution, becuase of the lack of proper ECS system + //if (Container != nullptr && Container->GetType() == FE_ENTITY) + //{ + // FEEntity* SelectedEntity = reinterpret_cast(Container); + // if (SelectedEntity->Prefab == nullptr) + // { + // HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); + // ENGINE.SetClearColor(OriginalClearColor); + // HALO_SELECTION_EFFECT.PostProcess->bActive = true; + + // return; + // } + //} + + //if (Container == nullptr) + //{ + // HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); + // ENGINE.SetClearColor(OriginalClearColor); + // HALO_SELECTION_EFFECT.PostProcess->bActive = true; + + // return; + //} + + //if (Container->GetType() == FE_ENTITY) + //{ + // FEEntity* SelectedEntity = SCENE.GetEntity(Container->GetObjectID()); + + // for (int i = 0; i < SelectedEntity->Prefab->ComponentsCount(); i++) + // { + // FEMaterial* RegularMaterial = SelectedEntity->Prefab->GetComponent(i)->GameModel->Material; + + // SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; + // HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + // HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + // + // RENDERER.RenderEntity(SelectedEntity, ENGINE.GetCamera(), false, i); + // + // SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; + // } + //} + //else if (Container->GetType() == FE_ENTITY_INSTANCED) + //{ + // FEEntityInstanced* SelectedEntity = reinterpret_cast(SCENE.GetEntity(Container->GetObjectID())); + + // if (InstancedSubObjectIndexSelected != -1) + // { + // static FEEntity* DummyEntity = SCENE.AddEntity(SelectedEntity->Prefab, "dummyEntity"); + // DummyEntity->SetVisibility(true); + // DummyEntity->Prefab = SelectedEntity->Prefab; + // DummyEntity->Transform = FETransformComponent(SelectedEntity->GetTransformedInstancedMatrix(InstancedSubObjectIndexSelected)); + + // for (int i = 0; i < DummyEntity->Prefab->ComponentsCount(); i++) + // { + // FEMaterial* RegularMaterial = DummyEntity->Prefab->GetComponent(i)->GameModel->Material; + + // DummyEntity->Prefab->GetComponent(i)->GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; + + // HALO_SELECTION_EFFECT.HaloMaterial->SetBaseColor(glm::vec3(0.61f, 0.86f, 1.0f)); + // HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + // HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + + // RENDERER.RenderEntity(DummyEntity, ENGINE.GetCamera(), false, i); + + // SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; + // } + + // DummyEntity->SetVisibility(false); + // } + // else + // { + // for (int i = 0; i < SelectedEntity->Prefab->ComponentsCount(); i++) + // { + // FEMaterial* RegularMaterial = SelectedEntity->Prefab->GetComponent(i)->GameModel->Material; + // SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; + // HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + // HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + + // HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawInstancedObjectShader; + // FEMaterial* RegularBillboardMaterial = SelectedEntity->Prefab->GetComponent(i)->GameModel->GetBillboardMaterial(); + // SelectedEntity->Prefab->GetComponent(i)->GameModel->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); + + // RENDERER.RenderEntityInstanced(SelectedEntity, ENGINE.GetCamera(), nullptr, false, false, i); + + // HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; + // SelectedEntity->Prefab->GetComponent(i)->GameModel->SetBillboardMaterial(RegularBillboardMaterial); + // SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; + // } + // } + //} + //else if (Container->GetType() == FE_TERRAIN) + //{ + // FETerrain* SelectedTerrain = SCENE.GetTerrain(Container->GetObjectID()); + + // SelectedTerrain->Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); + // SelectedTerrain->Shader->UpdateParameterData("baseColor", glm::vec3(1.0f, 0.25f, 0.0f)); + // const float RegularLODLevel = SelectedTerrain->GetLODLevel(); + // SelectedTerrain->SetLODLevel(0.0f); + // RENDERER.RenderTerrain(SelectedTerrain, ENGINE.GetCamera()); + // SelectedTerrain->SetLODLevel(RegularLODLevel); + // SelectedTerrain->Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); + // SelectedTerrain->Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); + //} HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); ENGINE.SetClearColor(OriginalClearColor); @@ -513,7 +631,14 @@ void FEEditorSelectedObject::SetSelectedByIndex(const size_t Index) } } - Container = ObjectsUnderMouse[Index]; + // Temporary solution, becuase of the lack of proper ECS system + FENewEntity* NewEntity = SCENE.GetNewStyleEntityByOldStyleID(ObjectsUnderMouse[Index]->GetObjectID()); + if (NewEntity != nullptr) + { + Container = NewEntity; + } + + //Container = ObjectsUnderMouse[Index]; if (OnUpdateFunc != nullptr) OnUpdateFunc(); } @@ -563,18 +688,4 @@ FETerrain* FEEditorSelectedObject::GetTerrain() const } return nullptr; -} - -//template -//T* FEEditorSelectedObject::getSelected(FEObjectType type) -//{ -// if (container == nullptr) -// return nullptr; -// -// if (type == FE_ENTITY || type == FE_ENTITY_INSTANCED) -// { -// return SCENE.getEntity(container->getObjectID()); -// } -// -// return nullptr; -//} \ No newline at end of file +} \ No newline at end of file diff --git a/FEEditorSelectedObject.h b/FEEditorSelectedObject.h index a7ad793..e42431a 100644 --- a/FEEditorSelectedObject.h +++ b/FEEditorSelectedObject.h @@ -18,19 +18,17 @@ class FEEditorSelectedObject void ReInitializeResources(); void SetOnUpdateFunc(void(*Func)()); - FEObject* GetSelected() const; + FENewEntity* GetSelected() const; FEEntity* GetEntity() const; FETerrain* GetTerrain() const; FELight* GetLight() const; - /*template - T* getSelected(FEObjectType type);*/ - bool GetDirtyFlag() const; void SetDirtyFlag(bool NewValue); - void SetSelected(FEObject* SelectedObject); + //void SetSelected(FEObject* SelectedObject); + void SetSelected(FENewEntity* SelectedObject); void Clear(); glm::dvec3 MouseRay(double MouseX, double MouseY) const; @@ -50,7 +48,8 @@ class FEEditorSelectedObject FEShader* FEPixelAccurateInstancedSelection = nullptr; FEShader* FEPixelAccurateSelection = nullptr; private: - FEObject* Container = nullptr; + FENewEntity* Container = nullptr; + //FENewEntity* NewContainer = nullptr; bool bDirtyFlag = false; diff --git a/FEProject.cpp b/FEProject.cpp index 049a421..5a2b8c8 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -61,6 +61,8 @@ void FEProjectManager::CloseCurrentProject() void FEProjectManager::OpenProject(const int ProjectIndex) { + SCENE.Clear(); + PROJECT_MANAGER.SetCurrent(List[ProjectIndex]); PROJECT_MANAGER.GetCurrent()->LoadScene(); IndexChosen = -1; @@ -100,15 +102,15 @@ void FEProjectManager::OpenProject(const int ProjectIndex) PREVIEW_MANAGER.UpdateAll(); SELECTED.Clear(); - // cleaning dirty flag of entities - const std::vector EntityList = SCENE.GetEntityList(); - for (size_t i = 0; i < EntityList.size(); i++) - { - FEEntity* Entity = SCENE.GetEntity(EntityList[i]); - // but before that update AABB - Entity->GetAABB(); - Entity->Transform.SetDirtyFlag(false); - } + // Cleaning dirty flag of entities. + //const std::vector EntityList = SCENE.GetEntityList(); + //for (size_t i = 0; i < EntityList.size(); i++) + //{ + // FEEntity* Entity = SCENE.GetEntity(EntityList[i]); + // // But before that update AABB. + // Entity->GetAABB(); + // Entity->Transform.SetDirtyFlag(false); + //} } void FEProjectManager::DisplayProjectSelection() @@ -1197,6 +1199,11 @@ void FEProject::LoadScene() SCENE.GetEntity(EntityList[i])->SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(EntityList[i])->Transform); + FENewEntity* NewEntity = SCENE.GetNewStyleEntityByOldStyleID(EntityList[i]); + if (NewEntity != nullptr) + { + NewEntity->GetComponent() = SCENE.GetEntity(EntityList[i])->Transform; + } } } else diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index b169fbf..5eddfc6 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit b169fbf3e918652b9e5244945015ac346a3a4a94 +Subproject commit 5eddfc618720cbf75d86cd3312989bb22d66d2d9 From dc96441f56d7bf0e66d1c9bee59f230ceeca750d Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Mon, 1 Jul 2024 21:48:15 -0400 Subject: [PATCH 13/46] Another iteration on moving to ECS. --- FEEditor.cpp | 26 +++--- FEEditor.h | 6 +- FEEditorGizmoManager.cpp | 38 ++++---- FEEditorPreviewManager.cpp | 95 ++++++++++--------- FEEditorPreviewManager.h | 4 +- FEEditorSelectedObject.cpp | 187 +++++++++++++++++++++---------------- FEEditorSelectedObject.h | 4 +- SubSystems/FocalEngine | 2 +- 8 files changed, 193 insertions(+), 169 deletions(-) diff --git a/FEEditor.cpp b/FEEditor.cpp index ea8eeaa..1d2cbc1 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -73,14 +73,14 @@ void FEEditor::SetMouseY(const double NewValue) MouseY = NewValue; } -std::string FEEditor::GetObjectNameInClipboard() +std::string FEEditor::GetSceneEntityIDInClipboard() { - return ObjectNameInClipboard; + return SceneEntityIDInClipboard; } -void FEEditor::SetObjectNameInClipboard(const std::string NewValue) +void FEEditor::SetSceneEntityIDInClipboard(const std::string NewValue) { - ObjectNameInClipboard = NewValue; + SceneEntityIDInClipboard = NewValue; } void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) @@ -187,22 +187,22 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) if (!ImGui::GetIO().WantCaptureKeyboard && Mods == GLFW_MOD_CONTROL && Key == GLFW_KEY_C && Action == GLFW_RELEASE) { - if (SELECTED.GetEntity() != nullptr) - EDITOR.SetObjectNameInClipboard(SELECTED.GetEntity()->GetObjectID()); + if (SELECTED.GetSelected() != nullptr) + EDITOR.SetSceneEntityIDInClipboard(SELECTED.GetSelected()->GetObjectID()); } if (!ImGui::GetIO().WantCaptureKeyboard && Mods == GLFW_MOD_CONTROL && Key == GLFW_KEY_V && Action == GLFW_RELEASE) { - if (!EDITOR.GetObjectNameInClipboard().empty()) + if (!EDITOR.GetSceneEntityIDInClipboard().empty()) { // FIX ME! - FEEntity* NewEntity = SCENE.AddEntity(SCENE.GetEntity(EDITOR.GetObjectNameInClipboard())->Prefab, ""); + // There should be proper FEScene::DuplicateNewStyleEntity that will duplicate the entity and all its components + // Also place it in same scene graph node as the original entity ? + FEEntity* NewEntity = SCENE.AddEntity(SCENE.GetEntity(EDITOR.GetSceneEntityIDInClipboard())->Prefab, ""); FENewEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(NewEntity->GetObjectID()); - NewNewEntity->GetComponent() = SCENE.GetEntity(EDITOR.GetObjectNameInClipboard())->Transform; - NewNewEntity->GetComponent().SetPosition(NewEntity->Transform.GetPosition() * 1.1f); - - //NewEntity->Transform = SCENE.GetEntity(EDITOR.GetObjectNameInClipboard())->Transform; - //NewEntity->Transform.SetPosition(NewEntity->Transform.GetPosition() * 1.1f); + FENewEntity* EntityToCopy = SCENE.GetNewStyleEntity(EDITOR.GetSceneEntityIDInClipboard()); + NewNewEntity->GetComponent() = EntityToCopy->GetComponent(); + NewNewEntity->GetComponent().SetPosition(EntityToCopy->GetComponent().GetPosition() * 1.1f); SELECTED.SetSelected(NewNewEntity); } diff --git a/FEEditor.h b/FEEditor.h index 3d73891..7d55b8f 100644 --- a/FEEditor.h +++ b/FEEditor.h @@ -24,8 +24,8 @@ class FEEditor void SetMouseY(double NewValue); // Clipboard - std::string GetObjectNameInClipboard(); - void SetObjectNameInClipboard(std::string NewValue); + std::string GetSceneEntityIDInClipboard(); + void SetSceneEntityIDInClipboard(std::string NewValue); private: SINGLETON_PRIVATE_PART(FEEditor) @@ -36,7 +36,7 @@ class FEEditor bool bIsCameraInputActive = false; // Clipboard - std::string ObjectNameInClipboard; + std::string SceneEntityIDInClipboard; // Scene window static ImGuiWindow* SceneWindow; diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index 3be6441..c8e547a 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -558,41 +558,39 @@ bool GizmoManager::WasSelected(int Index) { DeactivateAllGizmo(); - if (SELECTED.ObjectsUnderMouse[Index]->GetType() == FE_CAMERA) + if (SELECTED.SceneEntitiesUnderMouse[Index]->GetType() == FE_CAMERA) return true; - FEEntity* SelectedEntity = nullptr; - if (SELECTED.ObjectsUnderMouse[Index]->GetType() == FE_ENTITY) - SelectedEntity = SCENE.GetEntity(SELECTED.ObjectsUnderMouse[Index]->GetObjectID()); + FENewEntity* SelectedEntity = SELECTED.SceneEntitiesUnderMouse[Index]; + FETransformComponent& CurrentTransform = SelectedEntity->GetComponent(); - const int EntityNameHash = SelectedEntity == nullptr ? -1 : SelectedEntity->GetNameHash(); - if (GizmosState == TRANSFORM_GIZMOS && EntityNameHash == TransformationXGizmoEntity->GetNameHash()) + if (GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == TransformationXGizmoEntity->GetObjectID()) { bTransformationXGizmoActive = true; } - else if (GizmosState == TRANSFORM_GIZMOS && EntityNameHash == TransformationYGizmoEntity->GetNameHash()) + else if (GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == TransformationYGizmoEntity->GetObjectID()) { bTransformationYGizmoActive = true; } - else if (GizmosState == TRANSFORM_GIZMOS && EntityNameHash == TransformationZGizmoEntity->GetNameHash()) + else if (GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == TransformationZGizmoEntity->GetObjectID()) { bTransformationZGizmoActive = true; } - else if (GizmosState == TRANSFORM_GIZMOS && EntityNameHash == TransformationXYGizmoEntity->GetNameHash()) + else if (GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == TransformationXYGizmoEntity->GetObjectID()) { bTransformationXYGizmoActive = true; } - else if (GizmosState == TRANSFORM_GIZMOS && EntityNameHash == TransformationYZGizmoEntity->GetNameHash()) + else if (GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == TransformationYZGizmoEntity->GetObjectID()) { bTransformationYZGizmoActive = true; } - else if (GizmosState == TRANSFORM_GIZMOS && EntityNameHash == TransformationXZGizmoEntity->GetNameHash()) + else if (GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == TransformationXZGizmoEntity->GetObjectID()) { bTransformationXZGizmoActive = true; } - else if (GizmosState == SCALE_GIZMOS && EntityNameHash == ScaleXGizmoEntity->GetNameHash()) + else if (GizmosState == SCALE_GIZMOS && SelectedEntity->GetObjectID() == ScaleXGizmoEntity->GetObjectID()) { - if (SelectedEntity != nullptr && SelectedEntity->Transform.IsUniformScalingSet()) + if (SelectedEntity != nullptr && CurrentTransform.IsUniformScalingSet()) { bScaleXGizmoActive = true; bScaleYGizmoActive = true; @@ -601,9 +599,9 @@ bool GizmoManager::WasSelected(int Index) bScaleXGizmoActive = true; } - else if (GizmosState == SCALE_GIZMOS && EntityNameHash == ScaleYGizmoEntity->GetNameHash()) + else if (GizmosState == SCALE_GIZMOS && SelectedEntity->GetObjectID() == ScaleYGizmoEntity->GetObjectID()) { - if (SelectedEntity != nullptr && SelectedEntity->Transform.IsUniformScalingSet()) + if (SelectedEntity != nullptr && CurrentTransform.IsUniformScalingSet()) { bScaleXGizmoActive = true; bScaleYGizmoActive = true; @@ -612,9 +610,9 @@ bool GizmoManager::WasSelected(int Index) bScaleYGizmoActive = true; } - else if (GizmosState == SCALE_GIZMOS && EntityNameHash == ScaleZGizmoEntity->GetNameHash()) + else if (GizmosState == SCALE_GIZMOS && SelectedEntity->GetObjectID() == ScaleZGizmoEntity->GetObjectID()) { - if (SelectedEntity != nullptr && SelectedEntity->Transform.IsUniformScalingSet()) + if (SelectedEntity != nullptr && CurrentTransform.IsUniformScalingSet()) { bScaleXGizmoActive = true; bScaleYGizmoActive = true; @@ -623,15 +621,15 @@ bool GizmoManager::WasSelected(int Index) bScaleZGizmoActive = true; } - else if (GizmosState == ROTATE_GIZMOS && EntityNameHash == RotateXGizmoEntity->GetNameHash()) + else if (GizmosState == ROTATE_GIZMOS && SelectedEntity->GetObjectID() == RotateXGizmoEntity->GetObjectID()) { bRotateXGizmoActive = true; } - else if (GizmosState == ROTATE_GIZMOS && EntityNameHash == RotateYGizmoEntity->GetNameHash()) + else if (GizmosState == ROTATE_GIZMOS && SelectedEntity->GetObjectID() == RotateYGizmoEntity->GetObjectID()) { bRotateYGizmoActive = true; } - else if (GizmosState == ROTATE_GIZMOS && EntityNameHash == RotateZGizmoEntity->GetNameHash()) + else if (GizmosState == ROTATE_GIZMOS && SelectedEntity->GetObjectID() == RotateZGizmoEntity->GetObjectID()) { bRotateZGizmoActive = true; } diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index 9814c2e..1971ac8 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -6,7 +6,7 @@ FEEditorPreviewManager::FEEditorPreviewManager() {} FEEditorPreviewManager::~FEEditorPreviewManager() {} glm::vec4 FEEditorPreviewManager::OriginalClearColor = glm::vec4(); -FETransformComponent FEEditorPreviewManager::OriginalMeshTransform = FETransformComponent(); +FETransformComponent FEEditorPreviewManager::OriginalTransform = FETransformComponent(); glm::vec3 FEEditorPreviewManager::OriginalCameraPosition = glm::vec3(); float FEEditorPreviewManager::OriginalAspectRation = 0.0f; float FEEditorPreviewManager::OriginalCameraPitch = 0.0f; @@ -19,8 +19,8 @@ void FEEditorPreviewManager::InitializeResources() PreviewFB = RESOURCE_MANAGER.CreateFramebuffer(FE_COLOR_ATTACHMENT | FE_DEPTH_ATTACHMENT, 128, 128); PreviewGameModel = new FEGameModel(nullptr, nullptr, "editorPreviewGameModel"); PreviewPrefab = new FEPrefab(PreviewGameModel, "editorPreviewPrefab"); - PreviewEntity = SCENE.AddEntity(PreviewPrefab, "editorPreviewEntity"); - PreviewEntity->SetVisibility(false); + PreviewEntity = SCENE.AddNewStyleEntity("editorPreviewEntity"); + PreviewEntity->AddComponent(PreviewGameModel).SetVisibility(false); MeshPreviewMaterial = RESOURCE_MANAGER.CreateMaterial("meshPreviewMaterial"); RESOURCE_MANAGER.MakeMaterialStandard(MeshPreviewMaterial); MeshPreviewMaterial->Shader = RESOURCE_MANAGER.CreateShader("FEMeshPreviewShader", RESOURCE_MANAGER.LoadGLSL("Resources//Materials//FE_MeshPreview_VS.glsl").c_str(), @@ -36,8 +36,8 @@ void FEEditorPreviewManager::InitializeResources() void FEEditorPreviewManager::ReInitializeEntities() { - PreviewEntity = SCENE.AddEntity(PreviewPrefab, "editorPreviewEntity"); - PreviewEntity->SetVisibility(false); + PreviewEntity = SCENE.AddNewStyleEntity("editorPreviewEntity"); + PreviewEntity->AddComponent(PreviewGameModel).SetVisibility(false); } void FEEditorPreviewManager::UpdateAll() @@ -81,12 +81,12 @@ void FEEditorPreviewManager::BeforePreviewActions() OriginalExposure = ENGINE.GetCamera()->GetExposure(); ENGINE.GetCamera()->SetExposure(1.0f); - OriginalMeshTransform = PreviewEntity->Transform; + OriginalTransform = PreviewEntity->GetComponent(); // The transform impacts the AABB. Therefore, the necessary values must be set prior to any calculations. - PreviewEntity->Transform.SetPosition(glm::vec3(0.0, 0.0, 0.0)); - PreviewEntity->Transform.SetScale(glm::vec3(1.0, 1.0, 1.0)); - PreviewEntity->Transform.SetRotation(glm::vec3(15.0, -15.0, 0.0)); + PreviewEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, 0.0)); + PreviewEntity->GetComponent().SetScale(glm::vec3(1.0, 1.0, 1.0)); + PreviewEntity->GetComponent().SetRotation(glm::vec3(15.0, -15.0, 0.0)); ENGINE.GetCamera()->SetAspectRatio(1.0f); FE_GL_ERROR(glViewport(0, 0, 128, 128)); @@ -95,13 +95,13 @@ void FEEditorPreviewManager::BeforePreviewActions() ENGINE.GetCamera()->SetRoll(0.0f); ENGINE.GetCamera()->SetYaw(0.0f); - PreviewEntity->SetVisibility(true); + PreviewEntity->GetComponent().SetVisibility(true); } void FEEditorPreviewManager::AfterPreviewActions() { // We are reversing all of our previously applied transformations. - PreviewEntity->Transform = OriginalMeshTransform; + PreviewEntity->GetComponent() = OriginalTransform; ENGINE.GetCamera()->SetPosition(OriginalCameraPosition); ENGINE.GetCamera()->SetAspectRatio(OriginalAspectRation); @@ -113,7 +113,7 @@ void FEEditorPreviewManager::AfterPreviewActions() ENGINE.SetClearColor(OriginalClearColor); - PreviewEntity->SetVisibility(false); + PreviewEntity->GetComponent().SetVisibility(false); } void FEEditorPreviewManager::CreateMeshPreview(const std::string MeshID) @@ -127,13 +127,15 @@ void FEEditorPreviewManager::CreateMeshPreview(const std::string MeshID) BeforePreviewActions(); - FEAABB MeshAABB = PreviewEntity->GetAABB(); - const glm::vec3 min = MeshAABB.GetMin(); - const glm::vec3 max = MeshAABB.GetMax(); + //FEAABB MeshAABB = PreviewEntity->GetAABB(); + FEAABB MeshAABB = PreviewEntity->GetComponent().GameModel->Mesh->GetAABB(); + MeshAABB.Transform(PreviewEntity->GetComponent().GetTransformMatrix()); + const glm::vec3 Min = MeshAABB.GetMin(); + const glm::vec3 Max = MeshAABB.GetMax(); - const float XSize = sqrt((max.x - min.x) * (max.x - min.x)); - const float YSize = sqrt((max.y - min.y) * (max.y - min.y)); - const float ZSize = sqrt((max.z - min.z) * (max.z - min.z)); + const float XSize = sqrt((Max.x - Min.x) * (Max.x - Min.x)); + const float YSize = sqrt((Max.y - Min.y) * (Max.y - Min.y)); + const float ZSize = sqrt((Max.z - Min.z) * (Max.z - Min.z)); FEDirectionalLight* CurrentDirectionalLight = nullptr; const std::vector LightList = SCENE.GetLightsList(); @@ -152,11 +154,11 @@ void FEEditorPreviewManager::CreateMeshPreview(const std::string MeshID) CurrentDirectionalLight->SetIntensity(10.0f); // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. - PreviewEntity->Transform.SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); + PreviewEntity->GetComponent().SetPosition(-glm::vec3(Max.x - XSize / 2.0f, Max.y - YSize / 2.0f, Max.z - ZSize / 2.0f)); ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); - // rendering mesh to texture - RENDERER.RenderEntity(PreviewEntity, ENGINE.GetCamera()); + // Rendering mesh to texture. + RENDERER.RenderGameModelComponent(PreviewEntity->GetComponent(), PreviewEntity->GetComponent(), ENGINE.GetCamera()); CurrentDirectionalLight->Transform.SetRotation(RegularLightRotation); CurrentDirectionalLight->SetIntensity(RegularLightIntensity); @@ -226,14 +228,13 @@ void FEEditorPreviewManager::CreateMaterialPreview(const std::string MaterialID) PreviewGameModel->Mesh = RESOURCE_MANAGER.GetMesh("7F251E3E0D08013E3579315F"/*"sphere"*/); PreviewGameModel->Material = PreviewMaterial; - PreviewEntity->SetReceivingShadows(false); - + PreviewEntity->GetComponent().SetReceivingShadows(false); BeforePreviewActions(); ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, 70.0f)); - // rendering material to texture - RENDERER.RenderEntityForward(PreviewEntity, ENGINE.GetCamera(), true); + // Rendering material to texture + RENDERER.RenderGameModelComponentForward(PreviewEntity->GetComponent(), PreviewEntity->GetComponent(), ENGINE.GetCamera(), true); CurrentDirectionalLight->Transform.SetRotation(RegularLightRotation); CurrentDirectionalLight->SetIntensity(RegularLightIntensity); @@ -336,11 +337,12 @@ void FEEditorPreviewManager::CreateGameModelPreview(const std::string GameModelI PreviewGameModel->Mesh = GameModel->Mesh; PreviewGameModel->Material = GameModel->Material; - PreviewEntity->SetReceivingShadows(false); - + PreviewEntity->GetComponent().SetReceivingShadows(false); BeforePreviewActions(); - FEAABB MeshAABB = PreviewEntity->GetAABB(); + //FEAABB MeshAABB = PreviewEntity->GetAABB(); + FEAABB MeshAABB = PreviewEntity->GetComponent().GameModel->Mesh->GetAABB(); + MeshAABB.Transform(PreviewEntity->GetComponent().GetTransformMatrix()); const glm::vec3 min = MeshAABB.GetMin(); const glm::vec3 max = MeshAABB.GetMax(); @@ -349,11 +351,11 @@ void FEEditorPreviewManager::CreateGameModelPreview(const std::string GameModelI const float ZSize = sqrt((max.z - min.z) * (max.z - min.z)); // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. - PreviewEntity->Transform.SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); + PreviewEntity->GetComponent().SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); // rendering game model to texture - RENDERER.RenderEntityForward(PreviewEntity, ENGINE.GetCamera(), true); + RENDERER.RenderGameModelComponentForward(PreviewEntity->GetComponent(), PreviewEntity->GetComponent(), ENGINE.GetCamera(), true); CurrentDirectionalLight->Transform.SetRotation(RegularLightRotation); CurrentDirectionalLight->SetIntensity(RegularLightIntensity); @@ -393,8 +395,7 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel PreviewGameModel->Mesh = GameModel->Mesh; PreviewGameModel->Material = GameModel->Material; - PreviewEntity->SetReceivingShadows(false); - + PreviewEntity->GetComponent().SetReceivingShadows(false); if (*ResultingTexture == nullptr) *ResultingTexture = RESOURCE_MANAGER.CreateSameFormatTexture(PreviewFB->GetColorAttachment()); FETexture* TempTexture = PreviewFB->GetColorAttachment(); @@ -402,7 +403,9 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel BeforePreviewActions(); - FEAABB MeshAABB = PreviewEntity->GetAABB(); + //FEAABB MeshAABB = PreviewEntity->GetAABB(); + FEAABB MeshAABB = PreviewEntity->GetComponent().GameModel->Mesh->GetAABB(); + MeshAABB.Transform(PreviewEntity->GetComponent().GetTransformMatrix()); const glm::vec3 min = MeshAABB.GetMin(); const glm::vec3 max = MeshAABB.GetMax(); @@ -411,11 +414,11 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel const float ZSize = sqrt((max.z - min.z) * (max.z - min.z)); // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. - PreviewEntity->Transform.SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); + PreviewEntity->GetComponent().SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); // rendering game model to texture - RENDERER.RenderEntityForward(PreviewEntity, ENGINE.GetCamera(), true); + RENDERER.RenderGameModelComponentForward(PreviewEntity->GetComponent(), PreviewEntity->GetComponent(), ENGINE.GetCamera(), true); CurrentDirectionalLight->Transform.SetRotation(RegularLightRotation); CurrentDirectionalLight->SetIntensity(RegularLightIntensity); @@ -474,7 +477,7 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) if (Prefab->ComponentsCount() < 1) return; - const FEGameModel* GameModel = Prefab->GetComponent(0)->GameModel; + FEGameModel* GameModel = Prefab->GetComponent(0)->GameModel; if (GameModel == nullptr) return; @@ -497,13 +500,16 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) const bool RegularFog = RENDERER.IsDistanceFogEnabled(); RENDERER.SetDistanceFogEnabled(false); - PreviewEntity->Prefab = Prefab; - PreviewEntity->SetReceivingShadows(false); - + //Fix ME! + //PreviewEntity->Prefab = Prefab; + PreviewEntity->GetComponent().GameModel = GameModel; + PreviewEntity->GetComponent().SetReceivingShadows(false); BeforePreviewActions(); - PreviewEntity->SetDirtyFlag(true); - FEAABB MeshAABB = PreviewEntity->GetAABB(); + //PreviewEntity->SetDirtyFlag(true); + //FEAABB MeshAABB = PreviewEntity->GetAABB(); + FEAABB MeshAABB = PreviewEntity->GetComponent().GameModel->Mesh->GetAABB(); + MeshAABB.Transform(PreviewEntity->GetComponent().GetTransformMatrix()); const glm::vec3 min = MeshAABB.GetMin(); const glm::vec3 max = MeshAABB.GetMax(); @@ -512,13 +518,14 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) const float ZSize = sqrt((max.z - min.z) * (max.z - min.z)); // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. - PreviewEntity->Transform.SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); + PreviewEntity->GetComponent().SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); // rendering game model to texture - RENDERER.RenderEntityForward(PreviewEntity, ENGINE.GetCamera(), true); + RENDERER.RenderGameModelComponentForward(PreviewEntity->GetComponent(), PreviewEntity->GetComponent(), ENGINE.GetCamera(), true); - PreviewEntity->Prefab = PreviewPrefab; + //PreviewEntity->Prefab = PreviewPrefab; + PreviewEntity->GetComponent().GameModel = PreviewGameModel; CurrentDirectionalLight->Transform.SetRotation(RegularLightRotation); CurrentDirectionalLight->SetIntensity(RegularLightIntensity); diff --git a/FEEditorPreviewManager.h b/FEEditorPreviewManager.h index dfed7de..aebf487 100644 --- a/FEEditorPreviewManager.h +++ b/FEEditorPreviewManager.h @@ -30,7 +30,7 @@ class FEEditorPreviewManager void UpdateAll(); FEFramebuffer* PreviewFB; - FEEntity* PreviewEntity; + FENewEntity* PreviewEntity; FEPrefab* PreviewPrefab; FEGameModel* PreviewGameModel; FEMaterial* MeshPreviewMaterial; @@ -41,7 +41,7 @@ class FEEditorPreviewManager std::unordered_map PrefabPreviewTextures; static glm::vec4 OriginalClearColor; - static FETransformComponent OriginalMeshTransform; + static FETransformComponent OriginalTransform; static glm::vec3 OriginalCameraPosition; static float OriginalAspectRation; static float OriginalCameraPitch; diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index c406f18..a205a1c 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -155,7 +155,7 @@ glm::dvec3 FEEditorSelectedObject::MouseRay(const double MouseX, const double Mo void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, const double MouseY) { - SELECTED.ObjectsUnderMouse.clear(); + SELECTED.SceneEntitiesUnderMouse.clear(); SELECTED.InstancedSubObjectsInfo.clear(); const glm::vec3 MouseRayVector = MouseRay(MouseX, MouseY); @@ -188,26 +188,27 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons } } - SELECTED.ObjectsUnderMouse.push_back(InstancedEntity); + SELECTED.SceneEntitiesUnderMouse.push_back(InstancedEntity); } else {*/ - SELECTED.ObjectsUnderMouse.push_back(SCENE.GetEntity(EntityList[i])); + SELECTED.SceneEntitiesUnderMouse.push_back(NewStyleEntity/*SCENE.GetEntity(EntityList[i])*/); //} } } } - const std::vector TerrainList = SCENE.GetTerrainList(); + // FIX ME! + /*const std::vector TerrainList = SCENE.GetTerrainList(); for (size_t i = 0; i < TerrainList.size(); i++) { float Distance = 0; FEAABB Box = SCENE.GetTerrain(TerrainList[i])->GetAABB(); if (Box.RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) { - SELECTED.ObjectsUnderMouse.push_back(SCENE.GetTerrain(TerrainList[i])); + SELECTED.SceneEntitiesUnderMouse.push_back(SCENE.GetTerrain(TerrainList[i])); } - } + }*/ } int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, const double MouseY) @@ -224,7 +225,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons ENGINE.SetClearColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.0f)); FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); - for (size_t i = 0; i < SELECTED.ObjectsUnderMouse.size(); i++) + for (size_t i = 0; i < SELECTED.SceneEntitiesUnderMouse.size(); i++) { #ifdef EDITOR_SELECTION_DEBUG_MODE int r = (i + 1) * 50 & 255; @@ -235,82 +236,108 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons int g = ((i + 1) >> 8) & 255; int b = ((i + 1) >> 16) & 255; #endif - - if (SELECTED.ObjectsUnderMouse[i]->GetType() == FE_ENTITY) + FENewEntity* PotentiallySelectedEntity = SELECTED.SceneEntitiesUnderMouse[i]; + if (PotentiallySelectedEntity->HasComponent()) { - PotentiallySelectedEntity = SCENE.GetEntity(SELECTED.ObjectsUnderMouse[i]->GetObjectID()); - if (!PotentiallySelectedEntity->IsVisible()) + FERenderableComponent& RenderableComponent = PotentiallySelectedEntity->GetComponent(); + if (!RenderableComponent.OldStyleEntity->IsVisible()) continue; - for (int j = 0; j < PotentiallySelectedEntity->Prefab->ComponentsCount(); j++) + for (int j = 0; j < RenderableComponent.OldStyleEntity->Prefab->ComponentsCount(); j++) { - FEMaterial* RegularMaterial = PotentiallySelectedEntity->Prefab->GetComponent(j)->GameModel->Material; - PotentiallySelectedEntity->Prefab->GetComponent(j)->GameModel->Material = PixelAccurateSelectionMaterial; + FEMaterial* RegularMaterial = RenderableComponent.OldStyleEntity->Prefab->GetComponent(j)->GameModel->Material; + RenderableComponent.OldStyleEntity->Prefab->GetComponent(j)->GameModel->Material = PixelAccurateSelectionMaterial; PixelAccurateSelectionMaterial->SetBaseColor(glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - RENDERER.RenderEntity(PotentiallySelectedEntity, ENGINE.GetCamera(), false, j); + RENDERER.RenderEntity(RenderableComponent.OldStyleEntity, ENGINE.GetCamera(), false, j); - PotentiallySelectedEntity->Prefab->GetComponent(j)->GameModel->Material = RegularMaterial; + RenderableComponent.OldStyleEntity->Prefab->GetComponent(j)->GameModel->Material = RegularMaterial; } + PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr); PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr, 1); } - else if (SELECTED.ObjectsUnderMouse[i]->GetType() == FE_ENTITY_INSTANCED) - { - FEEntityInstanced* PotentiallySelectedEntityInstanced = reinterpret_cast(SCENE.GetEntity((SELECTED.ObjectsUnderMouse[i]->GetObjectID()))); - if (!PotentiallySelectedEntityInstanced->IsVisible()) - continue; - - if (InstancedSubObjectsInfo.find(PotentiallySelectedEntityInstanced) == InstancedSubObjectsInfo.end()) - { - for (int j = 0; j < PotentiallySelectedEntityInstanced->Prefab->ComponentsCount(); j++) - { - FEMaterial* RegularMaterial = PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->Material; - PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->Material = PixelAccurateSelectionMaterial; - - PixelAccurateSelectionMaterial->SetBaseColor(glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); - PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); - PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - - PixelAccurateSelectionMaterial->Shader = FEPixelAccurateInstancedSelection; - FEMaterial* RegularBillboardMaterials = PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->GetBillboardMaterial(); - PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->SetBillboardMaterial(PixelAccurateSelectionMaterial); - RENDERER.RenderEntityInstanced(PotentiallySelectedEntityInstanced, ENGINE.GetCamera(), nullptr, false, false, j); - PixelAccurateSelectionMaterial->Shader = FEPixelAccurateSelection; - PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->SetBillboardMaterial(RegularBillboardMaterials); - PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->Material = RegularMaterial; - - PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr); - PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr, 1); - } - } - } - else if (SELECTED.ObjectsUnderMouse[i]->GetType() == FE_TERRAIN) - { - FETerrain* PotentiallySelectedTerrain = SCENE.GetTerrain(SELECTED.ObjectsUnderMouse[i]->GetObjectID()); - if (PotentiallySelectedTerrain != nullptr) - { - if (!PotentiallySelectedTerrain->IsVisible()) - continue; - - PotentiallySelectedTerrain->Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); - PotentiallySelectedTerrain->Shader->UpdateParameterData("baseColor", glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); - RENDERER.RenderTerrain(PotentiallySelectedTerrain, ENGINE.GetCamera()); - PotentiallySelectedTerrain->Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); - PotentiallySelectedTerrain->Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); - } - } + //if (SELECTED.SceneEntitiesUnderMouse[i]->GetType() == FE_ENTITY) + //{ + // PotentiallySelectedEntity = SCENE.GetEntity(SELECTED.SceneEntitiesUnderMouse[i]->GetObjectID()); + // if (!PotentiallySelectedEntity->IsVisible()) + // continue; + + // for (int j = 0; j < PotentiallySelectedEntity->Prefab->ComponentsCount(); j++) + // { + // FEMaterial* RegularMaterial = PotentiallySelectedEntity->Prefab->GetComponent(j)->GameModel->Material; + // PotentiallySelectedEntity->Prefab->GetComponent(j)->GameModel->Material = PixelAccurateSelectionMaterial; + // PixelAccurateSelectionMaterial->SetBaseColor(glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); + // PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); + // PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + // PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + + // RENDERER.RenderEntity(PotentiallySelectedEntity, ENGINE.GetCamera(), false, j); + + // PotentiallySelectedEntity->Prefab->GetComponent(j)->GameModel->Material = RegularMaterial; + // } + // PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr); + // PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr, 1); + //} + //else if (SELECTED.SceneEntitiesUnderMouse[i]->GetType() == FE_ENTITY_INSTANCED) + //{ + // FEEntityInstanced* PotentiallySelectedEntityInstanced = reinterpret_cast(SCENE.GetEntity((SELECTED.SceneEntitiesUnderMouse[i]->GetObjectID()))); + // if (!PotentiallySelectedEntityInstanced->IsVisible()) + // continue; + + // if (InstancedSubObjectsInfo.find(PotentiallySelectedEntityInstanced) == InstancedSubObjectsInfo.end()) + // { + // for (int j = 0; j < PotentiallySelectedEntityInstanced->Prefab->ComponentsCount(); j++) + // { + // FEMaterial* RegularMaterial = PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->Material; + // PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->Material = PixelAccurateSelectionMaterial; + + // PixelAccurateSelectionMaterial->SetBaseColor(glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); + // PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); + // PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + // PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + + // PixelAccurateSelectionMaterial->Shader = FEPixelAccurateInstancedSelection; + // FEMaterial* RegularBillboardMaterials = PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->GetBillboardMaterial(); + // PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->SetBillboardMaterial(PixelAccurateSelectionMaterial); + + // RENDERER.RenderEntityInstanced(PotentiallySelectedEntityInstanced, ENGINE.GetCamera(), nullptr, false, false, j); + + // PixelAccurateSelectionMaterial->Shader = FEPixelAccurateSelection; + // PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->SetBillboardMaterial(RegularBillboardMaterials); + // PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->Material = RegularMaterial; + + // PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr); + // PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr, 1); + // } + // } + //} + //else if (SELECTED.SceneEntitiesUnderMouse[i]->GetType() == FE_TERRAIN) + //{ + // FETerrain* PotentiallySelectedTerrain = SCENE.GetTerrain(SELECTED.SceneEntitiesUnderMouse[i]->GetObjectID()); + // if (PotentiallySelectedTerrain != nullptr) + // { + // if (!PotentiallySelectedTerrain->IsVisible()) + // continue; + + // PotentiallySelectedTerrain->Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); + // PotentiallySelectedTerrain->Shader->UpdateParameterData("baseColor", glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); + // RENDERER.RenderTerrain(PotentiallySelectedTerrain, ENGINE.GetCamera()); + // PotentiallySelectedTerrain->Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); + // PotentiallySelectedTerrain->Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); + // } + //} } - int LastColorShiftIndex = static_cast(SELECTED.ObjectsUnderMouse.size() - 1); + int LastColorShiftIndex = static_cast(SELECTED.SceneEntitiesUnderMouse.size() - 1); - auto it = InstancedSubObjectsInfo.begin(); + // FIX ME! + /*auto it = InstancedSubObjectsInfo.begin(); while (it != InstancedSubObjectsInfo.end()) { for (size_t j = 0; j < it->second.size(); j++) @@ -341,7 +368,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons DummyEntity->SetVisibility(false); } it++; - } + }*/ FE_GL_ERROR(glReadPixels(static_cast(MouseX), GLint(ENGINE.GetRenderTargetHeight() - MouseY), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, ColorUnderMouse)); PixelAccurateSelectionFB->UnBind(); @@ -349,7 +376,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons ENGINE.SetClearColor(OriginalClearColor); #ifndef EDITOR_SELECTION_DEBUG_MODE - if (!SELECTED.ObjectsUnderMouse.empty()) + if (!SELECTED.SceneEntitiesUnderMouse.empty()) { ColorIndex = 0; ColorIndex |= static_cast(ColorUnderMouse[2]); @@ -360,9 +387,9 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons ColorIndex -= 1; - if (ColorIndex != -1 && ColorIndex >= static_cast(SELECTED.ObjectsUnderMouse.size())) + if (ColorIndex != -1 && ColorIndex >= static_cast(SELECTED.SceneEntitiesUnderMouse.size())) { - ColorIndex -= static_cast(SELECTED.ObjectsUnderMouse.size()); + ColorIndex -= static_cast(SELECTED.SceneEntitiesUnderMouse.size()); const FEEntityInstanced* SelectedSubObjectInInstance = nullptr; auto it = InstancedSubObjectsInfo.begin(); @@ -381,9 +408,9 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons if (SelectedSubObjectInInstance != nullptr) { - for (size_t i = 0; i < SELECTED.ObjectsUnderMouse.size(); i++) + for (size_t i = 0; i < SELECTED.SceneEntitiesUnderMouse.size(); i++) { - if (SELECTED.ObjectsUnderMouse[i]->GetObjectID() == SelectedSubObjectInInstance->GetObjectID()) + if (SELECTED.SceneEntitiesUnderMouse[i]->GetObjectID() == SelectedSubObjectInInstance->GetObjectID()) { return static_cast(i); } @@ -501,7 +528,7 @@ void FEEditorSelectedObject::OnCameraUpdate() const } } - //// Temporary solution, becuase of the lack of proper ECS system + //// Temporary solution, because of the lack of proper ECS system //if (Container != nullptr && Container->GetType() == FE_ENTITY) //{ // FEEntity* SelectedEntity = reinterpret_cast(Container); @@ -616,29 +643,23 @@ int FEEditorSelectedObject::DebugGetLastColorIndex() const void FEEditorSelectedObject::SetSelectedByIndex(const size_t Index) { - if (Index < 0 || Index >= ObjectsUnderMouse.size()) + if (Index < 0 || Index >= SceneEntitiesUnderMouse.size()) return; if (Container != nullptr) { - if (SCENE.GetEntityInstanced(Container->GetObjectID()) != nullptr) + // FIX ME! + /*if (SCENE.GetEntityInstanced(Container->GetObjectID()) != nullptr) { - if (ObjectsUnderMouse[Index]->GetObjectID() != Container->GetObjectID()) + if (SceneEntitiesUnderMouse[Index]->GetObjectID() != Container->GetObjectID()) { SCENE.GetEntityInstanced(Container->GetObjectID())->SetSelectMode(false); InstancedSubObjectIndexSelected = -1; } - } - } - - // Temporary solution, becuase of the lack of proper ECS system - FENewEntity* NewEntity = SCENE.GetNewStyleEntityByOldStyleID(ObjectsUnderMouse[Index]->GetObjectID()); - if (NewEntity != nullptr) - { - Container = NewEntity; + }*/ } - //Container = ObjectsUnderMouse[Index]; + Container = SceneEntitiesUnderMouse[Index]; if (OnUpdateFunc != nullptr) OnUpdateFunc(); } diff --git a/FEEditorSelectedObject.h b/FEEditorSelectedObject.h index e42431a..b1b6c4d 100644 --- a/FEEditorSelectedObject.h +++ b/FEEditorSelectedObject.h @@ -27,13 +27,12 @@ class FEEditorSelectedObject bool GetDirtyFlag() const; void SetDirtyFlag(bool NewValue); - //void SetSelected(FEObject* SelectedObject); void SetSelected(FENewEntity* SelectedObject); void Clear(); glm::dvec3 MouseRay(double MouseX, double MouseY) const; void DetermineEntityUnderMouse(double MouseX, double MouseY); - std::vector ObjectsUnderMouse; + std::vector SceneEntitiesUnderMouse; bool CheckForSelectionisNeeded = false; int GetIndexOfObjectUnderMouse(double MouseX, double MouseY); @@ -49,7 +48,6 @@ class FEEditorSelectedObject FEShader* FEPixelAccurateSelection = nullptr; private: FENewEntity* Container = nullptr; - //FENewEntity* NewContainer = nullptr; bool bDirtyFlag = false; diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 5eddfc6..a0a4c93 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 5eddfc618720cbf75d86cd3312989bb22d66d2d9 +Subproject commit a0a4c936fc5144f177827d703c8542cd1bbd20ac From 0f51264f92e2745c5bf3d59d615d89fa70acfe5d Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Tue, 2 Jul 2024 15:10:03 -0400 Subject: [PATCH 14/46] Facilitated engine update related to ECS. --- EditorWindows/InspectorWindow.cpp | 1046 ++++++++++++++-------------- EditorWindows/SceneGraphWindow.cpp | 19 +- FEEditor.cpp | 51 +- FEEditorGizmoManager.cpp | 461 ++++++------ FEEditorSelectedObject.cpp | 72 +- FEProject.cpp | 41 +- SubSystems/FocalEngine | 2 +- 7 files changed, 872 insertions(+), 820 deletions(-) diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index d6b3461..ef9d237 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -143,16 +143,14 @@ void FEEditorInspectorWindow::ShowTransformConfiguration(FEObject* Object, FETra // ********************* REAL WORLD COMPARISON SCALE ********************* if (Object->GetType() == FE_ENTITY || Object->GetType() == FE_ENTITY_INSTANCED) { - FEEntity* Entity = SCENE.GetEntity(Object->GetObjectID()); - FENewEntity* NewStyleEntity = SCENE.GetNewStyleEntityByOldStyleID(Object->GetObjectID()); + FENewEntity* Entity = SCENE.GetNewStyleEntity(Object->GetObjectID()); + if (Entity == nullptr) + return; - //// Temporary solution, becuase of the lack of proper ECS system - //if (Object->GetType() == FE_ENTITY) - //{ - // Entity = reinterpret_cast(Object); - //} + if (Entity->HasComponent() == false) + return; - FEAABB RealAABB = Entity->GetAABB().Transform(NewStyleEntity->GetComponent().GetTransformMatrix()); + FEAABB RealAABB = Entity->GetComponent().GameModel->GetMesh()->GetAABB().Transform(Entity->GetComponent().GetTransformMatrix()); const glm::vec3 Min = RealAABB.GetMin(); const glm::vec3 Max = RealAABB.GetMax(); @@ -422,541 +420,567 @@ void FEEditorInspectorWindow::Render() ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); ImGui::Begin("Inspector", nullptr, ImGuiWindowFlags_None); - - // Test new ECS. + if (SELECTED.GetSelected() == nullptr) { ImGui::PopStyleVar(); ImGui::End(); return; } - else - { - FENewEntity* NewStyleEntity = SELECTED.GetSelected(); - if (NewStyleEntity->HasComponent()) - { - FETagComponent& Tag = NewStyleEntity->GetComponent(); - char Buffer[256]; - memset(Buffer, 0, 256); - strcpy_s(Buffer, Tag.Tag.c_str()); - if (ImGui::InputText("Tag", Buffer, 256)) - { - Tag.Tag = std::string(Buffer); - } - } - if (NewStyleEntity->HasComponent()) - { - FETransformComponent& Transform = NewStyleEntity->GetComponent(); - ShowTransformConfiguration(NewStyleEntity->GetName(), &Transform); - } + FENewEntity* EntitySelected = SELECTED.GetSelected(); - /*if (NewStyleEntity->HasComponent()) + if (EntitySelected->HasComponent()) + { + FETagComponent& Tag = EntitySelected->GetComponent(); + char Buffer[256]; + memset(Buffer, 0, 256); + strcpy_s(Buffer, Tag.Tag.c_str()); + if (ImGui::InputText("Tag", Buffer, 256)) { - FERenderableComponent& Renderable = NewStyleEntity->GetComponent(); - if (Renderable.OldStyleEntity != nullptr) - { - FEEntity* OldStyleEntity = Renderable.OldStyleEntity; - ShowTransformConfiguration(OldStyleEntity, &OldStyleEntity->Transform); - } - }*/ - - - ImGui::PopStyleVar(); - ImGui::End(); - return; + Tag.Tag = std::string(Buffer); + } } - - if (SELECTED.GetSelected() == nullptr) + if (EntitySelected->HasComponent()) { - ImGui::PopStyleVar(); - ImGui::End(); - return; + FETransformComponent& Transform = EntitySelected->GetComponent(); + ShowTransformConfiguration(EntitySelected->GetName(), &Transform); } - if (SELECTED.GetEntity() != nullptr) + if (EntitySelected->HasComponent()) { - FEEntity* Entity = SELECTED.GetEntity(); - - if (Entity->GetType() == FE_ENTITY) - { - ShowTransformConfiguration(Entity, &Entity->Transform); - - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f)); - - ImGui::InputInt("Force old matrix order", &Entity->Transform.OldWayForce); - ImGui::Checkbox("Use old matrix order globaly", &Entity->Transform.OldWayGlobal); + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f)); - bool bActive = Entity->IsWireframeMode(); - ImGui::Checkbox("WireframeMode", &bActive); - Entity->SetWireframeMode(bActive); - - ImGui::Separator(); - ImGui::Text("Prefab : "); - // Temporary solution, becuase of the lack of proper ECS system - if (Entity->Prefab != nullptr) - { - FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Entity->Prefab->GetObjectID()); + FEGameModelComponent& GameModelComponent = EntitySelected->GetComponent(); + bool bActive = GameModelComponent.IsWireframeMode(); + ImGui::Checkbox("WireframeMode", &bActive); + GameModelComponent.SetWireframeMode(bActive); - if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - { - EntityToModify = Entity; - SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); - - } - EntityChangePrefabTarget->StickToItem(); - } - else - { - ImGui::Text("No prefab assigned."); - } - - bool bOpenContextMenu = false; - if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) - bOpenContextMenu = true; - - if (bOpenContextMenu) - ImGui::OpenPopup("##Inspector_context_menu"); - - CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = false; - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); - if (ImGui::BeginPopup("##Inspector_context_menu")) - { - CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = true; - - if (ImGui::MenuItem("Show in folder")) - { - CONTENT_BROWSER_WINDOW.OpenItemParentFolder(Entity->Prefab); - } + ImGui::Text("Game Model : "); + FETexture* PreviewTexture = PREVIEW_MANAGER.GetGameModelPreview(GameModelComponent.GameModel->GetObjectID()); - ImGui::EndPopup(); - } - ImGui::PopStyleVar(); - - ImGui::Separator(); - - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - } - else if (Entity->GetType() == FE_ENTITY_INSTANCED) + if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) { - FEEntityInstanced* InstancedEntity = reinterpret_cast(Entity); - - if (SELECTED.InstancedSubObjectIndexSelected != -1) - { - std::string InstancedSubObjectInfo = "index: "; - - ImGui::Text("Selected instance info:"); - InstancedSubObjectInfo = "index: " + std::to_string(SELECTED.InstancedSubObjectIndexSelected); - ImGui::Text(InstancedSubObjectInfo.c_str()); - - FETransformComponent TempTransform = FETransformComponent(InstancedEntity->GetTransformedInstancedMatrix(SELECTED.InstancedSubObjectIndexSelected)); - ShowTransformConfiguration("selected instance", &TempTransform); - InstancedEntity->ModifyInstance(SELECTED.InstancedSubObjectIndexSelected, TempTransform.GetTransformMatrix()); - - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - - if (ImGui::ImageButton((void*)(intptr_t)ArrowToGroundIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - { - InstancedEntity->TryToSnapInstance(SELECTED.InstancedSubObjectIndexSelected); - } - ShowToolTip("Selected instance will attempt to snap to the terrain."); - - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - } - else - { - ShowTransformConfiguration(Entity, &Entity->Transform); - - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f)); - - ImGui::Separator(); - - ImGui::Text("Prefab : "); - FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Entity->Prefab->GetObjectID()); - if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - { - EntityToModify = Entity; - SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); - } - EntityChangePrefabTarget->StickToItem(); - - bool bOpenContextMenu = false; - if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) - bOpenContextMenu = true; - - if (bOpenContextMenu) - ImGui::OpenPopup("##Inspector_context_menu"); - - CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = false; - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); - if (ImGui::BeginPopup("##Inspector_context_menu")) - { - CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = true; - - if (ImGui::MenuItem("Show in folder")) - { - CONTENT_BROWSER_WINDOW.OpenItemParentFolder(Entity->Prefab); - } - - ImGui::EndPopup(); - } - ImGui::PopStyleVar(); - ImGui::Separator(); - - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - - ImGui::Text("Snapped to: "); - ImGui::SameLine(); - - const std::vector TerrainList = SCENE.GetTerrainList(); - static std::string CurrentTerrain = "none"; - - if (InstancedEntity->GetSnappedToTerrain() == nullptr) - { - CurrentTerrain = "none"; - } - else - { - CurrentTerrain = InstancedEntity->GetSnappedToTerrain()->GetName(); - } - - ImGui::SetNextItemWidth(220); - if (ImGui::BeginCombo("##Terrain", CurrentTerrain.c_str(), ImGuiWindowFlags_None)) - { - const bool is_selected = (CurrentTerrain == "none"); - if (ImGui::Selectable("none", is_selected)) - { - if (InstancedEntity->GetSnappedToTerrain() != nullptr) - InstancedEntity->GetSnappedToTerrain()->UnSnapInstancedEntity(InstancedEntity); - } - - if (is_selected) - ImGui::SetItemDefaultFocus(); - - for (size_t i = 0; i < TerrainList.size(); i++) - { - const bool is_selected = (CurrentTerrain == TerrainList[i]); - if (ImGui::Selectable(SCENE.GetTerrain(TerrainList[i])->GetName().c_str(), is_selected)) - { - SCENE.GetTerrain(TerrainList[i])->SnapInstancedEntity(InstancedEntity); - } - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - ImGui::EndCombo(); - } - - if (InstancedEntity->GetSnappedToTerrain() != nullptr) - { - ImGui::Text("Terrain layer: "); - ImGui::SameLine(); - - const int CurrentLayer = InstancedEntity->GetTerrainLayer(); - FETerrain* CurrentTerrain = InstancedEntity->GetSnappedToTerrain(); - - std::string caption = "none"; - const auto layer = CurrentTerrain->GetLayerInSlot(CurrentLayer); - if (layer != nullptr) - caption = layer->GetName(); - - ImGui::SetNextItemWidth(220); - if (ImGui::BeginCombo("##TerrainLayers", caption.c_str(), ImGuiWindowFlags_None)) - { - const bool is_selected = (CurrentLayer == -1); - ImGui::PushID("none_TerrainLayers_entity"); - if (ImGui::Selectable("none", is_selected)) - { - if (CurrentTerrain != nullptr) - CurrentTerrain->UnConnectInstancedEntityFromLayer(InstancedEntity); - } - ImGui::PopID(); - - if (is_selected) - ImGui::SetItemDefaultFocus(); - - for (size_t i = 0; i < FE_TERRAIN_MAX_LAYERS; i++) - { - FETerrainLayer* layer = CurrentTerrain->GetLayerInSlot(i); - if (layer == nullptr) - break; - - const bool is_selected = (CurrentLayer == i); - ImGui::PushID(layer->GetObjectID().c_str()); - if (ImGui::Selectable(layer->GetName().c_str(), is_selected)) - { - CurrentTerrain->ConnectInstancedEntityToLayer(InstancedEntity, int(i)); - } - ImGui::PopID(); - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - ImGui::EndCombo(); - } - - if (CurrentLayer != -1) - { - ImGui::Text("Minimal layer intensity:"); - float MinLevel = InstancedEntity->GetMinimalLayerIntensity(); - ImGui::SameLine(); - ImGui::SetNextItemWidth(80); - ImGui::DragFloat("##minLevel", &MinLevel); - InstancedEntity->SetMinimalLayerIntensity(MinLevel); - } - } - - ImGui::Separator(); - - ImGui::Text("Seed:"); - int seed = InstancedEntity->SpawnInfo.Seed; - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - ImGui::DragInt("##Seed", &seed); - InstancedEntity->SpawnInfo.Seed = seed; - - ImGui::Text("Object count:"); - int ObjectCount = InstancedEntity->SpawnInfo.ObjectCount; - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - ImGui::DragInt("##Object count", &ObjectCount); - if (ObjectCount <= 0) - ObjectCount = 1; - InstancedEntity->SpawnInfo.ObjectCount = ObjectCount; - - ImGui::Text("Radius:"); - float radius = InstancedEntity->SpawnInfo.Radius; - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - ImGui::DragFloat("##Radius", &radius); - if (radius < 0.0f) - radius = 0.1f; - InstancedEntity->SpawnInfo.Radius = radius; - - // Scale deviation. - ImGui::Text("Scale: "); - - ImGui::SameLine(); - ImGui::Text("min "); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(100); - float MinScale = InstancedEntity->SpawnInfo.GetMinScale(); - ImGui::DragFloat("##minScale", &MinScale, 0.01f); - InstancedEntity->SpawnInfo.SetMinScale(MinScale); - - ImGui::SameLine(); - ImGui::Text("max "); - - ImGui::SameLine(); - float MaxScale = InstancedEntity->SpawnInfo.GetMaxScale(); - ImGui::SetNextItemWidth(100); - ImGui::DragFloat("##maxScale", &MaxScale, 0.01f); - InstancedEntity->SpawnInfo.SetMaxScale(MaxScale); - - ImGui::Text("Rotation deviation:"); - float RotationDeviationX = InstancedEntity->SpawnInfo.RotationDeviation.x; - ImGui::Text("X:"); - ImGui::SameLine(); - ImGui::DragFloat("##Rotation deviation X", &RotationDeviationX, 0.01f); - if (RotationDeviationX < 0.01f) - RotationDeviationX = 0.01f; - if (RotationDeviationX > 1.0f) - RotationDeviationX = 1.0f; - InstancedEntity->SpawnInfo.RotationDeviation.x = RotationDeviationX; - - float RotationDeviationY = InstancedEntity->SpawnInfo.RotationDeviation.y; - ImGui::Text("Y:"); - ImGui::SameLine(); - ImGui::DragFloat("##Rotation deviation Y", &RotationDeviationY, 0.01f); - if (RotationDeviationY < 0.01f) - RotationDeviationY = 0.01f; - if (RotationDeviationY > 1.0f) - RotationDeviationY = 1.0f; - InstancedEntity->SpawnInfo.RotationDeviation.y = RotationDeviationY; - - float RotationDeviationZ = InstancedEntity->SpawnInfo.RotationDeviation.z; - ImGui::Text("Z:"); - ImGui::SameLine(); - ImGui::DragFloat("##Rotation deviation z", &RotationDeviationZ, 0.01f); - if (RotationDeviationZ < 0.01f) - RotationDeviationZ = 0.01f; - if (RotationDeviationZ > 1.0f) - RotationDeviationZ = 1.0f; - InstancedEntity->SpawnInfo.RotationDeviation.z = RotationDeviationZ; - - if (ImGui::Button("Spawn/Re-Spawn")) - { - InstancedEntity->Clear(); - InstancedEntity->Populate(InstancedEntity->SpawnInfo); - } - - if (ImGui::Button("Add instance")) - { - glm::mat4 NewInstanceMatrix = glm::identity(); - NewInstanceMatrix = glm::translate(NewInstanceMatrix, ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - InstancedEntity->AddInstance(NewInstanceMatrix); - - PROJECT_MANAGER.GetCurrent()->SetModified(true); - } - - if (InstancedEntity->IsSelectMode()) - { - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.0f, 0.75f, 0.0f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); - } - else - { - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - } - - ImGui::Separator(); - if (ImGui::ImageButton((void*)(intptr_t)MouseCursorIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - { - SCENE.SetSelectMode(InstancedEntity, !InstancedEntity->IsSelectMode()); - if (!InstancedEntity->IsSelectMode()) - { - SELECTED.Clear(); - // FIX ME! - //SELECTED.SetSelected(InstancedEntity); - } - } - ShowToolTip("Individual selection mode - Used to select individual instances."); - - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - } + //EntityToModify = EntitySelected; + //SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); } - } - else if (SELECTED.GetTerrain() != nullptr) - { - FETerrain* CurrentTerrain = SELECTED.GetTerrain(); - DisplayTerrainSettings(CurrentTerrain); + //EntityChangePrefabTarget->StickToItem(); - if (CurrentTerrain->GetBrushMode() != FE_TERRAIN_BRUSH_NONE) - { - // FIX ME! - // To hide gizmos. - /*if (SELECTED.GetTerrain() != nullptr) - SELECTED.SetSelected(SELECTED.GetTerrain());*/ + bool bOpenContextMenu = false; + if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) + bOpenContextMenu = true; - CurrentTerrain->SetBrushActive(bLeftMousePressed); + if (bOpenContextMenu) + ImGui::OpenPopup("##Inspector_context_menu"); - if (bShiftPressed) - { - if (CurrentTerrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW) - CurrentTerrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED); - } - else - { - if (CurrentTerrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) - CurrentTerrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); - } + CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = false; + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); + if (ImGui::BeginPopup("##Inspector_context_menu")) + { + CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = true; - /*if (EDITOR.bLeftMousePressed) + if (ImGui::MenuItem("Show in folder")) { - if (EDITOR.bShiftPressed) - { - currentTerrain->setBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED); - } - else - { - currentTerrain->setBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); - } + CONTENT_BROWSER_WINDOW.OpenItemParentFolder(GameModelComponent.GameModel); } - else - { - currentTerrain->setBrushMode(FE_TERRAIN_BRUSH_NONE); - }*/ - //currentTerrain->setBrushActive(EDITOR.bLeftMousePressed); - //currentTerrain->setBrushInversed(EDITOR.bShiftPressed); + ImGui::EndPopup(); } - else - { - // FIX ME! - // To show gizmos. - /*if (SELECTED.GetTerrain() != nullptr) - SELECTED.SetSelected(SELECTED.GetTerrain());*/ - } - } - else if (SELECTED.GetLight() != nullptr) - { - DisplayLightProperties(SELECTED.GetLight()); - } - else if (SELECTED.GetSelected()->GetType() == FE_CAMERA) - { - FEBasicCamera* Camera = ENGINE.GetCamera(); - - // ********* POSITION ********* - glm::vec3 CameraPosition = Camera->GetPosition(); - - ImGui::Text("Position : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(90); - ImGui::DragFloat("##X pos", &CameraPosition[0], 0.1f); - ShowToolTip("X position"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(90); - ImGui::DragFloat("##Y pos", &CameraPosition[1], 0.1f); - ShowToolTip("Y position"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(90); - ImGui::DragFloat("##Z pos", &CameraPosition[2], 0.1f); - ShowToolTip("Z position"); - - Camera->SetPosition(CameraPosition); - - // ********* ROTATION ********* - glm::vec3 CameraRotation = glm::vec3(Camera->GetYaw(), Camera->GetPitch(), Camera->GetRoll()); - - ImGui::Text("Rotation : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(90); - ImGui::DragFloat("##X rot", &CameraRotation[0], 0.1f); - ShowToolTip("X rotation"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(90); - ImGui::DragFloat("##Y rot", &CameraRotation[1], 0.1f); - ShowToolTip("Y rotation"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(90); - ImGui::DragFloat("##Z rot", &CameraRotation[2], 0.1f); - ShowToolTip("Z rotation"); + ImGui::PopStyleVar(); - Camera->SetYaw(CameraRotation[0]); - Camera->SetPitch(CameraRotation[1]); - Camera->SetRoll(CameraRotation[2]); + ImGui::Separator(); - float CameraSpeed = Camera->GetMovementSpeed(); - ImGui::Text("Camera speed in m/s : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(70); - ImGui::DragFloat("##Camera_speed", &CameraSpeed, 0.01f, 0.01f, 100.0f); - Camera->SetMovementSpeed(CameraSpeed); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); } + // FIX ME! + //if (SELECTED.GetEntity() != nullptr) + //{ + // FEEntity* Entity = SELECTED.GetEntity(); + + // if (Entity->GetType() == FE_ENTITY) + // { + // ShowTransformConfiguration(Entity, &Entity->Transform); + + // ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); + // ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); + // ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f)); + + // ImGui::InputInt("Force old matrix order", &Entity->Transform.OldWayForce); + // ImGui::Checkbox("Use old matrix order globaly", &Entity->Transform.OldWayGlobal); + + // bool bActive = Entity->IsWireframeMode(); + // ImGui::Checkbox("WireframeMode", &bActive); + // Entity->SetWireframeMode(bActive); + + // ImGui::Separator(); + // ImGui::Text("Prefab : "); + // // Temporary solution, becuase of the lack of proper ECS system + // if (Entity->Prefab != nullptr) + // { + // FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Entity->Prefab->GetObjectID()); + + // if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + // { + // EntityToModify = Entity; + // SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); + + // } + // EntityChangePrefabTarget->StickToItem(); + // } + // else + // { + // ImGui::Text("No prefab assigned."); + // } + + // bool bOpenContextMenu = false; + // if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) + // bOpenContextMenu = true; + + // if (bOpenContextMenu) + // ImGui::OpenPopup("##Inspector_context_menu"); + + // CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = false; + // ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); + // if (ImGui::BeginPopup("##Inspector_context_menu")) + // { + // CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = true; + + // if (ImGui::MenuItem("Show in folder")) + // { + // CONTENT_BROWSER_WINDOW.OpenItemParentFolder(Entity->Prefab); + // } + + // ImGui::EndPopup(); + // } + // ImGui::PopStyleVar(); + + // ImGui::Separator(); + + // ImGui::PopStyleColor(); + // ImGui::PopStyleColor(); + // ImGui::PopStyleColor(); + // } + // else if (Entity->GetType() == FE_ENTITY_INSTANCED) + // { + // FEEntityInstanced* InstancedEntity = reinterpret_cast(Entity); + + // if (SELECTED.InstancedSubObjectIndexSelected != -1) + // { + // std::string InstancedSubObjectInfo = "index: "; + + // ImGui::Text("Selected instance info:"); + // InstancedSubObjectInfo = "index: " + std::to_string(SELECTED.InstancedSubObjectIndexSelected); + // ImGui::Text(InstancedSubObjectInfo.c_str()); + + // FETransformComponent TempTransform = FETransformComponent(InstancedEntity->GetTransformedInstancedMatrix(SELECTED.InstancedSubObjectIndexSelected)); + // ShowTransformConfiguration("selected instance", &TempTransform); + // InstancedEntity->ModifyInstance(SELECTED.InstancedSubObjectIndexSelected, TempTransform.GetTransformMatrix()); + + // ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); + // ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + // ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + + // if (ImGui::ImageButton((void*)(intptr_t)ArrowToGroundIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + // { + // InstancedEntity->TryToSnapInstance(SELECTED.InstancedSubObjectIndexSelected); + // } + // ShowToolTip("Selected instance will attempt to snap to the terrain."); + + // ImGui::PopStyleColor(); + // ImGui::PopStyleColor(); + // ImGui::PopStyleColor(); + // } + // else + // { + // ShowTransformConfiguration(Entity, &Entity->Transform); + + // ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); + // ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); + // ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f)); + + // ImGui::Separator(); + + // ImGui::Text("Prefab : "); + // FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Entity->Prefab->GetObjectID()); + // if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + // { + // EntityToModify = Entity; + // SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); + // } + // EntityChangePrefabTarget->StickToItem(); + + // bool bOpenContextMenu = false; + // if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) + // bOpenContextMenu = true; + + // if (bOpenContextMenu) + // ImGui::OpenPopup("##Inspector_context_menu"); + + // CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = false; + // ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); + // if (ImGui::BeginPopup("##Inspector_context_menu")) + // { + // CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = true; + + // if (ImGui::MenuItem("Show in folder")) + // { + // CONTENT_BROWSER_WINDOW.OpenItemParentFolder(Entity->Prefab); + // } + + // ImGui::EndPopup(); + // } + // ImGui::PopStyleVar(); + // ImGui::Separator(); + + // ImGui::PopStyleColor(); + // ImGui::PopStyleColor(); + // ImGui::PopStyleColor(); + + // ImGui::Text("Snapped to: "); + // ImGui::SameLine(); + + // const std::vector TerrainList = SCENE.GetTerrainList(); + // static std::string CurrentTerrain = "none"; + + // if (InstancedEntity->GetSnappedToTerrain() == nullptr) + // { + // CurrentTerrain = "none"; + // } + // else + // { + // CurrentTerrain = InstancedEntity->GetSnappedToTerrain()->GetName(); + // } + + // ImGui::SetNextItemWidth(220); + // if (ImGui::BeginCombo("##Terrain", CurrentTerrain.c_str(), ImGuiWindowFlags_None)) + // { + // const bool is_selected = (CurrentTerrain == "none"); + // if (ImGui::Selectable("none", is_selected)) + // { + // if (InstancedEntity->GetSnappedToTerrain() != nullptr) + // InstancedEntity->GetSnappedToTerrain()->UnSnapInstancedEntity(InstancedEntity); + // } + + // if (is_selected) + // ImGui::SetItemDefaultFocus(); + + // for (size_t i = 0; i < TerrainList.size(); i++) + // { + // const bool is_selected = (CurrentTerrain == TerrainList[i]); + // if (ImGui::Selectable(SCENE.GetTerrain(TerrainList[i])->GetName().c_str(), is_selected)) + // { + // SCENE.GetTerrain(TerrainList[i])->SnapInstancedEntity(InstancedEntity); + // } + + // if (is_selected) + // ImGui::SetItemDefaultFocus(); + // } + // ImGui::EndCombo(); + // } + + // if (InstancedEntity->GetSnappedToTerrain() != nullptr) + // { + // ImGui::Text("Terrain layer: "); + // ImGui::SameLine(); + + // const int CurrentLayer = InstancedEntity->GetTerrainLayer(); + // FETerrain* CurrentTerrain = InstancedEntity->GetSnappedToTerrain(); + + // std::string caption = "none"; + // const auto layer = CurrentTerrain->GetLayerInSlot(CurrentLayer); + // if (layer != nullptr) + // caption = layer->GetName(); + + // ImGui::SetNextItemWidth(220); + // if (ImGui::BeginCombo("##TerrainLayers", caption.c_str(), ImGuiWindowFlags_None)) + // { + // const bool is_selected = (CurrentLayer == -1); + // ImGui::PushID("none_TerrainLayers_entity"); + // if (ImGui::Selectable("none", is_selected)) + // { + // if (CurrentTerrain != nullptr) + // CurrentTerrain->UnConnectInstancedEntityFromLayer(InstancedEntity); + // } + // ImGui::PopID(); + + // if (is_selected) + // ImGui::SetItemDefaultFocus(); + + // for (size_t i = 0; i < FE_TERRAIN_MAX_LAYERS; i++) + // { + // FETerrainLayer* layer = CurrentTerrain->GetLayerInSlot(i); + // if (layer == nullptr) + // break; + + // const bool is_selected = (CurrentLayer == i); + // ImGui::PushID(layer->GetObjectID().c_str()); + // if (ImGui::Selectable(layer->GetName().c_str(), is_selected)) + // { + // CurrentTerrain->ConnectInstancedEntityToLayer(InstancedEntity, int(i)); + // } + // ImGui::PopID(); + + // if (is_selected) + // ImGui::SetItemDefaultFocus(); + // } + // ImGui::EndCombo(); + // } + + // if (CurrentLayer != -1) + // { + // ImGui::Text("Minimal layer intensity:"); + // float MinLevel = InstancedEntity->GetMinimalLayerIntensity(); + // ImGui::SameLine(); + // ImGui::SetNextItemWidth(80); + // ImGui::DragFloat("##minLevel", &MinLevel); + // InstancedEntity->SetMinimalLayerIntensity(MinLevel); + // } + // } + + // ImGui::Separator(); + + // ImGui::Text("Seed:"); + // int seed = InstancedEntity->SpawnInfo.Seed; + // ImGui::SameLine(); + // ImGui::SetNextItemWidth(200); + // ImGui::DragInt("##Seed", &seed); + // InstancedEntity->SpawnInfo.Seed = seed; + + // ImGui::Text("Object count:"); + // int ObjectCount = InstancedEntity->SpawnInfo.ObjectCount; + // ImGui::SameLine(); + // ImGui::SetNextItemWidth(200); + // ImGui::DragInt("##Object count", &ObjectCount); + // if (ObjectCount <= 0) + // ObjectCount = 1; + // InstancedEntity->SpawnInfo.ObjectCount = ObjectCount; + + // ImGui::Text("Radius:"); + // float radius = InstancedEntity->SpawnInfo.Radius; + // ImGui::SameLine(); + // ImGui::SetNextItemWidth(200); + // ImGui::DragFloat("##Radius", &radius); + // if (radius < 0.0f) + // radius = 0.1f; + // InstancedEntity->SpawnInfo.Radius = radius; + + // // Scale deviation. + // ImGui::Text("Scale: "); + + // ImGui::SameLine(); + // ImGui::Text("min "); + + // ImGui::SameLine(); + // ImGui::SetNextItemWidth(100); + // float MinScale = InstancedEntity->SpawnInfo.GetMinScale(); + // ImGui::DragFloat("##minScale", &MinScale, 0.01f); + // InstancedEntity->SpawnInfo.SetMinScale(MinScale); + + // ImGui::SameLine(); + // ImGui::Text("max "); + + // ImGui::SameLine(); + // float MaxScale = InstancedEntity->SpawnInfo.GetMaxScale(); + // ImGui::SetNextItemWidth(100); + // ImGui::DragFloat("##maxScale", &MaxScale, 0.01f); + // InstancedEntity->SpawnInfo.SetMaxScale(MaxScale); + + // ImGui::Text("Rotation deviation:"); + // float RotationDeviationX = InstancedEntity->SpawnInfo.RotationDeviation.x; + // ImGui::Text("X:"); + // ImGui::SameLine(); + // ImGui::DragFloat("##Rotation deviation X", &RotationDeviationX, 0.01f); + // if (RotationDeviationX < 0.01f) + // RotationDeviationX = 0.01f; + // if (RotationDeviationX > 1.0f) + // RotationDeviationX = 1.0f; + // InstancedEntity->SpawnInfo.RotationDeviation.x = RotationDeviationX; + + // float RotationDeviationY = InstancedEntity->SpawnInfo.RotationDeviation.y; + // ImGui::Text("Y:"); + // ImGui::SameLine(); + // ImGui::DragFloat("##Rotation deviation Y", &RotationDeviationY, 0.01f); + // if (RotationDeviationY < 0.01f) + // RotationDeviationY = 0.01f; + // if (RotationDeviationY > 1.0f) + // RotationDeviationY = 1.0f; + // InstancedEntity->SpawnInfo.RotationDeviation.y = RotationDeviationY; + + // float RotationDeviationZ = InstancedEntity->SpawnInfo.RotationDeviation.z; + // ImGui::Text("Z:"); + // ImGui::SameLine(); + // ImGui::DragFloat("##Rotation deviation z", &RotationDeviationZ, 0.01f); + // if (RotationDeviationZ < 0.01f) + // RotationDeviationZ = 0.01f; + // if (RotationDeviationZ > 1.0f) + // RotationDeviationZ = 1.0f; + // InstancedEntity->SpawnInfo.RotationDeviation.z = RotationDeviationZ; + + // if (ImGui::Button("Spawn/Re-Spawn")) + // { + // InstancedEntity->Clear(); + // InstancedEntity->Populate(InstancedEntity->SpawnInfo); + // } + + // if (ImGui::Button("Add instance")) + // { + // glm::mat4 NewInstanceMatrix = glm::identity(); + // NewInstanceMatrix = glm::translate(NewInstanceMatrix, ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + // InstancedEntity->AddInstance(NewInstanceMatrix); + + // PROJECT_MANAGER.GetCurrent()->SetModified(true); + // } + + // if (InstancedEntity->IsSelectMode()) + // { + // ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.0f, 0.75f, 0.0f)); + // ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); + // ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); + // } + // else + // { + // ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); + // ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + // ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + // } + + // ImGui::Separator(); + // if (ImGui::ImageButton((void*)(intptr_t)MouseCursorIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + // { + // SCENE.SetSelectMode(InstancedEntity, !InstancedEntity->IsSelectMode()); + // if (!InstancedEntity->IsSelectMode()) + // { + // SELECTED.Clear(); + // // FIX ME! + // //SELECTED.SetSelected(InstancedEntity); + // } + // } + // ShowToolTip("Individual selection mode - Used to select individual instances."); + + // ImGui::PopStyleColor(); + // ImGui::PopStyleColor(); + // ImGui::PopStyleColor(); + // } + // } + //} + //else if (SELECTED.GetTerrain() != nullptr) + //{ + // FETerrain* CurrentTerrain = SELECTED.GetTerrain(); + // DisplayTerrainSettings(CurrentTerrain); + + // if (CurrentTerrain->GetBrushMode() != FE_TERRAIN_BRUSH_NONE) + // { + // // FIX ME! + // // To hide gizmos. + // /*if (SELECTED.GetTerrain() != nullptr) + // SELECTED.SetSelected(SELECTED.GetTerrain());*/ + + // CurrentTerrain->SetBrushActive(bLeftMousePressed); + + // if (bShiftPressed) + // { + // if (CurrentTerrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW) + // CurrentTerrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED); + // } + // else + // { + // if (CurrentTerrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) + // CurrentTerrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); + // } + + // /*if (EDITOR.bLeftMousePressed) + // { + // if (EDITOR.bShiftPressed) + // { + // currentTerrain->setBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED); + // } + // else + // { + // currentTerrain->setBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); + // } + // } + // else + // { + // currentTerrain->setBrushMode(FE_TERRAIN_BRUSH_NONE); + // }*/ + + // //currentTerrain->setBrushActive(EDITOR.bLeftMousePressed); + // //currentTerrain->setBrushInversed(EDITOR.bShiftPressed); + // } + // else + // { + // // FIX ME! + // // To show gizmos. + // /*if (SELECTED.GetTerrain() != nullptr) + // SELECTED.SetSelected(SELECTED.GetTerrain());*/ + // } + //} + //else if (SELECTED.GetLight() != nullptr) + //{ + // DisplayLightProperties(SELECTED.GetLight()); + //} + //else if (SELECTED.GetSelected()->GetType() == FE_CAMERA) + //{ + // FEBasicCamera* Camera = ENGINE.GetCamera(); + + // // ********* POSITION ********* + // glm::vec3 CameraPosition = Camera->GetPosition(); + + // ImGui::Text("Position : "); + // ImGui::SameLine(); + // ImGui::SetNextItemWidth(90); + // ImGui::DragFloat("##X pos", &CameraPosition[0], 0.1f); + // ShowToolTip("X position"); + + // ImGui::SameLine(); + // ImGui::SetNextItemWidth(90); + // ImGui::DragFloat("##Y pos", &CameraPosition[1], 0.1f); + // ShowToolTip("Y position"); + + // ImGui::SameLine(); + // ImGui::SetNextItemWidth(90); + // ImGui::DragFloat("##Z pos", &CameraPosition[2], 0.1f); + // ShowToolTip("Z position"); + + // Camera->SetPosition(CameraPosition); + + // // ********* ROTATION ********* + // glm::vec3 CameraRotation = glm::vec3(Camera->GetYaw(), Camera->GetPitch(), Camera->GetRoll()); + + // ImGui::Text("Rotation : "); + // ImGui::SameLine(); + // ImGui::SetNextItemWidth(90); + // ImGui::DragFloat("##X rot", &CameraRotation[0], 0.1f); + // ShowToolTip("X rotation"); + + // ImGui::SameLine(); + // ImGui::SetNextItemWidth(90); + // ImGui::DragFloat("##Y rot", &CameraRotation[1], 0.1f); + // ShowToolTip("Y rotation"); + + // ImGui::SameLine(); + // ImGui::SetNextItemWidth(90); + // ImGui::DragFloat("##Z rot", &CameraRotation[2], 0.1f); + // ShowToolTip("Z rotation"); + + // Camera->SetYaw(CameraRotation[0]); + // Camera->SetPitch(CameraRotation[1]); + // Camera->SetRoll(CameraRotation[2]); + + // float CameraSpeed = Camera->GetMovementSpeed(); + // ImGui::Text("Camera speed in m/s : "); + // ImGui::SameLine(); + // ImGui::SetNextItemWidth(70); + // ImGui::DragFloat("##Camera_speed", &CameraSpeed, 0.01f, 0.01f, 100.0f); + // Camera->SetMovementSpeed(CameraSpeed); + //} + ImGui::PopStyleVar(); ImGui::End(); } diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index b666885..64fc736 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -99,12 +99,9 @@ static void CreateNewEntityCallBack(const std::vector SelectionsResul if (SelectedPrefab == nullptr) return; - // FIX ME! - FEEntity* NewEntity = SCENE.AddEntity(SelectedPrefab); - FENewEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(NewEntity->GetObjectID()); - NewNewEntity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - //NewEntity->Transform.SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - SELECTED.SetSelected(NewNewEntity); + FENewEntity* NewEntity = SCENE.AddNewStyleEntity(); + NewEntity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + SELECTED.SetSelected(NewEntity); PROJECT_MANAGER.GetCurrent()->SetModified(true); } @@ -391,8 +388,8 @@ void FEEditorSceneGraphWindow::Render() if (ImGui::IsItemClicked()) { // FIX ME! - FENewEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])->GetObjectID()); - SELECTED.SetSelected(NewNewEntity); + //FENewEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])->GetObjectID()); + //SELECTED.SetSelected(NewNewEntity); SELECTED.SetDirtyFlag(false); } @@ -638,10 +635,10 @@ void FEEditorSceneGraphWindow::Render() (SELECTED.GetSelected()->GetType() == FE_ENTITY || SELECTED.GetSelected()->GetType() == FE_ENTITY_INSTANCED || SELECTED.GetSelected()->GetType() == FE_TERRAIN) && bDisplaySelectedObjAABB) { - if (SELECTED.GetSelected()->HasComponent()) + if (SELECTED.GetSelected()->HasComponent()) { - FEEntity* OldStyleEntity = SELECTED.GetSelected()->GetComponent().OldStyleEntity; - FEAABB SelectedAABB = OldStyleEntity->GetAABB().Transform(SELECTED.GetSelected()->GetComponent().GetTransformMatrix()); + FEGameModel* GameModel = SELECTED.GetSelected()->GetComponent().GameModel; + FEAABB SelectedAABB = GameModel->GetMesh()->GetAABB().Transform(SELECTED.GetSelected()->GetComponent().GetTransformMatrix()); //const FEAABB SelectedAABB = SELECTED.GetEntity() != nullptr ? SELECTED.GetEntity()->GetAABB() : SELECTED.GetTerrain()->GetAABB(); RENDERER.DrawAABB(SelectedAABB); diff --git a/FEEditor.cpp b/FEEditor.cpp index 1d2cbc1..d3bac01 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -7,17 +7,30 @@ bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) { if (Object->GetType() == FE_PREFAB) { - // FIX ME! - FEEntity* NewEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())); - FENewEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(NewEntity->GetObjectID()); + FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())->GetComponent(0)->GameModel; + + FENewEntity* NewNewEntity = SCENE.AddNewStyleEntity(Object->GetName()); + NewNewEntity->GetComponent().GameModel = GameModel; NewNewEntity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - //NewEntity->Transform.SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); SELECTED.SetSelected(NewNewEntity); PROJECT_MANAGER.GetCurrent()->SetModified(true); return true; } + // FIX ME! + //if (Object->GetType() == FE_PREFAB) + //{ + // FEEntity* NewEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())); + // FENewEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(NewEntity->GetObjectID()); + // NewNewEntity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + // //NewEntity->Transform.SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + // SELECTED.SetSelected(NewNewEntity); + // PROJECT_MANAGER.GetCurrent()->SetModified(true); + + // return true; + //} + return false; } @@ -198,11 +211,13 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) // FIX ME! // There should be proper FEScene::DuplicateNewStyleEntity that will duplicate the entity and all its components // Also place it in same scene graph node as the original entity ? - FEEntity* NewEntity = SCENE.AddEntity(SCENE.GetEntity(EDITOR.GetSceneEntityIDInClipboard())->Prefab, ""); - FENewEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(NewEntity->GetObjectID()); FENewEntity* EntityToCopy = SCENE.GetNewStyleEntity(EDITOR.GetSceneEntityIDInClipboard()); + FENewEntity* NewNewEntity = SCENE.AddNewStyleEntity(EntityToCopy->GetName() + "_Copy"); NewNewEntity->GetComponent() = EntityToCopy->GetComponent(); NewNewEntity->GetComponent().SetPosition(EntityToCopy->GetComponent().GetPosition() * 1.1f); + if (EntityToCopy->HasComponent()) + NewNewEntity->AddComponent(EntityToCopy->GetComponent().GameModel); + SELECTED.SetSelected(NewNewEntity); } @@ -249,31 +264,31 @@ void FEEditor::InitializeResources() EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("637C784B2E5E5C6548190E1B"/*"scaleGizmoMesh"*/)); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("19622421516E5B317E1B5360"/*"rotateGizmoMesh"*/)); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateXGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().GameModel); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateZGizmoEntity); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(PREVIEW_MANAGER.PreviewEntity); diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index c8e547a..d69a1a3 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -22,14 +22,15 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); TransformationXGizmoEntity = SCENE.AddNewStyleEntity("TransformationXGizmoEntity"); - TransformationXGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM"), "TransformationXGizmoEntity")); - RESOURCE_MANAGER.MakePrefabStandard(TransformationXGizmoEntity->GetComponent().OldStyleEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); - TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + //TransformationXGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM"), "TransformationXGizmoEntity")); + TransformationXGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM")); + TransformationXGizmoEntity->SetName("TransformationXGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationXGizmoEntity->GetComponent().GameModel); + TransformationXGizmoEntity->GetComponent().SetCastShadows(false); + TransformationXGizmoEntity->GetComponent().SetReceivingShadows(false); TransformationXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); TransformationXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); @@ -41,14 +42,15 @@ void GizmoManager::InitializeResources() RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); TransformationYGizmoEntity = SCENE.AddNewStyleEntity("TransformationYGizmoEntity"); - TransformationYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"), "TransformationYGizmoEntity")); - RESOURCE_MANAGER.MakePrefabStandard(TransformationYGizmoEntity->GetComponent().OldStyleEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); - TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + //TransformationYGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"), "TransformationYGizmoEntity")); + TransformationYGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM")); + TransformationYGizmoEntity->SetName("TransformationYGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationYGizmoEntity->GetComponent().GameModel); + TransformationYGizmoEntity->GetComponent().SetCastShadows(false); + TransformationYGizmoEntity->GetComponent().SetReceivingShadows(false); TransformationYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); TransformationYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); - TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); /*TransformationYGizmoEntity = SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"), "transformationYGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(TransformationYGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(TransformationYGizmoEntity->Prefab->GetComponent(0)->GameModel); @@ -67,14 +69,15 @@ void GizmoManager::InitializeResources() RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); TransformationZGizmoEntity = SCENE.AddNewStyleEntity("TransformationZGizmoEntity"); - TransformationZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"), "TransformationZGizmoEntity")); - RESOURCE_MANAGER.MakePrefabStandard(TransformationZGizmoEntity->GetComponent().OldStyleEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); - TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + //TransformationZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"), "TransformationZGizmoEntity")); + TransformationZGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM")); + TransformationYGizmoEntity->SetName("TransformationZGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationZGizmoEntity->GetComponent().GameModel); + TransformationZGizmoEntity->GetComponent().SetCastShadows(false); + TransformationZGizmoEntity->GetComponent().SetReceivingShadows(false); TransformationZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); TransformationZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); /*TransformationZGizmoEntity = SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"), "transformationZGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(TransformationZGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(TransformationZGizmoEntity->Prefab->GetComponent(0)->GameModel); @@ -93,15 +96,16 @@ void GizmoManager::InitializeResources() RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); TransformationXYGizmoEntity = SCENE.AddNewStyleEntity("TransformationXYGizmoEntity"); - TransformationXYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"), "TransformationXYGizmoEntity")); - RESOURCE_MANAGER.MakePrefabStandard(TransformationXYGizmoEntity->GetComponent().OldStyleEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationXYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); - TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + //TransformationXYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"), "TransformationXYGizmoEntity")); + TransformationXYGizmoEntity->AddComponent(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM")); + TransformationXYGizmoEntity->SetName("TransformationXYGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationXYGizmoEntity->GetComponent().GameModel); + TransformationXYGizmoEntity->GetComponent().SetCastShadows(false); + TransformationXYGizmoEntity->GetComponent().SetReceivingShadows(false); TransformationXYGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); TransformationXYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); TransformationXYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationXYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); //TransformationXYGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"), "transformationXYGizmoEntity"); //RESOURCE_MANAGER.MakePrefabStandard(TransformationXYGizmoEntity->Prefab); //RESOURCE_MANAGER.MakeGameModelStandard(TransformationXYGizmoEntity->Prefab->GetComponent(0)->GameModel); @@ -120,15 +124,16 @@ void GizmoManager::InitializeResources() RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); TransformationYZGizmoEntity = SCENE.AddNewStyleEntity("TransformationYZGizmoEntity"); - TransformationYZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"), "TransformationYZGizmoEntity")); - RESOURCE_MANAGER.MakePrefabStandard(TransformationYZGizmoEntity->GetComponent().OldStyleEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationYZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); - TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + //TransformationYZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"), "TransformationYZGizmoEntity")); + TransformationYZGizmoEntity->AddComponent(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM")); + TransformationYZGizmoEntity->SetName("TransformationYZGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationYZGizmoEntity->GetComponent().GameModel); + TransformationYZGizmoEntity->GetComponent().SetCastShadows(false); + TransformationYZGizmoEntity->GetComponent().SetReceivingShadows(false); TransformationYZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); TransformationYZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); TransformationYZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationYZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); //TransformationYZGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"), "transformationYZGizmoEntity"); //RESOURCE_MANAGER.MakePrefabStandard(TransformationYZGizmoEntity->Prefab); //RESOURCE_MANAGER.MakeGameModelStandard(TransformationYZGizmoEntity->Prefab->GetComponent(0)->GameModel); @@ -147,15 +152,16 @@ void GizmoManager::InitializeResources() RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); TransformationXZGizmoEntity = SCENE.AddNewStyleEntity("TransformationXZGizmoEntity"); - TransformationXZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"), "TransformationXZGizmoEntity")); - RESOURCE_MANAGER.MakePrefabStandard(TransformationXZGizmoEntity->GetComponent().OldStyleEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationXZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); - TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + //TransformationXZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"), "TransformationXZGizmoEntity")); + TransformationXZGizmoEntity->SetName("TransformationXZGizmoEntity"); + TransformationXZGizmoEntity->AddComponent(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM")); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationXZGizmoEntity->GetComponent().GameModel); + TransformationXZGizmoEntity->GetComponent().SetCastShadows(false); + TransformationXZGizmoEntity->GetComponent().SetReceivingShadows(false); TransformationXZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); TransformationXZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); TransformationXZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationXZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); //TransformationXZGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"), "transformationXZGizmoEntity"); //RESOURCE_MANAGER.MakePrefabStandard(TransformationXZGizmoEntity->Prefab); //RESOURCE_MANAGER.MakeGameModelStandard(TransformationXZGizmoEntity->Prefab->GetComponent(0)->GameModel); @@ -179,14 +185,15 @@ void GizmoManager::InitializeResources() RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); ScaleXGizmoEntity = SCENE.AddNewStyleEntity("ScaleXGizmoEntity"); - ScaleXGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM"), "ScaleXGizmoEntity")); - RESOURCE_MANAGER.MakePrefabStandard(ScaleXGizmoEntity->GetComponent().OldStyleEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(ScaleXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); - ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + //ScaleXGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM"), "ScaleXGizmoEntity")); + ScaleXGizmoEntity->AddComponent(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM")); + ScaleXGizmoEntity->SetName("ScaleXGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(ScaleXGizmoEntity->GetComponent().GameModel); + ScaleXGizmoEntity->GetComponent().SetCastShadows(false); + ScaleXGizmoEntity->GetComponent().SetReceivingShadows(false); ScaleXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); ScaleXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + ScaleXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); /*ScaleXGizmoEntity = SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "scaleXGizmoGM"), "scaleXGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(ScaleXGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(ScaleXGizmoEntity->Prefab->GetComponent(0)->GameModel); @@ -205,14 +212,15 @@ void GizmoManager::InitializeResources() RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); ScaleYGizmoEntity = SCENE.AddNewStyleEntity("ScaleYGizmoEntity"); - ScaleYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM"), "ScaleYGizmoEntity")); - RESOURCE_MANAGER.MakePrefabStandard(ScaleYGizmoEntity->GetComponent().OldStyleEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(ScaleYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); - ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + //ScaleYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM"), "ScaleYGizmoEntity")); + ScaleYGizmoEntity->AddComponent(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM")); + ScaleYGizmoEntity->SetName("ScaleYGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(ScaleYGizmoEntity->GetComponent().GameModel); + ScaleYGizmoEntity->GetComponent().SetCastShadows(false); + ScaleYGizmoEntity->GetComponent().SetReceivingShadows(false); ScaleYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); ScaleYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); - ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + ScaleYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); /*ScaleYGizmoEntity = SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "scaleYGizmoGM"), "scaleYGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(ScaleYGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(ScaleYGizmoEntity->Prefab->GetComponent(0)->GameModel); @@ -231,14 +239,15 @@ void GizmoManager::InitializeResources() RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); ScaleZGizmoEntity = SCENE.AddNewStyleEntity("ScaleZGizmoEntity"); - ScaleZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM"), "ScaleZGizmoEntity")); - RESOURCE_MANAGER.MakePrefabStandard(ScaleZGizmoEntity->GetComponent().OldStyleEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(ScaleZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); - ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + //ScaleZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM"), "ScaleZGizmoEntity")); + ScaleZGizmoEntity->AddComponent(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM")); + ScaleZGizmoEntity->SetName("ScaleZGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(ScaleZGizmoEntity->GetComponent().GameModel); + ScaleZGizmoEntity->GetComponent().SetCastShadows(false); + ScaleZGizmoEntity->GetComponent().SetReceivingShadows(false); ScaleZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); ScaleZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + ScaleZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); /*ScaleZGizmoEntity = SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "scaleZGizmoGM"), "scaleZGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(ScaleZGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(ScaleZGizmoEntity->Prefab->GetComponent(0)->GameModel); @@ -261,14 +270,15 @@ void GizmoManager::InitializeResources() RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); RotateXGizmoEntity = SCENE.AddNewStyleEntity("RotateXGizmoEntity"); - RotateXGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM"), "RotateXGizmoEntity")); - RESOURCE_MANAGER.MakePrefabStandard(RotateXGizmoEntity->GetComponent().OldStyleEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(RotateXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); - RotateXGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - RotateXGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + //RotateXGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM"), "RotateXGizmoEntity")); + RotateXGizmoEntity->AddComponent(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM")); + RotateXGizmoEntity->SetName("RotateXGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(RotateXGizmoEntity->GetComponent().GameModel); + RotateXGizmoEntity->GetComponent().SetCastShadows(false); + RotateXGizmoEntity->GetComponent().SetReceivingShadows(false); RotateXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); RotateXGizmoEntity->GetComponent().SetRotation(RotateXStandardRotation); - RotateXGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + RotateXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); /*RotateXGizmoEntity = SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "rotateXGizmoGM"), "rotateXGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(RotateXGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(RotateXGizmoEntity->Prefab->GetComponent(0)->GameModel); @@ -287,14 +297,15 @@ void GizmoManager::InitializeResources() RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); RotateYGizmoEntity = SCENE.AddNewStyleEntity("RotateYGizmoEntity"); - RotateYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM"), "RotateYGizmoEntity")); - RESOURCE_MANAGER.MakePrefabStandard(RotateYGizmoEntity->GetComponent().OldStyleEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(RotateYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); - RotateYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - RotateYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + //RotateYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM"), "RotateYGizmoEntity")); + RotateYGizmoEntity->AddComponent(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM")); + RotateYGizmoEntity->SetName("RotateYGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(RotateYGizmoEntity->GetComponent().GameModel); + RotateYGizmoEntity->GetComponent().SetCastShadows(false); + RotateYGizmoEntity->GetComponent().SetReceivingShadows(false); RotateYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); RotateYGizmoEntity->GetComponent().SetRotation(RotateYStandardRotation); - RotateYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + RotateYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); /*RotateYGizmoEntity = SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "rotateYGizmoGM"), "rotateYGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(RotateYGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(RotateYGizmoEntity->Prefab->GetComponent(0)->GameModel); @@ -313,14 +324,15 @@ void GizmoManager::InitializeResources() RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); RotateZGizmoEntity = SCENE.AddNewStyleEntity("RotateZGizmoEntity"); - RotateZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM"), "RotateZGizmoEntity")); - RESOURCE_MANAGER.MakePrefabStandard(RotateZGizmoEntity->GetComponent().OldStyleEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(RotateZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel); - RotateZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - RotateZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); + //RotateZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM"), "RotateZGizmoEntity")); + RotateZGizmoEntity->AddComponent(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM")); + RotateZGizmoEntity->SetName("RotateZGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(RotateZGizmoEntity->GetComponent().GameModel); + RotateZGizmoEntity->GetComponent().SetCastShadows(false); + RotateZGizmoEntity->GetComponent().SetReceivingShadows(false); RotateZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); RotateZGizmoEntity->GetComponent().SetRotation(RotateZStandardRotation); - RotateZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + RotateZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); /*RotateZGizmoEntity = SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "rotateZGizmoGM"), "rotateZGizmoEntity"); RESOURCE_MANAGER.MakePrefabStandard(RotateZGizmoEntity->Prefab); RESOURCE_MANAGER.MakeGameModelStandard(RotateZGizmoEntity->Prefab->GetComponent(0)->GameModel); @@ -341,13 +353,13 @@ void GizmoManager::InitializeResources() void GizmoManager::HideAllGizmo() { - TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); - TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); - TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + TransformationXGizmoEntity->GetComponent().SetVisibility(false); + TransformationYGizmoEntity->GetComponent().SetVisibility(false); + TransformationZGizmoEntity->GetComponent().SetVisibility(false); - TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); - TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); - TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + TransformationXYGizmoEntity->GetComponent().SetVisibility(false); + TransformationYZGizmoEntity->GetComponent().SetVisibility(false); + TransformationXZGizmoEntity->GetComponent().SetVisibility(false); bTransformationXGizmoActive = false; bTransformationYGizmoActive = false; @@ -357,17 +369,17 @@ void GizmoManager::HideAllGizmo() bTransformationYZGizmoActive = false; bTransformationXZGizmoActive = false; - ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); - ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); - ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + ScaleXGizmoEntity->GetComponent().SetVisibility(false); + ScaleYGizmoEntity->GetComponent().SetVisibility(false); + ScaleZGizmoEntity->GetComponent().SetVisibility(false); bScaleXGizmoActive = false; bScaleYGizmoActive = false; bScaleZGizmoActive = false; - RotateXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); - RotateYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); - RotateZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + RotateXGizmoEntity->GetComponent().SetVisibility(false); + RotateYGizmoEntity->GetComponent().SetVisibility(false); + RotateZGizmoEntity->GetComponent().SetVisibility(false); bRotateXGizmoActive = false; bRotateYGizmoActive = false; @@ -395,29 +407,29 @@ void GizmoManager::UpdateGizmoState(int NewState) { case TRANSFORM_GIZMOS: { - TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + TransformationXGizmoEntity->GetComponent().SetVisibility(true); + TransformationYGizmoEntity->GetComponent().SetVisibility(true); + TransformationZGizmoEntity->GetComponent().SetVisibility(true); - TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + TransformationXYGizmoEntity->GetComponent().SetVisibility(true); + TransformationYZGizmoEntity->GetComponent().SetVisibility(true); + TransformationXZGizmoEntity->GetComponent().SetVisibility(true); break; } case SCALE_GIZMOS: { - ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + ScaleXGizmoEntity->GetComponent().SetVisibility(true); + ScaleYGizmoEntity->GetComponent().SetVisibility(true); + ScaleZGizmoEntity->GetComponent().SetVisibility(true); break; } case ROTATE_GIZMOS: { - RotateXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - RotateYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - RotateZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + RotateXGizmoEntity->GetComponent().SetVisibility(true); + RotateYGizmoEntity->GetComponent().SetVisibility(true); + RotateZGizmoEntity->GetComponent().SetVisibility(true); break; } @@ -470,86 +482,86 @@ void GizmoManager::Render() if (GIZMO_MANAGER.GizmosState == TRANSFORM_GIZMOS) { // X Gizmos - GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); + GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); if (GIZMO_MANAGER.bTransformationXZGizmoActive || GIZMO_MANAGER.bTransformationXYGizmoActive || GIZMO_MANAGER.bTransformationXGizmoActive) - GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // Y Gizmos - GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); + GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); if (GIZMO_MANAGER.bTransformationYZGizmoActive || GIZMO_MANAGER.bTransformationXYGizmoActive || GIZMO_MANAGER.bTransformationYGizmoActive) - GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // Z Gizmos - GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); + GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); if (GIZMO_MANAGER.bTransformationYZGizmoActive || GIZMO_MANAGER.bTransformationXZGizmoActive || GIZMO_MANAGER.bTransformationZGizmoActive) - GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // XY Gizmos - GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); + GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); if (GIZMO_MANAGER.bTransformationXYGizmoActive) - GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // YZ Gizmos - GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); + GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); if (GIZMO_MANAGER.bTransformationYZGizmoActive) - GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // XZ Gizmos - GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); + GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); if (GIZMO_MANAGER.bTransformationXZGizmoActive) - GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); } else if (GIZMO_MANAGER.GizmosState == SCALE_GIZMOS) { // X Gizmos - GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); + GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); if (GIZMO_MANAGER.bScaleXGizmoActive) - GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // Y Gizmos - GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); + GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); if (GIZMO_MANAGER.bScaleYGizmoActive) - GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // Z Gizmos - GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); + GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); if (GIZMO_MANAGER.bScaleZGizmoActive) - GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); } else if (GIZMO_MANAGER.GizmosState == ROTATE_GIZMOS) { if (SELECTED.SELECTED.GetSelected() != nullptr) { - GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().SetVisibility(true); + GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().SetVisibility(true); + GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().SetVisibility(true); } // X Gizmos - GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); + GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); if (GIZMO_MANAGER.bRotateXGizmoActive) { - GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); - GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); - GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().SetVisibility(false); + GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().SetVisibility(false); } // Y Gizmos - GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); + GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); if (GIZMO_MANAGER.bRotateYGizmoActive) { - GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); - GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); - GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().SetVisibility(false); + GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().SetVisibility(false); } // Z Gizmos - GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); + GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); if (GIZMO_MANAGER.bRotateZGizmoActive) { - GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().OldStyleEntity->Prefab->GetComponent(0)->GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); - GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); - GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(false); + GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().SetVisibility(false); + GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().SetVisibility(false); } } } @@ -954,24 +966,24 @@ void GizmoManager::OnSelectedObjectUpdate() if (GIZMO_MANAGER.GizmosState == TRANSFORM_GIZMOS) { - GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().SetVisibility(true); + GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().SetVisibility(true); + GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().SetVisibility(true); + GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().SetVisibility(true); + GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().SetVisibility(true); + GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().SetVisibility(true); } else if (GIZMO_MANAGER.GizmosState == SCALE_GIZMOS) { - GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().SetVisibility(true); + GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().SetVisibility(true); + GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().SetVisibility(true); } else if (GIZMO_MANAGER.GizmosState == ROTATE_GIZMOS) { - GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); - GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().OldStyleEntity->SetVisibility(true); + GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().SetVisibility(true); + GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().SetVisibility(true); + GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().SetVisibility(true); } } } @@ -1055,10 +1067,11 @@ void GizmoManager::ReInitializeEntities() // TransformationXGizmo TransformationXGizmoEntity = SCENE.AddNewStyleEntity("TransformationXGizmoEntity"); - TransformationXGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXGizmoGM")[0], "TransformationXGizmoEntity")); - TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); - TransformationXGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXGizmoGM")[0]); + TransformationXGizmoEntity->SetName("TransformationXGizmoEntity"); + TransformationXGizmoEntity->GetComponent().SetCastShadows(false); + TransformationXGizmoEntity->GetComponent().SetReceivingShadows(false); + TransformationXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); TransformationXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); TransformationXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); // Temporary overly complicated solution, because of new and old entity system. @@ -1066,181 +1079,133 @@ void GizmoManager::ReInitializeEntities() // TransformationYGizmo TransformationYGizmoEntity = SCENE.AddNewStyleEntity("TransformationYGizmoEntity"); - TransformationYGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationYGizmoGM")[0], "TransformationYGizmoEntity")); - TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); - TransformationYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYGizmoGM")[0]); + TransformationYGizmoEntity->SetName("TransformationYGizmoEntity"); + TransformationYGizmoEntity->GetComponent().SetCastShadows(false); + TransformationYGizmoEntity->GetComponent().SetReceivingShadows(false); + TransformationYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); TransformationYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); TransformationYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); - //TransformationYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationYGizmoGM")[0], "transformationYGizmoEntity"); - //TransformationYGizmoEntity->SetCastShadows(false); - //TransformationYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); - //TransformationYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); - //TransformationYGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // TransformationZGizmo TransformationZGizmoEntity = SCENE.AddNewStyleEntity("TransformationZGizmoEntity"); - TransformationZGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationZGizmoGM")[0], "TransformationZGizmoEntity")); - TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); - TransformationZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationZGizmoGM")[0]); + TransformationZGizmoEntity->SetName("TransformationZGizmoEntity"); + TransformationZGizmoEntity->GetComponent().SetCastShadows(false); + TransformationZGizmoEntity->GetComponent().SetReceivingShadows(false); + TransformationZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); TransformationZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); TransformationZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - //TransformationZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationZGizmoGM")[0], "transformationZGizmoEntity"); - //TransformationZGizmoEntity->SetCastShadows(false); - //TransformationZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); - //TransformationZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - //TransformationZGizmoEntity->SetIsPostprocessApplied(false); - // Temporary overly complicated solution, because of new and old entity system. SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // Plane gizmos TransformationXYGizmoEntity = SCENE.AddNewStyleEntity("TransformationXYGizmoEntity"); - TransformationXYGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXYGizmoGM")[0], "TransformationXYGizmoEntity")); - TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); - TransformationXYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationXYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXYGizmoGM")[0]); + TransformationXYGizmoEntity->SetName("TransformationXYGizmoEntity"); + TransformationXYGizmoEntity->GetComponent().SetCastShadows(false); + TransformationXYGizmoEntity->GetComponent().SetReceivingShadows(false); + TransformationXYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); TransformationXYGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); TransformationXYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); TransformationXYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - /*TransformationXYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXYGizmoGM")[0], "transformationXYGizmoEntity"); - TransformationXYGizmoEntity->SetCastShadows(false); - TransformationXYGizmoEntity->Transform.SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); - TransformationXYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); - TransformationXYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - TransformationXYGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); TransformationYZGizmoEntity = SCENE.AddNewStyleEntity("TransformationYZGizmoEntity"); - TransformationYZGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationYZGizmoGM")[0], "TransformationYZGizmoEntity")); - TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); - TransformationYZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationYZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYZGizmoGM")[0]); + TransformationYZGizmoEntity->SetName("TransformationYZGizmoEntity"); + TransformationYZGizmoEntity->GetComponent().SetCastShadows(false); + TransformationYZGizmoEntity->GetComponent().SetReceivingShadows(false); + TransformationYZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); TransformationYZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); TransformationYZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); TransformationYZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - /*TransformationYZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationYZGizmoGM")[0], "transformationYZGizmoEntity"); - TransformationYZGizmoEntity->SetCastShadows(false); - TransformationYZGizmoEntity->Transform.SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); - TransformationYZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); - TransformationYZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - TransformationYZGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); TransformationXZGizmoEntity = SCENE.AddNewStyleEntity("TransformationXZGizmoEntity"); - TransformationXZGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXZGizmoGM")[0], "TransformationXZGizmoEntity")); - TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); - TransformationXZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + TransformationXZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXZGizmoGM")[0]); + TransformationXZGizmoEntity->SetName("TransformationXZGizmoEntity"); + TransformationXZGizmoEntity->GetComponent().SetCastShadows(false); + TransformationXZGizmoEntity->GetComponent().SetReceivingShadows(false); + TransformationXZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); TransformationXZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); TransformationXZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); TransformationXZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - /*TransformationXZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("TransformationXZGizmoGM")[0], "transformationXZGizmoEntity"); - TransformationXZGizmoEntity->SetCastShadows(false); - TransformationXZGizmoEntity->Transform.SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); - TransformationXZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); - TransformationXZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - TransformationXZGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // ScaleXGizmo ScaleXGizmoEntity = SCENE.AddNewStyleEntity("ScaleXGizmoEntity"); - ScaleXGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("ScaleXGizmoGM")[0], "ScaleXGizmoEntity")); - ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); - ScaleXGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + ScaleXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleXGizmoGM")[0]); + ScaleXGizmoEntity->SetName("ScaleXGizmoEntity"); + ScaleXGizmoEntity->GetComponent().SetCastShadows(false); + ScaleXGizmoEntity->GetComponent().SetReceivingShadows(false); + ScaleXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); ScaleXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); ScaleXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - /*ScaleXGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("scaleXGizmoGM")[0], "scaleXGizmoEntity"); - ScaleXGizmoEntity->SetCastShadows(false); - ScaleXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); - ScaleXGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - ScaleXGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // ScaleYGizmo ScaleYGizmoEntity = SCENE.AddNewStyleEntity("ScaleYGizmoEntity"); - ScaleYGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("ScaleYGizmoGM")[0], "ScaleYGizmoEntity")); - ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); - ScaleYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + ScaleYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleYGizmoGM")[0]); + ScaleYGizmoEntity->SetName("ScaleYGizmoEntity"); + ScaleYGizmoEntity->GetComponent().SetCastShadows(false); + ScaleYGizmoEntity->GetComponent().SetReceivingShadows(false); + ScaleYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); ScaleYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); ScaleYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); - /*ScaleYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("scaleYGizmoGM")[0], "scaleYGizmoEntity"); - ScaleYGizmoEntity->SetCastShadows(false); - ScaleYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); - ScaleYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); - ScaleYGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // ScaleZGizmo ScaleZGizmoEntity = SCENE.AddNewStyleEntity("ScaleZGizmoEntity"); - ScaleZGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("ScaleZGizmoGM")[0], "ScaleZGizmoEntity")); - ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); - ScaleZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + ScaleZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleZGizmoGM")[0]); + ScaleZGizmoEntity->SetName("ScaleZGizmoEntity"); + ScaleZGizmoEntity->GetComponent().SetCastShadows(false); + ScaleZGizmoEntity->GetComponent().SetReceivingShadows(false); + ScaleZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); ScaleZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); ScaleZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - /*ScaleZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("scaleZGizmoGM")[0], "scaleZGizmoEntity"); - ScaleZGizmoEntity->SetCastShadows(false); - ScaleZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); - ScaleZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - ScaleZGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // RotateXGizmo RotateXGizmoEntity = SCENE.AddNewStyleEntity("RotateXGizmoEntity"); - RotateXGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("RotateXGizmoGM")[0], "RotateXGizmoEntity")); - RotateXGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - RotateXGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); - RotateXGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + RotateXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateXGizmoGM")[0]); + RotateXGizmoEntity->SetName("RotateXGizmoEntity"); + RotateXGizmoEntity->GetComponent().SetCastShadows(false); + RotateXGizmoEntity->GetComponent().SetReceivingShadows(false); + RotateXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); RotateXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); RotateXGizmoEntity->GetComponent().SetRotation(RotateXStandardRotation); - /*RotateXGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("rotateXGizmoGM")[0], "rotateXGizmoEntity"); - RotateXGizmoEntity->SetCastShadows(false); - RotateXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateXGizmoEntity->Transform.SetRotation(RotateXStandardRotation); - RotateXGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // RotateYGizmo RotateYGizmoEntity = SCENE.AddNewStyleEntity("RotateYGizmoEntity"); - RotateYGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("RotateYGizmoGM")[0], "RotateYGizmoEntity")); - RotateYGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - RotateYGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); - RotateYGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + RotateYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateYGizmoGM")[0]); + RotateYGizmoEntity->SetName("RotateYGizmoEntity"); + RotateYGizmoEntity->GetComponent().SetCastShadows(false); + RotateYGizmoEntity->GetComponent().SetReceivingShadows(false); + RotateYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); RotateYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); RotateYGizmoEntity->GetComponent().SetRotation(RotateYStandardRotation); - /*RotateYGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("rotateYGizmoGM")[0], "rotateYGizmoEntity"); - RotateYGizmoEntity->SetCastShadows(false); - RotateYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateYGizmoEntity->Transform.SetRotation(RotateYStandardRotation); - RotateYGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // RotateZGizmo RotateZGizmoEntity = SCENE.AddNewStyleEntity("RotateZGizmoEntity"); - RotateZGizmoEntity->AddComponent(SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("RotateZGizmoGM")[0], "RotateZGizmoEntity")); - RotateZGizmoEntity->GetComponent().OldStyleEntity->SetCastShadows(false); - RotateZGizmoEntity->GetComponent().OldStyleEntity->SetReceivingShadows(false); - RotateZGizmoEntity->GetComponent().OldStyleEntity->SetIsPostprocessApplied(false); + RotateZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateZGizmoGM")[0]); + RotateZGizmoEntity->SetName("RotateZGizmoEntity"); + RotateZGizmoEntity->GetComponent().SetCastShadows(false); + RotateZGizmoEntity->GetComponent().SetReceivingShadows(false); + RotateZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); RotateZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); RotateZGizmoEntity->GetComponent().SetRotation(RotateZStandardRotation); - /*RotateZGizmoEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefabByName("rotateZGizmoGM")[0], "rotateZGizmoEntity"); - RotateZGizmoEntity->SetCastShadows(false); - RotateZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateZGizmoEntity->Transform.SetRotation(RotateZStandardRotation); - RotateZGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); } \ No newline at end of file diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index a205a1c..efb5707 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -159,16 +159,21 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons SELECTED.InstancedSubObjectsInfo.clear(); const glm::vec3 MouseRayVector = MouseRay(MouseX, MouseY); - const std::vector EntityList = SCENE.GetEntityList(); + const std::vector EntityList = SCENE.GetNewEntityList(); for (size_t i = 0; i < EntityList.size(); i++) { float Distance = 0; - FEEntity* Entity = SCENE.GetEntity(EntityList[i]); - FENewEntity* NewStyleEntity = SCENE.GetNewStyleEntityByOldStyleID(Entity->GetObjectID()); - if (NewStyleEntity != nullptr && NewStyleEntity->HasComponent()) + //FEEntity* Entity = SCENE.GetEntity(EntityList[i]); + //FENewEntity* NewStyleEntity = SCENE.GetNewStyleEntityByOldStyleID(Entity->GetObjectID()); + + FENewEntity* NewStyleEntity = SCENE.GetNewStyleEntity(EntityList[i]); + if (NewStyleEntity != nullptr && NewStyleEntity->HasComponent()) { - FEAABB Box = Entity->GetAABB().Transform(NewStyleEntity->GetComponent().GetTransformMatrix()); + FEGameModelComponent& GameModelComponent = NewStyleEntity->GetComponent(); + + FEAABB Box = GameModelComponent.GameModel->GetMesh()->GetAABB().Transform(NewStyleEntity->GetComponent().GetTransformMatrix()); + //FEAABB Box = Entity->GetAABB().Transform(NewStyleEntity->GetComponent().GetTransformMatrix()); //FEAABB Box = SCENE.GetEntity(EntityList[i])->GetAABB(); if (Box.RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) { @@ -237,25 +242,38 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons int b = ((i + 1) >> 16) & 255; #endif FENewEntity* PotentiallySelectedEntity = SELECTED.SceneEntitiesUnderMouse[i]; - if (PotentiallySelectedEntity->HasComponent()) + if (PotentiallySelectedEntity->HasComponent()) { - FERenderableComponent& RenderableComponent = PotentiallySelectedEntity->GetComponent(); - if (!RenderableComponent.OldStyleEntity->IsVisible()) + FEGameModelComponent& GameModelComponent = PotentiallySelectedEntity->GetComponent(); + if (!GameModelComponent.IsVisible()) continue; - for (int j = 0; j < RenderableComponent.OldStyleEntity->Prefab->ComponentsCount(); j++) - { - FEMaterial* RegularMaterial = RenderableComponent.OldStyleEntity->Prefab->GetComponent(j)->GameModel->Material; - RenderableComponent.OldStyleEntity->Prefab->GetComponent(j)->GameModel->Material = PixelAccurateSelectionMaterial; + // FIX ME! Prefab not supported + FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; + GameModelComponent.GameModel->Material = PixelAccurateSelectionMaterial; + PixelAccurateSelectionMaterial->SetBaseColor(glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); + PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); + PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + + RENDERER.RenderGameModelComponent(GameModelComponent, PotentiallySelectedEntity->GetComponent(), ENGINE.GetCamera(), false); + //RENDERER.RenderEntity(GameModelComponent.OldStyleEntity, ENGINE.GetCamera(), false, j); + + GameModelComponent.GameModel->Material = RegularMaterial; + + //for (int j = 0; j < GameModelComponent.OldStyleEntity->Prefab->ComponentsCount(); j++) + //{ + /*FEMaterial* RegularMaterial = GameModelComponent.OldStyleEntity->Prefab->GetComponent(j)->GameModel->Material; + GameModelComponent.OldStyleEntity->Prefab->GetComponent(j)->GameModel->Material = PixelAccurateSelectionMaterial; PixelAccurateSelectionMaterial->SetBaseColor(glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - RENDERER.RenderEntity(RenderableComponent.OldStyleEntity, ENGINE.GetCamera(), false, j); + RENDERER.RenderEntity(GameModelComponent.OldStyleEntity, ENGINE.GetCamera(), false, j); - RenderableComponent.OldStyleEntity->Prefab->GetComponent(j)->GameModel->Material = RegularMaterial; - } + GameModelComponent.OldStyleEntity->Prefab->GetComponent(j)->GameModel->Material = RegularMaterial;*/ + //} PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr); PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr, 1); @@ -451,7 +469,7 @@ void FEEditorSelectedObject::OnCameraUpdate() const //FE_GL_ERROR(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT)); - if (Container == nullptr || !Container->HasComponent()) + if (Container == nullptr || !Container->HasComponent()) { HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); ENGINE.SetClearColor(OriginalClearColor); @@ -460,10 +478,22 @@ void FEEditorSelectedObject::OnCameraUpdate() const return; } - FERenderableComponent& RenderableComponent = Container->GetComponent(); - FEEntity* SelectedEntity = RenderableComponent.OldStyleEntity; + FEGameModelComponent& GameModelComponent = Container->GetComponent(); + + FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; - if (SelectedEntity->GetType() == FE_ENTITY) + GameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + + RENDERER.RenderGameModelComponent(GameModelComponent, Container->GetComponent(), ENGINE.GetCamera(), false); + //RENDERER.RenderEntity(SelectedEntity, ENGINE.GetCamera(), false, i); + + GameModelComponent.GameModel->Material = RegularMaterial; + + // FIX ME! + //FEEntity* SelectedEntity = GameModelComponent.OldStyleEntity; + /*if (SelectedEntity->GetType() == FE_ENTITY) { for (int i = 0; i < SelectedEntity->Prefab->ComponentsCount(); i++) { @@ -526,7 +556,9 @@ void FEEditorSelectedObject::OnCameraUpdate() const SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; } } - } + }*/ + + //// Temporary solution, because of the lack of proper ECS system //if (Container != nullptr && Container->GetType() == FE_ENTITY) diff --git a/FEProject.cpp b/FEProject.cpp index 5a2b8c8..0435165 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -1183,35 +1183,53 @@ void FEProject::LoadScene() } else { + FENewEntity* NewEntity = SCENE.AddNewStyleEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + // For compatibility with old projects. if (Root["entities"][EntityList[i]].isMember("gameModel")) { - FEPrefab* TempPrefab = RESOURCE_MANAGER.CreatePrefab(RESOURCE_MANAGER.GetGameModel(Root["entities"][EntityList[i]]["gameModel"].asCString())); - SCENE.AddEntity(TempPrefab, Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + //FEPrefab* TempPrefab = RESOURCE_MANAGER.CreatePrefab(RESOURCE_MANAGER.GetGameModel(Root["entities"][EntityList[i]]["gameModel"].asCString())); + //SCENE.AddEntity(TempPrefab, Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + + FEGameModel* GameModel = RESOURCE_MANAGER.GetGameModel(Root["entities"][EntityList[i]]["gameModel"].asCString()); + NewEntity->AddComponent(GameModel); } else { - SCENE.AddEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), - Root["entities"][EntityList[i]]["name"].asString(), - Root["entities"][EntityList[i]]["ID"].asString()); + /*SCENE.AddEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), + Root["entities"][EntityList[i]]["name"].asString(), + Root["entities"][EntityList[i]]["ID"].asString());*/ + + FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString())->GetComponent(0)->GameModel; + NewEntity->AddComponent(GameModel); } if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) - SCENE.GetEntity(EntityList[i])->SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); - - ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(EntityList[i])->Transform); + { + //SCENE.GetEntity(EntityList[i])->SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); + NewEntity->GetComponent().SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); + } + + ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &NewEntity->GetComponent()); + /*ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(EntityList[i])->Transform); FENewEntity* NewEntity = SCENE.GetNewStyleEntityByOldStyleID(EntityList[i]); if (NewEntity != nullptr) { NewEntity->GetComponent() = SCENE.GetEntity(EntityList[i])->Transform; - } + }*/ } } + // For compatibility with old projects. else { - SCENE.AddEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), + FENewEntity* NewEntity = SCENE.AddNewStyleEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString())->GetComponent(0)->GameModel; + NewEntity->AddComponent(GameModel); + ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &NewEntity->GetComponent()); + + /*SCENE.AddEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), EntityList[i], Root["entities"][EntityList[i]]["ID"].asString()); - ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(EntityList[i])->Transform); + ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(EntityList[i])->Transform);*/ } } @@ -1447,6 +1465,7 @@ void FEProject::AddFileToDeleteList(const std::string FileName) FilesToDelete.push_back(FileName); } +// FIX ME! Deprecate. void FEProject::LoadSceneVer0() { std::ifstream SceneFile; diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index a0a4c93..772d704 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit a0a4c936fc5144f177827d703c8542cd1bbd20ac +Subproject commit 772d7045df736f87bca27624258cc7a52050e22e From 28b4b29b9a1e60f736e64e16e9ebed2da4ce476a Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Thu, 4 Jul 2024 21:37:28 -0400 Subject: [PATCH 15/46] Engine update; Made changes to accommodate new aspects of ECS. --- EditorWindows/InspectorWindow.cpp | 273 ++++++++++- FEEditorGizmoManager.cpp | 4 + FEEditorSelectedObject.cpp | 238 ++++------ FEProject.cpp | 742 +++++++++++++++--------------- SubSystems/FocalEngine | 2 +- main.cpp | 2 +- 6 files changed, 745 insertions(+), 516 deletions(-) diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index ef9d237..41ddb21 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -420,7 +420,7 @@ void FEEditorInspectorWindow::Render() ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); ImGui::Begin("Inspector", nullptr, ImGuiWindowFlags_None); - + if (SELECTED.GetSelected() == nullptr) { ImGui::PopStyleVar(); @@ -498,6 +498,271 @@ void FEEditorInspectorWindow::Render() ImGui::PopStyleColor(); } + if (EntitySelected->HasComponent()) + { + FEInstancedRenderingComponent& InstancedComponent = EntitySelected->GetComponent(); + + if (SELECTED.InstancedSubObjectIndexSelected != -1) + { + std::string InstancedSubObjectInfo = "index: "; + + ImGui::Text("Selected instance info:"); + InstancedSubObjectInfo = "index: " + std::to_string(SELECTED.InstancedSubObjectIndexSelected); + ImGui::Text(InstancedSubObjectInfo.c_str()); + + FETransformComponent TempTransform = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(SELECTED.InstancedSubObjectIndexSelected)); + ShowTransformConfiguration("selected instance", &TempTransform); + + INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(EntitySelected, SELECTED.InstancedSubObjectIndexSelected, TempTransform.GetTransformMatrix()); + //InstancedEntity->ModifyInstance(SELECTED.InstancedSubObjectIndexSelected, TempTransform.GetTransformMatrix()); + + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + + if (ImGui::ImageButton((void*)(intptr_t)ArrowToGroundIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + { + INSTANCED_RENDERING_SYSTEM.TryToSnapIndividualInstance(EntitySelected, SELECTED.InstancedSubObjectIndexSelected); + //InstancedEntity->TryToSnapInstance(SELECTED.InstancedSubObjectIndexSelected); + } + ShowToolTip("Selected instance will attempt to snap to the terrain."); + + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + } + else + { + ImGui::Text("Snapped to: "); + ImGui::SameLine(); + + const std::vector TerrainList = SCENE.GetTerrainList(); + static std::string CurrentTerrain = "none"; + + if (InstancedComponent.GetSnappedToTerrain() == nullptr) + { + CurrentTerrain = "none"; + } + else + { + CurrentTerrain = InstancedComponent.GetSnappedToTerrain()->GetName(); + } + + ImGui::SetNextItemWidth(220); + if (ImGui::BeginCombo("##Terrain", CurrentTerrain.c_str(), ImGuiWindowFlags_None)) + { + const bool is_selected = (CurrentTerrain == "none"); + if (ImGui::Selectable("none", is_selected)) + { + //if (InstancedComponent.GetSnappedToTerrain() != nullptr) + // InstancedComponent.GetSnappedToTerrain()->UnSnapInstancedEntity(InstancedEntity); + } + + if (is_selected) + ImGui::SetItemDefaultFocus(); + + for (size_t i = 0; i < TerrainList.size(); i++) + { + const bool is_selected = (CurrentTerrain == TerrainList[i]); + if (ImGui::Selectable(SCENE.GetTerrain(TerrainList[i])->GetName().c_str(), is_selected)) + { + //SCENE.GetTerrain(TerrainList[i])->SnapInstancedEntity(InstancedEntity); + } + + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } + + if (InstancedComponent.GetSnappedToTerrain() != nullptr) + { + ImGui::Text("Terrain layer: "); + ImGui::SameLine(); + + const int CurrentLayer = InstancedComponent.GetTerrainLayer(); + FETerrain* CurrentTerrain = InstancedComponent.GetSnappedToTerrain(); + + std::string caption = "none"; + const auto layer = CurrentTerrain->GetLayerInSlot(CurrentLayer); + if (layer != nullptr) + caption = layer->GetName(); + + ImGui::SetNextItemWidth(220); + if (ImGui::BeginCombo("##TerrainLayers", caption.c_str(), ImGuiWindowFlags_None)) + { + const bool is_selected = (CurrentLayer == -1); + ImGui::PushID("none_TerrainLayers_entity"); + if (ImGui::Selectable("none", is_selected)) + { + //if (CurrentTerrain != nullptr) + //CurrentTerrain->UnConnectInstancedEntityFromLayer(InstancedEntity); + } + ImGui::PopID(); + + if (is_selected) + ImGui::SetItemDefaultFocus(); + + for (size_t i = 0; i < FE_TERRAIN_MAX_LAYERS; i++) + { + FETerrainLayer* layer = CurrentTerrain->GetLayerInSlot(i); + if (layer == nullptr) + break; + + const bool is_selected = (CurrentLayer == i); + ImGui::PushID(layer->GetObjectID().c_str()); + if (ImGui::Selectable(layer->GetName().c_str(), is_selected)) + { + //CurrentTerrain->ConnectInstancedEntityToLayer(InstancedEntity, int(i)); + } + ImGui::PopID(); + + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } + + if (CurrentLayer != -1) + { + ImGui::Text("Minimal layer intensity to spawn:"); + float MinLevel = InstancedComponent.GetMinimalLayerIntensityToSpawn(); + ImGui::SameLine(); + ImGui::SetNextItemWidth(80); + ImGui::DragFloat("##minLevel", &MinLevel); + InstancedComponent.SetMinimalLayerIntensityToSpawn(MinLevel); + } + } + + ImGui::Separator(); + + ImGui::Text("Seed:"); + int seed = InstancedComponent.SpawnInfo.Seed; + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + ImGui::DragInt("##Seed", &seed); + InstancedComponent.SpawnInfo.Seed = seed; + + ImGui::Text("Object count:"); + int ObjectCount = InstancedComponent.SpawnInfo.ObjectCount; + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + ImGui::DragInt("##Object count", &ObjectCount); + if (ObjectCount <= 0) + ObjectCount = 1; + InstancedComponent.SpawnInfo.ObjectCount = ObjectCount; + + ImGui::Text("Radius:"); + float radius = InstancedComponent.SpawnInfo.Radius; + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + ImGui::DragFloat("##Radius", &radius); + if (radius < 0.0f) + radius = 0.1f; + InstancedComponent.SpawnInfo.Radius = radius; + + // Scale deviation. + ImGui::Text("Scale: "); + + ImGui::SameLine(); + ImGui::Text("min "); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(100); + float MinScale = InstancedComponent.SpawnInfo.GetMinScale(); + ImGui::DragFloat("##minScale", &MinScale, 0.01f); + InstancedComponent.SpawnInfo.SetMinScale(MinScale); + + ImGui::SameLine(); + ImGui::Text("max "); + + ImGui::SameLine(); + float MaxScale = InstancedComponent.SpawnInfo.GetMaxScale(); + ImGui::SetNextItemWidth(100); + ImGui::DragFloat("##maxScale", &MaxScale, 0.01f); + InstancedComponent.SpawnInfo.SetMaxScale(MaxScale); + + ImGui::Text("Rotation deviation:"); + float RotationDeviationX = InstancedComponent.SpawnInfo.RotationDeviation.x; + ImGui::Text("X:"); + ImGui::SameLine(); + ImGui::DragFloat("##Rotation deviation X", &RotationDeviationX, 0.01f); + if (RotationDeviationX < 0.01f) + RotationDeviationX = 0.01f; + if (RotationDeviationX > 1.0f) + RotationDeviationX = 1.0f; + InstancedComponent.SpawnInfo.RotationDeviation.x = RotationDeviationX; + + float RotationDeviationY = InstancedComponent.SpawnInfo.RotationDeviation.y; + ImGui::Text("Y:"); + ImGui::SameLine(); + ImGui::DragFloat("##Rotation deviation Y", &RotationDeviationY, 0.01f); + if (RotationDeviationY < 0.01f) + RotationDeviationY = 0.01f; + if (RotationDeviationY > 1.0f) + RotationDeviationY = 1.0f; + InstancedComponent.SpawnInfo.RotationDeviation.y = RotationDeviationY; + + float RotationDeviationZ = InstancedComponent.SpawnInfo.RotationDeviation.z; + ImGui::Text("Z:"); + ImGui::SameLine(); + ImGui::DragFloat("##Rotation deviation z", &RotationDeviationZ, 0.01f); + if (RotationDeviationZ < 0.01f) + RotationDeviationZ = 0.01f; + if (RotationDeviationZ > 1.0f) + RotationDeviationZ = 1.0f; + InstancedComponent.SpawnInfo.RotationDeviation.z = RotationDeviationZ; + + if (ImGui::Button("Spawn/Re-Spawn")) + { + INSTANCED_RENDERING_SYSTEM.ClearInstance(EntitySelected); + INSTANCED_RENDERING_SYSTEM.PopulateInstance(EntitySelected, InstancedComponent.SpawnInfo); + //InstancedComponent.Clear(); + //InstancedComponent.Populate(InstancedComponent.SpawnInfo); + } + + if (ImGui::Button("Add instance")) + { + glm::mat4 NewInstanceMatrix = glm::identity(); + NewInstanceMatrix = glm::translate(NewInstanceMatrix, ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + //InstancedComponent.AddInstance(NewInstanceMatrix); + INSTANCED_RENDERING_SYSTEM.AddIndividualInstance(EntitySelected, NewInstanceMatrix); + + PROJECT_MANAGER.GetCurrent()->SetModified(true); + } + + if (INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(EntitySelected)) + { + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.0f, 0.75f, 0.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); + } + else + { + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + } + + ImGui::Separator(); + if (ImGui::ImageButton((void*)(intptr_t)MouseCursorIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + { + INSTANCED_RENDERING_SYSTEM.SetIndividualSelectMode(EntitySelected, !INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(EntitySelected)); + //SCENE.SetIndividualSelectMode(InstancedEntity, !InstancedComponent.IsIndividualSelectMode()); + if (!INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(EntitySelected)) + { + SELECTED.Clear(); + SELECTED.SetSelected(EntitySelected); + } + } + ShowToolTip("Individual selection mode - Used to select individual instances."); + + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + } + } + // FIX ME! //if (SELECTED.GetEntity() != nullptr) //{ @@ -837,7 +1102,7 @@ void FEEditorInspectorWindow::Render() // PROJECT_MANAGER.GetCurrent()->SetModified(true); // } - // if (InstancedEntity->IsSelectMode()) + // if (InstancedEntity->IsIndividualSelectMode()) // { // ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.0f, 0.75f, 0.0f)); // ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); @@ -853,8 +1118,8 @@ void FEEditorInspectorWindow::Render() // ImGui::Separator(); // if (ImGui::ImageButton((void*)(intptr_t)MouseCursorIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) // { - // SCENE.SetSelectMode(InstancedEntity, !InstancedEntity->IsSelectMode()); - // if (!InstancedEntity->IsSelectMode()) + // SCENE.SetIndividualSelectMode(InstancedEntity, !InstancedEntity->IsIndividualSelectMode()); + // if (!InstancedEntity->IsIndividualSelectMode()) // { // SELECTED.Clear(); // // FIX ME! diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index d69a1a3..b785648 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -459,6 +459,10 @@ void GizmoManager::DeactivateAllGizmo() void GizmoManager::Render() { + // If we cleared the scene, we should not render gizmos. + if (SCENE.GetEntityByName("TransformationXGizmoEntity").empty() || SCENE.GetEntityByName("TransformationXGizmoEntity")[0] == nullptr) + return; + if (SELECTED.GetSelected() == nullptr || SELECTED.GetSelected()->GetType() == FE_CAMERA) { HideAllGizmo(); diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index efb5707..c605143 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -127,7 +127,7 @@ void FEEditorSelectedObject::Clear() // FIX ME! /*if (InstancedSubObjectIndexSelected != -1 && SCENE.GetEntityInstanced(Container->GetObjectID()) != nullptr) { - SCENE.GetEntityInstanced(Container->GetObjectID())->SetSelectMode(false); + SCENE.GetEntityInstanced(Container->GetObjectID())->SetIndividualSelectMode(false); }*/ InstancedSubObjectIndexSelected = -1; @@ -164,29 +164,53 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons { float Distance = 0; - //FEEntity* Entity = SCENE.GetEntity(EntityList[i]); - //FENewEntity* NewStyleEntity = SCENE.GetNewStyleEntityByOldStyleID(Entity->GetObjectID()); - FENewEntity* NewStyleEntity = SCENE.GetNewStyleEntity(EntityList[i]); if (NewStyleEntity != nullptr && NewStyleEntity->HasComponent()) { FEGameModelComponent& GameModelComponent = NewStyleEntity->GetComponent(); - FEAABB Box = GameModelComponent.GameModel->GetMesh()->GetAABB().Transform(NewStyleEntity->GetComponent().GetTransformMatrix()); - //FEAABB Box = Entity->GetAABB().Transform(NewStyleEntity->GetComponent().GetTransformMatrix()); - //FEAABB Box = SCENE.GetEntity(EntityList[i])->GetAABB(); + FEAABB Box; + if (!NewStyleEntity->HasComponent()) + { + Box = GameModelComponent.GameModel->GetMesh()->GetAABB().Transform(NewStyleEntity->GetComponent().GetTransformMatrix()); + } + else if (NewStyleEntity->HasComponent()) + { + Box = INSTANCED_RENDERING_SYSTEM.GetAABB(NewStyleEntity); + } + if (Box.RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) { + if (NewStyleEntity->HasComponent()) + { + FEInstancedRenderingComponent& InstancedComponent = NewStyleEntity->GetComponent(); + //FEEntityInstanced* InstancedEntity = reinterpret_cast(SCENE.GetEntity(EntityList[i])); + if (INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(NewStyleEntity)) + { + // FIX ME! + /*InstancedSubObjectsInfo[InstancedEntity] = std::vector(); + for (size_t j = 0; j < InstancedEntity->IndividualInstancedAABB.size(); j++) + { + if (InstancedEntity->IndividualInstancedAABB[j].RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) + { + InstancedSubObjectsInfo[InstancedEntity].push_back(static_cast(j)); + } + }*/ + } + } + + SELECTED.SceneEntitiesUnderMouse.push_back(NewStyleEntity); + // FIX ME! /*if (SCENE.GetEntity(EntityList[i])->GetType() == FE_ENTITY_INSTANCED) { FEEntityInstanced* InstancedEntity = reinterpret_cast(SCENE.GetEntity(EntityList[i])); - if (InstancedEntity->IsSelectMode()) + if (InstancedEntity->IsIndividualSelectMode()) { InstancedSubObjectsInfo[InstancedEntity] = std::vector(); - for (size_t j = 0; j < InstancedEntity->InstancedAABB.size(); j++) + for (size_t j = 0; j < InstancedEntity->IndividualInstancedAABB.size(); j++) { - if (InstancedEntity->InstancedAABB[j].RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) + if (InstancedEntity->IndividualInstancedAABB[j].RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) { InstancedSubObjectsInfo[InstancedEntity].push_back(static_cast(j)); } @@ -197,7 +221,7 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons } else {*/ - SELECTED.SceneEntitiesUnderMouse.push_back(NewStyleEntity/*SCENE.GetEntity(EntityList[i])*/); + //SELECTED.SceneEntitiesUnderMouse.push_back(NewStyleEntity/*SCENE.GetEntity(EntityList[i])*/); //} } } @@ -256,30 +280,28 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - RENDERER.RenderGameModelComponent(GameModelComponent, PotentiallySelectedEntity->GetComponent(), ENGINE.GetCamera(), false); - //RENDERER.RenderEntity(GameModelComponent.OldStyleEntity, ENGINE.GetCamera(), false, j); - - GameModelComponent.GameModel->Material = RegularMaterial; - - //for (int j = 0; j < GameModelComponent.OldStyleEntity->Prefab->ComponentsCount(); j++) - //{ - /*FEMaterial* RegularMaterial = GameModelComponent.OldStyleEntity->Prefab->GetComponent(j)->GameModel->Material; - GameModelComponent.OldStyleEntity->Prefab->GetComponent(j)->GameModel->Material = PixelAccurateSelectionMaterial; - PixelAccurateSelectionMaterial->SetBaseColor(glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); - PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); - PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + if (!PotentiallySelectedEntity->HasComponent()) + { + RENDERER.RenderGameModelComponent(GameModelComponent, PotentiallySelectedEntity->GetComponent(), ENGINE.GetCamera(), false); + } + else if (PotentiallySelectedEntity->HasComponent()) + { + PixelAccurateSelectionMaterial->Shader = FEPixelAccurateInstancedSelection; + FEMaterial* RegularBillboardMaterials = GameModelComponent.GameModel->GetBillboardMaterial(); + GameModelComponent.GameModel->SetBillboardMaterial(PixelAccurateSelectionMaterial); - RENDERER.RenderEntity(GameModelComponent.OldStyleEntity, ENGINE.GetCamera(), false, j); + FEInstancedRenderingComponent& InstancedComponent = PotentiallySelectedEntity->GetComponent(); + RENDERER.RenderGameModelComponentWithInstanced(PotentiallySelectedEntity->GetComponent(), GameModelComponent, InstancedComponent, ENGINE.GetCamera(), nullptr, false, false); - GameModelComponent.OldStyleEntity->Prefab->GetComponent(j)->GameModel->Material = RegularMaterial;*/ - //} + PixelAccurateSelectionMaterial->Shader = FEPixelAccurateSelection; + GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterials); + } + GameModelComponent.GameModel->Material = RegularMaterial; PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr); PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr, 1); } - //if (SELECTED.SceneEntitiesUnderMouse[i]->GetType() == FE_ENTITY) //{ // PotentiallySelectedEntity = SCENE.GetEntity(SELECTED.SceneEntitiesUnderMouse[i]->GetObjectID()); @@ -479,17 +501,59 @@ void FEEditorSelectedObject::OnCameraUpdate() const } FEGameModelComponent& GameModelComponent = Container->GetComponent(); - FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; GameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - RENDERER.RenderGameModelComponent(GameModelComponent, Container->GetComponent(), ENGINE.GetCamera(), false); - //RENDERER.RenderEntity(SelectedEntity, ENGINE.GetCamera(), false, i); + if (!Container->HasComponent()) + { + RENDERER.RenderGameModelComponent(GameModelComponent, Container->GetComponent(), ENGINE.GetCamera(), false); + } + else if (Container->HasComponent()) + { + //FEEntityInstanced* SelectedInstancedEntity = reinterpret_cast(SelectedEntity); + if (InstancedSubObjectIndexSelected != -1) + { + // FIX ME! + /*static FEEntity* DummyEntity = SCENE.AddEntity(SelectedInstancedEntity->Prefab, "dummyEntity"); + DummyEntity->SetVisibility(true); + DummyEntity->Prefab = SelectedInstancedEntity->Prefab; + DummyEntity->Transform = FETransformComponent(SelectedInstancedEntity->GetTransformedInstancedMatrix(InstancedSubObjectIndexSelected)); + + for (int i = 0; i < DummyEntity->Prefab->ComponentsCount(); i++) + { + FEMaterial* RegularMaterial = DummyEntity->Prefab->GetComponent(i)->GameModel->Material; + + DummyEntity->Prefab->GetComponent(i)->GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; + + HALO_SELECTION_EFFECT.HaloMaterial->SetBaseColor(glm::vec3(0.61f, 0.86f, 1.0f)); + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + + RENDERER.RenderEntity(DummyEntity, ENGINE.GetCamera(), false, i); + + SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; + } + + DummyEntity->SetVisibility(false);*/ + } + else + { + HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawInstancedObjectShader; + FEMaterial* RegularBillboardMaterial = GameModelComponent.GameModel->GetBillboardMaterial(); + GameModelComponent.GameModel->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); + + RENDERER.RenderGameModelComponentWithInstanced(Container->GetComponent(), GameModelComponent, Container->GetComponent(), ENGINE.GetCamera(), nullptr, false, false); + + HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; + GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterial); + } + } GameModelComponent.GameModel->Material = RegularMaterial; + // FIX ME! //FEEntity* SelectedEntity = GameModelComponent.OldStyleEntity; @@ -558,111 +622,6 @@ void FEEditorSelectedObject::OnCameraUpdate() const } }*/ - - - //// Temporary solution, because of the lack of proper ECS system - //if (Container != nullptr && Container->GetType() == FE_ENTITY) - //{ - // FEEntity* SelectedEntity = reinterpret_cast(Container); - // if (SelectedEntity->Prefab == nullptr) - // { - // HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); - // ENGINE.SetClearColor(OriginalClearColor); - // HALO_SELECTION_EFFECT.PostProcess->bActive = true; - - // return; - // } - //} - - //if (Container == nullptr) - //{ - // HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); - // ENGINE.SetClearColor(OriginalClearColor); - // HALO_SELECTION_EFFECT.PostProcess->bActive = true; - - // return; - //} - - //if (Container->GetType() == FE_ENTITY) - //{ - // FEEntity* SelectedEntity = SCENE.GetEntity(Container->GetObjectID()); - - // for (int i = 0; i < SelectedEntity->Prefab->ComponentsCount(); i++) - // { - // FEMaterial* RegularMaterial = SelectedEntity->Prefab->GetComponent(i)->GameModel->Material; - - // SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; - // HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - // HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - // - // RENDERER.RenderEntity(SelectedEntity, ENGINE.GetCamera(), false, i); - // - // SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; - // } - //} - //else if (Container->GetType() == FE_ENTITY_INSTANCED) - //{ - // FEEntityInstanced* SelectedEntity = reinterpret_cast(SCENE.GetEntity(Container->GetObjectID())); - - // if (InstancedSubObjectIndexSelected != -1) - // { - // static FEEntity* DummyEntity = SCENE.AddEntity(SelectedEntity->Prefab, "dummyEntity"); - // DummyEntity->SetVisibility(true); - // DummyEntity->Prefab = SelectedEntity->Prefab; - // DummyEntity->Transform = FETransformComponent(SelectedEntity->GetTransformedInstancedMatrix(InstancedSubObjectIndexSelected)); - - // for (int i = 0; i < DummyEntity->Prefab->ComponentsCount(); i++) - // { - // FEMaterial* RegularMaterial = DummyEntity->Prefab->GetComponent(i)->GameModel->Material; - - // DummyEntity->Prefab->GetComponent(i)->GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; - - // HALO_SELECTION_EFFECT.HaloMaterial->SetBaseColor(glm::vec3(0.61f, 0.86f, 1.0f)); - // HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - // HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - - // RENDERER.RenderEntity(DummyEntity, ENGINE.GetCamera(), false, i); - - // SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; - // } - - // DummyEntity->SetVisibility(false); - // } - // else - // { - // for (int i = 0; i < SelectedEntity->Prefab->ComponentsCount(); i++) - // { - // FEMaterial* RegularMaterial = SelectedEntity->Prefab->GetComponent(i)->GameModel->Material; - // SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; - // HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - // HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - - // HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawInstancedObjectShader; - // FEMaterial* RegularBillboardMaterial = SelectedEntity->Prefab->GetComponent(i)->GameModel->GetBillboardMaterial(); - // SelectedEntity->Prefab->GetComponent(i)->GameModel->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); - - // RENDERER.RenderEntityInstanced(SelectedEntity, ENGINE.GetCamera(), nullptr, false, false, i); - - // HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; - // SelectedEntity->Prefab->GetComponent(i)->GameModel->SetBillboardMaterial(RegularBillboardMaterial); - // SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; - // } - // } - //} - //else if (Container->GetType() == FE_TERRAIN) - //{ - // FETerrain* SelectedTerrain = SCENE.GetTerrain(Container->GetObjectID()); - - // SelectedTerrain->Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); - // SelectedTerrain->Shader->UpdateParameterData("baseColor", glm::vec3(1.0f, 0.25f, 0.0f)); - // const float RegularLODLevel = SelectedTerrain->GetLODLevel(); - // SelectedTerrain->SetLODLevel(0.0f); - // RENDERER.RenderTerrain(SelectedTerrain, ENGINE.GetCamera()); - // SelectedTerrain->SetLODLevel(RegularLODLevel); - // SelectedTerrain->Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); - // SelectedTerrain->Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); - //} - HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); ENGINE.SetClearColor(OriginalClearColor); HALO_SELECTION_EFFECT.PostProcess->bActive = true; @@ -680,15 +639,14 @@ void FEEditorSelectedObject::SetSelectedByIndex(const size_t Index) if (Container != nullptr) { - // FIX ME! - /*if (SCENE.GetEntityInstanced(Container->GetObjectID()) != nullptr) + if (Container->HasComponent()) { if (SceneEntitiesUnderMouse[Index]->GetObjectID() != Container->GetObjectID()) { - SCENE.GetEntityInstanced(Container->GetObjectID())->SetSelectMode(false); + INSTANCED_RENDERING_SYSTEM.SetIndividualSelectMode(Container, false); InstancedSubObjectIndexSelected = -1; } - }*/ + } } Container = SceneEntitiesUnderMouse[Index]; diff --git a/FEProject.cpp b/FEProject.cpp index 0435165..6ce1a43 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -89,14 +89,14 @@ void FEProjectManager::OpenProject(const int ProjectIndex) // all parts of Gizmos are standard resources except entities, so we need to register them again. // if it is first start and those entities are already registered these calls just returns false. - auto it = EDITOR_INTERNAL_RESOURCES.InternalEditorObjects.begin(); + /*auto it = EDITOR_INTERNAL_RESOURCES.InternalEditorObjects.begin(); while (it != EDITOR_INTERNAL_RESOURCES.InternalEditorObjects.end()) { if (it->second->GetType() == FE_ENTITY) SCENE.AddEntity(reinterpret_cast(it->second)); it++; - } + }*/ // after loading project we should update our previews PREVIEW_MANAGER.UpdateAll(); @@ -876,11 +876,11 @@ void FEProject::LoadScene() SceneFile.close(); Json::Value Root; - JSONCPP_STRING Err; + JSONCPP_STRING Error; Json::CharReaderBuilder Builder; const std::unique_ptr Reader(Builder.newCharReader()); - if (!Reader->parse(FileData.c_str(), FileData.c_str() + FileData.size(), &Root, &Err)) + if (!Reader->parse(FileData.c_str(), FileData.c_str() + FileData.size(), &Root, &Error)) return; // Read project file version. @@ -1085,39 +1085,41 @@ void FEProject::LoadScene() SCENE.AddTerrain(NewTerrain); } - // loading Entities + // Loading entities. std::vector EntityList = Root["entities"].getMemberNames(); for (size_t i = 0; i < EntityList.size(); i++) { + FENewEntity* NewEntity = SCENE.AddNewStyleEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + if (Root["entities"][EntityList[i]].isMember("type")) { if (Root["entities"][EntityList[i]]["type"] == "FE_ENTITY_INSTANCED") { - FEEntityInstanced* InstancedEntity = nullptr; - InstancedEntity = SCENE.AddEntityInstanced(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), - Root["entities"][EntityList[i]]["name"].asString(), - Root["entities"][EntityList[i]]["ID"].asString()); + FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString())->GetComponent(0)->GameModel; + FEGameModelComponent& GameModelComponent = NewEntity->AddComponent(GameModel); + FEInstancedRenderingComponent& InstancedComponent = NewEntity->AddComponent(); if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) - InstancedEntity->SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); + GameModelComponent.SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); - ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(EntityList[i])->Transform); + ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &NewEntity->GetComponent()); - InstancedEntity->SpawnInfo.Seed = Root["entities"][EntityList[i]]["spawnInfo"]["seed"].asInt(); - InstancedEntity->SpawnInfo.ObjectCount = Root["entities"][EntityList[i]]["spawnInfo"]["objectCount"].asInt(); - InstancedEntity->SpawnInfo.Radius = Root["entities"][EntityList[i]]["spawnInfo"]["radius"].asFloat(); - InstancedEntity->SpawnInfo.SetMinScale(Root["entities"][EntityList[i]]["spawnInfo"]["minScale"].asFloat()); - InstancedEntity->SpawnInfo.SetMaxScale(Root["entities"][EntityList[i]]["spawnInfo"]["maxScale"].asFloat()); - InstancedEntity->SpawnInfo.RotationDeviation.x = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.x"].asFloat(); - InstancedEntity->SpawnInfo.RotationDeviation.y = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.y"].asFloat(); - InstancedEntity->SpawnInfo.RotationDeviation.z = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.z"].asFloat(); + FESpawnInfo SpawnInfo; + SpawnInfo.Seed = Root["entities"][EntityList[i]]["spawnInfo"]["seed"].asInt(); + SpawnInfo.ObjectCount = Root["entities"][EntityList[i]]["spawnInfo"]["objectCount"].asInt(); + SpawnInfo.Radius = Root["entities"][EntityList[i]]["spawnInfo"]["radius"].asFloat(); + SpawnInfo.SetMinScale(Root["entities"][EntityList[i]]["spawnInfo"]["minScale"].asFloat()); + SpawnInfo.SetMaxScale(Root["entities"][EntityList[i]]["spawnInfo"]["maxScale"].asFloat()); + SpawnInfo.RotationDeviation.x = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.x"].asFloat(); + SpawnInfo.RotationDeviation.y = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.y"].asFloat(); + SpawnInfo.RotationDeviation.z = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.z"].asFloat(); if (Root["entities"][EntityList[i]]["snappedToTerrain"].asString() != "none") { + // FIX ME! FETerrain* Terrain = SCENE.GetTerrain(Root["entities"][EntityList[i]]["snappedToTerrain"].asString()); - Terrain->SnapInstancedEntity(InstancedEntity); - - if (Root["entities"][EntityList[i]].isMember("terrainLayer")) + Terrain->SnapInstancedEntity(NewEntity); + /*if (Root["entities"][EntityList[i]].isMember("terrainLayer")) { if (Root["entities"][EntityList[i]]["terrainLayer"].asInt() != -1) { @@ -1125,15 +1127,15 @@ void FEProject::LoadScene() } InstancedEntity->SetMinimalLayerIntensity(Root["entities"][EntityList[i]]["minimalLayerIntensity"].asFloat()); - } + }*/ } - InstancedEntity->Populate(InstancedEntity->SpawnInfo); + INSTANCED_RENDERING_SYSTEM.PopulateInstance(NewEntity, SpawnInfo); if (Root["entities"][EntityList[i]]["modificationsToSpawn"].asBool()) { std::ifstream InfoFile; - InfoFile.open(ProjectFolder + InstancedEntity->GetObjectID() + ".txt"); + InfoFile.open(ProjectFolder + NewEntity->GetObjectID() + ".txt"); std::string InfoFileData((std::istreambuf_iterator(InfoFile)), std::istreambuf_iterator()); @@ -1150,7 +1152,7 @@ void FEProject::LoadScene() { if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_DELETED) { - InstancedEntity->DeleteInstance(EntityFileRoot["modifications"][j]["index"].asInt()); + INSTANCED_RENDERING_SYSTEM.DeleteIndividualInstance(NewEntity, EntityFileRoot["modifications"][j]["index"].asInt()); } else if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_MODIFIED) { @@ -1163,7 +1165,7 @@ void FEProject::LoadScene() } } - InstancedEntity->ModifyInstance(EntityFileRoot["modifications"][static_cast(j)]["index"].asInt(), ModifedMatrix); + INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(NewEntity, EntityFileRoot["modifications"][j]["index"].asInt(), ModifedMatrix); } else if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_ADDED) { @@ -1176,14 +1178,14 @@ void FEProject::LoadScene() } } - InstancedEntity->AddInstance(ModifedMatrix); + INSTANCED_RENDERING_SYSTEM.AddIndividualInstance(NewEntity, ModifedMatrix); } } } } else { - FENewEntity* NewEntity = SCENE.AddNewStyleEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + // For compatibility with old projects. if (Root["entities"][EntityList[i]].isMember("gameModel")) { @@ -1221,7 +1223,7 @@ void FEProject::LoadScene() // For compatibility with old projects. else { - FENewEntity* NewEntity = SCENE.AddNewStyleEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + //FENewEntity* NewEntity = SCENE.AddNewStyleEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString())->GetComponent(0)->GameModel; NewEntity->AddComponent(GameModel); ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &NewEntity->GetComponent()); @@ -1468,352 +1470,352 @@ void FEProject::AddFileToDeleteList(const std::string FileName) // FIX ME! Deprecate. void FEProject::LoadSceneVer0() { - std::ifstream SceneFile; - SceneFile.open(ProjectFolder + "scene.txt"); - - std::string FileData((std::istreambuf_iterator(SceneFile)), std::istreambuf_iterator()); - - Json::Value Root; - JSONCPP_STRING Err; - Json::CharReaderBuilder Builder; - - const std::unique_ptr Reader(Builder.newCharReader()); - if (!Reader->parse(FileData.c_str(), FileData.c_str() + FileData.size(), &Root, &Err)) - return; - - // correction for loading Meshes - std::unordered_map MeshNameToID; - MeshNameToID["sphere"] = RESOURCE_MANAGER.GetMesh("7F251E3E0D08013E3579315F")->GetObjectID(); - MeshNameToID["cube"] = RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R")->GetObjectID(); - MeshNameToID["plane"] = RESOURCE_MANAGER.GetMesh("1Y251E6E6T78013635793156")->GetObjectID(); - // loading Meshes - std::vector MeshList = Root["meshes"].getMemberNames(); - for (size_t i = 0; i < MeshList.size(); i++) - { - RESOURCE_MANAGER.LoadFEMesh((ProjectFolder + Root["meshes"][MeshList[i]]["fileName"].asCString()).c_str(), Root["meshes"][MeshList[i]]["name"].asCString()); - MeshNameToID[Root["meshes"][MeshList[i]]["name"].asCString()] = Root["meshes"][MeshList[i]]["ID"].asCString(); - } - // correction for loading Textures - std::unordered_map TextureNameToID; - // loading Textures - std::vector TexturesList = Root["textures"].getMemberNames(); - for (size_t i = 0; i < TexturesList.size(); i++) - { - // read type of texture if it is not standard then skip it. - if (Root["textures"][TexturesList[i]]["type"] == 33322) - { - continue; - } - - FETexture* LoadedTexture = RESOURCE_MANAGER.LoadFETextureAsync((ProjectFolder + Root["textures"][TexturesList[i]]["fileName"].asCString()).c_str(), Root["textures"][TexturesList[i]]["name"].asString()); - TextureNameToID[Root["textures"][TexturesList[i]]["name"].asString()] = LoadedTexture->GetObjectID(); - } - - // correction for loading Materials - std::unordered_map MaterialNameToID; - // loading Materials - std::vector MaterialsList = Root["materials"].getMemberNames(); - for (size_t i = 0; i < MaterialsList.size(); i++) - { - FEMaterial* NewMaterial = RESOURCE_MANAGER.CreateMaterial(MaterialsList[i], Root["materials"][MaterialsList[i]]["ID"].asString()); - MaterialNameToID[MaterialsList[i]] = NewMaterial->GetObjectID(); - - //newMat->shader = RESOURCE_MANAGER.getShader("FEPhongShader"); - //newMat->shader = RESOURCE_MANAGER.getShader("FESolidColorShader"); - NewMaterial->Shader = RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/); - - std::vector MembersList = Root["materials"][MaterialsList[i]].getMemberNames(); - for (size_t j = 0; j < MembersList.size(); j++) - { - if (MembersList[j] == "textures") - { - for (size_t k = 0; k < FE_MAX_TEXTURES_PER_MATERIAL; k++) - { - if (Root["materials"][MaterialsList[i]]["textures"].isMember(std::to_string(k).c_str())) - { - std::string TextureID = TextureNameToID[Root["materials"][MaterialsList[i]]["textures"][std::to_string(k).c_str()].asCString()]; - NewMaterial->Textures[k] = RESOURCE_MANAGER.GetTexture(TextureID); - } - } - } - - if (MembersList[j] == "textureBindings") - { - for (size_t k = 0; k < FE_MAX_TEXTURES_PER_MATERIAL; k++) - { - if (Root["materials"][MaterialsList[i]]["textureBindings"].isMember(std::to_string(k).c_str())) - { - int Binding = Root["materials"][MaterialsList[i]]["textureBindings"][std::to_string(k).c_str()].asInt(); - NewMaterial->TextureBindings[k] = Binding; - } - } - } - - if (MembersList[j] == "textureChannels") - { - for (size_t k = 0; k < FE_MAX_TEXTURES_PER_MATERIAL; k++) - { - if (Root["materials"][MaterialsList[i]]["textureChannels"].isMember(std::to_string(k).c_str())) - { - int Binding = Root["materials"][MaterialsList[i]]["textureChannels"][std::to_string(k).c_str()].asInt(); - NewMaterial->TextureChannels[k] = Binding; - } - } - } - } - - NewMaterial->SetMetalness(Root["materials"][MaterialsList[i]]["metalness"].asFloat()); - NewMaterial->SetRoughness(Root["materials"][MaterialsList[i]]["roughness"].asFloat()); - NewMaterial->SetNormalMapIntensity(Root["materials"][MaterialsList[i]]["normalMapIntensity"].asFloat()); - NewMaterial->SetAmbientOcclusionIntensity(Root["materials"][MaterialsList[i]]["ambientOcclusionIntensity"].asFloat()); - NewMaterial->SetAmbientOcclusionMapIntensity(Root["materials"][MaterialsList[i]]["ambientOcclusionMapIntensity"].asFloat()); - NewMaterial->SetRoughnessMapIntensity(Root["materials"][MaterialsList[i]]["roughnessMapIntensity"].asFloat()); - NewMaterial->SetMetalnessMapIntensity(Root["materials"][MaterialsList[i]]["metalnessMapIntensity"].asFloat()); - } - - // correction for loading gameModels - std::unordered_map GameModelNameToID; - // loading gameModels - std::vector GameModelList = Root["gameModels"].getMemberNames(); - for (size_t i = 0; i < GameModelList.size(); i++) - { - FEGameModel* NewGameModel = RESOURCE_MANAGER.CreateGameModel(RESOURCE_MANAGER.GetMesh(MeshNameToID[Root["gameModels"][GameModelList[i]]["mesh"].asCString()]), - RESOURCE_MANAGER.GetMaterial(MaterialNameToID[Root["gameModels"][GameModelList[i]]["material"].asCString()]), - GameModelList[i], Root["gameModels"][GameModelList[i]]["ID"].asString()); - GameModelNameToID[GameModelList[i]] = Root["gameModels"][GameModelList[i]]["ID"].asString(); - - NewGameModel->SetScaleFactor(Root["gameModels"][GameModelList[i]]["scaleFactor"].asFloat()); - - bool bHaveLODLevels = Root["gameModels"][GameModelList[i]]["LODs"]["haveLODlevels"].asBool(); - NewGameModel->SetUsingLOD(bHaveLODLevels); - if (bHaveLODLevels) - { - NewGameModel->SetCullDistance(Root["gameModels"][GameModelList[i]]["LODs"]["cullDistance"].asFloat()); - NewGameModel->SetBillboardZeroRotaion(Root["gameModels"][GameModelList[i]]["LODs"]["billboardZeroRotaion"].asFloat()); - - size_t LODCount = Root["gameModels"][GameModelList[i]]["LODs"]["LODCount"].asInt(); - for (size_t j = 0; j < LODCount; j++) - { - NewGameModel->SetLODMesh(j, RESOURCE_MANAGER.GetMesh(MeshNameToID[Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["mesh"].asString()])); - NewGameModel->SetLODMaxDrawDistance(j, Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["maxDrawDistance"].asFloat()); - - bool bLODBillboard = Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["isBillboard"].asBool(); - NewGameModel->SetIsLODBillboard(j, bLODBillboard); - if (bLODBillboard) - NewGameModel->SetBillboardMaterial(RESOURCE_MANAGER.GetMaterial(MaterialNameToID[Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["billboardMaterial"].asString()])); - } - } - } - - // correction for loading Terrains - std::unordered_map TerrainNameToID; - // loading Terrains - std::vector TerrainList = Root["terrains"].getMemberNames(); - for (size_t i = 0; i < TerrainList.size(); i++) - { - FETerrain* NewTerrain = RESOURCE_MANAGER.CreateTerrain(false, TerrainList[i], Root["terrains"][TerrainList[i]]["ID"].asString()); - TerrainNameToID[NewTerrain->GetName()] = NewTerrain->GetObjectID(); - NewTerrain->HeightMap = RESOURCE_MANAGER.LoadFEHeightmap((ProjectFolder + Root["terrains"][TerrainList[i]]["heightMap"]["fileName"].asCString()).c_str(), NewTerrain, Root["terrains"][TerrainList[i]]["heightMap"]["name"].asCString()); - - NewTerrain->SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); - NewTerrain->SetDisplacementScale(Root["terrains"][TerrainList[i]]["displacementScale"].asFloat()); - glm::vec2 TileMult; - TileMult.x = Root["terrains"][TerrainList[i]]["tileMult"]["X"].asFloat(); - TileMult.y = Root["terrains"][TerrainList[i]]["tileMult"]["Y"].asFloat(); - NewTerrain->SetTileMult(TileMult); - NewTerrain->SetLODLevel(Root["terrains"][TerrainList[i]]["LODlevel"].asFloat()); - NewTerrain->SetChunkPerSide(Root["terrains"][TerrainList[i]]["chunkPerSide"].asFloat()); - NewTerrain->SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); - NewTerrain->SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); - ReadTransformToJson(Root["terrains"][TerrainList[i]]["transformation"], &NewTerrain->Transform); - - SCENE.AddTerrain(NewTerrain); - } - - // loading Entities - std::vector EntityList = Root["entities"].getMemberNames(); - std::string EntityID; - for (size_t i = 0; i < EntityList.size(); i++) - { - if (Root["entities"][EntityList[i]].isMember("type")) - { - if (Root["entities"][EntityList[i]]["type"] == "FE_ENTITY_INSTANCED") - { - EntityID = Root["entities"][EntityList[i]]["ID"].asString(); - FEEntityInstanced* InstancedEntity = SCENE.AddEntityInstanced(RESOURCE_MANAGER.GetGameModel(GameModelNameToID[Root["entities"][EntityList[i]]["gameModel"].asCString()]), EntityList[i], EntityID); - ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(EntityID)->Transform); - - InstancedEntity->SpawnInfo.Seed = Root["entities"][EntityList[i]]["spawnInfo"]["seed"].asInt(); - InstancedEntity->SpawnInfo.ObjectCount = Root["entities"][EntityList[i]]["spawnInfo"]["objectCount"].asInt(); - InstancedEntity->SpawnInfo.Radius = Root["entities"][EntityList[i]]["spawnInfo"]["radius"].asFloat(); - InstancedEntity->SpawnInfo.SetMinScale(Root["entities"][EntityList[i]]["spawnInfo"]["minScale"].asFloat()); - InstancedEntity->SpawnInfo.SetMaxScale(Root["entities"][EntityList[i]]["spawnInfo"]["maxScale"].asFloat()); - InstancedEntity->SpawnInfo.RotationDeviation.x = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.x"].asFloat(); - InstancedEntity->SpawnInfo.RotationDeviation.y = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.y"].asFloat(); - InstancedEntity->SpawnInfo.RotationDeviation.z = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.z"].asFloat(); - - if (Root["entities"][EntityList[i]]["snappedToTerrain"].asString() != "none") - { - FETerrain* Terrain = SCENE.GetTerrain(TerrainNameToID[Root["entities"][EntityList[i]]["snappedToTerrain"].asString()]); - Terrain->SnapInstancedEntity(InstancedEntity); - } - - InstancedEntity->Populate(InstancedEntity->SpawnInfo); - - if (Root["entities"][EntityList[i]]["modificationsToSpawn"].asBool()) - { - std::ifstream InfoFile; - InfoFile.open(ProjectFolder + InstancedEntity->GetObjectID() + ".txt"); - - std::string InfoFileData((std::istreambuf_iterator(InfoFile)), std::istreambuf_iterator()); - - Json::Value EntityFileRoot; - JSONCPP_STRING Err; - Json::CharReaderBuilder Builder; - - const std::unique_ptr Reader(Builder.newCharReader()); - if (!Reader->parse(InfoFileData.c_str(), InfoFileData.c_str() + InfoFileData.size(), &EntityFileRoot, &Err)) - return; - - size_t Count = EntityFileRoot["modifications"].size(); - for (int j = 0; j < Count; j++) - { - if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_DELETED) - { - InstancedEntity->DeleteInstance(EntityFileRoot["modifications"][j]["index"].asInt()); - } - else if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_MODIFIED) - { - glm::mat4 ModifedMatrix; - for (int k = 0; k < 4; k++) - { - for (int p = 0; p < 4; p++) - { - ModifedMatrix[k][p] = EntityFileRoot["modifications"][j]["modification"][k][p].asFloat(); - } - } - - InstancedEntity->ModifyInstance(EntityFileRoot["modifications"][j]["index"].asInt(), ModifedMatrix); - } - else if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_ADDED) - { - glm::mat4 ModifedMatrix; - for (int k = 0; k < 4; k++) - { - for (int p = 0; p < 4; p++) - { - ModifedMatrix[k][p] = EntityFileRoot["modifications"][j]["modification"][k][p].asFloat(); - } - } - - InstancedEntity->AddInstance(ModifedMatrix); - } - } - } - } - else - { - SCENE.AddEntity(RESOURCE_MANAGER.GetGameModel(GameModelNameToID[Root["entities"][EntityList[i]]["gameModel"].asCString()]), EntityList[i], Root["entities"][EntityList[i]]["ID"].asString()); - ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(Root["entities"][EntityList[i]]["ID"].asString())->Transform); - } - } - else - { - SCENE.AddEntity(RESOURCE_MANAGER.GetGameModel(GameModelNameToID[Root["entities"][EntityList[i]]["gameModel"].asCString()]), EntityList[i], Root["entities"][EntityList[i]]["ID"].asString()); - ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(Root["entities"][EntityList[i]]["ID"].asString())->Transform); - } - } - - // loading Lights - std::vector LightList = Root["lights"].getMemberNames(); - for (size_t i = 0; i < LightList.size(); i++) - { - FELight* LightTest = SCENE.AddLight(static_cast(Root["lights"][LightList[i]]["type"].asInt() + 9), LightList[i]); - FELight* Light = SCENE.GetLight(LightTest->GetObjectID()); - - // general light information - Light->SetIntensity(Root["lights"][LightList[i]]["intensity"].asFloat()); - ReadTransformToJson(Root["lights"][LightList[i]]["transformation"], &Light->Transform); - Light->SetCastShadows(Root["lights"][LightList[i]]["castShadows"].asBool()); - Light->SetLightEnabled(Root["lights"][LightList[i]]["enabled"].asBool()); - Light->SetColor(glm::vec3(Root["lights"][LightList[i]]["color"]["R"].asFloat(), - Root["lights"][LightList[i]]["color"]["G"].asFloat(), - Root["lights"][LightList[i]]["color"]["B"].asFloat())); - Light->SetIsStaticShadowBias(Root["lights"][LightList[i]]["staticShadowBias"].asBool()); - Light->SetShadowBias(Root["lights"][LightList[i]]["shadowBias"].asFloat()); - Light->SetShadowBiasVariableIntensity(Root["lights"][LightList[i]]["shadowBiasVariableIntensity"].asFloat()); - - if (Light->GetType() == FE_POINT_LIGHT) - { - reinterpret_cast(Light)->SetRange(Root["lights"][LightList[i]]["range"].asFloat()); - } - else if (Light->GetType() == FE_SPOT_LIGHT) - { - reinterpret_cast(Light)->SetSpotAngle(Root["lights"][LightList[i]]["spotAngle"].asFloat()); - reinterpret_cast(Light)->SetSpotAngleOuter(Root["lights"][LightList[i]]["spotAngleOuter"].asFloat()); - - reinterpret_cast(Light)->SetDirection(glm::vec3(Root["lights"][LightList[i]]["direction"]["X"].asFloat(), - Root["lights"][LightList[i]]["direction"]["Y"].asFloat(), - Root["lights"][LightList[i]]["direction"]["Z"].asFloat())); - } - else if (Light->GetType() == FE_DIRECTIONAL_LIGHT) - { - FEDirectionalLight* DirectionalLight = reinterpret_cast(Light); - - DirectionalLight->SetDirection(glm::vec3(Root["lights"][LightList[i]]["direction"]["X"].asFloat(), - Root["lights"][LightList[i]]["direction"]["Y"].asFloat(), - Root["lights"][LightList[i]]["direction"]["Z"].asFloat())); - - DirectionalLight->SetActiveCascades(Root["lights"][LightList[i]]["CSM"]["activeCascades"].asInt()); - DirectionalLight->SetShadowCoverage(Root["lights"][LightList[i]]["CSM"]["shadowCoverage"].asFloat()); - DirectionalLight->SetCSMZDepth(Root["lights"][LightList[i]]["CSM"]["CSMZDepth"].asFloat()); - DirectionalLight->SetCSMXYDepth(Root["lights"][LightList[i]]["CSM"]["CSMXYDepth"].asFloat()); - } - } + //std::ifstream SceneFile; + //SceneFile.open(ProjectFolder + "scene.txt"); + + //std::string FileData((std::istreambuf_iterator(SceneFile)), std::istreambuf_iterator()); + + //Json::Value Root; + //JSONCPP_STRING Err; + //Json::CharReaderBuilder Builder; + + //const std::unique_ptr Reader(Builder.newCharReader()); + //if (!Reader->parse(FileData.c_str(), FileData.c_str() + FileData.size(), &Root, &Err)) + // return; + + //// correction for loading Meshes + //std::unordered_map MeshNameToID; + //MeshNameToID["sphere"] = RESOURCE_MANAGER.GetMesh("7F251E3E0D08013E3579315F")->GetObjectID(); + //MeshNameToID["cube"] = RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R")->GetObjectID(); + //MeshNameToID["plane"] = RESOURCE_MANAGER.GetMesh("1Y251E6E6T78013635793156")->GetObjectID(); + //// loading Meshes + //std::vector MeshList = Root["meshes"].getMemberNames(); + //for (size_t i = 0; i < MeshList.size(); i++) + //{ + // RESOURCE_MANAGER.LoadFEMesh((ProjectFolder + Root["meshes"][MeshList[i]]["fileName"].asCString()).c_str(), Root["meshes"][MeshList[i]]["name"].asCString()); + // MeshNameToID[Root["meshes"][MeshList[i]]["name"].asCString()] = Root["meshes"][MeshList[i]]["ID"].asCString(); + //} + //// correction for loading Textures + //std::unordered_map TextureNameToID; + //// loading Textures + //std::vector TexturesList = Root["textures"].getMemberNames(); + //for (size_t i = 0; i < TexturesList.size(); i++) + //{ + // // read type of texture if it is not standard then skip it. + // if (Root["textures"][TexturesList[i]]["type"] == 33322) + // { + // continue; + // } + + // FETexture* LoadedTexture = RESOURCE_MANAGER.LoadFETextureAsync((ProjectFolder + Root["textures"][TexturesList[i]]["fileName"].asCString()).c_str(), Root["textures"][TexturesList[i]]["name"].asString()); + // TextureNameToID[Root["textures"][TexturesList[i]]["name"].asString()] = LoadedTexture->GetObjectID(); + //} - // loading Effects settings - // *********** Gamma Correction & Exposure *********** - ENGINE.GetCamera()->SetGamma(Root["effects"]["Gamma Correction & Exposure"]["Gamma"].asFloat()); - ENGINE.GetCamera()->SetExposure(Root["effects"]["Gamma Correction & Exposure"]["Exposure"].asFloat()); - // *********** Anti-Aliasing(FXAA) *********** - RENDERER.SetFXAASpanMax(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAASpanMax"].asFloat()); - RENDERER.SetFXAAReduceMin(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAAReduceMin"].asFloat()); - RENDERER.SetFXAAReduceMul(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAAReduceMul"].asFloat()); - // *********** Bloom *********** - //PPEffect = RENDERER.getPostProcessEffect("bloom"); - RENDERER.SetBloomThreshold(Root["effects"]["Bloom"]["thresholdBrightness"].asFloat()); - RENDERER.SetBloomSize(Root["effects"]["Bloom"]["BloomSize"].asFloat()); - // *********** Depth of Field *********** - RENDERER.SetDOFNearDistance(Root["effects"]["Depth of Field"]["Near distance"].asFloat()); - RENDERER.SetDOFFarDistance(Root["effects"]["Depth of Field"]["Far distance"].asFloat()); - RENDERER.SetDOFStrength(Root["effects"]["Depth of Field"]["Strength"].asFloat()); - RENDERER.SetDOFDistanceDependentStrength(Root["effects"]["Depth of Field"]["Distance dependent strength"].asFloat()); - // *********** Distance fog *********** - RENDERER.SetDistanceFogEnabled(Root["effects"]["Distance fog"]["Density"].asFloat() > -1.0f ? true : false); - RENDERER.SetDistanceFogDensity(Root["effects"]["Distance fog"]["Density"].asFloat()); - RENDERER.SetDistanceFogGradient(Root["effects"]["Distance fog"]["Gradient"].asFloat()); - // *********** Chromatic Aberration *********** - RENDERER.SetChromaticAberrationIntensity(Root["effects"]["Chromatic Aberration"]["Shift strength"].asFloat()); - // *********** Sky *********** - RENDERER.SetSkyEnabled(Root["effects"]["Sky"]["Enabled"].asFloat() > 0.0f ? true : false); - RENDERER.SetDistanceToSky(Root["effects"]["Sky"]["Sphere size"].asFloat()); + //// correction for loading Materials + //std::unordered_map MaterialNameToID; + //// loading Materials + //std::vector MaterialsList = Root["materials"].getMemberNames(); + //for (size_t i = 0; i < MaterialsList.size(); i++) + //{ + // FEMaterial* NewMaterial = RESOURCE_MANAGER.CreateMaterial(MaterialsList[i], Root["materials"][MaterialsList[i]]["ID"].asString()); + // MaterialNameToID[MaterialsList[i]] = NewMaterial->GetObjectID(); + + // //newMat->shader = RESOURCE_MANAGER.getShader("FEPhongShader"); + // //newMat->shader = RESOURCE_MANAGER.getShader("FESolidColorShader"); + // NewMaterial->Shader = RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/); + + // std::vector MembersList = Root["materials"][MaterialsList[i]].getMemberNames(); + // for (size_t j = 0; j < MembersList.size(); j++) + // { + // if (MembersList[j] == "textures") + // { + // for (size_t k = 0; k < FE_MAX_TEXTURES_PER_MATERIAL; k++) + // { + // if (Root["materials"][MaterialsList[i]]["textures"].isMember(std::to_string(k).c_str())) + // { + // std::string TextureID = TextureNameToID[Root["materials"][MaterialsList[i]]["textures"][std::to_string(k).c_str()].asCString()]; + // NewMaterial->Textures[k] = RESOURCE_MANAGER.GetTexture(TextureID); + // } + // } + // } + + // if (MembersList[j] == "textureBindings") + // { + // for (size_t k = 0; k < FE_MAX_TEXTURES_PER_MATERIAL; k++) + // { + // if (Root["materials"][MaterialsList[i]]["textureBindings"].isMember(std::to_string(k).c_str())) + // { + // int Binding = Root["materials"][MaterialsList[i]]["textureBindings"][std::to_string(k).c_str()].asInt(); + // NewMaterial->TextureBindings[k] = Binding; + // } + // } + // } + + // if (MembersList[j] == "textureChannels") + // { + // for (size_t k = 0; k < FE_MAX_TEXTURES_PER_MATERIAL; k++) + // { + // if (Root["materials"][MaterialsList[i]]["textureChannels"].isMember(std::to_string(k).c_str())) + // { + // int Binding = Root["materials"][MaterialsList[i]]["textureChannels"][std::to_string(k).c_str()].asInt(); + // NewMaterial->TextureChannels[k] = Binding; + // } + // } + // } + // } + + // NewMaterial->SetMetalness(Root["materials"][MaterialsList[i]]["metalness"].asFloat()); + // NewMaterial->SetRoughness(Root["materials"][MaterialsList[i]]["roughness"].asFloat()); + // NewMaterial->SetNormalMapIntensity(Root["materials"][MaterialsList[i]]["normalMapIntensity"].asFloat()); + // NewMaterial->SetAmbientOcclusionIntensity(Root["materials"][MaterialsList[i]]["ambientOcclusionIntensity"].asFloat()); + // NewMaterial->SetAmbientOcclusionMapIntensity(Root["materials"][MaterialsList[i]]["ambientOcclusionMapIntensity"].asFloat()); + // NewMaterial->SetRoughnessMapIntensity(Root["materials"][MaterialsList[i]]["roughnessMapIntensity"].asFloat()); + // NewMaterial->SetMetalnessMapIntensity(Root["materials"][MaterialsList[i]]["metalnessMapIntensity"].asFloat()); + //} - // loading Camera settings - ENGINE.GetCamera()->SetPosition(glm::vec3(Root["camera"]["position"]["X"].asFloat(), - Root["camera"]["position"]["Y"].asFloat(), - Root["camera"]["position"]["Z"].asFloat())); + //// correction for loading gameModels + //std::unordered_map GameModelNameToID; + //// loading gameModels + //std::vector GameModelList = Root["gameModels"].getMemberNames(); + //for (size_t i = 0; i < GameModelList.size(); i++) + //{ + // FEGameModel* NewGameModel = RESOURCE_MANAGER.CreateGameModel(RESOURCE_MANAGER.GetMesh(MeshNameToID[Root["gameModels"][GameModelList[i]]["mesh"].asCString()]), + // RESOURCE_MANAGER.GetMaterial(MaterialNameToID[Root["gameModels"][GameModelList[i]]["material"].asCString()]), + // GameModelList[i], Root["gameModels"][GameModelList[i]]["ID"].asString()); + // GameModelNameToID[GameModelList[i]] = Root["gameModels"][GameModelList[i]]["ID"].asString(); + + // NewGameModel->SetScaleFactor(Root["gameModels"][GameModelList[i]]["scaleFactor"].asFloat()); + + // bool bHaveLODLevels = Root["gameModels"][GameModelList[i]]["LODs"]["haveLODlevels"].asBool(); + // NewGameModel->SetUsingLOD(bHaveLODLevels); + // if (bHaveLODLevels) + // { + // NewGameModel->SetCullDistance(Root["gameModels"][GameModelList[i]]["LODs"]["cullDistance"].asFloat()); + // NewGameModel->SetBillboardZeroRotaion(Root["gameModels"][GameModelList[i]]["LODs"]["billboardZeroRotaion"].asFloat()); + + // size_t LODCount = Root["gameModels"][GameModelList[i]]["LODs"]["LODCount"].asInt(); + // for (size_t j = 0; j < LODCount; j++) + // { + // NewGameModel->SetLODMesh(j, RESOURCE_MANAGER.GetMesh(MeshNameToID[Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["mesh"].asString()])); + // NewGameModel->SetLODMaxDrawDistance(j, Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["maxDrawDistance"].asFloat()); + + // bool bLODBillboard = Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["isBillboard"].asBool(); + // NewGameModel->SetIsLODBillboard(j, bLODBillboard); + // if (bLODBillboard) + // NewGameModel->SetBillboardMaterial(RESOURCE_MANAGER.GetMaterial(MaterialNameToID[Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["billboardMaterial"].asString()])); + // } + // } + //} - ENGINE.GetCamera()->SetFov(Root["camera"]["fov"].asFloat()); - ENGINE.GetCamera()->SetNearPlane(Root["camera"]["nearPlane"].asFloat()); - ENGINE.GetCamera()->SetFarPlane(Root["camera"]["farPlane"].asFloat()); + //// correction for loading Terrains + //std::unordered_map TerrainNameToID; + //// loading Terrains + //std::vector TerrainList = Root["terrains"].getMemberNames(); + //for (size_t i = 0; i < TerrainList.size(); i++) + //{ + // FETerrain* NewTerrain = RESOURCE_MANAGER.CreateTerrain(false, TerrainList[i], Root["terrains"][TerrainList[i]]["ID"].asString()); + // TerrainNameToID[NewTerrain->GetName()] = NewTerrain->GetObjectID(); + // NewTerrain->HeightMap = RESOURCE_MANAGER.LoadFEHeightmap((ProjectFolder + Root["terrains"][TerrainList[i]]["heightMap"]["fileName"].asCString()).c_str(), NewTerrain, Root["terrains"][TerrainList[i]]["heightMap"]["name"].asCString()); + + // NewTerrain->SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); + // NewTerrain->SetDisplacementScale(Root["terrains"][TerrainList[i]]["displacementScale"].asFloat()); + // glm::vec2 TileMult; + // TileMult.x = Root["terrains"][TerrainList[i]]["tileMult"]["X"].asFloat(); + // TileMult.y = Root["terrains"][TerrainList[i]]["tileMult"]["Y"].asFloat(); + // NewTerrain->SetTileMult(TileMult); + // NewTerrain->SetLODLevel(Root["terrains"][TerrainList[i]]["LODlevel"].asFloat()); + // NewTerrain->SetChunkPerSide(Root["terrains"][TerrainList[i]]["chunkPerSide"].asFloat()); + // NewTerrain->SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); + // NewTerrain->SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); + // ReadTransformToJson(Root["terrains"][TerrainList[i]]["transformation"], &NewTerrain->Transform); + + // SCENE.AddTerrain(NewTerrain); + //} - ENGINE.GetCamera()->SetYaw(Root["camera"]["yaw"].asFloat()); - ENGINE.GetCamera()->SetPitch(Root["camera"]["pitch"].asFloat()); - ENGINE.GetCamera()->SetRoll(Root["camera"]["roll"].asFloat()); + //// loading Entities + //std::vector EntityList = Root["entities"].getMemberNames(); + //std::string EntityID; + //for (size_t i = 0; i < EntityList.size(); i++) + //{ + // if (Root["entities"][EntityList[i]].isMember("type")) + // { + // if (Root["entities"][EntityList[i]]["type"] == "FE_ENTITY_INSTANCED") + // { + // EntityID = Root["entities"][EntityList[i]]["ID"].asString(); + // FEEntityInstanced* InstancedEntity = SCENE.AddEntityInstanced(RESOURCE_MANAGER.GetGameModel(GameModelNameToID[Root["entities"][EntityList[i]]["gameModel"].asCString()]), EntityList[i], EntityID); + // ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(EntityID)->Transform); + + // InstancedEntity->SpawnInfo.Seed = Root["entities"][EntityList[i]]["spawnInfo"]["seed"].asInt(); + // InstancedEntity->SpawnInfo.ObjectCount = Root["entities"][EntityList[i]]["spawnInfo"]["objectCount"].asInt(); + // InstancedEntity->SpawnInfo.Radius = Root["entities"][EntityList[i]]["spawnInfo"]["radius"].asFloat(); + // InstancedEntity->SpawnInfo.SetMinScale(Root["entities"][EntityList[i]]["spawnInfo"]["minScale"].asFloat()); + // InstancedEntity->SpawnInfo.SetMaxScale(Root["entities"][EntityList[i]]["spawnInfo"]["maxScale"].asFloat()); + // InstancedEntity->SpawnInfo.RotationDeviation.x = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.x"].asFloat(); + // InstancedEntity->SpawnInfo.RotationDeviation.y = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.y"].asFloat(); + // InstancedEntity->SpawnInfo.RotationDeviation.z = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.z"].asFloat(); + + // if (Root["entities"][EntityList[i]]["snappedToTerrain"].asString() != "none") + // { + // FETerrain* Terrain = SCENE.GetTerrain(TerrainNameToID[Root["entities"][EntityList[i]]["snappedToTerrain"].asString()]); + // Terrain->SnapInstancedEntity(InstancedEntity); + // } + + // InstancedEntity->Populate(InstancedEntity->SpawnInfo); + + // if (Root["entities"][EntityList[i]]["modificationsToSpawn"].asBool()) + // { + // std::ifstream InfoFile; + // InfoFile.open(ProjectFolder + InstancedEntity->GetObjectID() + ".txt"); + + // std::string InfoFileData((std::istreambuf_iterator(InfoFile)), std::istreambuf_iterator()); + + // Json::Value EntityFileRoot; + // JSONCPP_STRING Err; + // Json::CharReaderBuilder Builder; + + // const std::unique_ptr Reader(Builder.newCharReader()); + // if (!Reader->parse(InfoFileData.c_str(), InfoFileData.c_str() + InfoFileData.size(), &EntityFileRoot, &Err)) + // return; + + // size_t Count = EntityFileRoot["modifications"].size(); + // for (int j = 0; j < Count; j++) + // { + // if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_DELETED) + // { + // InstancedEntity->DeleteInstance(EntityFileRoot["modifications"][j]["index"].asInt()); + // } + // else if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_MODIFIED) + // { + // glm::mat4 ModifedMatrix; + // for (int k = 0; k < 4; k++) + // { + // for (int p = 0; p < 4; p++) + // { + // ModifedMatrix[k][p] = EntityFileRoot["modifications"][j]["modification"][k][p].asFloat(); + // } + // } + + // InstancedEntity->ModifyInstance(EntityFileRoot["modifications"][j]["index"].asInt(), ModifedMatrix); + // } + // else if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_ADDED) + // { + // glm::mat4 ModifedMatrix; + // for (int k = 0; k < 4; k++) + // { + // for (int p = 0; p < 4; p++) + // { + // ModifedMatrix[k][p] = EntityFileRoot["modifications"][j]["modification"][k][p].asFloat(); + // } + // } + + // InstancedEntity->AddInstance(ModifedMatrix); + // } + // } + // } + // } + // else + // { + // SCENE.AddEntity(RESOURCE_MANAGER.GetGameModel(GameModelNameToID[Root["entities"][EntityList[i]]["gameModel"].asCString()]), EntityList[i], Root["entities"][EntityList[i]]["ID"].asString()); + // ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(Root["entities"][EntityList[i]]["ID"].asString())->Transform); + // } + // } + // else + // { + // SCENE.AddEntity(RESOURCE_MANAGER.GetGameModel(GameModelNameToID[Root["entities"][EntityList[i]]["gameModel"].asCString()]), EntityList[i], Root["entities"][EntityList[i]]["ID"].asString()); + // ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(Root["entities"][EntityList[i]]["ID"].asString())->Transform); + // } + //} - ENGINE.GetCamera()->SetAspectRatio(Root["camera"]["aspectRatio"].asFloat()); + //// loading Lights + //std::vector LightList = Root["lights"].getMemberNames(); + //for (size_t i = 0; i < LightList.size(); i++) + //{ + // FELight* LightTest = SCENE.AddLight(static_cast(Root["lights"][LightList[i]]["type"].asInt() + 9), LightList[i]); + // FELight* Light = SCENE.GetLight(LightTest->GetObjectID()); + + // // general light information + // Light->SetIntensity(Root["lights"][LightList[i]]["intensity"].asFloat()); + // ReadTransformToJson(Root["lights"][LightList[i]]["transformation"], &Light->Transform); + // Light->SetCastShadows(Root["lights"][LightList[i]]["castShadows"].asBool()); + // Light->SetLightEnabled(Root["lights"][LightList[i]]["enabled"].asBool()); + // Light->SetColor(glm::vec3(Root["lights"][LightList[i]]["color"]["R"].asFloat(), + // Root["lights"][LightList[i]]["color"]["G"].asFloat(), + // Root["lights"][LightList[i]]["color"]["B"].asFloat())); + // Light->SetIsStaticShadowBias(Root["lights"][LightList[i]]["staticShadowBias"].asBool()); + // Light->SetShadowBias(Root["lights"][LightList[i]]["shadowBias"].asFloat()); + // Light->SetShadowBiasVariableIntensity(Root["lights"][LightList[i]]["shadowBiasVariableIntensity"].asFloat()); + + // if (Light->GetType() == FE_POINT_LIGHT) + // { + // reinterpret_cast(Light)->SetRange(Root["lights"][LightList[i]]["range"].asFloat()); + // } + // else if (Light->GetType() == FE_SPOT_LIGHT) + // { + // reinterpret_cast(Light)->SetSpotAngle(Root["lights"][LightList[i]]["spotAngle"].asFloat()); + // reinterpret_cast(Light)->SetSpotAngleOuter(Root["lights"][LightList[i]]["spotAngleOuter"].asFloat()); + + // reinterpret_cast(Light)->SetDirection(glm::vec3(Root["lights"][LightList[i]]["direction"]["X"].asFloat(), + // Root["lights"][LightList[i]]["direction"]["Y"].asFloat(), + // Root["lights"][LightList[i]]["direction"]["Z"].asFloat())); + // } + // else if (Light->GetType() == FE_DIRECTIONAL_LIGHT) + // { + // FEDirectionalLight* DirectionalLight = reinterpret_cast(Light); + + // DirectionalLight->SetDirection(glm::vec3(Root["lights"][LightList[i]]["direction"]["X"].asFloat(), + // Root["lights"][LightList[i]]["direction"]["Y"].asFloat(), + // Root["lights"][LightList[i]]["direction"]["Z"].asFloat())); + + // DirectionalLight->SetActiveCascades(Root["lights"][LightList[i]]["CSM"]["activeCascades"].asInt()); + // DirectionalLight->SetShadowCoverage(Root["lights"][LightList[i]]["CSM"]["shadowCoverage"].asFloat()); + // DirectionalLight->SetCSMZDepth(Root["lights"][LightList[i]]["CSM"]["CSMZDepth"].asFloat()); + // DirectionalLight->SetCSMXYDepth(Root["lights"][LightList[i]]["CSM"]["CSMXYDepth"].asFloat()); + // } + //} - SceneFile.close(); + //// loading Effects settings + //// *********** Gamma Correction & Exposure *********** + //ENGINE.GetCamera()->SetGamma(Root["effects"]["Gamma Correction & Exposure"]["Gamma"].asFloat()); + //ENGINE.GetCamera()->SetExposure(Root["effects"]["Gamma Correction & Exposure"]["Exposure"].asFloat()); + //// *********** Anti-Aliasing(FXAA) *********** + //RENDERER.SetFXAASpanMax(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAASpanMax"].asFloat()); + //RENDERER.SetFXAAReduceMin(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAAReduceMin"].asFloat()); + //RENDERER.SetFXAAReduceMul(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAAReduceMul"].asFloat()); + //// *********** Bloom *********** + ////PPEffect = RENDERER.getPostProcessEffect("bloom"); + //RENDERER.SetBloomThreshold(Root["effects"]["Bloom"]["thresholdBrightness"].asFloat()); + //RENDERER.SetBloomSize(Root["effects"]["Bloom"]["BloomSize"].asFloat()); + //// *********** Depth of Field *********** + //RENDERER.SetDOFNearDistance(Root["effects"]["Depth of Field"]["Near distance"].asFloat()); + //RENDERER.SetDOFFarDistance(Root["effects"]["Depth of Field"]["Far distance"].asFloat()); + //RENDERER.SetDOFStrength(Root["effects"]["Depth of Field"]["Strength"].asFloat()); + //RENDERER.SetDOFDistanceDependentStrength(Root["effects"]["Depth of Field"]["Distance dependent strength"].asFloat()); + //// *********** Distance fog *********** + //RENDERER.SetDistanceFogEnabled(Root["effects"]["Distance fog"]["Density"].asFloat() > -1.0f ? true : false); + //RENDERER.SetDistanceFogDensity(Root["effects"]["Distance fog"]["Density"].asFloat()); + //RENDERER.SetDistanceFogGradient(Root["effects"]["Distance fog"]["Gradient"].asFloat()); + //// *********** Chromatic Aberration *********** + //RENDERER.SetChromaticAberrationIntensity(Root["effects"]["Chromatic Aberration"]["Shift strength"].asFloat()); + //// *********** Sky *********** + //RENDERER.SetSkyEnabled(Root["effects"]["Sky"]["Enabled"].asFloat() > 0.0f ? true : false); + //RENDERER.SetDistanceToSky(Root["effects"]["Sky"]["Sphere size"].asFloat()); + + //// loading Camera settings + //ENGINE.GetCamera()->SetPosition(glm::vec3(Root["camera"]["position"]["X"].asFloat(), + // Root["camera"]["position"]["Y"].asFloat(), + // Root["camera"]["position"]["Z"].asFloat())); + + //ENGINE.GetCamera()->SetFov(Root["camera"]["fov"].asFloat()); + //ENGINE.GetCamera()->SetNearPlane(Root["camera"]["nearPlane"].asFloat()); + //ENGINE.GetCamera()->SetFarPlane(Root["camera"]["farPlane"].asFloat()); + + //ENGINE.GetCamera()->SetYaw(Root["camera"]["yaw"].asFloat()); + //ENGINE.GetCamera()->SetPitch(Root["camera"]["pitch"].asFloat()); + //ENGINE.GetCamera()->SetRoll(Root["camera"]["roll"].asFloat()); + + //ENGINE.GetCamera()->SetAspectRatio(Root["camera"]["aspectRatio"].asFloat()); + + //SceneFile.close(); } bool FEProject::IsModified() diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 772d704..8211f05 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 772d7045df736f87bca27624258cc7a52050e22e +Subproject commit 8211f05bdc3ee71e26570e16433f299228d2e19b diff --git a/main.cpp b/main.cpp index 0f239d3..863eb1d 100644 --- a/main.cpp +++ b/main.cpp @@ -25,7 +25,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine ENGINE.Render(); #ifdef EDITOR_SELECTION_DEBUG_MODE - std::string objectsUnderMouse = "objectsUnderMouse: " + std::to_string(SELECTED.ObjectsUnderMouse.size()); + std::string objectsUnderMouse = "SceneEntitiesUnderMouse: " + std::to_string(SELECTED.SceneEntitiesUnderMouse.size()); ImGui::Text(objectsUnderMouse.c_str()); std::string colorIndex = "colorIndex: " + std::to_string(SELECTED.ColorIndex); From 5c1a0e1a3d8b09e7ee030f926d868fc5e7a0e9f6 Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Sun, 7 Jul 2024 21:45:45 -0400 Subject: [PATCH 16/46] Engine update; Further transitioned to ECS; Deleted the old LoadSceneVer0 function for the old project file format. --- EditorWindows/DeletePopups.cpp | 71 +-- EditorWindows/InspectorWindow.cpp | 714 ++++++--------------------- EditorWindows/InspectorWindow.h | 5 +- EditorWindows/SceneGraphWindow.cpp | 101 ++-- EditorWindows/ShaderEditorWindow.cpp | 7 +- FEEditor.cpp | 68 +-- FEEditorGizmoManager.cpp | 70 ++- FEEditorGizmoManager.h | 26 +- FEEditorPreviewManager.h | 2 +- FEEditorSelectedObject.cpp | 452 +++++------------ FEEditorSelectedObject.h | 16 +- FEProject.cpp | 654 ++++++------------------ FEProject.h | 1 - SubSystems/FocalEngine | 2 +- 14 files changed, 638 insertions(+), 1551 deletions(-) diff --git a/EditorWindows/DeletePopups.cpp b/EditorWindows/DeletePopups.cpp index a3e43bf..6fc7d1f 100644 --- a/EditorWindows/DeletePopups.cpp +++ b/EditorWindows/DeletePopups.cpp @@ -64,7 +64,7 @@ void DeleteTexturePopup::Render() std::vector DeleteTexturePopup::MaterialsThatUsesTexture(const FETexture* Texture) { - std::vector result; + std::vector Result; const std::vector MateriasList = RESOURCE_MANAGER.GetMaterialList(); for (size_t i = 0; i < MateriasList.size(); i++) @@ -75,7 +75,7 @@ std::vector DeleteTexturePopup::MaterialsThatUsesTexture(const FETe { if (CurrentMaterial->Textures[j] == Texture) { - result.push_back(CurrentMaterial); + Result.push_back(CurrentMaterial); break; } } @@ -84,15 +84,15 @@ std::vector DeleteTexturePopup::MaterialsThatUsesTexture(const FETe const std::vector TerrainList = SCENE.GetTerrainList(); for (size_t i = 0; i < TerrainList.size(); i++) { - const FETerrain* CurrentTerrain = SCENE.GetTerrain(TerrainList[i]); - //if (CurrentTerrain->heightMap != nullptr && CurrentTerrain->heightMap->getObjectID() == Texture->getObjectID()) - //{ - // continue; - // result.push_back(nullptr); - //} + /*FEEntity* CurrentTerrain = SCENE.GetNewStyleEntity(TerrainList[i]); + FETerrainComponent& TerrainComponent = CurrentTerrain->GetComponent(); + if (TerrainComponent.HeightMap != nullptr && TerrainComponent.HeightMap->GetObjectID() == Texture->GetObjectID()) + { + Result.push_back(nullptr); + }*/ } - return result; + return Result; } void DeleteTexturePopup::DeleteTexture(FETexture* Texture) @@ -161,11 +161,11 @@ void DeleteMeshPopup::Render() ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); // check if this mesh is used in some game model // to-do: should be done through counter, not by searching each time. - const int result = TimesMeshUsed(ObjToWorkWith); + const int Result = TimesMeshUsed(ObjToWorkWith); ImGui::Text(("Do you want to delete \"" + ObjToWorkWith->GetName() + "\" mesh ?").c_str()); - if (result > 0) - ImGui::Text(("It is used in " + std::to_string(result) + " game models !").c_str()); + if (Result > 0) + ImGui::Text(("It is used in " + std::to_string(Result) + " game models !").c_str()); ImGui::SetCursorPosX(ImGui::GetWindowWidth() / 4.0f - 120 / 2.0f); if (ImGui::Button("Delete", ImVec2(120, 0))) @@ -194,17 +194,17 @@ void DeleteMeshPopup::Render() int DeleteMeshPopup::TimesMeshUsed(const FEMesh* Mesh) { - int result = 0; + int Result = 0; const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); for (size_t i = 0; i < GameModelList.size(); i++) { const FEGameModel* CurrentGameModel = RESOURCE_MANAGER.GetGameModel(GameModelList[i]); if (CurrentGameModel->Mesh == Mesh) - result++; + Result++; } - return result; + return Result; } void DeleteMeshPopup::DeleteMesh(FEMesh* Mesh) @@ -267,11 +267,11 @@ void DeleteGameModelPopup::Render() ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); // check if this game model is used in some prefabs // to-do: should be done through counter, not by searching each time. - const int result = TimesGameModelUsed(ObjToWorkWith); + const int Result = TimesGameModelUsed(ObjToWorkWith); ImGui::Text(("Do you want to delete \"" + ObjToWorkWith->GetName() + "\" game model ?").c_str()); - if (result > 0) - ImGui::Text(("It is used in " + std::to_string(result) + " prefabs !").c_str()); + if (Result > 0) + ImGui::Text(("It is used in " + std::to_string(Result) + " prefabs !").c_str()); ImGui::SetCursorPosX(ImGui::GetWindowWidth() / 4.0f - 120.0f / 2.0f); if (ImGui::Button("Delete", ImVec2(120, 0))) @@ -301,7 +301,7 @@ void DeleteGameModelPopup::Render() int DeleteGameModelPopup::TimesGameModelUsed(const FEGameModel* GameModel) { - int result = 0; + int Result = 0; const std::vector PrefabList = RESOURCE_MANAGER.GetPrefabList(); for (int i = 0; i < PrefabList.size(); i++) @@ -310,11 +310,11 @@ int DeleteGameModelPopup::TimesGameModelUsed(const FEGameModel* GameModel) for (int j = 0; j < CurrentPrefab->ComponentsCount(); j++) { if (CurrentPrefab->GetComponent(j)->GameModel == GameModel) - result++; + Result++; } } - return result; + return Result; } void DeleteGameModelPopup::DeleteGameModel(FEGameModel* GameModel) @@ -359,11 +359,11 @@ void DeletePrefabPopup::Render() ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); // check if this prefab is used in some entities // to-do: should be done through counter, not by searching each time. - const int result = TimesPrefabUsed(ObjToWorkWith); + const int Result = TimesPrefabUsed(ObjToWorkWith); ImGui::Text(("Do you want to delete \"" + ObjToWorkWith->GetName() + "\" prefab ?").c_str()); - if (result > 0) - ImGui::Text(("It is used in " + std::to_string(result) + " entities !").c_str()); + if (Result > 0) + ImGui::Text(("It is used in " + std::to_string(Result) + " entities !").c_str()); ImGui::SetCursorPosX(ImGui::GetWindowWidth() / 4.0f - 120.0f / 2.0f); if (ImGui::Button("Delete", ImVec2(120, 0))) @@ -393,17 +393,18 @@ void DeletePrefabPopup::Render() int DeletePrefabPopup::TimesPrefabUsed(const FEPrefab* Prefab) { - int result = 0; - const std::vector EntitiesList = SCENE.GetEntityList(); + int Result = 0; + // FIX ME! Prefabs + /*const std::vector EntitiesList = SCENE.GetEntityList(); for (size_t i = 0; i < EntitiesList.size(); i++) { const FEEntity* CurrentEntity = SCENE.GetEntity(EntitiesList[i]); if (CurrentEntity->Prefab == Prefab) - result++; - } + Result++; + }*/ - return result; + return Result; } void DeletePrefabPopup::DeletePrefab(FEPrefab* Prefab) @@ -447,11 +448,11 @@ void DeleteMaterialPopup::Render() ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); // check if this material is used in some game model // to-do: should be done through counter, not by searching each time. - const int result = TimesMaterialUsed(ObjToWorkWith); + const int Result = TimesMaterialUsed(ObjToWorkWith); ImGui::Text(("Do you want to delete \"" + ObjToWorkWith->GetName() + "\" material ?").c_str()); - if (result > 0) - ImGui::Text(("It is used in " + std::to_string(result) + " game models !").c_str()); + if (Result > 0) + ImGui::Text(("It is used in " + std::to_string(Result) + " game models !").c_str()); ImGui::SetCursorPosX(ImGui::GetWindowWidth() / 4.0f - 120 / 2.0f); if (ImGui::Button("Delete", ImVec2(120, 0))) @@ -481,17 +482,17 @@ void DeleteMaterialPopup::Render() int DeleteMaterialPopup::TimesMaterialUsed(const FEMaterial* Material) { - int result = 0; + int Result = 0; const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); for (size_t i = 0; i < GameModelList.size(); i++) { const FEGameModel* CurrentGameModel = RESOURCE_MANAGER.GetGameModel(GameModelList[i]); if (CurrentGameModel->Material == Material) - result++; + Result++; } - return result; + return Result; } void DeleteMaterialPopup::DeleteMaterial(FEMaterial* Material) diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index 41ddb21..77dfb71 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -2,6 +2,7 @@ FEEditorInspectorWindow* FEEditorInspectorWindow::Instance = nullptr; FEEntity* FEEditorInspectorWindow::EntityToModify = nullptr; +FEEntity* FEEditorInspectorWindow::TerrainToWorkWith = nullptr; FEEditorInspectorWindow::FEEditorInspectorWindow() { @@ -143,7 +144,7 @@ void FEEditorInspectorWindow::ShowTransformConfiguration(FEObject* Object, FETra // ********************* REAL WORLD COMPARISON SCALE ********************* if (Object->GetType() == FE_ENTITY || Object->GetType() == FE_ENTITY_INSTANCED) { - FENewEntity* Entity = SCENE.GetNewStyleEntity(Object->GetObjectID()); + FEEntity* Entity = SCENE.GetNewStyleEntity(Object->GetObjectID()); if (Entity == nullptr) return; @@ -176,27 +177,29 @@ void FEEditorInspectorWindow::ShowTransformConfiguration(FEObject* Object, FETra bool FEEditorInspectorWindow::EntityChangePrefabTargetCallBack(FEObject* Object, void** EntityPointer) { - FEEntity* Entity = SELECTED.GetEntity(); + // FIX ME! Prefabs + /*FEEntity* Entity = SELECTED.GetEntity(); if (Entity == nullptr) return false; Entity->Prefab = (RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())); - return true; + return true;*/ + return false; } bool FEEditorInspectorWindow::TerrainChangeMaterialTargetCallBack(FEObject* Object, void** LayerIndex) { - FETerrain* Terrain = SELECTED.GetTerrain(); - if (Terrain == nullptr) + if (SELECTED.GetSelected() == nullptr || !SELECTED.GetSelected()->HasComponent()) return false; FEMaterial* MaterialToAssign = RESOURCE_MANAGER.GetMaterial(Object->GetObjectID()); if (!MaterialToAssign->IsCompackPacking()) return false; + FETerrainComponent& Terrain = SELECTED.GetSelected()->GetComponent(); const int TempLayerIndex = *(int*)LayerIndex; if (TempLayerIndex >= 0 && TempLayerIndex < FE_TERRAIN_MAX_LAYERS) - Terrain->GetLayerInSlot(TempLayerIndex)->SetMaterial(MaterialToAssign); + Terrain.GetLayerInSlot(TempLayerIndex)->SetMaterial(MaterialToAssign); return true; } @@ -384,9 +387,10 @@ void FEEditorInspectorWindow::DisplayLightProperties(FELight* Light) const Light->SetIntensity(intensity); } +// FIX ME! void FEEditorInspectorWindow::ChangePrefabOfEntityCallBack(const std::vector SelectionsResult) { - if (EntityToModify == nullptr) + /*if (EntityToModify == nullptr) return; if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) @@ -396,7 +400,7 @@ void FEEditorInspectorWindow::ChangePrefabOfEntityCallBack(const std::vectorPrefab = SelectedPrefab; - } + }*/ } void FEEditorInspectorWindow::DisplayLightsProperties() const @@ -428,7 +432,7 @@ void FEEditorInspectorWindow::Render() return; } - FENewEntity* EntitySelected = SELECTED.GetSelected(); + FEEntity* EntitySelected = SELECTED.GetSelected(); if (EntitySelected->HasComponent()) { @@ -498,9 +502,9 @@ void FEEditorInspectorWindow::Render() ImGui::PopStyleColor(); } - if (EntitySelected->HasComponent()) + if (EntitySelected->HasComponent()) { - FEInstancedRenderingComponent& InstancedComponent = EntitySelected->GetComponent(); + FEInstancedComponent& InstancedComponent = EntitySelected->GetComponent(); if (SELECTED.InstancedSubObjectIndexSelected != -1) { @@ -551,25 +555,27 @@ void FEEditorInspectorWindow::Render() ImGui::SetNextItemWidth(220); if (ImGui::BeginCombo("##Terrain", CurrentTerrain.c_str(), ImGuiWindowFlags_None)) { - const bool is_selected = (CurrentTerrain == "none"); - if (ImGui::Selectable("none", is_selected)) + const bool bIsSelected = (CurrentTerrain == "none"); + if (ImGui::Selectable("none", bIsSelected)) { - //if (InstancedComponent.GetSnappedToTerrain() != nullptr) - // InstancedComponent.GetSnappedToTerrain()->UnSnapInstancedEntity(InstancedEntity); + if (InstancedComponent.GetSnappedToTerrain() != nullptr) + { + TERRAIN_SYSTEM.UnSnapInstancedEntity(InstancedComponent.GetSnappedToTerrain(), EntitySelected); + } } - if (is_selected) + if (bIsSelected) ImGui::SetItemDefaultFocus(); for (size_t i = 0; i < TerrainList.size(); i++) { - const bool is_selected = (CurrentTerrain == TerrainList[i]); - if (ImGui::Selectable(SCENE.GetTerrain(TerrainList[i])->GetName().c_str(), is_selected)) + const bool bIsSelected = (CurrentTerrain == TerrainList[i]); + if (ImGui::Selectable(SCENE.GetNewStyleEntity(TerrainList[i])->GetName().c_str(), bIsSelected)) { - //SCENE.GetTerrain(TerrainList[i])->SnapInstancedEntity(InstancedEntity); + TERRAIN_SYSTEM.SnapInstancedEntity(SCENE.GetNewStyleEntity(TerrainList[i]), EntitySelected); } - if (is_selected) + if (bIsSelected) ImGui::SetItemDefaultFocus(); } ImGui::EndCombo(); @@ -581,43 +587,43 @@ void FEEditorInspectorWindow::Render() ImGui::SameLine(); const int CurrentLayer = InstancedComponent.GetTerrainLayer(); - FETerrain* CurrentTerrain = InstancedComponent.GetSnappedToTerrain(); + FEEntity* TerrainEntity = InstancedComponent.GetSnappedToTerrain(); + FETerrainComponent& TerrainComponent = TerrainEntity->GetComponent(); - std::string caption = "none"; - const auto layer = CurrentTerrain->GetLayerInSlot(CurrentLayer); - if (layer != nullptr) - caption = layer->GetName(); + std::string Caption = "none"; + FETerrainLayer* Layer = TerrainComponent.GetLayerInSlot(CurrentLayer); + if (Layer != nullptr) + Caption = Layer->GetName(); ImGui::SetNextItemWidth(220); - if (ImGui::BeginCombo("##TerrainLayers", caption.c_str(), ImGuiWindowFlags_None)) + if (ImGui::BeginCombo("##TerrainLayers", Caption.c_str(), ImGuiWindowFlags_None)) { - const bool is_selected = (CurrentLayer == -1); + const bool bIsSelected = (CurrentLayer == -1); ImGui::PushID("none_TerrainLayers_entity"); - if (ImGui::Selectable("none", is_selected)) + if (ImGui::Selectable("none", bIsSelected)) { - //if (CurrentTerrain != nullptr) - //CurrentTerrain->UnConnectInstancedEntityFromLayer(InstancedEntity); + TERRAIN_SYSTEM.UnConnectInstancedEntityFromLayer(EntitySelected); } ImGui::PopID(); - if (is_selected) + if (bIsSelected) ImGui::SetItemDefaultFocus(); for (size_t i = 0; i < FE_TERRAIN_MAX_LAYERS; i++) { - FETerrainLayer* layer = CurrentTerrain->GetLayerInSlot(i); - if (layer == nullptr) + FETerrainLayer* Layer = TerrainComponent.GetLayerInSlot(i); + if (Layer == nullptr) break; - const bool is_selected = (CurrentLayer == i); - ImGui::PushID(layer->GetObjectID().c_str()); - if (ImGui::Selectable(layer->GetName().c_str(), is_selected)) + const bool bIsSelected = (CurrentLayer == i); + ImGui::PushID(/*Layer->GetObjectID().c_str()*/static_cast(i)); + if (ImGui::Selectable(Layer->GetName().c_str(), bIsSelected)) { - //CurrentTerrain->ConnectInstancedEntityToLayer(InstancedEntity, int(i)); + TERRAIN_SYSTEM.ConnectInstancedEntityToLayer(TerrainEntity, EntitySelected, static_cast(i)); } ImGui::PopID(); - if (is_selected) + if (bIsSelected) ImGui::SetItemDefaultFocus(); } ImGui::EndCombo(); @@ -717,15 +723,12 @@ void FEEditorInspectorWindow::Render() { INSTANCED_RENDERING_SYSTEM.ClearInstance(EntitySelected); INSTANCED_RENDERING_SYSTEM.PopulateInstance(EntitySelected, InstancedComponent.SpawnInfo); - //InstancedComponent.Clear(); - //InstancedComponent.Populate(InstancedComponent.SpawnInfo); } if (ImGui::Button("Add instance")) { glm::mat4 NewInstanceMatrix = glm::identity(); NewInstanceMatrix = glm::translate(NewInstanceMatrix, ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - //InstancedComponent.AddInstance(NewInstanceMatrix); INSTANCED_RENDERING_SYSTEM.AddIndividualInstance(EntitySelected, NewInstanceMatrix); PROJECT_MANAGER.GetCurrent()->SetModified(true); @@ -748,7 +751,6 @@ void FEEditorInspectorWindow::Render() if (ImGui::ImageButton((void*)(intptr_t)MouseCursorIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) { INSTANCED_RENDERING_SYSTEM.SetIndividualSelectMode(EntitySelected, !INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(EntitySelected)); - //SCENE.SetIndividualSelectMode(InstancedEntity, !InstancedComponent.IsIndividualSelectMode()); if (!INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(EntitySelected)) { SELECTED.Clear(); @@ -763,429 +765,37 @@ void FEEditorInspectorWindow::Render() } } - // FIX ME! - //if (SELECTED.GetEntity() != nullptr) - //{ - // FEEntity* Entity = SELECTED.GetEntity(); - - // if (Entity->GetType() == FE_ENTITY) - // { - // ShowTransformConfiguration(Entity, &Entity->Transform); - - // ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); - // ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); - // ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f)); - - // ImGui::InputInt("Force old matrix order", &Entity->Transform.OldWayForce); - // ImGui::Checkbox("Use old matrix order globaly", &Entity->Transform.OldWayGlobal); - - // bool bActive = Entity->IsWireframeMode(); - // ImGui::Checkbox("WireframeMode", &bActive); - // Entity->SetWireframeMode(bActive); - - // ImGui::Separator(); - // ImGui::Text("Prefab : "); - // // Temporary solution, becuase of the lack of proper ECS system - // if (Entity->Prefab != nullptr) - // { - // FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Entity->Prefab->GetObjectID()); - - // if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - // { - // EntityToModify = Entity; - // SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); - - // } - // EntityChangePrefabTarget->StickToItem(); - // } - // else - // { - // ImGui::Text("No prefab assigned."); - // } - - // bool bOpenContextMenu = false; - // if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) - // bOpenContextMenu = true; - - // if (bOpenContextMenu) - // ImGui::OpenPopup("##Inspector_context_menu"); - - // CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = false; - // ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); - // if (ImGui::BeginPopup("##Inspector_context_menu")) - // { - // CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = true; - - // if (ImGui::MenuItem("Show in folder")) - // { - // CONTENT_BROWSER_WINDOW.OpenItemParentFolder(Entity->Prefab); - // } - - // ImGui::EndPopup(); - // } - // ImGui::PopStyleVar(); - - // ImGui::Separator(); - - // ImGui::PopStyleColor(); - // ImGui::PopStyleColor(); - // ImGui::PopStyleColor(); - // } - // else if (Entity->GetType() == FE_ENTITY_INSTANCED) - // { - // FEEntityInstanced* InstancedEntity = reinterpret_cast(Entity); - - // if (SELECTED.InstancedSubObjectIndexSelected != -1) - // { - // std::string InstancedSubObjectInfo = "index: "; - - // ImGui::Text("Selected instance info:"); - // InstancedSubObjectInfo = "index: " + std::to_string(SELECTED.InstancedSubObjectIndexSelected); - // ImGui::Text(InstancedSubObjectInfo.c_str()); - - // FETransformComponent TempTransform = FETransformComponent(InstancedEntity->GetTransformedInstancedMatrix(SELECTED.InstancedSubObjectIndexSelected)); - // ShowTransformConfiguration("selected instance", &TempTransform); - // InstancedEntity->ModifyInstance(SELECTED.InstancedSubObjectIndexSelected, TempTransform.GetTransformMatrix()); - - // ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); - // ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - // ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - - // if (ImGui::ImageButton((void*)(intptr_t)ArrowToGroundIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - // { - // InstancedEntity->TryToSnapInstance(SELECTED.InstancedSubObjectIndexSelected); - // } - // ShowToolTip("Selected instance will attempt to snap to the terrain."); - - // ImGui::PopStyleColor(); - // ImGui::PopStyleColor(); - // ImGui::PopStyleColor(); - // } - // else - // { - // ShowTransformConfiguration(Entity, &Entity->Transform); - - // ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); - // ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); - // ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f)); - - // ImGui::Separator(); - - // ImGui::Text("Prefab : "); - // FETexture* PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Entity->Prefab->GetObjectID()); - // if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - // { - // EntityToModify = Entity; - // SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); - // } - // EntityChangePrefabTarget->StickToItem(); - - // bool bOpenContextMenu = false; - // if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) - // bOpenContextMenu = true; - - // if (bOpenContextMenu) - // ImGui::OpenPopup("##Inspector_context_menu"); - - // CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = false; - // ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); - // if (ImGui::BeginPopup("##Inspector_context_menu")) - // { - // CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = true; - - // if (ImGui::MenuItem("Show in folder")) - // { - // CONTENT_BROWSER_WINDOW.OpenItemParentFolder(Entity->Prefab); - // } - - // ImGui::EndPopup(); - // } - // ImGui::PopStyleVar(); - // ImGui::Separator(); - - // ImGui::PopStyleColor(); - // ImGui::PopStyleColor(); - // ImGui::PopStyleColor(); - - // ImGui::Text("Snapped to: "); - // ImGui::SameLine(); - - // const std::vector TerrainList = SCENE.GetTerrainList(); - // static std::string CurrentTerrain = "none"; - - // if (InstancedEntity->GetSnappedToTerrain() == nullptr) - // { - // CurrentTerrain = "none"; - // } - // else - // { - // CurrentTerrain = InstancedEntity->GetSnappedToTerrain()->GetName(); - // } - - // ImGui::SetNextItemWidth(220); - // if (ImGui::BeginCombo("##Terrain", CurrentTerrain.c_str(), ImGuiWindowFlags_None)) - // { - // const bool is_selected = (CurrentTerrain == "none"); - // if (ImGui::Selectable("none", is_selected)) - // { - // if (InstancedEntity->GetSnappedToTerrain() != nullptr) - // InstancedEntity->GetSnappedToTerrain()->UnSnapInstancedEntity(InstancedEntity); - // } - - // if (is_selected) - // ImGui::SetItemDefaultFocus(); - - // for (size_t i = 0; i < TerrainList.size(); i++) - // { - // const bool is_selected = (CurrentTerrain == TerrainList[i]); - // if (ImGui::Selectable(SCENE.GetTerrain(TerrainList[i])->GetName().c_str(), is_selected)) - // { - // SCENE.GetTerrain(TerrainList[i])->SnapInstancedEntity(InstancedEntity); - // } - - // if (is_selected) - // ImGui::SetItemDefaultFocus(); - // } - // ImGui::EndCombo(); - // } - - // if (InstancedEntity->GetSnappedToTerrain() != nullptr) - // { - // ImGui::Text("Terrain layer: "); - // ImGui::SameLine(); - - // const int CurrentLayer = InstancedEntity->GetTerrainLayer(); - // FETerrain* CurrentTerrain = InstancedEntity->GetSnappedToTerrain(); - - // std::string caption = "none"; - // const auto layer = CurrentTerrain->GetLayerInSlot(CurrentLayer); - // if (layer != nullptr) - // caption = layer->GetName(); - - // ImGui::SetNextItemWidth(220); - // if (ImGui::BeginCombo("##TerrainLayers", caption.c_str(), ImGuiWindowFlags_None)) - // { - // const bool is_selected = (CurrentLayer == -1); - // ImGui::PushID("none_TerrainLayers_entity"); - // if (ImGui::Selectable("none", is_selected)) - // { - // if (CurrentTerrain != nullptr) - // CurrentTerrain->UnConnectInstancedEntityFromLayer(InstancedEntity); - // } - // ImGui::PopID(); - - // if (is_selected) - // ImGui::SetItemDefaultFocus(); - - // for (size_t i = 0; i < FE_TERRAIN_MAX_LAYERS; i++) - // { - // FETerrainLayer* layer = CurrentTerrain->GetLayerInSlot(i); - // if (layer == nullptr) - // break; - - // const bool is_selected = (CurrentLayer == i); - // ImGui::PushID(layer->GetObjectID().c_str()); - // if (ImGui::Selectable(layer->GetName().c_str(), is_selected)) - // { - // CurrentTerrain->ConnectInstancedEntityToLayer(InstancedEntity, int(i)); - // } - // ImGui::PopID(); - - // if (is_selected) - // ImGui::SetItemDefaultFocus(); - // } - // ImGui::EndCombo(); - // } - - // if (CurrentLayer != -1) - // { - // ImGui::Text("Minimal layer intensity:"); - // float MinLevel = InstancedEntity->GetMinimalLayerIntensity(); - // ImGui::SameLine(); - // ImGui::SetNextItemWidth(80); - // ImGui::DragFloat("##minLevel", &MinLevel); - // InstancedEntity->SetMinimalLayerIntensity(MinLevel); - // } - // } - - // ImGui::Separator(); - - // ImGui::Text("Seed:"); - // int seed = InstancedEntity->SpawnInfo.Seed; - // ImGui::SameLine(); - // ImGui::SetNextItemWidth(200); - // ImGui::DragInt("##Seed", &seed); - // InstancedEntity->SpawnInfo.Seed = seed; - - // ImGui::Text("Object count:"); - // int ObjectCount = InstancedEntity->SpawnInfo.ObjectCount; - // ImGui::SameLine(); - // ImGui::SetNextItemWidth(200); - // ImGui::DragInt("##Object count", &ObjectCount); - // if (ObjectCount <= 0) - // ObjectCount = 1; - // InstancedEntity->SpawnInfo.ObjectCount = ObjectCount; - - // ImGui::Text("Radius:"); - // float radius = InstancedEntity->SpawnInfo.Radius; - // ImGui::SameLine(); - // ImGui::SetNextItemWidth(200); - // ImGui::DragFloat("##Radius", &radius); - // if (radius < 0.0f) - // radius = 0.1f; - // InstancedEntity->SpawnInfo.Radius = radius; - - // // Scale deviation. - // ImGui::Text("Scale: "); - - // ImGui::SameLine(); - // ImGui::Text("min "); - - // ImGui::SameLine(); - // ImGui::SetNextItemWidth(100); - // float MinScale = InstancedEntity->SpawnInfo.GetMinScale(); - // ImGui::DragFloat("##minScale", &MinScale, 0.01f); - // InstancedEntity->SpawnInfo.SetMinScale(MinScale); - - // ImGui::SameLine(); - // ImGui::Text("max "); - - // ImGui::SameLine(); - // float MaxScale = InstancedEntity->SpawnInfo.GetMaxScale(); - // ImGui::SetNextItemWidth(100); - // ImGui::DragFloat("##maxScale", &MaxScale, 0.01f); - // InstancedEntity->SpawnInfo.SetMaxScale(MaxScale); - - // ImGui::Text("Rotation deviation:"); - // float RotationDeviationX = InstancedEntity->SpawnInfo.RotationDeviation.x; - // ImGui::Text("X:"); - // ImGui::SameLine(); - // ImGui::DragFloat("##Rotation deviation X", &RotationDeviationX, 0.01f); - // if (RotationDeviationX < 0.01f) - // RotationDeviationX = 0.01f; - // if (RotationDeviationX > 1.0f) - // RotationDeviationX = 1.0f; - // InstancedEntity->SpawnInfo.RotationDeviation.x = RotationDeviationX; - - // float RotationDeviationY = InstancedEntity->SpawnInfo.RotationDeviation.y; - // ImGui::Text("Y:"); - // ImGui::SameLine(); - // ImGui::DragFloat("##Rotation deviation Y", &RotationDeviationY, 0.01f); - // if (RotationDeviationY < 0.01f) - // RotationDeviationY = 0.01f; - // if (RotationDeviationY > 1.0f) - // RotationDeviationY = 1.0f; - // InstancedEntity->SpawnInfo.RotationDeviation.y = RotationDeviationY; - - // float RotationDeviationZ = InstancedEntity->SpawnInfo.RotationDeviation.z; - // ImGui::Text("Z:"); - // ImGui::SameLine(); - // ImGui::DragFloat("##Rotation deviation z", &RotationDeviationZ, 0.01f); - // if (RotationDeviationZ < 0.01f) - // RotationDeviationZ = 0.01f; - // if (RotationDeviationZ > 1.0f) - // RotationDeviationZ = 1.0f; - // InstancedEntity->SpawnInfo.RotationDeviation.z = RotationDeviationZ; - - // if (ImGui::Button("Spawn/Re-Spawn")) - // { - // InstancedEntity->Clear(); - // InstancedEntity->Populate(InstancedEntity->SpawnInfo); - // } - - // if (ImGui::Button("Add instance")) - // { - // glm::mat4 NewInstanceMatrix = glm::identity(); - // NewInstanceMatrix = glm::translate(NewInstanceMatrix, ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - // InstancedEntity->AddInstance(NewInstanceMatrix); - - // PROJECT_MANAGER.GetCurrent()->SetModified(true); - // } - - // if (InstancedEntity->IsIndividualSelectMode()) - // { - // ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.0f, 0.75f, 0.0f)); - // ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); - // ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); - // } - // else - // { - // ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); - // ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - // ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - // } - - // ImGui::Separator(); - // if (ImGui::ImageButton((void*)(intptr_t)MouseCursorIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - // { - // SCENE.SetIndividualSelectMode(InstancedEntity, !InstancedEntity->IsIndividualSelectMode()); - // if (!InstancedEntity->IsIndividualSelectMode()) - // { - // SELECTED.Clear(); - // // FIX ME! - // //SELECTED.SetSelected(InstancedEntity); - // } - // } - // ShowToolTip("Individual selection mode - Used to select individual instances."); - - // ImGui::PopStyleColor(); - // ImGui::PopStyleColor(); - // ImGui::PopStyleColor(); - // } - // } - //} - //else if (SELECTED.GetTerrain() != nullptr) - //{ - // FETerrain* CurrentTerrain = SELECTED.GetTerrain(); - // DisplayTerrainSettings(CurrentTerrain); - - // if (CurrentTerrain->GetBrushMode() != FE_TERRAIN_BRUSH_NONE) - // { - // // FIX ME! - // // To hide gizmos. - // /*if (SELECTED.GetTerrain() != nullptr) - // SELECTED.SetSelected(SELECTED.GetTerrain());*/ - - // CurrentTerrain->SetBrushActive(bLeftMousePressed); - - // if (bShiftPressed) - // { - // if (CurrentTerrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW) - // CurrentTerrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED); - // } - // else - // { - // if (CurrentTerrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) - // CurrentTerrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); - // } - - // /*if (EDITOR.bLeftMousePressed) - // { - // if (EDITOR.bShiftPressed) - // { - // currentTerrain->setBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED); - // } - // else - // { - // currentTerrain->setBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); - // } - // } - // else - // { - // currentTerrain->setBrushMode(FE_TERRAIN_BRUSH_NONE); - // }*/ - - // //currentTerrain->setBrushActive(EDITOR.bLeftMousePressed); - // //currentTerrain->setBrushInversed(EDITOR.bShiftPressed); - // } - // else - // { - // // FIX ME! - // // To show gizmos. - // /*if (SELECTED.GetTerrain() != nullptr) - // SELECTED.SetSelected(SELECTED.GetTerrain());*/ - // } - //} + if (EntitySelected->HasComponent()) + { + FETerrainComponent& TerrainComponent = EntitySelected->GetComponent(); + DisplayTerrainSettings(EntitySelected); + + if (TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE) + { + // To hide gizmos. + SELECTED.SetSelected(EntitySelected); + + TERRAIN_SYSTEM.SetBrushActive(EntitySelected, bLeftMousePressed); + + if (bShiftPressed) + { + if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW) + TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED); + } + else + { + if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) + TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); + } + } + else + { + // To show gizmos. + SELECTED.SetSelected(EntitySelected); + } + } + + //else if (SELECTED.GetLight() != nullptr) //{ // DisplayLightProperties(SELECTED.GetLight()); @@ -1250,8 +860,7 @@ void FEEditorInspectorWindow::Render() ImGui::End(); } -static FETerrain* TerrainToWorkWith = nullptr; -static void CreateNewTerrainLayerWithMaterialCallBack(std::vector SelectionsResult) +void FEEditorInspectorWindow::CreateNewTerrainLayerWithMaterialCallBack(std::vector SelectionsResult) { if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_MATERIAL) { @@ -1262,14 +871,14 @@ static void CreateNewTerrainLayerWithMaterialCallBack(std::vector Sel if (SelectedMaterial == nullptr) return; - RESOURCE_MANAGER.ActivateTerrainVacantLayerSlot(TerrainToWorkWith, SelectedMaterial); + TERRAIN_SYSTEM.ActivateVacantLayerSlot(TerrainToWorkWith, SelectedMaterial); } TerrainToWorkWith = nullptr; } static size_t TempLayerIndex = -1; -static void ChangeMaterialInTerrainLayerCallBack(std::vector SelectionsResult) +void FEEditorInspectorWindow::ChangeMaterialInTerrainLayerCallBack(std::vector SelectionsResult) { if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_MATERIAL) { @@ -1280,28 +889,30 @@ static void ChangeMaterialInTerrainLayerCallBack(std::vector Selectio if (SelectedMaterial == nullptr) return; - TerrainToWorkWith->GetLayerInSlot(TempLayerIndex)->SetMaterial(SelectedMaterial); + FETerrainComponent& TerrainComponent = TerrainToWorkWith->GetComponent(); + TerrainComponent.GetLayerInSlot(TempLayerIndex)->SetMaterial(SelectedMaterial); } TerrainToWorkWith = nullptr; TempLayerIndex = -1; } -void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) +void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) { - if (TerrainChangeLayerMaterialTargets.size() != Terrain->LayersUsed()) + FETerrainComponent& TerrainComponent = TerrainEntity->GetComponent(); + if (TerrainChangeLayerMaterialTargets.size() != TerrainComponent.LayersUsed()) { for (size_t i = 0; i < TerrainChangeLayerMaterialTargets.size(); i++) { delete TerrainChangeLayerMaterialTargets[i]; } - TerrainChangeLayerMaterialTargets.resize(Terrain->LayersUsed()); - TerrainChangeMaterialIndecies.resize(Terrain->LayersUsed()); - for (size_t i = 0; i < size_t(Terrain->LayersUsed()); i++) + TerrainChangeLayerMaterialTargets.resize(TerrainComponent.LayersUsed()); + TerrainChangeMaterialIndecies.resize(TerrainComponent.LayersUsed()); + for (size_t i = 0; i < size_t(TerrainComponent.LayersUsed()); i++) { TerrainChangeMaterialIndecies[i] = int(i); - TerrainChangeLayerMaterialTargets[i] = DRAG_AND_DROP_MANAGER.AddTarget(FE_MATERIAL, TerrainChangeMaterialTargetCallBack, (void**)&TerrainChangeMaterialIndecies[i], "Drop to assing material to " + Terrain->GetLayerInSlot(i)->GetName()); + TerrainChangeLayerMaterialTargets[i] = DRAG_AND_DROP_MANAGER.AddTarget(FE_MATERIAL, TerrainChangeMaterialTargetCallBack, (void**)&TerrainChangeMaterialIndecies[i], "Drop to assing material to " + TerrainComponent.GetLayerInSlot(i)->GetName()); } } @@ -1309,29 +920,29 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) { if (ImGui::BeginTabItem("General")) { - bool bActive = Terrain->IsWireframeMode(); + bool bActive = TerrainComponent.IsWireframeMode(); ImGui::Checkbox("WireframeMode", &bActive); - Terrain->SetWireframeMode(bActive); + TerrainComponent.SetWireframeMode(bActive); int IData = *(int*)RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/)->GetParameterData("debugFlag"); ImGui::SliderInt("debugFlag", &IData, 0, 10); RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/)->UpdateParameterData("debugFlag", IData); - float DisplacementScale = Terrain->GetDisplacementScale(); + float DisplacementScale = TerrainComponent.GetDisplacementScale(); ImGui::DragFloat("displacementScale", &DisplacementScale, 0.02f, -10.0f, 10.0f); - Terrain->SetDisplacementScale(DisplacementScale); + TerrainComponent.SetDisplacementScale(DisplacementScale); - float LODLevel = Terrain->GetLODLevel(); + float LODLevel = TerrainComponent.GetLODLevel(); ImGui::DragFloat("LODlevel", &LODLevel, 2.0f, 2.0f, 128.0f); - Terrain->SetLODLevel(LODLevel); + TerrainComponent.SetLODLevel(LODLevel); ShowToolTip("Bigger LODlevel more details terraine will have and less performance you will get."); - float ChunkPerSide = Terrain->GetChunkPerSide(); + float ChunkPerSide = TerrainComponent.GetChunkPerSide(); ImGui::DragFloat("chunkPerSide", &ChunkPerSide, 2.0f, 1.0f, 16.0f); - Terrain->SetChunkPerSide(ChunkPerSide); + TerrainComponent.SetChunkPerSide(ChunkPerSide); // ********************* REAL WORLD COMPARISON SCALE ********************* - FEAABB RealAABB = Terrain->GetAABB(); + FEAABB RealAABB = TERRAIN_SYSTEM.GetAABB(TerrainEntity); glm::vec3 min = RealAABB.GetMin(); glm::vec3 max = RealAABB.GetMax(); @@ -1345,7 +956,7 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) ImGui::Text(SizeInM.c_str()); // ********************* REAL WORLD COMPARISON SCALE END ********************* - ShowTransformConfiguration(Terrain, &Terrain->Transform); + //ShowTransformConfiguration(Terrain, &TerrainComponent.Transform); ImGui::EndTabItem(); } @@ -1354,13 +965,13 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) ExportHeightMapButton->Render(); if (ExportHeightMapButton->IsClicked()) { - std::string filePath = ""; - FILE_SYSTEM.ShowFileSaveDialog(filePath, TEXTURE_LOAD_FILTER, 1); + std::string FilePath = ""; + FILE_SYSTEM.ShowFileSaveDialog(FilePath, TEXTURE_LOAD_FILTER, 1); - if (!filePath.empty()) + if (!FilePath.empty()) { - filePath += ".png"; - RESOURCE_MANAGER.ExportFETextureToPNG(Terrain->HeightMap, filePath.c_str()); + FilePath += ".png"; + RESOURCE_MANAGER.ExportFETextureToPNG(TerrainComponent.HeightMap, FilePath.c_str()); } } @@ -1373,7 +984,8 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) if (!FilePath.empty()) { - FETexture* LoadedTexture = RESOURCE_MANAGER.LoadPNGHeightmap(FilePath.c_str(), Terrain); + TERRAIN_SYSTEM.LoadHeightMap(FilePath.c_str(), TerrainEntity); + FETexture* LoadedTexture = TerrainComponent.HeightMap;// RESOURCE_MANAGER.LoadPNGHeightmap(FilePath.c_str(), Terrain); if (LoadedTexture == RESOURCE_MANAGER.NoTexture) { LOG.Add(std::string("can't load height map: ") + FilePath, "FE_LOG_LOADING", FE_LOG_ERROR); @@ -1386,21 +998,21 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) } } - float HighScale = Terrain->GetHightScale(); + float HighScale = TerrainComponent.GetHightScale(); ImGui::DragFloat("hight range in m", &HighScale); - Terrain->SetHightScale(HighScale); + TerrainComponent.SetHightScale(HighScale); - float CurrentBrushSize = Terrain->GetBrushSize(); + float CurrentBrushSize = TERRAIN_SYSTEM.GetBrushSize(); ImGui::DragFloat("brushSize", &CurrentBrushSize, 0.1f, 0.01f, 100.0f); - Terrain->SetBrushSize(CurrentBrushSize); + TERRAIN_SYSTEM.SetBrushSize(CurrentBrushSize); - float CurrentBrushIntensity = Terrain->GetBrushIntensity(); + float CurrentBrushIntensity = TERRAIN_SYSTEM.GetBrushIntensity(); ImGui::DragFloat("brushIntensity", &CurrentBrushIntensity, 0.0001f, 0.0001f, 10.0f); - Terrain->SetBrushIntensity(CurrentBrushIntensity); + TERRAIN_SYSTEM.SetBrushIntensity(CurrentBrushIntensity); SetDefaultStyle(SculptBrushButton); - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW || - Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) + if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW || + TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) SetSelectedStyle(SculptBrushButton); SculptBrushButton->Render(); @@ -1408,19 +1020,19 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) if (SculptBrushButton->IsClicked()) { - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW || - Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) + if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW || + TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); + TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_NONE); } else { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); + TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); } } SetDefaultStyle(LevelBrushButton); - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_LEVEL) + if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_LEVEL) SetSelectedStyle(LevelBrushButton); ImGui::SameLine(); @@ -1429,18 +1041,18 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) if (LevelBrushButton->IsClicked()) { - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_LEVEL) + if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_LEVEL) { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); + TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_NONE); } else { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_LEVEL); + TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_LEVEL); } } SetDefaultStyle(SmoothBrushButton); - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_SMOOTH) + if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_SMOOTH) SetSelectedStyle(SmoothBrushButton); ImGui::SameLine(); @@ -1449,13 +1061,13 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) if (SmoothBrushButton->IsClicked()) { - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_SMOOTH) + if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_SMOOTH) { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); + TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_NONE); } else { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_SMOOTH); + TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_SMOOTH); } } @@ -1463,39 +1075,39 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) } if (ImGui::BeginTabItem("Paint")) { - glm::vec2 TileMult = Terrain->GetTileMult(); + glm::vec2 TileMult = TerrainComponent.GetTileMult(); ImGui::DragFloat2("all layers tile factors", &TileMult[0], 0.1f, 1.0f, 100.0f); - Terrain->SetTileMult(TileMult); + TerrainComponent.SetTileMult(TileMult); - float CurrentBrushSize = Terrain->GetBrushSize(); + float CurrentBrushSize = TERRAIN_SYSTEM.GetBrushSize(); ImGui::DragFloat("brushSize", &CurrentBrushSize, 0.1f, 0.01f, 100.0f); - Terrain->SetBrushSize(CurrentBrushSize); + TERRAIN_SYSTEM.SetBrushSize(CurrentBrushSize); - float CurrentBrushIntensity = Terrain->GetBrushIntensity(); + float CurrentBrushIntensity = TERRAIN_SYSTEM.GetBrushIntensity(); ImGui::DragFloat("brushIntensity", &CurrentBrushIntensity, 0.0001f, 0.0001f, 10.0f); - Terrain->SetBrushIntensity(CurrentBrushIntensity); + TERRAIN_SYSTEM.SetBrushIntensity(CurrentBrushIntensity); SetDefaultStyle(LayerBrushButton); - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_LAYER_DRAW) + if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_LAYER_DRAW) SetSelectedStyle(LayerBrushButton); LayerBrushButton->Render(); ShowToolTip("Layer draw brush. Left mouse to paint currently selected layer, hold shift to decrease layer influence."); static int SelectedLayer = -1; - if (SelectedLayer != -1 && Terrain->GetLayerInSlot(SelectedLayer) == nullptr) + if (SelectedLayer != -1 && TerrainComponent.GetLayerInSlot(SelectedLayer) == nullptr) SelectedLayer = -1; if (LayerBrushButton->IsClicked()) { if (SelectedLayer != -1) { - if (Terrain->GetBrushMode() == FE_TERRAIN_BRUSH_LAYER_DRAW) + if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_LAYER_DRAW) { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); + TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_NONE); } else { - Terrain->SetBrushMode(FE_TERRAIN_BRUSH_LAYER_DRAW); + TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_LAYER_DRAW); } } @@ -1524,13 +1136,13 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) for (size_t i = 0; i < FE_TERRAIN_MAX_LAYERS; i++) { - FETerrainLayer* layer = Terrain->GetLayerInSlot(i); - if (layer == nullptr) + FETerrainLayer* Layer = TerrainComponent.GetLayerInSlot(i); + if (Layer == nullptr) break; ImVec2 PostionBeforeDraw = ImGui::GetCursorPos(); - ImVec2 TextSize = ImGui::CalcTextSize(layer->GetName().c_str()); + ImVec2 TextSize = ImGui::CalcTextSize(Layer->GetName().c_str()); ImGui::SetCursorPos(PostionBeforeDraw + ImVec2(ImGui::GetContentRegionAvail().x / 2.0f - TextSize.x / 2.0f, 16)); if (TerrainLayerRenameIndex == i) @@ -1549,14 +1161,14 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) ImGui::IsMouseClicked(0) && !ImGui::IsItemHovered() || ImGui::GetFocusID() != ImGui::GetID("##newNameTerrainLayerEditor")) { PROJECT_MANAGER.GetCurrent()->SetModified(true); - layer->SetName(TerrainLayerRename); + Layer->SetName(TerrainLayerRename); TerrainLayerRenameIndex = -1; } } else { - ImGui::Text(layer->GetName().c_str()); + ImGui::Text(Layer->GetName().c_str()); } ImGui::SetCursorPos(PostionBeforeDraw); @@ -1564,7 +1176,7 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) if (ImGui::Selectable("##item", SelectedLayer == i ? true : false, ImGuiSelectableFlags_None, ImVec2(ImGui::GetContentRegionAvail().x - 0, 64))) { SelectedLayer = int(i); - Terrain->SetBrushLayerIndex(SelectedLayer); + TERRAIN_SYSTEM.SetBrushLayerIndex(SelectedLayer); } TerrainChangeLayerMaterialTargets[i]->StickToItem(); ImGui::PopID(); @@ -1574,7 +1186,7 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) ImGui::SetCursorPos(PostionBeforeDraw); ImColor ImageTint = ImGui::IsItemHovered() ? ImColor(1.0f, 1.0f, 1.0f, 0.5f) : ImColor(1.0f, 1.0f, 1.0f, 1.0f); - FETexture* PreviewTexture = PREVIEW_MANAGER.GetMaterialPreview(layer->GetMaterial()->GetObjectID()); + FETexture* PreviewTexture = PREVIEW_MANAGER.GetMaterialPreview(Layer->GetMaterial()->GetObjectID()); ImGui::Image((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), ImageTint); } @@ -1595,7 +1207,7 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) { bContextMenuOpened = true; - if (Terrain->GetLayerInSlot(FE_TERRAIN_MAX_LAYERS - 1) != nullptr) + if (TerrainComponent.GetLayerInSlot(FE_TERRAIN_MAX_LAYERS - 1) != nullptr) ImGui::BeginDisabled(); if (ImGui::MenuItem("Add layer...")) @@ -1616,21 +1228,21 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) } else { - TerrainToWorkWith = Terrain; + TerrainToWorkWith = TerrainEntity; SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, CreateNewTerrainLayerWithMaterialCallBack, nullptr, FinalMaterialList); } } - if (Terrain->GetLayerInSlot(FE_TERRAIN_MAX_LAYERS - 1) != nullptr) + if (TerrainComponent.GetLayerInSlot(FE_TERRAIN_MAX_LAYERS - 1) != nullptr) ImGui::EndDisabled(); if (HoveredTerrainLayerItem != -1) { - FETerrainLayer* layer = Terrain->GetLayerInSlot(HoveredTerrainLayerItem); - if (layer != nullptr) + FETerrainLayer* Layer = TerrainComponent.GetLayerInSlot(HoveredTerrainLayerItem); + if (Layer != nullptr) { ImGui::Separator(); - std::string LayerName = layer->GetName(); + std::string LayerName = Layer->GetName(); ImGui::Text((std::string("Actions with ") + LayerName).c_str()); ImGui::Separator(); @@ -1638,23 +1250,23 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) { TerrainLayerRenameIndex = HoveredTerrainLayerItem; - strcpy_s(TerrainLayerRename, layer->GetName().size() + 1, layer->GetName().c_str()); + strcpy_s(TerrainLayerRename, Layer->GetName().size() + 1, Layer->GetName().c_str()); bLastFrameTerrainLayerRenameEditWasVisiable = false; } if (ImGui::MenuItem("Fill")) { - RESOURCE_MANAGER.FillTerrainLayerMask(Terrain, HoveredTerrainLayerItem); + TERRAIN_SYSTEM.FillTerrainLayerMask(TerrainEntity, HoveredTerrainLayerItem); } if (ImGui::MenuItem("Clear")) { - RESOURCE_MANAGER.ClearTerrainLayerMask(Terrain, HoveredTerrainLayerItem); + TERRAIN_SYSTEM.ClearTerrainLayerMask(TerrainEntity, HoveredTerrainLayerItem); } if (ImGui::MenuItem("Delete")) { - RESOURCE_MANAGER.DeleteTerrainLayerMask(Terrain, HoveredTerrainLayerItem); + TERRAIN_SYSTEM.DeleteTerrainLayerMask(TerrainEntity, HoveredTerrainLayerItem); } ImGui::Separator(); @@ -1677,30 +1289,30 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FETerrain* Terrain) } else { - TerrainToWorkWith = Terrain; + TerrainToWorkWith = TerrainEntity; TempLayerIndex = HoveredTerrainLayerItem; - SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialInTerrainLayerCallBack, Terrain->GetLayerInSlot(HoveredTerrainLayerItem)->GetMaterial(), FinalMaterialList); + SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialInTerrainLayerCallBack, TerrainComponent.GetLayerInSlot(HoveredTerrainLayerItem)->GetMaterial(), FinalMaterialList); } } if (ImGui::MenuItem("Export mask...")) { - std::string filePath = ""; - FILE_SYSTEM.ShowFileSaveDialog(filePath, TEXTURE_LOAD_FILTER, 1); - if (!filePath.empty()) + std::string FilePath = ""; + FILE_SYSTEM.ShowFileSaveDialog(FilePath, TEXTURE_LOAD_FILTER, 1); + if (!FilePath.empty()) { - filePath += ".png"; - RESOURCE_MANAGER.SaveTerrainLayerMask(filePath.c_str(), Terrain, HoveredTerrainLayerItem); + FilePath += ".png"; + TERRAIN_SYSTEM.SaveTerrainLayerMask(TerrainEntity, FilePath, HoveredTerrainLayerItem); } } if (ImGui::MenuItem("Import mask...")) { - std::string filePath = ""; - FILE_SYSTEM.ShowFileOpenDialog(filePath, TEXTURE_LOAD_FILTER, 1); - if (!filePath.empty()) + std::string FilePath = ""; + FILE_SYSTEM.ShowFileOpenDialog(FilePath, TEXTURE_LOAD_FILTER, 1); + if (!FilePath.empty()) { - RESOURCE_MANAGER.LoadTerrainLayerMask(filePath.c_str(), Terrain, HoveredTerrainLayerItem); + TERRAIN_SYSTEM.LoadTerrainLayerMask(TerrainEntity, FilePath, HoveredTerrainLayerItem); PROJECT_MANAGER.GetCurrent()->SetModified(true); } } diff --git a/EditorWindows/InspectorWindow.h b/EditorWindows/InspectorWindow.h index dd3a29d..8c138d7 100644 --- a/EditorWindows/InspectorWindow.h +++ b/EditorWindows/InspectorWindow.h @@ -16,6 +16,9 @@ class FEEditorInspectorWindow void DisplayLightsProperties() const; // Terrain settings + static FEEntity* TerrainToWorkWith; + static void CreateNewTerrainLayerWithMaterialCallBack(std::vector SelectionsResult); + static void ChangeMaterialInTerrainLayerCallBack(std::vector SelectionsResult); ImGuiButton* ExportHeightMapButton = nullptr; ImGuiButton* ImportHeightMapButton = nullptr; ImGuiImageButton* SculptBrushButton = nullptr; @@ -29,7 +32,7 @@ class FEEditorInspectorWindow std::vector TerrainChangeMaterialIndecies; std::vector TerrainChangeLayerMaterialTargets; int HoveredTerrainLayerItem = -1; - void DisplayTerrainSettings(FETerrain* Terrain); + void DisplayTerrainSettings(FEEntity* TerrainEntity); int TerrainLayerRenameIndex = -1; char TerrainLayerRename[1024]; bool bLastFrameTerrainLayerRenameEditWasVisiable = false; diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 64fc736..8e77b93 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -82,10 +82,11 @@ static void CreateNewInstancedEntityCallBack(const std::vector Select if (SelectedPrefab == nullptr) return; - FEEntityInstanced* NewEntity = SCENE.AddEntityInstanced(SelectedPrefab); - NewEntity->Transform.SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - // FIX ME! - //SELECTED.SetSelected(NewEntity); + FEEntity* NewEntity = SCENE.AddNewStyleEntity(); + NewEntity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + NewEntity->AddComponent(SelectedPrefab->GetComponent(0)->GameModel); + NewEntity->AddComponent(); + SELECTED.SetSelected(NewEntity); PROJECT_MANAGER.GetCurrent()->SetModified(true); } @@ -99,7 +100,7 @@ static void CreateNewEntityCallBack(const std::vector SelectionsResul if (SelectedPrefab == nullptr) return; - FENewEntity* NewEntity = SCENE.AddNewStyleEntity(); + FEEntity* NewEntity = SCENE.AddNewStyleEntity(); NewEntity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); SELECTED.SetSelected(NewEntity); @@ -107,9 +108,10 @@ static void CreateNewEntityCallBack(const std::vector SelectionsResul } } +// FIX ME! void FEEditorSceneGraphWindow::ChangePrefabOfEntityCallBack(const std::vector SelectionsResult) { - if (EntityToModify == nullptr) + /*if (EntityToModify == nullptr) return; if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) @@ -119,14 +121,15 @@ void FEEditorSceneGraphWindow::ChangePrefabOfEntityCallBack(const std::vectorPrefab = SelectedPrefab; - } + }*/ } void FEEditorSceneGraphWindow::DrawCorrectIcon(const FEObject* SceneObject) const { ImGui::SetCursorPosX(20); - if (SceneObject->GetType() == FE_ENTITY || SceneObject->GetType() == FE_ENTITY_INSTANCED) + // FIX ME! + /*if (SceneObject->GetType() == FE_ENTITY || SceneObject->GetType() == FE_ENTITY_INSTANCED) { const FEEntity* entity = SCENE.GetEntity(SceneObject->GetObjectID()); @@ -142,7 +145,7 @@ void FEEditorSceneGraphWindow::DrawCorrectIcon(const FEObject* SceneObject) cons { ImGui::Image((void*)(intptr_t)EntityIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); } - } + }*/ if (SceneObject->GetType() == FE_DIRECTIONAL_LIGHT) { @@ -317,14 +320,15 @@ void FEEditorSceneGraphWindow::Render() ImGui::PopStyleColor(); ImGui::PopStyleColor(); - const std::vector EntityList = SCENE.GetEntityList(); std::vector SceneObjectsList; - for (size_t i = 0; i < EntityList.size(); i++) - { - if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(SCENE.GetEntity(EntityList[i]))) - continue; - SceneObjectsList.push_back(EntityList[i]); - } + // FIX ME! + //const std::vector EntityList = SCENE.GetEntityList(); + //for (size_t i = 0; i < EntityList.size(); i++) + //{ + // if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(SCENE.GetEntity(EntityList[i]))) + // continue; + // SceneObjectsList.push_back(EntityList[i]); + //} const std::vector LightList = SCENE.GetLightsList(); for (size_t i = 0; i < LightList.size(); i++) @@ -388,7 +392,7 @@ void FEEditorSceneGraphWindow::Render() if (ImGui::IsItemClicked()) { // FIX ME! - //FENewEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])->GetObjectID()); + //FEEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])->GetObjectID()); //SELECTED.SetSelected(NewNewEntity); SELECTED.SetDirtyFlag(false); } @@ -430,7 +434,7 @@ void FEEditorSceneGraphWindow::Render() if (ImGui::MenuItem("Terrain")) { - const std::vector TerrainList = SCENE.GetTerrainList(); + /*const std::vector TerrainList = SCENE.GetTerrainList(); const size_t NextId = TerrainList.size(); size_t index = 0; std::string NewName = "terrain_" + std::to_string(NextId + index); @@ -452,11 +456,13 @@ void FEEditorSceneGraphWindow::Render() index++; NewName = "terrain_" + std::to_string(NextId + index); - } + }*/ + + FEEntity* NewEntity = SCENE.AddNewStyleEntity("Unnamed terrain"); + FETransformComponent& TransformComponent = NewEntity->GetComponent(); + FETerrainComponent& TerrainComponent = NewEntity->AddComponent(); + TerrainComponent.HeightMap = RESOURCE_MANAGER.CreateBlankHightMapTexture(); - FETerrain* NewTerrain = RESOURCE_MANAGER.CreateTerrain(true, NewName); - SCENE.AddTerrain(NewTerrain); - NewTerrain->HeightMap->SetDirtyFlag(true); PROJECT_MANAGER.GetCurrent()->SetModified(true); } @@ -487,38 +493,31 @@ void FEEditorSceneGraphWindow::Render() { if (ImGui::MenuItem("Rename")) { - if (SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - RenamePopUp::getInstance().Show(SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex])); - } - else if (SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) + if (SCENE.GetNewStyleEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) { - RenamePopUp::getInstance().Show(SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex])); - } - else if (SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - RenamePopUp::getInstance().Show(SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex])); - //renameLightWindow.show(SCENE.getLight(filteredSceneObjectsList[sceneObjectHoveredIndex])); + RenamePopUp::getInstance().Show(SCENE.GetNewStyleEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex])); } } if (ImGui::MenuItem("Delete")) { - if (SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) + FEEntity* Entity = SCENE.GetNewStyleEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); + if (Entity != nullptr) { - const FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); - if (SELECTED.GetEntity() == Entity) + if (SELECTED.GetSelected() == Entity) SELECTED.Clear(); - SCENE.DeleteEntity(Entity->GetObjectID()); + SCENE.DeleteNewEntity(Entity); } - else if (SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) + + // FIX ME! + /*if (SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) { - const FETerrain* Terrain = SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex]); - if (SELECTED.GetTerrain() == Terrain) + const FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); + if (SELECTED.GetEntity() == Entity) SELECTED.Clear(); - SCENE.DeleteTerrain(Terrain->GetObjectID()); + SCENE.DeleteEntity(Entity->GetObjectID()); } else if (SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) { @@ -527,7 +526,7 @@ void FEEditorSceneGraphWindow::Render() SELECTED.Clear(); SCENE.DeleteLight(Light->GetObjectID()); - } + }*/ } /*if (ImGui::MenuItem("*DEBUG* Test model camera on this")) @@ -541,11 +540,6 @@ void FEEditorSceneGraphWindow::Render() const FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); Position = Entity->Transform.GetPosition(); } - else if (SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - const FETerrain* Terrain = SCENE.GetTerrain(FilteredSceneObjectsList[SceneObjectHoveredIndex]); - Position = Terrain->Transform.GetPosition(); - } else if (SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) { const FELight* Light = SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]); @@ -632,30 +626,29 @@ void FEEditorSceneGraphWindow::Render() // Draw AABB if (SELECTED.GetSelected() != nullptr && - (SELECTED.GetSelected()->GetType() == FE_ENTITY || SELECTED.GetSelected()->GetType() == FE_ENTITY_INSTANCED || SELECTED.GetSelected()->GetType() == FE_TERRAIN) && + (SELECTED.GetSelected()->HasComponent() || SELECTED.GetSelected()->HasComponent()) && bDisplaySelectedObjAABB) { if (SELECTED.GetSelected()->HasComponent()) { FEGameModel* GameModel = SELECTED.GetSelected()->GetComponent().GameModel; FEAABB SelectedAABB = GameModel->GetMesh()->GetAABB().Transform(SELECTED.GetSelected()->GetComponent().GetTransformMatrix()); - //const FEAABB SelectedAABB = SELECTED.GetEntity() != nullptr ? SELECTED.GetEntity()->GetAABB() : SELECTED.GetTerrain()->GetAABB(); RENDERER.DrawAABB(SelectedAABB); - if (SELECTED.GetSelected()->GetType() == FE_ENTITY_INSTANCED) + if (SELECTED.GetSelected()->HasComponent()) { static bool bDisplaySubObjAABB = false; ImGui::Checkbox("Display AABB of instanced entity subobjects", &bDisplaySubObjAABB); if (bDisplaySubObjAABB) { - const FEEntityInstanced* EntityInstanced = reinterpret_cast (SELECTED.GetSelected()); - const int MaxIterations = EntityInstanced->InstancedAABB.size() * 8 >= FE_MAX_LINES ? FE_MAX_LINES : int(EntityInstanced->InstancedAABB.size()); - + FEInstancedComponent& InstancedComponent = SELECTED.GetSelected()->GetComponent(); + const int MaxIterations = InstancedComponent.IndividualInstancedAABB.size() * 8 >= FE_MAX_LINES ? FE_MAX_LINES : int(InstancedComponent.IndividualInstancedAABB.size()); + for (size_t j = 0; j < MaxIterations; j++) { - RENDERER.DrawAABB(EntityInstanced->InstancedAABB[j]); + RENDERER.DrawAABB(InstancedComponent.IndividualInstancedAABB[j]); } } } diff --git a/EditorWindows/ShaderEditorWindow.cpp b/EditorWindows/ShaderEditorWindow.cpp index ab29058..2c17796 100644 --- a/EditorWindows/ShaderEditorWindow.cpp +++ b/EditorWindows/ShaderEditorWindow.cpp @@ -469,10 +469,11 @@ void ShaderEditorWindow::ReplaceShader(FEShader* OldShader, FEShader* NewShader) const std::vector TerrainList = SCENE.GetTerrainList(); for (size_t i = 0; i < TerrainList.size(); i++) { - FETerrain* TempTerrain = SCENE.GetTerrain(TerrainList[i]); - if (TempTerrain->Shader->GetNameHash() == OldShader->GetNameHash()) + FEEntity* TempTerrain = SCENE.GetNewStyleEntity(TerrainList[i]); + FETerrainComponent& TerrainComponent = TempTerrain->GetComponent(); + if (TerrainComponent.Shader->GetNameHash() == OldShader->GetNameHash()) { - TempTerrain->Shader = NewShader; + TerrainComponent.Shader = NewShader; } } } \ No newline at end of file diff --git a/FEEditor.cpp b/FEEditor.cpp index d3bac01..5c62538 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -9,7 +9,7 @@ bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) { FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())->GetComponent(0)->GameModel; - FENewEntity* NewNewEntity = SCENE.AddNewStyleEntity(Object->GetName()); + FEEntity* NewNewEntity = SCENE.AddNewStyleEntity(Object->GetName()); NewNewEntity->GetComponent().GameModel = GameModel; NewNewEntity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); SELECTED.SetSelected(NewNewEntity); @@ -22,7 +22,7 @@ bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) //if (Object->GetType() == FE_PREFAB) //{ // FEEntity* NewEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())); - // FENewEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(NewEntity->GetObjectID()); + // FEEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(NewEntity->GetObjectID()); // NewNewEntity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); // //NewEntity->Transform.SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); // SELECTED.SetSelected(NewNewEntity); @@ -124,9 +124,9 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) if (Button == GLFW_MOUSE_BUTTON_1 && Action == GLFW_PRESS) { bool bEditingTerrain = false; - if (SELECTED.GetTerrain() != nullptr) + if (SELECTED.GetSelected() != nullptr && SELECTED.GetSelected()->HasComponent()) { - bEditingTerrain = SELECTED.GetTerrain()->GetBrushMode() != FE_TERRAIN_BRUSH_NONE; + bEditingTerrain = TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE; } if (!bEditingTerrain) @@ -173,26 +173,17 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) if (!ImGui::GetIO().WantCaptureKeyboard && Key == GLFW_KEY_DELETE) { - if (SELECTED.GetSelected() != nullptr && SELECTED.GetSelected()->GetType() == FE_ENTITY_INSTANCED) + if (SELECTED.GetSelected() != nullptr) { - if (SELECTED.InstancedSubObjectIndexSelected != -1) + if (SELECTED.InstancedSubObjectIndexSelected != -1 && SELECTED.GetSelected()->HasComponent()) { - FEEntityInstanced* SelectedEntityInstanced = SCENE.GetEntityInstanced(SELECTED.GetSelected()->GetObjectID()); - SelectedEntityInstanced->DeleteInstance(SELECTED.InstancedSubObjectIndexSelected); - SELECTED.Clear(); - PROJECT_MANAGER.GetCurrent()->SetModified(true); + INSTANCED_RENDERING_SYSTEM.DeleteIndividualInstance(SELECTED.GetSelected(), SELECTED.InstancedSubObjectIndexSelected); + } + else + { + SCENE.DeleteNewEntity(SELECTED.GetSelected()); } - } - if (SELECTED.GetEntity() != nullptr) - { - SCENE.DeleteEntity(SELECTED.GetEntity()->GetObjectID()); - SELECTED.Clear(); - PROJECT_MANAGER.GetCurrent()->SetModified(true); - } - else if (SELECTED.GetTerrain() != nullptr) - { - SCENE.DeleteTerrain(SELECTED.GetTerrain()->GetObjectID()); SELECTED.Clear(); PROJECT_MANAGER.GetCurrent()->SetModified(true); } @@ -211,8 +202,8 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) // FIX ME! // There should be proper FEScene::DuplicateNewStyleEntity that will duplicate the entity and all its components // Also place it in same scene graph node as the original entity ? - FENewEntity* EntityToCopy = SCENE.GetNewStyleEntity(EDITOR.GetSceneEntityIDInClipboard()); - FENewEntity* NewNewEntity = SCENE.AddNewStyleEntity(EntityToCopy->GetName() + "_Copy"); + FEEntity* EntityToCopy = SCENE.GetNewStyleEntity(EDITOR.GetSceneEntityIDInClipboard()); + FEEntity* NewNewEntity = SCENE.AddNewStyleEntity(EntityToCopy->GetName() + "_Copy"); NewNewEntity->GetComponent() = EntityToCopy->GetComponent(); NewNewEntity->GetComponent().SetPosition(EntityToCopy->GetComponent().GetPosition() * 1.1f); if (EntityToCopy->HasComponent()) @@ -315,9 +306,9 @@ void FEEditor::MouseMoveCallback(double Xpos, double Ypos) if (SELECTED.GetSelected() != nullptr) { - if (SELECTED.GetTerrain() != nullptr) + if (SELECTED.GetSelected() != nullptr && SELECTED.GetSelected()->HasComponent()) { - if (SELECTED.GetTerrain()->GetBrushMode() != FE_TERRAIN_BRUSH_NONE) + if (TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE) return; } @@ -936,13 +927,13 @@ void FEEditor::DisplayEffectsWindow() const if (ImGui::CollapsingHeader("Sky", 0)) { - bool bEnabledSky = RENDERER.IsSkyEnabled(); + bool bEnabledSky = SKY_DOME_SYSTEM.IsEnabled(); if (ImGui::Checkbox("enable sky", &bEnabledSky)) { - RENDERER.SetSkyEnabled(bEnabledSky); + SKY_DOME_SYSTEM.SetEnabled(bEnabledSky); } - ImGui::Text("Sphere size:"); + /*ImGui::Text("Sphere size:"); ImGui::SetNextItemWidth(FieldWidth); float size = RENDERER.GetDistanceToSky(); ImGui::DragFloat("##Sphere size", &size, 0.01f, 0.0f, 200.0f); @@ -954,7 +945,7 @@ void FEEditor::DisplayEffectsWindow() const if (ResetButton->IsClicked()) { RENDERER.SetDistanceToSky(50.0f); - } + }*/ ImGui::PopID(); } @@ -1089,27 +1080,6 @@ void FEEditor::DisplayEffectsWindow() const ImGui::DragFloat("SSAO small details weight", &TempFloat, 0.01f); RENDERER.SetSSAOSmallDetailsWeight(TempFloat); } - - /*bool bEnabledSky = RENDERER.IsSkyEnabled(); - if (ImGui::Checkbox("enable sky", &bEnabledSky)) - { - RENDERER.SetSkyEnabld(bEnabledSky); - } - - ImGui::Text("Sphere size:"); - ImGui::SetNextItemWidth(FieldWidth); - float size = RENDERER.GetDistanceToSky(); - ImGui::DragFloat("##Sphere size", &size, 0.01f, 0.0f, 200.0f); - RENDERER.SetDistanceToSky(size); - - ImGui::PushID(GUIID++); - ImGui::SameLine(); - ResetButton->Render(); - if (ResetButton->IsClicked()) - { - RENDERER.SetDistanceToSky(50.0f); - } - ImGui::PopID();*/ } ImGui::PopStyleVar(); diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index b785648..e01d86d 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -388,9 +388,9 @@ void GizmoManager::HideAllGizmo() void GizmoManager::UpdateGizmoState(int NewState) { - if (SELECTED.GetTerrain() != nullptr) + if (SELECTED.GetSelected() != nullptr && SELECTED.GetSelected()->HasComponent()) { - if (SELECTED.GetTerrain()->GetBrushMode() != FE_TERRAIN_BRUSH_NONE) + if (TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE) return; } @@ -577,7 +577,7 @@ bool GizmoManager::WasSelected(int Index) if (SELECTED.SceneEntitiesUnderMouse[Index]->GetType() == FE_CAMERA) return true; - FENewEntity* SelectedEntity = SELECTED.SceneEntitiesUnderMouse[Index]; + FEEntity* SelectedEntity = SELECTED.SceneEntitiesUnderMouse[Index]; FETransformComponent& CurrentTransform = SelectedEntity->GetComponent(); if (GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == TransformationXGizmoEntity->GetObjectID()) @@ -782,6 +782,8 @@ void GizmoManager::MouseMoveTransformationGizmos() float LastFrameMouseRayParametricIntersection = 0.0f; float LastFrameGizmoRayParametricIntersection = 0.0f; + bool bAppliedSomeChanges = false; + if (GIZMO_MANAGER.bTransformationXGizmoActive) { const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); @@ -795,7 +797,11 @@ void GizmoManager::MouseMoveTransformationGizmos() MouseRayParametricIntersection, GizmoRayParametricIntersection); const float Difference = GizmoRayParametricIntersection - LastFrameGizmoRayParametricIntersection; - MoveSelectedEntityAlongAxis(glm::vec3(Difference, 0.0f, 0.0f), ObjTransform); + if (abs(Difference) > FLT_EPSILON) + { + bAppliedSomeChanges = true; + MoveSelectedEntityAlongAxis(glm::vec3(Difference, 0.0f, 0.0f), ObjTransform); + } } if (GIZMO_MANAGER.bTransformationYGizmoActive) @@ -811,7 +817,11 @@ void GizmoManager::MouseMoveTransformationGizmos() MouseRayParametricIntersection, GizmoRayParametricIntersection); const float Difference = GizmoRayParametricIntersection - LastFrameGizmoRayParametricIntersection; - MoveSelectedEntityAlongAxis(glm::vec3(0.0f, Difference, 0.0f), ObjTransform); + if (abs(Difference) > FLT_EPSILON) + { + bAppliedSomeChanges = true; + MoveSelectedEntityAlongAxis(glm::vec3(0.0f, Difference, 0.0f), ObjTransform); + } } if (GIZMO_MANAGER.bTransformationZGizmoActive) @@ -827,28 +837,45 @@ void GizmoManager::MouseMoveTransformationGizmos() MouseRayParametricIntersection, GizmoRayParametricIntersection); const float Difference = GizmoRayParametricIntersection - LastFrameGizmoRayParametricIntersection; - MoveSelectedEntityAlongAxis(glm::vec3(0.0f, 0.0f, Difference), ObjTransform); + if (abs(Difference) > FLT_EPSILON) + { + bAppliedSomeChanges = true; + MoveSelectedEntityAlongAxis(glm::vec3(0.0f, 0.0f, Difference), ObjTransform); + } } if (GIZMO_MANAGER.bTransformationXYGizmoActive) { const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(0.0f, 0.0f, 1.0f)); - MoveSelectedEntityAlongAxis(Difference, ObjTransform); + if (!GEOMETRY.IsEpsilonEqual(Difference, glm::vec3(0.0f))) + { + bAppliedSomeChanges = true; + MoveSelectedEntityAlongAxis(Difference, ObjTransform); + } } if (GIZMO_MANAGER.bTransformationYZGizmoActive) { const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(1.0f, 0.0f, 0.0f)); - MoveSelectedEntityAlongAxis(Difference, ObjTransform); + if (!GEOMETRY.IsEpsilonEqual(Difference, glm::vec3(0.0f))) + { + bAppliedSomeChanges = true; + MoveSelectedEntityAlongAxis(Difference, ObjTransform); + } } if (GIZMO_MANAGER.bTransformationXZGizmoActive) { const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(0.0f, 1.0f, 0.0f)); - MoveSelectedEntityAlongAxis(Difference, ObjTransform); + if (!GEOMETRY.IsEpsilonEqual(Difference, glm::vec3(0.0f))) + { + bAppliedSomeChanges = true; + MoveSelectedEntityAlongAxis(Difference, ObjTransform); + } } - ApplyChangesToSelectedObject(ObjTransform); + if (bAppliedSomeChanges) + ApplyChangesToSelectedObject(ObjTransform); } void GizmoManager::MouseMoveScaleGizmos() @@ -959,9 +986,9 @@ void GizmoManager::OnSelectedObjectUpdate() } else { - if (SELECTED.GetTerrain() != nullptr) + if (SELECTED.GetSelected() != nullptr && SELECTED.GetSelected()->HasComponent()) { - if (SELECTED.GetTerrain()->GetBrushMode() != FE_TERRAIN_BRUSH_NONE) + if (TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE) { GIZMO_MANAGER.HideAllGizmo(); return; @@ -997,7 +1024,15 @@ FETransformComponent GizmoManager::GetTransformComponentOfSelectedObject() if (SELECTED.GetSelected() == nullptr) return FETransformComponent(); - return SELECTED.GetSelected()->GetComponent(); + if (SELECTED.InstancedSubObjectIndexSelected != -1 && SELECTED.GetSelected()->HasComponent()) + { + FEInstancedComponent& InstancedComponent = SELECTED.GetSelected()->GetComponent(); + return InstancedComponent.GetTransformedInstancedMatrix(SELECTED.InstancedSubObjectIndexSelected); + } + else + { + return SELECTED.GetSelected()->GetComponent(); + } /*if (SELECTED.GetSelected()->GetType() == FE_ENTITY) { @@ -1033,11 +1068,12 @@ void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent Changes) if (SELECTED.InstancedSubObjectIndexSelected != -1) { - //reinterpret_cast(SELECTED.GetEntity())->ModifyInstance(SELECTED.InstancedSubObjectIndexSelected, Changes.GetTransformMatrix()); - assert(false); + INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(SELECTED.GetSelected(), SELECTED.InstancedSubObjectIndexSelected, Changes.GetTransformMatrix()); + } + else + { + SELECTED.GetSelected()->GetComponent() = Changes; } - - SELECTED.GetSelected()->GetComponent() = Changes; /*if (SELECTED.GetSelected()->GetType() == FE_ENTITY) { diff --git a/FEEditorGizmoManager.h b/FEEditorGizmoManager.h index a4868e9..567e89b 100644 --- a/FEEditorGizmoManager.h +++ b/FEEditorGizmoManager.h @@ -22,38 +22,38 @@ class GizmoManager int GizmosState = TRANSFORM_GIZMOS; // Parent Gizmo Entity - FENewEntity* ParentGizmoEntity = nullptr; + FEEntity* ParentGizmoEntity = nullptr; FENaiveSceneGraphNode* ParentGizmoGraphNode = nullptr; - FENewEntity* TransformationXGizmoEntity = nullptr; - FENewEntity* TransformationYGizmoEntity = nullptr; - FENewEntity* TransformationZGizmoEntity = nullptr; + FEEntity* TransformationXGizmoEntity = nullptr; + FEEntity* TransformationYGizmoEntity = nullptr; + FEEntity* TransformationZGizmoEntity = nullptr; bool bTransformationXGizmoActive = false; bool bTransformationYGizmoActive = false; bool bTransformationZGizmoActive = false; - FENewEntity* TransformationXYGizmoEntity = nullptr; - FENewEntity* TransformationYZGizmoEntity = nullptr; - FENewEntity* TransformationXZGizmoEntity = nullptr; + FEEntity* TransformationXYGizmoEntity = nullptr; + FEEntity* TransformationYZGizmoEntity = nullptr; + FEEntity* TransformationXZGizmoEntity = nullptr; bool bTransformationXYGizmoActive = false; bool bTransformationYZGizmoActive = false; bool bTransformationXZGizmoActive = false; // Scale part. - FENewEntity* ScaleXGizmoEntity = nullptr; - FENewEntity* ScaleYGizmoEntity = nullptr; - FENewEntity* ScaleZGizmoEntity = nullptr; + FEEntity* ScaleXGizmoEntity = nullptr; + FEEntity* ScaleYGizmoEntity = nullptr; + FEEntity* ScaleZGizmoEntity = nullptr; bool bScaleXGizmoActive = false; bool bScaleYGizmoActive = false; bool bScaleZGizmoActive = false; // Rotate part. - FENewEntity* RotateXGizmoEntity = nullptr; - FENewEntity* RotateYGizmoEntity = nullptr; - FENewEntity* RotateZGizmoEntity = nullptr; + FEEntity* RotateXGizmoEntity = nullptr; + FEEntity* RotateYGizmoEntity = nullptr; + FEEntity* RotateZGizmoEntity = nullptr; bool bRotateXGizmoActive = false; bool bRotateYGizmoActive = false; diff --git a/FEEditorPreviewManager.h b/FEEditorPreviewManager.h index aebf487..459df4b 100644 --- a/FEEditorPreviewManager.h +++ b/FEEditorPreviewManager.h @@ -30,7 +30,7 @@ class FEEditorPreviewManager void UpdateAll(); FEFramebuffer* PreviewFB; - FENewEntity* PreviewEntity; + FEEntity* PreviewEntity; FEPrefab* PreviewPrefab; FEGameModel* PreviewGameModel; FEMaterial* MeshPreviewMaterial; diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index c605143..70a681c 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -38,6 +38,8 @@ void FEEditorSelectedObject::InitializeResources() const FEShaderParam ColorParam(glm::vec3(0.0f, 0.0f, 0.0f), "baseColor"); PixelAccurateSelectionMaterial->AddParameter(ColorParam); + + DummyEntity = SCENE.AddNewStyleEntity("Editor_Selection_Dummy_Entity"); } void FEEditorSelectedObject::ReInitializeResources() @@ -48,6 +50,9 @@ void FEEditorSelectedObject::ReInitializeResources() PixelAccurateSelectionFB = RESOURCE_MANAGER.CreateFramebuffer(FE_COLOR_ATTACHMENT | FE_DEPTH_ATTACHMENT, ENGINE.GetRenderTargetWidth(), ENGINE.GetRenderTargetHeight()); delete PixelAccurateSelectionFB->GetColorAttachment(); PixelAccurateSelectionFB->SetColorAttachment(RESOURCE_MANAGER.CreateTexture(GL_RGB, GL_RGB, ENGINE.GetRenderTargetWidth(), ENGINE.GetRenderTargetHeight())); + + if (SCENE.GetEntityByName("Editor_Selection_Dummy_Entity").empty()) + DummyEntity = SCENE.AddNewStyleEntity("Editor_Selection_Dummy_Entity"); } void FEEditorSelectedObject::SetOnUpdateFunc(void(*Func)()) @@ -55,7 +60,7 @@ void FEEditorSelectedObject::SetOnUpdateFunc(void(*Func)()) OnUpdateFunc = Func; } -FENewEntity* FEEditorSelectedObject::GetSelected() const +FEEntity* FEEditorSelectedObject::GetSelected() const { return Container; } @@ -70,49 +75,13 @@ void FEEditorSelectedObject::SetDirtyFlag(const bool NewValue) bDirtyFlag = NewValue; } -//void FEEditorSelectedObject::SetSelected(FEObject* SelectedObject) -//{ -// if (SelectedObject == nullptr) -// return; -// -// if (Container != SelectedObject) -// bDirtyFlag = true; -// -// if (Container != nullptr && Container->GetType() == FE_TERRAIN && Container != SelectedObject) -// { -// FETerrain* DeselectedTerrain = reinterpret_cast(Container); -// DeselectedTerrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); -// } -// -// // Temporary solution, becuase of the lack of proper ECS system -// FENewEntity* NewEntity = SCENE.GetNewStyleEntityByOldStyleID(SelectedObject->GetObjectID()); -// if (NewEntity != nullptr) -// { -// NewContainer = NewEntity; -// Container = nullptr; -// } -// else -// { -// Container = SelectedObject; -// NewContainer = nullptr; -// } -// -// //Container = SelectedObject; -// if (OnUpdateFunc != nullptr) -// OnUpdateFunc(); -//} - -void FEEditorSelectedObject::SetSelected(FENewEntity* SelectedObject) +void FEEditorSelectedObject::SetSelected(FEEntity* SelectedObject) { if (SelectedObject == nullptr) return; - // FIX ME! - //if (Container != nullptr && Container->GetType() == FE_TERRAIN && Container != SelectedObject) - //{ - // FETerrain* DeselectedTerrain = reinterpret_cast(Container); - // DeselectedTerrain->SetBrushMode(FE_TERRAIN_BRUSH_NONE); - //} + if (Container != nullptr && Container->HasComponent() && Container != SelectedObject) + TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_NONE); if (Container != SelectedObject) bDirtyFlag = true; @@ -124,11 +93,10 @@ void FEEditorSelectedObject::SetSelected(FENewEntity* SelectedObject) void FEEditorSelectedObject::Clear() { - // FIX ME! - /*if (InstancedSubObjectIndexSelected != -1 && SCENE.GetEntityInstanced(Container->GetObjectID()) != nullptr) + if (InstancedSubObjectIndexSelected != -1 && Container->HasComponent()) { - SCENE.GetEntityInstanced(Container->GetObjectID())->SetIndividualSelectMode(false); - }*/ + INSTANCED_RENDERING_SYSTEM.SetIndividualSelectMode(Container, false); + } InstancedSubObjectIndexSelected = -1; Container = nullptr; @@ -164,65 +132,45 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons { float Distance = 0; - FENewEntity* NewStyleEntity = SCENE.GetNewStyleEntity(EntityList[i]); - if (NewStyleEntity != nullptr && NewStyleEntity->HasComponent()) + FEEntity* NewStyleEntity = SCENE.GetNewStyleEntity(EntityList[i]); + if (NewStyleEntity != nullptr /*&& Entity->HasComponent()*/) { - FEGameModelComponent& GameModelComponent = NewStyleEntity->GetComponent(); + //FEGameModelComponent& GameModelComponent = Entity->GetComponent(); FEAABB Box; - if (!NewStyleEntity->HasComponent()) + if (NewStyleEntity->HasComponent() && !NewStyleEntity->HasComponent()) { - Box = GameModelComponent.GameModel->GetMesh()->GetAABB().Transform(NewStyleEntity->GetComponent().GetTransformMatrix()); + Box = NewStyleEntity->GetComponent().GameModel->GetMesh()->GetAABB().Transform(NewStyleEntity->GetComponent().GetTransformMatrix()); } - else if (NewStyleEntity->HasComponent()) + else if (NewStyleEntity->HasComponent() && NewStyleEntity->HasComponent()) { Box = INSTANCED_RENDERING_SYSTEM.GetAABB(NewStyleEntity); } + else if (NewStyleEntity->HasComponent()) + { + Box = TERRAIN_SYSTEM.GetAABB(NewStyleEntity); + } if (Box.RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) { - if (NewStyleEntity->HasComponent()) + if (NewStyleEntity->HasComponent()) { - FEInstancedRenderingComponent& InstancedComponent = NewStyleEntity->GetComponent(); - //FEEntityInstanced* InstancedEntity = reinterpret_cast(SCENE.GetEntity(EntityList[i])); + FEInstancedComponent& InstancedComponent = NewStyleEntity->GetComponent(); if (INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(NewStyleEntity)) { - // FIX ME! - /*InstancedSubObjectsInfo[InstancedEntity] = std::vector(); - for (size_t j = 0; j < InstancedEntity->IndividualInstancedAABB.size(); j++) + // Check ME! + InstancedSubObjectsInfo[NewStyleEntity] = std::vector(); + for (size_t j = 0; j < InstancedComponent.IndividualInstancedAABB.size(); j++) { - if (InstancedEntity->IndividualInstancedAABB[j].RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) + if (InstancedComponent.IndividualInstancedAABB[j].RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) { - InstancedSubObjectsInfo[InstancedEntity].push_back(static_cast(j)); + InstancedSubObjectsInfo[NewStyleEntity].push_back(static_cast(j)); } - }*/ + } } } SELECTED.SceneEntitiesUnderMouse.push_back(NewStyleEntity); - - // FIX ME! - /*if (SCENE.GetEntity(EntityList[i])->GetType() == FE_ENTITY_INSTANCED) - { - FEEntityInstanced* InstancedEntity = reinterpret_cast(SCENE.GetEntity(EntityList[i])); - if (InstancedEntity->IsIndividualSelectMode()) - { - InstancedSubObjectsInfo[InstancedEntity] = std::vector(); - for (size_t j = 0; j < InstancedEntity->IndividualInstancedAABB.size(); j++) - { - if (InstancedEntity->IndividualInstancedAABB[j].RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) - { - InstancedSubObjectsInfo[InstancedEntity].push_back(static_cast(j)); - } - } - } - - SELECTED.SceneEntitiesUnderMouse.push_back(InstancedEntity); - } - else - {*/ - //SELECTED.SceneEntitiesUnderMouse.push_back(NewStyleEntity/*SCENE.GetEntity(EntityList[i])*/); - //} } } } @@ -265,7 +213,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons int g = ((i + 1) >> 8) & 255; int b = ((i + 1) >> 16) & 255; #endif - FENewEntity* PotentiallySelectedEntity = SELECTED.SceneEntitiesUnderMouse[i]; + FEEntity* PotentiallySelectedEntity = SELECTED.SceneEntitiesUnderMouse[i]; if (PotentiallySelectedEntity->HasComponent()) { FEGameModelComponent& GameModelComponent = PotentiallySelectedEntity->GetComponent(); @@ -280,104 +228,48 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - if (!PotentiallySelectedEntity->HasComponent()) + if (!PotentiallySelectedEntity->HasComponent()) { RENDERER.RenderGameModelComponent(GameModelComponent, PotentiallySelectedEntity->GetComponent(), ENGINE.GetCamera(), false); } - else if (PotentiallySelectedEntity->HasComponent()) + else if (PotentiallySelectedEntity->HasComponent()) { - PixelAccurateSelectionMaterial->Shader = FEPixelAccurateInstancedSelection; - FEMaterial* RegularBillboardMaterials = GameModelComponent.GameModel->GetBillboardMaterial(); - GameModelComponent.GameModel->SetBillboardMaterial(PixelAccurateSelectionMaterial); + // Render instanced object only if it is not in individual select mode + if (/*InstancedSubObjectsInfo.find(PotentiallySelectedEntity) == InstancedSubObjectsInfo.end()*/!INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(PotentiallySelectedEntity)) + { + PixelAccurateSelectionMaterial->Shader = FEPixelAccurateInstancedSelection; + FEMaterial* RegularBillboardMaterials = GameModelComponent.GameModel->GetBillboardMaterial(); + GameModelComponent.GameModel->SetBillboardMaterial(PixelAccurateSelectionMaterial); - FEInstancedRenderingComponent& InstancedComponent = PotentiallySelectedEntity->GetComponent(); - RENDERER.RenderGameModelComponentWithInstanced(PotentiallySelectedEntity->GetComponent(), GameModelComponent, InstancedComponent, ENGINE.GetCamera(), nullptr, false, false); + FEInstancedComponent& InstancedComponent = PotentiallySelectedEntity->GetComponent(); + RENDERER.RenderGameModelComponentWithInstanced(PotentiallySelectedEntity->GetComponent(), GameModelComponent, InstancedComponent, ENGINE.GetCamera(), nullptr, false, false); - PixelAccurateSelectionMaterial->Shader = FEPixelAccurateSelection; - GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterials); + PixelAccurateSelectionMaterial->Shader = FEPixelAccurateSelection; + GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterials); + } } GameModelComponent.GameModel->Material = RegularMaterial; PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr); PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr, 1); } + else if (PotentiallySelectedEntity->HasComponent()) + { + FETerrainComponent& TerrainComponent = PotentiallySelectedEntity->GetComponent(); + if (!TerrainComponent.IsVisible()) + continue; - //if (SELECTED.SceneEntitiesUnderMouse[i]->GetType() == FE_ENTITY) - //{ - // PotentiallySelectedEntity = SCENE.GetEntity(SELECTED.SceneEntitiesUnderMouse[i]->GetObjectID()); - // if (!PotentiallySelectedEntity->IsVisible()) - // continue; - - // for (int j = 0; j < PotentiallySelectedEntity->Prefab->ComponentsCount(); j++) - // { - // FEMaterial* RegularMaterial = PotentiallySelectedEntity->Prefab->GetComponent(j)->GameModel->Material; - // PotentiallySelectedEntity->Prefab->GetComponent(j)->GameModel->Material = PixelAccurateSelectionMaterial; - // PixelAccurateSelectionMaterial->SetBaseColor(glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); - // PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); - // PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - // PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - - // RENDERER.RenderEntity(PotentiallySelectedEntity, ENGINE.GetCamera(), false, j); - - // PotentiallySelectedEntity->Prefab->GetComponent(j)->GameModel->Material = RegularMaterial; - // } - // PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr); - // PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr, 1); - //} - //else if (SELECTED.SceneEntitiesUnderMouse[i]->GetType() == FE_ENTITY_INSTANCED) - //{ - // FEEntityInstanced* PotentiallySelectedEntityInstanced = reinterpret_cast(SCENE.GetEntity((SELECTED.SceneEntitiesUnderMouse[i]->GetObjectID()))); - // if (!PotentiallySelectedEntityInstanced->IsVisible()) - // continue; - - // if (InstancedSubObjectsInfo.find(PotentiallySelectedEntityInstanced) == InstancedSubObjectsInfo.end()) - // { - // for (int j = 0; j < PotentiallySelectedEntityInstanced->Prefab->ComponentsCount(); j++) - // { - // FEMaterial* RegularMaterial = PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->Material; - // PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->Material = PixelAccurateSelectionMaterial; - - // PixelAccurateSelectionMaterial->SetBaseColor(glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); - // PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); - // PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - // PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - - // PixelAccurateSelectionMaterial->Shader = FEPixelAccurateInstancedSelection; - // FEMaterial* RegularBillboardMaterials = PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->GetBillboardMaterial(); - // PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->SetBillboardMaterial(PixelAccurateSelectionMaterial); - - // RENDERER.RenderEntityInstanced(PotentiallySelectedEntityInstanced, ENGINE.GetCamera(), nullptr, false, false, j); - - // PixelAccurateSelectionMaterial->Shader = FEPixelAccurateSelection; - // PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->SetBillboardMaterial(RegularBillboardMaterials); - // PotentiallySelectedEntityInstanced->Prefab->GetComponent(j)->GameModel->Material = RegularMaterial; - - // PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr); - // PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr, 1); - // } - // } - //} - //else if (SELECTED.SceneEntitiesUnderMouse[i]->GetType() == FE_TERRAIN) - //{ - // FETerrain* PotentiallySelectedTerrain = SCENE.GetTerrain(SELECTED.SceneEntitiesUnderMouse[i]->GetObjectID()); - // if (PotentiallySelectedTerrain != nullptr) - // { - // if (!PotentiallySelectedTerrain->IsVisible()) - // continue; - - // PotentiallySelectedTerrain->Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); - // PotentiallySelectedTerrain->Shader->UpdateParameterData("baseColor", glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); - // RENDERER.RenderTerrain(PotentiallySelectedTerrain, ENGINE.GetCamera()); - // PotentiallySelectedTerrain->Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); - // PotentiallySelectedTerrain->Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); - // } - //} + TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); + TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); + RENDERER.RenderTerrainComponent(PotentiallySelectedEntity, ENGINE.GetCamera()); + TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); + TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); + } } int LastColorShiftIndex = static_cast(SELECTED.SceneEntitiesUnderMouse.size() - 1); - // FIX ME! - /*auto it = InstancedSubObjectsInfo.begin(); + auto it = InstancedSubObjectsInfo.begin(); while (it != InstancedSubObjectsInfo.end()) { for (size_t j = 0; j < it->second.size(); j++) @@ -387,28 +279,34 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons int g = ((LastColorShiftIndex + 1) >> 8) & 255; int b = ((LastColorShiftIndex + 1) >> 16) & 255; - static FEEntity* DummyEntity = SCENE.AddEntity(it->first->Prefab, "dummyEntity"); - DummyEntity->SetVisibility(true); - DummyEntity->Prefab = it->first->Prefab; - DummyEntity->Transform = FETransformComponent(it->first->GetTransformedInstancedMatrix(it->second[j])); + static FEEntity* DummyEntity = SCENE.AddNewStyleEntity("DummyEntity"); + if (!DummyEntity->HasComponent()) + DummyEntity->AddComponent(); + + FEGameModelComponent& DummyGameModelComponent = DummyEntity->GetComponent(); + FEGameModelComponent& OriginalGameModelComponent = it->first->GetComponent(); + + DummyGameModelComponent.GameModel = OriginalGameModelComponent.GameModel; + DummyGameModelComponent.SetVisibility(true); - for (int k = 0; k < DummyEntity->Prefab->ComponentsCount(); k++) - { - FEMaterial* RegularMaterial = it->first->Prefab->GetComponent(k)->GameModel->Material; - DummyEntity->Prefab->GetComponent(k)->GameModel->Material = PixelAccurateSelectionMaterial; - PixelAccurateSelectionMaterial->SetBaseColor(glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); - PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); - PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - - RENDERER.RenderEntity(DummyEntity, ENGINE.GetCamera(), false, k); + FEInstancedComponent& InstancedComponent = it->first->GetComponent(); + DummyEntity->GetComponent() = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(it->second[j])); + + FEMaterial* RegularMaterial = OriginalGameModelComponent.GameModel->Material; + DummyGameModelComponent.GameModel->Material = PixelAccurateSelectionMaterial; + PixelAccurateSelectionMaterial->SetBaseColor(glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); + PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); + PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + + RENDERER.RenderGameModelComponent(DummyGameModelComponent, DummyEntity->GetComponent(), ENGINE.GetCamera(), false); - it->first->Prefab->GetComponent(k)->GameModel->Material = RegularMaterial; - } - DummyEntity->SetVisibility(false); + OriginalGameModelComponent.GameModel->Material = RegularMaterial; + + DummyGameModelComponent.SetVisibility(false); } it++; - }*/ + } FE_GL_ERROR(glReadPixels(static_cast(MouseX), GLint(ENGINE.GetRenderTargetHeight() - MouseY), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, ColorUnderMouse)); PixelAccurateSelectionFB->UnBind(); @@ -431,7 +329,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons { ColorIndex -= static_cast(SELECTED.SceneEntitiesUnderMouse.size()); - const FEEntityInstanced* SelectedSubObjectInInstance = nullptr; + const FEEntity* SelectedSubObjectInInstance = nullptr; auto it = InstancedSubObjectsInfo.begin(); while (it != InstancedSubObjectsInfo.end()) { @@ -491,7 +389,7 @@ void FEEditorSelectedObject::OnCameraUpdate() const //FE_GL_ERROR(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT)); - if (Container == nullptr || !Container->HasComponent()) + if (Container == nullptr /*|| !Container->HasComponent()*/) { HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); ENGINE.SetClearColor(OriginalClearColor); @@ -500,127 +398,83 @@ void FEEditorSelectedObject::OnCameraUpdate() const return; } - FEGameModelComponent& GameModelComponent = Container->GetComponent(); - FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; - - GameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - - if (!Container->HasComponent()) + if (Container->HasComponent()) { - RENDERER.RenderGameModelComponent(GameModelComponent, Container->GetComponent(), ENGINE.GetCamera(), false); - } - else if (Container->HasComponent()) - { - //FEEntityInstanced* SelectedInstancedEntity = reinterpret_cast(SelectedEntity); - if (InstancedSubObjectIndexSelected != -1) - { - // FIX ME! - /*static FEEntity* DummyEntity = SCENE.AddEntity(SelectedInstancedEntity->Prefab, "dummyEntity"); - DummyEntity->SetVisibility(true); - DummyEntity->Prefab = SelectedInstancedEntity->Prefab; - DummyEntity->Transform = FETransformComponent(SelectedInstancedEntity->GetTransformedInstancedMatrix(InstancedSubObjectIndexSelected)); - for (int i = 0; i < DummyEntity->Prefab->ComponentsCount(); i++) - { - FEMaterial* RegularMaterial = DummyEntity->Prefab->GetComponent(i)->GameModel->Material; + FEGameModelComponent& GameModelComponent = Container->GetComponent(); + FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; - DummyEntity->Prefab->GetComponent(i)->GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; + GameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - HALO_SELECTION_EFFECT.HaloMaterial->SetBaseColor(glm::vec3(0.61f, 0.86f, 1.0f)); - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - - RENDERER.RenderEntity(DummyEntity, ENGINE.GetCamera(), false, i); - - SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; - } - - DummyEntity->SetVisibility(false);*/ - } - else + if (!Container->HasComponent()) { - HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawInstancedObjectShader; - FEMaterial* RegularBillboardMaterial = GameModelComponent.GameModel->GetBillboardMaterial(); - GameModelComponent.GameModel->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); - - RENDERER.RenderGameModelComponentWithInstanced(Container->GetComponent(), GameModelComponent, Container->GetComponent(), ENGINE.GetCamera(), nullptr, false, false); - - HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; - GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterial); + RENDERER.RenderGameModelComponent(GameModelComponent, Container->GetComponent(), ENGINE.GetCamera(), false); } - } - - GameModelComponent.GameModel->Material = RegularMaterial; - - - // FIX ME! - //FEEntity* SelectedEntity = GameModelComponent.OldStyleEntity; - /*if (SelectedEntity->GetType() == FE_ENTITY) - { - for (int i = 0; i < SelectedEntity->Prefab->ComponentsCount(); i++) + else if (Container->HasComponent()) { - FEMaterial* RegularMaterial = SelectedEntity->Prefab->GetComponent(i)->GameModel->Material; - - SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - - RENDERER.RenderEntity(SelectedEntity, ENGINE.GetCamera(), false, i); - - SelectedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; - } - } - else if (SelectedEntity->GetType() == FE_ENTITY_INSTANCED) - { - FEEntityInstanced* SelectedInstancedEntity = reinterpret_cast(SelectedEntity); + //FEEntityInstanced* SelectedInstancedEntity = reinterpret_cast(SelectedEntity); + if (InstancedSubObjectIndexSelected != -1) + { + // FIX ME! + //static FEEntity* DummyEntity = SCENE.AddEntity(SelectedInstancedEntity->Prefab, "dummyEntity"); + if (!DummyEntity->HasComponent()) + DummyEntity->AddComponent(); + FEGameModelComponent& DummyGameModelComponent = DummyEntity->GetComponent(); + DummyGameModelComponent.GameModel = GameModelComponent.GameModel; + DummyGameModelComponent.SetVisibility(true); - if (InstancedSubObjectIndexSelected != -1) - { - static FEEntity* DummyEntity = SCENE.AddEntity(SelectedInstancedEntity->Prefab, "dummyEntity"); - DummyEntity->SetVisibility(true); - DummyEntity->Prefab = SelectedInstancedEntity->Prefab; - DummyEntity->Transform = FETransformComponent(SelectedInstancedEntity->GetTransformedInstancedMatrix(InstancedSubObjectIndexSelected)); + //DummyEntity->Prefab = SelectedInstancedEntity->Prefab; + FEInstancedComponent& InstancedComponent = Container->GetComponent(); + DummyEntity->GetComponent() = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(InstancedSubObjectIndexSelected)); + //FETransformComponent(SelectedInstancedEntity->GetTransformedInstancedMatrix(InstancedSubObjectIndexSelected)); - for (int i = 0; i < DummyEntity->Prefab->ComponentsCount(); i++) - { - FEMaterial* RegularMaterial = DummyEntity->Prefab->GetComponent(i)->GameModel->Material; + FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; - DummyEntity->Prefab->GetComponent(i)->GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; + DummyGameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; HALO_SELECTION_EFFECT.HaloMaterial->SetBaseColor(glm::vec3(0.61f, 0.86f, 1.0f)); HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - RENDERER.RenderEntity(DummyEntity, ENGINE.GetCamera(), false, i); + //RENDERER.RenderEntity(DummyEntity, ENGINE.GetCamera(), false, i); + RENDERER.RenderGameModelComponent(DummyGameModelComponent, DummyEntity->GetComponent(), ENGINE.GetCamera(), false); - SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; - } + //SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; + GameModelComponent.GameModel->Material = RegularMaterial; - DummyEntity->SetVisibility(false); - } - else - { - for (int i = 0; i < SelectedInstancedEntity->Prefab->ComponentsCount(); i++) + DummyGameModelComponent.SetVisibility(false); + } + else { - FEMaterial* RegularMaterial = SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->Material; - SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawInstancedObjectShader; - FEMaterial* RegularBillboardMaterial = SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->GetBillboardMaterial(); - SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); + FEMaterial* RegularBillboardMaterial = GameModelComponent.GameModel->GetBillboardMaterial(); + GameModelComponent.GameModel->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); - RENDERER.RenderEntityInstanced(SelectedInstancedEntity, ENGINE.GetCamera(), nullptr, false, false, i); + RENDERER.RenderGameModelComponentWithInstanced(Container->GetComponent(), GameModelComponent, Container->GetComponent(), ENGINE.GetCamera(), nullptr, false, false); HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; - SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->SetBillboardMaterial(RegularBillboardMaterial); - SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; + GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterial); } } - }*/ + + GameModelComponent.GameModel->Material = RegularMaterial; + } + else if (Container->HasComponent()) + { + FETerrainComponent& TerrainComponent = Container->GetComponent(); + TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); + TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f, 0.25f, 0.0f)); + const float RegularLODLevel = TerrainComponent.GetLODLevel(); + TerrainComponent.SetLODLevel(0.0f); + + RENDERER.RenderTerrainComponent(Container, ENGINE.GetCamera()); + + TerrainComponent.SetLODLevel(RegularLODLevel); + TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); + TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); + } HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); ENGINE.SetClearColor(OriginalClearColor); @@ -639,7 +493,7 @@ void FEEditorSelectedObject::SetSelectedByIndex(const size_t Index) if (Container != nullptr) { - if (Container->HasComponent()) + if (Container->HasComponent()) { if (SceneEntitiesUnderMouse[Index]->GetObjectID() != Container->GetObjectID()) { @@ -654,27 +508,6 @@ void FEEditorSelectedObject::SetSelectedByIndex(const size_t Index) OnUpdateFunc(); } -FEEntity* FEEditorSelectedObject::GetEntity() const -{ - if (Container == nullptr) - return nullptr; - - // Temporary solution, becuase of the lack of proper ECS system - if (Container->GetType() == FE_ENTITY) - { - FEEntity* SelectedEntity = reinterpret_cast(Container); - if (SelectedEntity->Prefab == nullptr) - return SelectedEntity; - } - - if (Container->GetType() == FE_ENTITY || Container->GetType() == FE_ENTITY_INSTANCED) - { - return SCENE.GetEntity(Container->GetObjectID()); - } - - return nullptr; -} - FELight* FEEditorSelectedObject::GetLight() const { if (Container == nullptr) @@ -685,18 +518,5 @@ FELight* FEEditorSelectedObject::GetLight() const return SCENE.GetLight(Container->GetObjectID()); } - return nullptr; -} - -FETerrain* FEEditorSelectedObject::GetTerrain() const -{ - if (Container == nullptr) - return nullptr; - - if (Container->GetType() == FE_TERRAIN) - { - return SCENE.GetTerrain(Container->GetObjectID()); - } - return nullptr; } \ No newline at end of file diff --git a/FEEditorSelectedObject.h b/FEEditorSelectedObject.h index b1b6c4d..bd385f4 100644 --- a/FEEditorSelectedObject.h +++ b/FEEditorSelectedObject.h @@ -18,21 +18,18 @@ class FEEditorSelectedObject void ReInitializeResources(); void SetOnUpdateFunc(void(*Func)()); - FENewEntity* GetSelected() const; - - FEEntity* GetEntity() const; - FETerrain* GetTerrain() const; + FEEntity* GetSelected() const; FELight* GetLight() const; bool GetDirtyFlag() const; void SetDirtyFlag(bool NewValue); - void SetSelected(FENewEntity* SelectedObject); + void SetSelected(FEEntity* SelectedObject); void Clear(); glm::dvec3 MouseRay(double MouseX, double MouseY) const; void DetermineEntityUnderMouse(double MouseX, double MouseY); - std::vector SceneEntitiesUnderMouse; + std::vector SceneEntitiesUnderMouse; bool CheckForSelectionisNeeded = false; int GetIndexOfObjectUnderMouse(double MouseX, double MouseY); @@ -40,15 +37,16 @@ class FEEditorSelectedObject void OnCameraUpdate() const; int DebugGetLastColorIndex() const; - std::unordered_map> InstancedSubObjectsInfo; + std::unordered_map> InstancedSubObjectsInfo; int InstancedSubObjectIndexSelected = -1; void SetSelectedByIndex(size_t Index); FEShader* FEPixelAccurateInstancedSelection = nullptr; FEShader* FEPixelAccurateSelection = nullptr; private: - FENewEntity* Container = nullptr; - + FEEntity* Container = nullptr; + FEEntity* DummyEntity = nullptr; + bool bDirtyFlag = false; void(*OnUpdateFunc)() = nullptr; diff --git a/FEProject.cpp b/FEProject.cpp index 6ce1a43..da33abc 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -579,138 +579,142 @@ void FEProject::SaveScene(bool bFullSave) Root["prefabs"] = PrefabData; // Saving Entities. - std::vector EntityList = SCENE.GetEntityList(); - Json::Value EntityData; - for (size_t i = 0; i < EntityList.size(); i++) - { - FEEntity* Entity = SCENE.GetEntity(EntityList[i]); - if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(Entity)) - continue; - - // Temporary solution, becuase of the lack of proper ECS system - bool bOmit = false; - for (size_t j = 0; j < ListOfOmitedObjects.size(); j++) - { - if (Entity->GetName().find(ListOfOmitedObjects[j]) != std::string::npos) - { - bOmit = true; - break; - } - } - if (bOmit) - continue; - - EntityData[Entity->GetObjectID()]["ID"] = Entity->GetObjectID(); - EntityData[Entity->GetObjectID()]["type"] = FEObjectTypeToString(Entity->GetType()); - EntityData[Entity->GetObjectID()]["name"] = Entity->GetName(); - EntityData[Entity->GetObjectID()]["visible"] = Entity->IsVisible(); - // Temporary solution, becuase of the lack of proper ECS system - if (Entity->Prefab != nullptr) - { - EntityData[Entity->GetObjectID()]["prefab"] = Entity->Prefab->GetObjectID(); - } - else - { - EntityData[Entity->GetObjectID()]["prefab"] = "none"; - } - WriteTransformToJson(EntityData[Entity->GetObjectID()]["transformation"], &Entity->Transform); - - if (Entity->GetType() == FE_ENTITY_INSTANCED) - { - FEEntityInstanced* InstancedEntity = reinterpret_cast(Entity); - EntityData[Entity->GetObjectID()]["modificationsToSpawn"] = InstancedEntity->GetSpawnModificationCount() == 0 ? false : true; - if (InstancedEntity->GetSpawnModificationCount()) - { - std::ofstream InfoFile; - Json::Value EntityFileRoot; - InfoFile.open(ProjectFolder + Entity->GetObjectID() + ".txt"); - - Json::Value ModificationsData; - auto ModificationList = InstancedEntity->GetSpawnModifications(); - for (int j = 0; j < ModificationList.size(); j++) - { - ModificationsData[j]["type"] = static_cast(ModificationList[j].Type); - ModificationsData[j]["index"] = ModificationList[j].Index; - if (ModificationList[j].Type != FE_CHANGE_DELETED) - { - for (int k = 0; k < 4; k++) - { - for (int p = 0; p < 4; p++) - { - ModificationsData[j]["modification"][k][p] = ModificationList[j].Modification[k][p]; - } - } - } - } - EntityFileRoot["modifications"] = ModificationsData; - - InfoFile << EntityFileRoot; - InfoFile.close(); - } + //std::vector EntityList = SCENE.GetEntityList(); + //Json::Value EntityData; + //for (size_t i = 0; i < EntityList.size(); i++) + //{ + // FEEntity* Entity = SCENE.GetEntity(EntityList[i]); + // if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(Entity)) + // continue; - EntityData[Entity->GetObjectID()]["spawnInfo"]["seed"] = InstancedEntity->SpawnInfo.Seed; - EntityData[Entity->GetObjectID()]["spawnInfo"]["objectCount"] = InstancedEntity->SpawnInfo.ObjectCount; - EntityData[Entity->GetObjectID()]["spawnInfo"]["radius"] = InstancedEntity->SpawnInfo.Radius; - EntityData[Entity->GetObjectID()]["spawnInfo"]["minScale"] = InstancedEntity->SpawnInfo.GetMinScale(); - EntityData[Entity->GetObjectID()]["spawnInfo"]["maxScale"] = InstancedEntity->SpawnInfo.GetMaxScale(); - EntityData[Entity->GetObjectID()]["spawnInfo"]["rotationDeviation.x"] = InstancedEntity->SpawnInfo.RotationDeviation.x; - EntityData[Entity->GetObjectID()]["spawnInfo"]["rotationDeviation.y"] = InstancedEntity->SpawnInfo.RotationDeviation.y; - EntityData[Entity->GetObjectID()]["spawnInfo"]["rotationDeviation.z"] = InstancedEntity->SpawnInfo.RotationDeviation.z; - if (InstancedEntity->GetSnappedToTerrain() == nullptr) - { - EntityData[Entity->GetObjectID()]["snappedToTerrain"] = "none"; - } - else - { - EntityData[Entity->GetObjectID()]["snappedToTerrain"] = InstancedEntity->GetSnappedToTerrain()->GetObjectID(); - EntityData[Entity->GetObjectID()]["terrainLayer"] = InstancedEntity->GetTerrainLayer(); - EntityData[Entity->GetObjectID()]["minimalLayerIntensity"] = InstancedEntity->GetMinimalLayerIntensity(); - } - } + // // Temporary solution, becuase of the lack of proper ECS system + // bool bOmit = false; + // for (size_t j = 0; j < ListOfOmitedObjects.size(); j++) + // { + // if (Entity->GetName().find(ListOfOmitedObjects[j]) != std::string::npos) + // { + // bOmit = true; + // break; + // } + // } + // if (bOmit) + // continue; - Entity->SetDirtyFlag(false); - } - Root["entities"] = EntityData; + // EntityData[Entity->GetObjectID()]["ID"] = Entity->GetObjectID(); + // EntityData[Entity->GetObjectID()]["type"] = FEObjectTypeToString(Entity->GetType()); + // EntityData[Entity->GetObjectID()]["name"] = Entity->GetName(); + // EntityData[Entity->GetObjectID()]["visible"] = Entity->IsVisible(); + // // Temporary solution, because of the lack of proper ECS system + // if (Entity->Prefab != nullptr) + // { + // EntityData[Entity->GetObjectID()]["prefab"] = Entity->Prefab->GetObjectID(); + // } + // else + // { + // EntityData[Entity->GetObjectID()]["prefab"] = "none"; + // } + // //WriteTransformToJson(EntityData[Entity->GetObjectID()]["transformation"], &Entity->Transform); + + // //if (Entity->GetType() == FE_ENTITY_INSTANCED) + // //{ + // // FEEntityInstanced* InstancedEntity = reinterpret_cast(Entity); + // // EntityData[Entity->GetObjectID()]["modificationsToSpawn"] = InstancedEntity->GetSpawnModificationCount() == 0 ? false : true; + // // if (InstancedEntity->GetSpawnModificationCount()) + // // { + // // std::ofstream InfoFile; + // // Json::Value EntityFileRoot; + // // InfoFile.open(ProjectFolder + Entity->GetObjectID() + ".txt"); + + // // Json::Value ModificationsData; + // // auto ModificationList = InstancedEntity->GetSpawnModifications(); + // // for (int j = 0; j < ModificationList.size(); j++) + // // { + // // ModificationsData[j]["type"] = static_cast(ModificationList[j].Type); + // // ModificationsData[j]["index"] = ModificationList[j].Index; + // // if (ModificationList[j].Type != FE_CHANGE_DELETED) + // // { + // // for (int k = 0; k < 4; k++) + // // { + // // for (int p = 0; p < 4; p++) + // // { + // // ModificationsData[j]["modification"][k][p] = ModificationList[j].Modification[k][p]; + // // } + // // } + // // } + // // } + // // EntityFileRoot["modifications"] = ModificationsData; + + // // InfoFile << EntityFileRoot; + // // InfoFile.close(); + // // } + + // // EntityData[Entity->GetObjectID()]["spawnInfo"]["seed"] = InstancedEntity->SpawnInfo.Seed; + // // EntityData[Entity->GetObjectID()]["spawnInfo"]["objectCount"] = InstancedEntity->SpawnInfo.ObjectCount; + // // EntityData[Entity->GetObjectID()]["spawnInfo"]["radius"] = InstancedEntity->SpawnInfo.Radius; + // // EntityData[Entity->GetObjectID()]["spawnInfo"]["minScale"] = InstancedEntity->SpawnInfo.GetMinScale(); + // // EntityData[Entity->GetObjectID()]["spawnInfo"]["maxScale"] = InstancedEntity->SpawnInfo.GetMaxScale(); + // // EntityData[Entity->GetObjectID()]["spawnInfo"]["rotationDeviation.x"] = InstancedEntity->SpawnInfo.RotationDeviation.x; + // // EntityData[Entity->GetObjectID()]["spawnInfo"]["rotationDeviation.y"] = InstancedEntity->SpawnInfo.RotationDeviation.y; + // // EntityData[Entity->GetObjectID()]["spawnInfo"]["rotationDeviation.z"] = InstancedEntity->SpawnInfo.RotationDeviation.z; + // // if (InstancedEntity->GetSnappedToTerrain() == nullptr) + // // { + // // EntityData[Entity->GetObjectID()]["snappedToTerrain"] = "none"; + // // } + // // else + // // { + // // // FIX ME! + // // //EntityData[Entity->GetObjectID()]["snappedToTerrain"] = InstancedEntity->GetSnappedToTerrain()->GetObjectID(); + // // EntityData[Entity->GetObjectID()]["terrainLayer"] = InstancedEntity->GetTerrainLayer(); + // // EntityData[Entity->GetObjectID()]["minimalLayerIntensity"] = InstancedEntity->GetMinimalLayerIntensity(); + // // } + // //} + + // Entity->SetDirtyFlag(false); + //} + //Root["entities"] = EntityData; // Saving Terrains. std::vector TerrainList = SCENE.GetTerrainList(); Json::Value TerrainData; for (size_t i = 0; i < TerrainList.size(); i++) { - FETerrain* Terrain = SCENE.GetTerrain(TerrainList[i]); + FEEntity* Terrain = SCENE.GetNewStyleEntity(TerrainList[i]); + FETerrainComponent& TerrainComponent = Terrain->GetComponent(); TerrainData[Terrain->GetObjectID()]["ID"] = Terrain->GetObjectID(); TerrainData[Terrain->GetObjectID()]["name"] = Terrain->GetName(); - TerrainData[Terrain->GetObjectID()]["heightMap"]["ID"] = Terrain->HeightMap->GetObjectID(); - TerrainData[Terrain->GetObjectID()]["heightMap"]["name"] = Terrain->HeightMap->GetName(); - TerrainData[Terrain->GetObjectID()]["heightMap"]["fileName"] = Terrain->HeightMap->GetObjectID() + ".texture"; - RESOURCE_MANAGER.SaveFETexture(Terrain->HeightMap, (GetProjectFolder() + Terrain->HeightMap->GetObjectID() + std::string(".texture")).c_str()); + TerrainData[Terrain->GetObjectID()]["heightMap"]["ID"] = TerrainComponent.HeightMap->GetObjectID(); + TerrainData[Terrain->GetObjectID()]["heightMap"]["name"] = TerrainComponent.HeightMap->GetName(); + TerrainData[Terrain->GetObjectID()]["heightMap"]["fileName"] = TerrainComponent.HeightMap->GetObjectID() + ".texture"; + RESOURCE_MANAGER.SaveFETexture(TerrainComponent.HeightMap, (GetProjectFolder() + TerrainComponent.HeightMap->GetObjectID() + std::string(".texture")).c_str()); - TerrainData[Terrain->GetObjectID()]["hightScale"] = Terrain->GetHightScale(); - TerrainData[Terrain->GetObjectID()]["displacementScale"] = Terrain->GetDisplacementScale(); - TerrainData[Terrain->GetObjectID()]["tileMult"]["X"] = Terrain->GetTileMult().x; - TerrainData[Terrain->GetObjectID()]["tileMult"]["Y"] = Terrain->GetTileMult().y; - TerrainData[Terrain->GetObjectID()]["LODlevel"] = Terrain->GetLODLevel(); - TerrainData[Terrain->GetObjectID()]["chunkPerSide"] = Terrain->GetChunkPerSide(); + TerrainData[Terrain->GetObjectID()]["hightScale"] = TerrainComponent.GetHightScale(); + TerrainData[Terrain->GetObjectID()]["displacementScale"] = TerrainComponent.GetDisplacementScale(); + TerrainData[Terrain->GetObjectID()]["tileMult"]["X"] = TerrainComponent.GetTileMult().x; + TerrainData[Terrain->GetObjectID()]["tileMult"]["Y"] = TerrainComponent.GetTileMult().y; + TerrainData[Terrain->GetObjectID()]["LODlevel"] = TerrainComponent.GetLODLevel(); + TerrainData[Terrain->GetObjectID()]["chunkPerSide"] = TerrainComponent.GetChunkPerSide(); - WriteTransformToJson(TerrainData[Terrain->GetObjectID()]["transformation"], &Terrain->Transform); + // FIX ME! + WriteTransformToJson(TerrainData[Terrain->GetObjectID()]["transformation"], &Terrain->GetComponent()); + //WriteTransformToJson(TerrainData[Terrain->GetObjectID()]["transformation"], &Terrain->Transform); // Saving terrains Layers. - for (int j = 0; j < Terrain->LayerMaps.size(); j++) + for (int j = 0; j < TerrainComponent.LayerMaps.size(); j++) { - if (Terrain->LayerMaps[j] != nullptr) + if (TerrainComponent.LayerMaps[j] != nullptr) { - TerrainData[Terrain->GetObjectID()]["layerMaps"][j]["ID"] = Terrain->LayerMaps[j]->GetObjectID(); - TerrainData[Terrain->GetObjectID()]["layerMaps"][j]["name"] = Terrain->LayerMaps[j]->GetName(); - TerrainData[Terrain->GetObjectID()]["layerMaps"][j]["fileName"] = Terrain->LayerMaps[j]->GetObjectID() + ".texture"; - RESOURCE_MANAGER.SaveFETexture(Terrain->LayerMaps[j], (GetProjectFolder() + Terrain->LayerMaps[j]->GetObjectID() + std::string(".texture")).c_str()); + TerrainData[Terrain->GetObjectID()]["layerMaps"][j]["ID"] = TerrainComponent.LayerMaps[j]->GetObjectID(); + TerrainData[Terrain->GetObjectID()]["layerMaps"][j]["name"] = TerrainComponent.LayerMaps[j]->GetName(); + TerrainData[Terrain->GetObjectID()]["layerMaps"][j]["fileName"] = TerrainComponent.LayerMaps[j]->GetObjectID() + ".texture"; + RESOURCE_MANAGER.SaveFETexture(TerrainComponent.LayerMaps[j], (GetProjectFolder() + TerrainComponent.LayerMaps[j]->GetObjectID() + std::string(".texture")).c_str()); } } for (int j = 0; j < FE_TERRAIN_MAX_LAYERS; j++) { - FETerrainLayer* CurrentLayer = Terrain->GetLayerInSlot(j); + FETerrainLayer* CurrentLayer = TerrainComponent.GetLayerInSlot(j); if (CurrentLayer == nullptr) { TerrainData[Terrain->GetObjectID()]["layers"][j]["acive"] = false; @@ -805,8 +809,8 @@ void FEProject::SaveScene(bool bFullSave) // *********** Chromatic Aberration *********** EffectsData["Chromatic Aberration"]["Shift strength"] = RENDERER.GetChromaticAberrationIntensity(); // *********** Sky *********** - EffectsData["Sky"]["Enabled"] = RENDERER.IsSkyEnabled() ? 1.0f : 0.0f; - EffectsData["Sky"]["Sphere size"] = RENDERER.GetDistanceToSky(); + //EffectsData["Sky"]["Enabled"] = RENDERER.IsSkyEnabled() ? 1.0f : 0.0f; + //EffectsData["Sky"]["Sphere size"] = RENDERER.GetDistanceToSky(); Root["effects"] = EffectsData; @@ -892,8 +896,6 @@ void FEProject::LoadScene() if (ProjectVersion == 0.0f) { LOG.Add("Can't find version in scene file of project from " + ProjectFolder, "FE_LOG_LOADING", FE_LOG_WARNING); - LOG.Add("Trying to load project with old version of loader.", "FE_LOG_LOADING", FE_LOG_WARNING); - LoadSceneVer0(); return; } else if (ProjectVersion == 0.01f) @@ -1040,24 +1042,26 @@ void FEProject::LoadScene() } } - // loading Terrains + // Loading Terrains. std::vector TerrainList = Root["terrains"].getMemberNames(); for (size_t i = 0; i < TerrainList.size(); i++) { - FETerrain* NewTerrain = RESOURCE_MANAGER.CreateTerrain(false, Root["terrains"][TerrainList[i]]["name"].asString(), Root["terrains"][TerrainList[i]]["ID"].asString()); - NewTerrain->HeightMap = RESOURCE_MANAGER.LoadFEHeightmap((ProjectFolder + Root["terrains"][TerrainList[i]]["heightMap"]["fileName"].asCString()).c_str(), NewTerrain, Root["terrains"][TerrainList[i]]["heightMap"]["name"].asCString()); + FEEntity* NewEntity = SCENE.AddNewStyleEntity(Root["terrains"][TerrainList[i]]["name"].asString(), Root["terrains"][TerrainList[i]]["ID"].asString()); + FETransformComponent& TransformComponent = NewEntity->GetComponent(); + FETerrainComponent& TerrainComponent = NewEntity->AddComponent(); + TERRAIN_SYSTEM.LoadHeightMap((ProjectFolder + Root["terrains"][TerrainList[i]]["heightMap"]["fileName"].asCString()).c_str(), NewEntity); - NewTerrain->SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); - NewTerrain->SetDisplacementScale(Root["terrains"][TerrainList[i]]["displacementScale"].asFloat()); + TerrainComponent.SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); + TerrainComponent.SetDisplacementScale(Root["terrains"][TerrainList[i]]["displacementScale"].asFloat()); glm::vec2 TileMult; TileMult.x = Root["terrains"][TerrainList[i]]["tileMult"]["X"].asFloat(); TileMult.y = Root["terrains"][TerrainList[i]]["tileMult"]["Y"].asFloat(); - NewTerrain->SetTileMult(TileMult); - NewTerrain->SetLODLevel(Root["terrains"][TerrainList[i]]["LODlevel"].asFloat()); - NewTerrain->SetChunkPerSide(Root["terrains"][TerrainList[i]]["chunkPerSide"].asFloat()); - NewTerrain->SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); - NewTerrain->SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); - ReadTransformToJson(Root["terrains"][TerrainList[i]]["transformation"], &NewTerrain->Transform); + TerrainComponent.SetTileMult(TileMult); + TerrainComponent.SetLODLevel(Root["terrains"][TerrainList[i]]["LODlevel"].asFloat()); + TerrainComponent.SetChunkPerSide(Root["terrains"][TerrainList[i]]["chunkPerSide"].asFloat()); + TerrainComponent.SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); + TerrainComponent.SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); + ReadTransformToJson(Root["terrains"][TerrainList[i]]["transformation"], &TransformComponent); if (ProjectVersion >= 0.02f) { @@ -1065,10 +1069,8 @@ void FEProject::LoadScene() { if (Root["terrains"][TerrainList[i]].isMember("layerMaps")) { - // Not using LoadFETextureAsync because these textures could be used for instanced entities initialization. - //FETexture* loadedTexture = RESOURCE_MANAGER.LoadFETextureAsync((projectFolder + root["terrains"][terrainList[i]]["layerMaps"][j]["fileName"].asCString()).c_str(), root["terrains"][terrainList[i]]["layerMaps"][j]["name"].asString(), nullptr, root["terrains"][terrainList[i]]["layerMaps"][j]["ID"].asString()); FETexture* LoadedTexture = RESOURCE_MANAGER.LoadFETexture((ProjectFolder + Root["terrains"][TerrainList[i]]["layerMaps"][j]["fileName"].asCString()).c_str(), Root["terrains"][TerrainList[i]]["layerMaps"][j]["name"].asString()); - NewTerrain->LayerMaps[j] = LoadedTexture; + TerrainComponent.LayerMaps[j] = LoadedTexture; } } @@ -1076,20 +1078,18 @@ void FEProject::LoadScene() { if (Root["terrains"][TerrainList[i]]["layers"][j]["acive"].asBool()) { - RESOURCE_MANAGER.ActivateTerrainVacantLayerSlot(NewTerrain, RESOURCE_MANAGER.GetMaterial(Root["terrains"][TerrainList[i]]["layers"][j]["materialID"].asCString())); - NewTerrain->GetLayerInSlot(j)->SetName(Root["terrains"][TerrainList[i]]["layers"][j]["name"].asCString()); + TERRAIN_SYSTEM.ActivateVacantLayerSlot(NewEntity, RESOURCE_MANAGER.GetMaterial(Root["terrains"][TerrainList[i]]["layers"][j]["materialID"].asCString())); + TerrainComponent.GetLayerInSlot(j)->SetName(Root["terrains"][TerrainList[i]]["layers"][j]["name"].asCString()); } } } - - SCENE.AddTerrain(NewTerrain); } // Loading entities. std::vector EntityList = Root["entities"].getMemberNames(); for (size_t i = 0; i < EntityList.size(); i++) { - FENewEntity* NewEntity = SCENE.AddNewStyleEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + FEEntity* NewEntity = SCENE.AddNewStyleEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); if (Root["entities"][EntityList[i]].isMember("type")) { @@ -1097,7 +1097,7 @@ void FEProject::LoadScene() { FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString())->GetComponent(0)->GameModel; FEGameModelComponent& GameModelComponent = NewEntity->AddComponent(GameModel); - FEInstancedRenderingComponent& InstancedComponent = NewEntity->AddComponent(); + FEInstancedComponent& InstancedComponent = NewEntity->AddComponent(); if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) GameModelComponent.SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); @@ -1116,18 +1116,18 @@ void FEProject::LoadScene() if (Root["entities"][EntityList[i]]["snappedToTerrain"].asString() != "none") { - // FIX ME! - FETerrain* Terrain = SCENE.GetTerrain(Root["entities"][EntityList[i]]["snappedToTerrain"].asString()); - Terrain->SnapInstancedEntity(NewEntity); - /*if (Root["entities"][EntityList[i]].isMember("terrainLayer")) + FEEntity* TerrainEntity = SCENE.GetNewStyleEntity(Root["entities"][EntityList[i]]["snappedToTerrain"].asString()); + TERRAIN_SYSTEM.SnapInstancedEntity(TerrainEntity, NewEntity); + + if (Root["entities"][EntityList[i]].isMember("terrainLayer")) { if (Root["entities"][EntityList[i]]["terrainLayer"].asInt() != -1) { - Terrain->ConnectInstancedEntityToLayer(InstancedEntity, Root["entities"][EntityList[i]]["terrainLayer"].asInt()); + TERRAIN_SYSTEM.ConnectInstancedEntityToLayer(TerrainEntity, NewEntity, Root["entities"][EntityList[i]]["terrainLayer"].asInt()); } - InstancedEntity->SetMinimalLayerIntensity(Root["entities"][EntityList[i]]["minimalLayerIntensity"].asFloat()); - }*/ + InstancedComponent.SetMinimalLayerIntensityToSpawn(Root["entities"][EntityList[i]]["minimalLayerIntensity"].asFloat()); + } } INSTANCED_RENDERING_SYSTEM.PopulateInstance(NewEntity, SpawnInfo); @@ -1185,7 +1185,6 @@ void FEProject::LoadScene() } else { - // For compatibility with old projects. if (Root["entities"][EntityList[i]].isMember("gameModel")) { @@ -1213,7 +1212,7 @@ void FEProject::LoadScene() ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &NewEntity->GetComponent()); /*ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(EntityList[i])->Transform); - FENewEntity* NewEntity = SCENE.GetNewStyleEntityByOldStyleID(EntityList[i]); + FEEntity* NewEntity = SCENE.GetNewStyleEntityByOldStyleID(EntityList[i]); if (NewEntity != nullptr) { NewEntity->GetComponent() = SCENE.GetEntity(EntityList[i])->Transform; @@ -1223,7 +1222,7 @@ void FEProject::LoadScene() // For compatibility with old projects. else { - //FENewEntity* NewEntity = SCENE.AddNewStyleEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + //FEEntity* NewEntity = SCENE.AddNewStyleEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString())->GetComponent(0)->GameModel; NewEntity->AddComponent(GameModel); ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &NewEntity->GetComponent()); @@ -1323,8 +1322,12 @@ void FEProject::LoadScene() // *********** Chromatic Aberration *********** RENDERER.SetChromaticAberrationIntensity(Root["effects"]["Chromatic Aberration"]["Shift strength"].asFloat()); // *********** Sky *********** - RENDERER.SetSkyEnabled(Root["effects"]["Sky"]["Enabled"].asFloat() > 0.0f ? true : false); - RENDERER.SetDistanceToSky(Root["effects"]["Sky"]["Sphere size"].asFloat()); + //SKY_DOME_SYSTEM.SetEnabled(Root["effects"]["Sky"]["Enabled"].asFloat() > 0.0f ? true : false); + //SKY_DOME_SYSTEM.SetDistanceToSky(Root["effects"]["Sky"]["Sphere size"].asFloat()); + //Fix Me! + FEEntity* SkyDome = SCENE.AddNewStyleEntity("SkyDome"); + SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); + SKY_DOME_SYSTEM.AddToEntity(SkyDome); // loading Camera settings ENGINE.GetCamera()->SetPosition(glm::vec3(Root["camera"]["position"]["X"].asFloat(), @@ -1467,357 +1470,6 @@ void FEProject::AddFileToDeleteList(const std::string FileName) FilesToDelete.push_back(FileName); } -// FIX ME! Deprecate. -void FEProject::LoadSceneVer0() -{ - //std::ifstream SceneFile; - //SceneFile.open(ProjectFolder + "scene.txt"); - - //std::string FileData((std::istreambuf_iterator(SceneFile)), std::istreambuf_iterator()); - - //Json::Value Root; - //JSONCPP_STRING Err; - //Json::CharReaderBuilder Builder; - - //const std::unique_ptr Reader(Builder.newCharReader()); - //if (!Reader->parse(FileData.c_str(), FileData.c_str() + FileData.size(), &Root, &Err)) - // return; - - //// correction for loading Meshes - //std::unordered_map MeshNameToID; - //MeshNameToID["sphere"] = RESOURCE_MANAGER.GetMesh("7F251E3E0D08013E3579315F")->GetObjectID(); - //MeshNameToID["cube"] = RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R")->GetObjectID(); - //MeshNameToID["plane"] = RESOURCE_MANAGER.GetMesh("1Y251E6E6T78013635793156")->GetObjectID(); - //// loading Meshes - //std::vector MeshList = Root["meshes"].getMemberNames(); - //for (size_t i = 0; i < MeshList.size(); i++) - //{ - // RESOURCE_MANAGER.LoadFEMesh((ProjectFolder + Root["meshes"][MeshList[i]]["fileName"].asCString()).c_str(), Root["meshes"][MeshList[i]]["name"].asCString()); - // MeshNameToID[Root["meshes"][MeshList[i]]["name"].asCString()] = Root["meshes"][MeshList[i]]["ID"].asCString(); - //} - //// correction for loading Textures - //std::unordered_map TextureNameToID; - //// loading Textures - //std::vector TexturesList = Root["textures"].getMemberNames(); - //for (size_t i = 0; i < TexturesList.size(); i++) - //{ - // // read type of texture if it is not standard then skip it. - // if (Root["textures"][TexturesList[i]]["type"] == 33322) - // { - // continue; - // } - - // FETexture* LoadedTexture = RESOURCE_MANAGER.LoadFETextureAsync((ProjectFolder + Root["textures"][TexturesList[i]]["fileName"].asCString()).c_str(), Root["textures"][TexturesList[i]]["name"].asString()); - // TextureNameToID[Root["textures"][TexturesList[i]]["name"].asString()] = LoadedTexture->GetObjectID(); - //} - - //// correction for loading Materials - //std::unordered_map MaterialNameToID; - //// loading Materials - //std::vector MaterialsList = Root["materials"].getMemberNames(); - //for (size_t i = 0; i < MaterialsList.size(); i++) - //{ - // FEMaterial* NewMaterial = RESOURCE_MANAGER.CreateMaterial(MaterialsList[i], Root["materials"][MaterialsList[i]]["ID"].asString()); - // MaterialNameToID[MaterialsList[i]] = NewMaterial->GetObjectID(); - - // //newMat->shader = RESOURCE_MANAGER.getShader("FEPhongShader"); - // //newMat->shader = RESOURCE_MANAGER.getShader("FESolidColorShader"); - // NewMaterial->Shader = RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/); - - // std::vector MembersList = Root["materials"][MaterialsList[i]].getMemberNames(); - // for (size_t j = 0; j < MembersList.size(); j++) - // { - // if (MembersList[j] == "textures") - // { - // for (size_t k = 0; k < FE_MAX_TEXTURES_PER_MATERIAL; k++) - // { - // if (Root["materials"][MaterialsList[i]]["textures"].isMember(std::to_string(k).c_str())) - // { - // std::string TextureID = TextureNameToID[Root["materials"][MaterialsList[i]]["textures"][std::to_string(k).c_str()].asCString()]; - // NewMaterial->Textures[k] = RESOURCE_MANAGER.GetTexture(TextureID); - // } - // } - // } - - // if (MembersList[j] == "textureBindings") - // { - // for (size_t k = 0; k < FE_MAX_TEXTURES_PER_MATERIAL; k++) - // { - // if (Root["materials"][MaterialsList[i]]["textureBindings"].isMember(std::to_string(k).c_str())) - // { - // int Binding = Root["materials"][MaterialsList[i]]["textureBindings"][std::to_string(k).c_str()].asInt(); - // NewMaterial->TextureBindings[k] = Binding; - // } - // } - // } - - // if (MembersList[j] == "textureChannels") - // { - // for (size_t k = 0; k < FE_MAX_TEXTURES_PER_MATERIAL; k++) - // { - // if (Root["materials"][MaterialsList[i]]["textureChannels"].isMember(std::to_string(k).c_str())) - // { - // int Binding = Root["materials"][MaterialsList[i]]["textureChannels"][std::to_string(k).c_str()].asInt(); - // NewMaterial->TextureChannels[k] = Binding; - // } - // } - // } - // } - - // NewMaterial->SetMetalness(Root["materials"][MaterialsList[i]]["metalness"].asFloat()); - // NewMaterial->SetRoughness(Root["materials"][MaterialsList[i]]["roughness"].asFloat()); - // NewMaterial->SetNormalMapIntensity(Root["materials"][MaterialsList[i]]["normalMapIntensity"].asFloat()); - // NewMaterial->SetAmbientOcclusionIntensity(Root["materials"][MaterialsList[i]]["ambientOcclusionIntensity"].asFloat()); - // NewMaterial->SetAmbientOcclusionMapIntensity(Root["materials"][MaterialsList[i]]["ambientOcclusionMapIntensity"].asFloat()); - // NewMaterial->SetRoughnessMapIntensity(Root["materials"][MaterialsList[i]]["roughnessMapIntensity"].asFloat()); - // NewMaterial->SetMetalnessMapIntensity(Root["materials"][MaterialsList[i]]["metalnessMapIntensity"].asFloat()); - //} - - //// correction for loading gameModels - //std::unordered_map GameModelNameToID; - //// loading gameModels - //std::vector GameModelList = Root["gameModels"].getMemberNames(); - //for (size_t i = 0; i < GameModelList.size(); i++) - //{ - // FEGameModel* NewGameModel = RESOURCE_MANAGER.CreateGameModel(RESOURCE_MANAGER.GetMesh(MeshNameToID[Root["gameModels"][GameModelList[i]]["mesh"].asCString()]), - // RESOURCE_MANAGER.GetMaterial(MaterialNameToID[Root["gameModels"][GameModelList[i]]["material"].asCString()]), - // GameModelList[i], Root["gameModels"][GameModelList[i]]["ID"].asString()); - // GameModelNameToID[GameModelList[i]] = Root["gameModels"][GameModelList[i]]["ID"].asString(); - - // NewGameModel->SetScaleFactor(Root["gameModels"][GameModelList[i]]["scaleFactor"].asFloat()); - - // bool bHaveLODLevels = Root["gameModels"][GameModelList[i]]["LODs"]["haveLODlevels"].asBool(); - // NewGameModel->SetUsingLOD(bHaveLODLevels); - // if (bHaveLODLevels) - // { - // NewGameModel->SetCullDistance(Root["gameModels"][GameModelList[i]]["LODs"]["cullDistance"].asFloat()); - // NewGameModel->SetBillboardZeroRotaion(Root["gameModels"][GameModelList[i]]["LODs"]["billboardZeroRotaion"].asFloat()); - - // size_t LODCount = Root["gameModels"][GameModelList[i]]["LODs"]["LODCount"].asInt(); - // for (size_t j = 0; j < LODCount; j++) - // { - // NewGameModel->SetLODMesh(j, RESOURCE_MANAGER.GetMesh(MeshNameToID[Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["mesh"].asString()])); - // NewGameModel->SetLODMaxDrawDistance(j, Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["maxDrawDistance"].asFloat()); - - // bool bLODBillboard = Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["isBillboard"].asBool(); - // NewGameModel->SetIsLODBillboard(j, bLODBillboard); - // if (bLODBillboard) - // NewGameModel->SetBillboardMaterial(RESOURCE_MANAGER.GetMaterial(MaterialNameToID[Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["billboardMaterial"].asString()])); - // } - // } - //} - - //// correction for loading Terrains - //std::unordered_map TerrainNameToID; - //// loading Terrains - //std::vector TerrainList = Root["terrains"].getMemberNames(); - //for (size_t i = 0; i < TerrainList.size(); i++) - //{ - // FETerrain* NewTerrain = RESOURCE_MANAGER.CreateTerrain(false, TerrainList[i], Root["terrains"][TerrainList[i]]["ID"].asString()); - // TerrainNameToID[NewTerrain->GetName()] = NewTerrain->GetObjectID(); - // NewTerrain->HeightMap = RESOURCE_MANAGER.LoadFEHeightmap((ProjectFolder + Root["terrains"][TerrainList[i]]["heightMap"]["fileName"].asCString()).c_str(), NewTerrain, Root["terrains"][TerrainList[i]]["heightMap"]["name"].asCString()); - - // NewTerrain->SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); - // NewTerrain->SetDisplacementScale(Root["terrains"][TerrainList[i]]["displacementScale"].asFloat()); - // glm::vec2 TileMult; - // TileMult.x = Root["terrains"][TerrainList[i]]["tileMult"]["X"].asFloat(); - // TileMult.y = Root["terrains"][TerrainList[i]]["tileMult"]["Y"].asFloat(); - // NewTerrain->SetTileMult(TileMult); - // NewTerrain->SetLODLevel(Root["terrains"][TerrainList[i]]["LODlevel"].asFloat()); - // NewTerrain->SetChunkPerSide(Root["terrains"][TerrainList[i]]["chunkPerSide"].asFloat()); - // NewTerrain->SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); - // NewTerrain->SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); - // ReadTransformToJson(Root["terrains"][TerrainList[i]]["transformation"], &NewTerrain->Transform); - - // SCENE.AddTerrain(NewTerrain); - //} - - //// loading Entities - //std::vector EntityList = Root["entities"].getMemberNames(); - //std::string EntityID; - //for (size_t i = 0; i < EntityList.size(); i++) - //{ - // if (Root["entities"][EntityList[i]].isMember("type")) - // { - // if (Root["entities"][EntityList[i]]["type"] == "FE_ENTITY_INSTANCED") - // { - // EntityID = Root["entities"][EntityList[i]]["ID"].asString(); - // FEEntityInstanced* InstancedEntity = SCENE.AddEntityInstanced(RESOURCE_MANAGER.GetGameModel(GameModelNameToID[Root["entities"][EntityList[i]]["gameModel"].asCString()]), EntityList[i], EntityID); - // ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(EntityID)->Transform); - - // InstancedEntity->SpawnInfo.Seed = Root["entities"][EntityList[i]]["spawnInfo"]["seed"].asInt(); - // InstancedEntity->SpawnInfo.ObjectCount = Root["entities"][EntityList[i]]["spawnInfo"]["objectCount"].asInt(); - // InstancedEntity->SpawnInfo.Radius = Root["entities"][EntityList[i]]["spawnInfo"]["radius"].asFloat(); - // InstancedEntity->SpawnInfo.SetMinScale(Root["entities"][EntityList[i]]["spawnInfo"]["minScale"].asFloat()); - // InstancedEntity->SpawnInfo.SetMaxScale(Root["entities"][EntityList[i]]["spawnInfo"]["maxScale"].asFloat()); - // InstancedEntity->SpawnInfo.RotationDeviation.x = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.x"].asFloat(); - // InstancedEntity->SpawnInfo.RotationDeviation.y = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.y"].asFloat(); - // InstancedEntity->SpawnInfo.RotationDeviation.z = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.z"].asFloat(); - - // if (Root["entities"][EntityList[i]]["snappedToTerrain"].asString() != "none") - // { - // FETerrain* Terrain = SCENE.GetTerrain(TerrainNameToID[Root["entities"][EntityList[i]]["snappedToTerrain"].asString()]); - // Terrain->SnapInstancedEntity(InstancedEntity); - // } - - // InstancedEntity->Populate(InstancedEntity->SpawnInfo); - - // if (Root["entities"][EntityList[i]]["modificationsToSpawn"].asBool()) - // { - // std::ifstream InfoFile; - // InfoFile.open(ProjectFolder + InstancedEntity->GetObjectID() + ".txt"); - - // std::string InfoFileData((std::istreambuf_iterator(InfoFile)), std::istreambuf_iterator()); - - // Json::Value EntityFileRoot; - // JSONCPP_STRING Err; - // Json::CharReaderBuilder Builder; - - // const std::unique_ptr Reader(Builder.newCharReader()); - // if (!Reader->parse(InfoFileData.c_str(), InfoFileData.c_str() + InfoFileData.size(), &EntityFileRoot, &Err)) - // return; - - // size_t Count = EntityFileRoot["modifications"].size(); - // for (int j = 0; j < Count; j++) - // { - // if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_DELETED) - // { - // InstancedEntity->DeleteInstance(EntityFileRoot["modifications"][j]["index"].asInt()); - // } - // else if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_MODIFIED) - // { - // glm::mat4 ModifedMatrix; - // for (int k = 0; k < 4; k++) - // { - // for (int p = 0; p < 4; p++) - // { - // ModifedMatrix[k][p] = EntityFileRoot["modifications"][j]["modification"][k][p].asFloat(); - // } - // } - - // InstancedEntity->ModifyInstance(EntityFileRoot["modifications"][j]["index"].asInt(), ModifedMatrix); - // } - // else if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_ADDED) - // { - // glm::mat4 ModifedMatrix; - // for (int k = 0; k < 4; k++) - // { - // for (int p = 0; p < 4; p++) - // { - // ModifedMatrix[k][p] = EntityFileRoot["modifications"][j]["modification"][k][p].asFloat(); - // } - // } - - // InstancedEntity->AddInstance(ModifedMatrix); - // } - // } - // } - // } - // else - // { - // SCENE.AddEntity(RESOURCE_MANAGER.GetGameModel(GameModelNameToID[Root["entities"][EntityList[i]]["gameModel"].asCString()]), EntityList[i], Root["entities"][EntityList[i]]["ID"].asString()); - // ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(Root["entities"][EntityList[i]]["ID"].asString())->Transform); - // } - // } - // else - // { - // SCENE.AddEntity(RESOURCE_MANAGER.GetGameModel(GameModelNameToID[Root["entities"][EntityList[i]]["gameModel"].asCString()]), EntityList[i], Root["entities"][EntityList[i]]["ID"].asString()); - // ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(Root["entities"][EntityList[i]]["ID"].asString())->Transform); - // } - //} - - //// loading Lights - //std::vector LightList = Root["lights"].getMemberNames(); - //for (size_t i = 0; i < LightList.size(); i++) - //{ - // FELight* LightTest = SCENE.AddLight(static_cast(Root["lights"][LightList[i]]["type"].asInt() + 9), LightList[i]); - // FELight* Light = SCENE.GetLight(LightTest->GetObjectID()); - - // // general light information - // Light->SetIntensity(Root["lights"][LightList[i]]["intensity"].asFloat()); - // ReadTransformToJson(Root["lights"][LightList[i]]["transformation"], &Light->Transform); - // Light->SetCastShadows(Root["lights"][LightList[i]]["castShadows"].asBool()); - // Light->SetLightEnabled(Root["lights"][LightList[i]]["enabled"].asBool()); - // Light->SetColor(glm::vec3(Root["lights"][LightList[i]]["color"]["R"].asFloat(), - // Root["lights"][LightList[i]]["color"]["G"].asFloat(), - // Root["lights"][LightList[i]]["color"]["B"].asFloat())); - // Light->SetIsStaticShadowBias(Root["lights"][LightList[i]]["staticShadowBias"].asBool()); - // Light->SetShadowBias(Root["lights"][LightList[i]]["shadowBias"].asFloat()); - // Light->SetShadowBiasVariableIntensity(Root["lights"][LightList[i]]["shadowBiasVariableIntensity"].asFloat()); - - // if (Light->GetType() == FE_POINT_LIGHT) - // { - // reinterpret_cast(Light)->SetRange(Root["lights"][LightList[i]]["range"].asFloat()); - // } - // else if (Light->GetType() == FE_SPOT_LIGHT) - // { - // reinterpret_cast(Light)->SetSpotAngle(Root["lights"][LightList[i]]["spotAngle"].asFloat()); - // reinterpret_cast(Light)->SetSpotAngleOuter(Root["lights"][LightList[i]]["spotAngleOuter"].asFloat()); - - // reinterpret_cast(Light)->SetDirection(glm::vec3(Root["lights"][LightList[i]]["direction"]["X"].asFloat(), - // Root["lights"][LightList[i]]["direction"]["Y"].asFloat(), - // Root["lights"][LightList[i]]["direction"]["Z"].asFloat())); - // } - // else if (Light->GetType() == FE_DIRECTIONAL_LIGHT) - // { - // FEDirectionalLight* DirectionalLight = reinterpret_cast(Light); - - // DirectionalLight->SetDirection(glm::vec3(Root["lights"][LightList[i]]["direction"]["X"].asFloat(), - // Root["lights"][LightList[i]]["direction"]["Y"].asFloat(), - // Root["lights"][LightList[i]]["direction"]["Z"].asFloat())); - - // DirectionalLight->SetActiveCascades(Root["lights"][LightList[i]]["CSM"]["activeCascades"].asInt()); - // DirectionalLight->SetShadowCoverage(Root["lights"][LightList[i]]["CSM"]["shadowCoverage"].asFloat()); - // DirectionalLight->SetCSMZDepth(Root["lights"][LightList[i]]["CSM"]["CSMZDepth"].asFloat()); - // DirectionalLight->SetCSMXYDepth(Root["lights"][LightList[i]]["CSM"]["CSMXYDepth"].asFloat()); - // } - //} - - //// loading Effects settings - //// *********** Gamma Correction & Exposure *********** - //ENGINE.GetCamera()->SetGamma(Root["effects"]["Gamma Correction & Exposure"]["Gamma"].asFloat()); - //ENGINE.GetCamera()->SetExposure(Root["effects"]["Gamma Correction & Exposure"]["Exposure"].asFloat()); - //// *********** Anti-Aliasing(FXAA) *********** - //RENDERER.SetFXAASpanMax(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAASpanMax"].asFloat()); - //RENDERER.SetFXAAReduceMin(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAAReduceMin"].asFloat()); - //RENDERER.SetFXAAReduceMul(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAAReduceMul"].asFloat()); - //// *********** Bloom *********** - ////PPEffect = RENDERER.getPostProcessEffect("bloom"); - //RENDERER.SetBloomThreshold(Root["effects"]["Bloom"]["thresholdBrightness"].asFloat()); - //RENDERER.SetBloomSize(Root["effects"]["Bloom"]["BloomSize"].asFloat()); - //// *********** Depth of Field *********** - //RENDERER.SetDOFNearDistance(Root["effects"]["Depth of Field"]["Near distance"].asFloat()); - //RENDERER.SetDOFFarDistance(Root["effects"]["Depth of Field"]["Far distance"].asFloat()); - //RENDERER.SetDOFStrength(Root["effects"]["Depth of Field"]["Strength"].asFloat()); - //RENDERER.SetDOFDistanceDependentStrength(Root["effects"]["Depth of Field"]["Distance dependent strength"].asFloat()); - //// *********** Distance fog *********** - //RENDERER.SetDistanceFogEnabled(Root["effects"]["Distance fog"]["Density"].asFloat() > -1.0f ? true : false); - //RENDERER.SetDistanceFogDensity(Root["effects"]["Distance fog"]["Density"].asFloat()); - //RENDERER.SetDistanceFogGradient(Root["effects"]["Distance fog"]["Gradient"].asFloat()); - //// *********** Chromatic Aberration *********** - //RENDERER.SetChromaticAberrationIntensity(Root["effects"]["Chromatic Aberration"]["Shift strength"].asFloat()); - //// *********** Sky *********** - //RENDERER.SetSkyEnabled(Root["effects"]["Sky"]["Enabled"].asFloat() > 0.0f ? true : false); - //RENDERER.SetDistanceToSky(Root["effects"]["Sky"]["Sphere size"].asFloat()); - - //// loading Camera settings - //ENGINE.GetCamera()->SetPosition(glm::vec3(Root["camera"]["position"]["X"].asFloat(), - // Root["camera"]["position"]["Y"].asFloat(), - // Root["camera"]["position"]["Z"].asFloat())); - - //ENGINE.GetCamera()->SetFov(Root["camera"]["fov"].asFloat()); - //ENGINE.GetCamera()->SetNearPlane(Root["camera"]["nearPlane"].asFloat()); - //ENGINE.GetCamera()->SetFarPlane(Root["camera"]["farPlane"].asFloat()); - - //ENGINE.GetCamera()->SetYaw(Root["camera"]["yaw"].asFloat()); - //ENGINE.GetCamera()->SetPitch(Root["camera"]["pitch"].asFloat()); - //ENGINE.GetCamera()->SetRoll(Root["camera"]["roll"].asFloat()); - - //ENGINE.GetCamera()->SetAspectRatio(Root["camera"]["aspectRatio"].asFloat()); - - //SceneFile.close(); -} - bool FEProject::IsModified() { return bModified; @@ -1840,14 +1492,16 @@ bool FEProject::ShouldIncludeInSceneFile(const FETexture* Texture) Json::Value TerrainData; for (size_t i = 0; i < TerrainList.size(); i++) { - const FETerrain* Terrain = SCENE.GetTerrain(TerrainList[i]); - if (Terrain->HeightMap->GetObjectID() == Texture->GetObjectID()) + FEEntity* Terrain = SCENE.GetNewStyleEntity(TerrainList[i]); + FETerrainComponent& TerrainComponent = Terrain->GetComponent(); + + if (TerrainComponent.HeightMap->GetObjectID() == Texture->GetObjectID()) return false; - if (Terrain->LayerMaps[0] != nullptr && Terrain->LayerMaps[0]->GetObjectID() == Texture->GetObjectID()) + if (TerrainComponent.LayerMaps[0] != nullptr && TerrainComponent.LayerMaps[0]->GetObjectID() == Texture->GetObjectID()) return false; - if (Terrain->LayerMaps[1] != nullptr && Terrain->LayerMaps[1]->GetObjectID() == Texture->GetObjectID()) + if (TerrainComponent.LayerMaps[1] != nullptr && TerrainComponent.LayerMaps[1]->GetObjectID() == Texture->GetObjectID()) return false; } diff --git a/FEProject.h b/FEProject.h index 7635bcf..0293a88 100644 --- a/FEProject.h +++ b/FEProject.h @@ -21,7 +21,6 @@ class FEProject void SaveScene(bool bFullSave = false); void SaveSceneTo(std::string NewPath); void LoadScene(); - void LoadSceneVer0(); FETexture* SceneScreenshot; void CreateDummyScreenshot(); diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 8211f05..efc44af 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 8211f05bdc3ee71e26570e16433f299228d2e19b +Subproject commit efc44af57aa8b7be945f4d8246a4dbf523ce79f2 From b37569b8db90be5695b1e14119e62ac53788bd72 Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Wed, 10 Jul 2024 20:20:18 -0400 Subject: [PATCH 17/46] Engine update; Made additional changes due to the engine update; Added conversion from old FEPrefab during scene load; Improved FEEditorInspectorWindow::ShowTransformConfiguration to display world transformations alongside local ones. --- EditorWindows/DeletePopups.cpp | 4 +- EditorWindows/InspectorWindow.cpp | 574 ++++++++++++++------------- EditorWindows/InspectorWindow.h | 3 +- EditorWindows/PrefabEditorWindow.cpp | 129 +++--- EditorWindows/SceneGraphWindow.cpp | 108 ++--- EditorWindows/ShaderEditorWindow.cpp | 4 +- FEEditor.cpp | 38 +- FEEditorGizmoManager.cpp | 131 +++--- FEEditorPreviewManager.cpp | 207 ++++------ FEEditorPreviewManager.h | 10 + FEEditorSelectedObject.cpp | 64 +-- FEEditorSelectedObject.h | 1 - FEProject.cpp | 368 +++++++++-------- SubSystems/FocalEngine | 2 +- 14 files changed, 775 insertions(+), 868 deletions(-) diff --git a/EditorWindows/DeletePopups.cpp b/EditorWindows/DeletePopups.cpp index 6fc7d1f..a36b56a 100644 --- a/EditorWindows/DeletePopups.cpp +++ b/EditorWindows/DeletePopups.cpp @@ -81,10 +81,10 @@ std::vector DeleteTexturePopup::MaterialsThatUsesTexture(const FETe } } - const std::vector TerrainList = SCENE.GetTerrainList(); + const std::vector TerrainList = SCENE.GetEntityIDListWith(); for (size_t i = 0; i < TerrainList.size(); i++) { - /*FEEntity* CurrentTerrain = SCENE.GetNewStyleEntity(TerrainList[i]); + /*FEEntity* CurrentTerrain = SCENE.GetEntity(TerrainList[i]); FETerrainComponent& TerrainComponent = CurrentTerrain->GetComponent(); if (TerrainComponent.HeightMap != nullptr && TerrainComponent.HeightMap->GetObjectID() == Texture->GetObjectID()) { diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index 77dfb71..7356ebc 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -54,125 +54,7 @@ void FEEditorInspectorWindow::Clear() void FEEditorInspectorWindow::ShowTransformConfiguration(FEObject* Object, FETransformComponent* Transform) const { - // ********************* POSITION ********************* - glm::vec3 TemporaryPosition = Transform->GetPosition(); - bool bModified = false; - - ImGui::Text("Position : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##X pos : ") + Object->GetName()).c_str(), &TemporaryPosition[0], 0.1f)) - bModified = true; - ShowToolTip("X position"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##Y pos : ") + Object->GetName()).c_str(), &TemporaryPosition[1], 0.1f)) - bModified = true; - ShowToolTip("Y position"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##Z pos : ") + Object->GetName()).c_str(), &TemporaryPosition[2], 0.1f)) - bModified = true; - ShowToolTip("Z position"); - - if (bModified) - Transform->SetPosition(TemporaryPosition); - - // ********************* ROTATION ********************* - glm::vec3 TemporaryRotation = Transform->GetRotation(); - bModified = false; - - ImGui::Text("Rotation : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##X rot : ") + Object->GetName()).c_str(), &TemporaryRotation[0], 0.1f, -360.0f, 360.0f)) - bModified = true; - ShowToolTip("X rotation"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##Y rot : ") + Object->GetName()).c_str(), &TemporaryRotation[1], 0.1f, -360.0f, 360.0f)) - bModified = true; - ShowToolTip("Y rotation"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##Z rot : ") + Object->GetName()).c_str(), &TemporaryRotation[2], 0.1f, -360.0f, 360.0f)) - bModified = true; - ShowToolTip("Z rotation"); - - if (bModified) - Transform->SetRotation(TemporaryRotation); - - // ********************* SCALE ********************* - bool bUniformScaling = Transform->IsUniformScalingSet(); - bModified = false; - - if (ImGui::Checkbox("Uniform scaling", &bUniformScaling)) - Transform->SetUniformScaling(bUniformScaling); - - glm::vec3 TemporaryScale = Transform->GetScale(); - ImGui::Text("Scale : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##X scale : ") + Object->GetName()).c_str(), &TemporaryScale[0], 0.01f, 0.01f, 1000.0f)) - bModified = true; - ShowToolTip("X scale"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##Y scale : ") + Object->GetName()).c_str(), &TemporaryScale[1], 0.01f, 0.01f, 1000.0f)) - bModified = true; - ShowToolTip("Y scale"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - if (ImGui::DragFloat((std::string("##Z scale : ") + Object->GetName()).c_str(), &TemporaryScale[2], 0.01f, 0.01f, 1000.0f)) - bModified = true; - ShowToolTip("Z scale"); - - if (bModified) - { - glm::vec3 OldScale = Transform->GetScale(); - Transform->ChangeXScaleBy(TemporaryScale[0] - OldScale[0]); - Transform->ChangeYScaleBy(TemporaryScale[1] - OldScale[1]); - Transform->ChangeZScaleBy(TemporaryScale[2] - OldScale[2]); - } - - // ********************* REAL WORLD COMPARISON SCALE ********************* - if (Object->GetType() == FE_ENTITY || Object->GetType() == FE_ENTITY_INSTANCED) - { - FEEntity* Entity = SCENE.GetNewStyleEntity(Object->GetObjectID()); - if (Entity == nullptr) - return; - - if (Entity->HasComponent() == false) - return; - - FEAABB RealAABB = Entity->GetComponent().GameModel->GetMesh()->GetAABB().Transform(Entity->GetComponent().GetTransformMatrix()); - const glm::vec3 Min = RealAABB.GetMin(); - const glm::vec3 Max = RealAABB.GetMax(); - - const float XSize = sqrt((Max.x - Min.x) * (Max.x - Min.x)); - const float YSize = sqrt((Max.y - Min.y) * (Max.y - Min.y)); - const float ZSize = sqrt((Max.z - Min.z) * (Max.z - Min.z)); - - std::string SizeInM = "Approximate object size: "; - SizeInM += std::to_string(std::max(XSize, std::max(YSize, ZSize))); - SizeInM += " m"; - - /*std::string dementionsInM = "Xlength: "; - dementionsInM += std::to_string(xSize); - dementionsInM += " m Ylength: "; - dementionsInM += std::to_string(ySize); - dementionsInM += " m Zlength: "; - dementionsInM += std::to_string(zSize); - dementionsInM += " m";*/ - - ImGui::Text(SizeInM.c_str()); - } + ShowTransformConfiguration(Object->GetName(), Transform); } bool FEEditorInspectorWindow::EntityChangePrefabTargetCallBack(FEObject* Object, void** EntityPointer) @@ -206,185 +88,329 @@ bool FEEditorInspectorWindow::TerrainChangeMaterialTargetCallBack(FEObject* Obje void FEEditorInspectorWindow::ShowTransformConfiguration(const std::string Name, FETransformComponent* Transform) const { + static float EditWidth = 70.0f; + bool bModified = false; // ********************* POSITION ********************* - glm::vec3 position = Transform->GetPosition(); + glm::vec3 Position = Transform->GetPosition(); ImGui::Text("Position : "); ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##X pos : ") + Name).c_str(), &position[0], 0.1f); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##X pos : ") + Name).c_str(), &Position[0], 0.1f)) + bModified = true; + ShowToolTip("X position"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##Y pos : ") + Name).c_str(), &Position[1], 0.1f)) + bModified = true; + ShowToolTip("Y position"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##Z pos : ") + Name).c_str(), &Position[2], 0.1f)) + bModified = true; + ShowToolTip("Z position"); + + if (bModified) + Transform->SetPosition(Position); + + bModified = false; + + // ********************* WORLD POSITION ********************* + glm::vec3 WorldPosition = Transform->GetPosition(false); + ImGui::Text("World Position : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##World X pos : ") + Name).c_str(), &WorldPosition[0], 0.1f)) + bModified = true; ShowToolTip("X position"); ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Y pos : ") + Name).c_str(), &position[1], 0.1f); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##World Y pos : ") + Name).c_str(), &WorldPosition[1], 0.1f)) + bModified = true; ShowToolTip("Y position"); ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Z pos : ") + Name).c_str(), &position[2], 0.1f); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##World Z pos : ") + Name).c_str(), &WorldPosition[2], 0.1f)) + bModified = true; ShowToolTip("Z position"); - Transform->SetPosition(position); + + if (bModified) + Transform->SetPosition(WorldPosition, false); + + bModified = false; // ********************* ROTATION ********************* - glm::vec3 rotation = Transform->GetRotation(); + glm::vec3 Rotation = Transform->GetRotation(); ImGui::Text("Rotation : "); ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##X rot : ") + Name).c_str(), &rotation[0], 0.1f, -360.0f, 360.0f); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##X rot : ") + Name).c_str(), &Rotation[0], 0.1f, -360.0f, 360.0f)) + bModified = true; + ShowToolTip("X rotation"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##Y rot : ") + Name).c_str(), &Rotation[1], 0.1f, -360.0f, 360.0f)) + bModified = true; + ShowToolTip("Y rotation"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##Z rot : ") + Name).c_str(), &Rotation[2], 0.1f, -360.0f, 360.0f)) + bModified = true; + ShowToolTip("Z rotation"); + + if (bModified) + Transform->SetRotation(Rotation); + + bModified = false; + + // ********************* WORLD ROTATION ********************* + glm::vec3 WorldRotation = Transform->GetRotation(false); + ImGui::Text("World Rotation : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##World X rot : ") + Name).c_str(), &WorldRotation[0], 0.1f, -360.0f, 360.0f)) + bModified = true; ShowToolTip("X rotation"); ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Y rot : ") + Name).c_str(), &rotation[1], 0.1f, -360.0f, 360.0f); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##World Y rot : ") + Name).c_str(), &WorldRotation[1], 0.1f, -360.0f, 360.0f)) + bModified = true; ShowToolTip("Y rotation"); ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Z rot : ") + Name).c_str(), &rotation[2], 0.1f, -360.0f, 360.0f); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##World Z rot : ") + Name).c_str(), &WorldRotation[2], 0.1f, -360.0f, 360.0f)) + bModified = true; ShowToolTip("Z rotation"); - Transform->SetRotation(rotation); + + if (bModified) + Transform->SetRotation(WorldRotation, false); + + bModified = false; // ********************* SCALE ********************* bool bUniformScaling = Transform->IsUniformScalingSet(); ImGui::Checkbox("Uniform scaling", &bUniformScaling); Transform->SetUniformScaling(bUniformScaling); - glm::vec3 scale = Transform->GetScale(); + glm::vec3 Scale = Transform->GetScale(); + float ScaleChangeSpeed = Scale.x * 0.01f; ImGui::Text("Scale : "); ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##X scale : ") + Name).c_str(), &scale[0], 0.01f, 0.01f, 1000.0f); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##X scale : ") + Name).c_str(), &Scale[0], ScaleChangeSpeed, 0.001f, 1000.0f)) + { + bModified = true; + if (bUniformScaling) + { + Scale[1] = Scale[0]; + Scale[2] = Scale[0]; + } + } + ShowToolTip("X scale"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##Y scale : ") + Name).c_str(), &Scale[1], ScaleChangeSpeed, 0.001f, 1000.0f)) + { + bModified = true; + if (bUniformScaling) + { + Scale[0] = Scale[1]; + Scale[2] = Scale[1]; + } + } + ShowToolTip("Y scale"); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##Z scale : ") + Name).c_str(), &Scale[2], ScaleChangeSpeed, 0.001f, 1000.0f)) + { + bModified = true; + if (bUniformScaling) + { + Scale[0] = Scale[2]; + Scale[1] = Scale[2]; + } + } + ShowToolTip("Z scale"); + + if (bModified) + Transform->SetScale(Scale); + + bModified = false; + + // ********************* WORLD SCALE ********************* + glm::vec3 WorldScale = Transform->GetScale(false); + ScaleChangeSpeed = WorldScale.x * 0.01f; + ImGui::Text("World Scale : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##World X scale : ") + Name).c_str(), &WorldScale[0], ScaleChangeSpeed, 0.001f, 1000.0f)) + { + bModified = true; + if (bUniformScaling) + { + WorldScale[1] = WorldScale[0]; + WorldScale[2] = WorldScale[0]; + } + } ShowToolTip("X scale"); ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Y scale : ") + Name).c_str(), &scale[1], 0.01f, 0.01f, 1000.0f); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##World Y scale : ") + Name).c_str(), &WorldScale[1], ScaleChangeSpeed, 0.001f, 1000.0f)) + { + bModified = true; + if (bUniformScaling) + { + WorldScale[0] = WorldScale[1]; + WorldScale[2] = WorldScale[1]; + } + } ShowToolTip("Y scale"); ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Z scale : ") + Name).c_str(), &scale[2], 0.01f, 0.01f, 1000.0f); + ImGui::SetNextItemWidth(EditWidth); + if (ImGui::DragFloat((std::string("##World Z scale : ") + Name).c_str(), &WorldScale[2], ScaleChangeSpeed, 0.001f, 1000.0f)) + { + bModified = true; + if (bUniformScaling) + { + WorldScale[0] = WorldScale[2]; + WorldScale[1] = WorldScale[2]; + } + } ShowToolTip("Z scale"); - glm::vec3 OldScale = Transform->GetScale(); - Transform->ChangeXScaleBy(scale[0] - OldScale[0]); - Transform->ChangeYScaleBy(scale[1] - OldScale[1]); - Transform->ChangeZScaleBy(scale[2] - OldScale[2]); + if (bModified) + Transform->SetScale(WorldScale, false); } -void FEEditorInspectorWindow::DisplayLightProperties(FELight* Light) const +void FEEditorInspectorWindow::DisplayLightProperties(FEEntity* LightEntity) const { - ShowTransformConfiguration(Light, &Light->Transform); + FELightComponent& LightComponent = LightEntity->GetComponent(); - if (Light->GetType() == FE_DIRECTIONAL_LIGHT) + if (LightComponent.GetType() == FE_DIRECTIONAL_LIGHT) { - FEDirectionalLight* DirectionalLight = reinterpret_cast(Light); ImGui::Separator(); ImGui::Text("-------------Shadow settings--------------"); ImGui::Text("Cast shadows:"); ImGui::SameLine(); ImGui::SetNextItemWidth(200); - bool bCastShadows = DirectionalLight->IsCastShadows(); + bool bCastShadows = LightComponent.IsCastShadows(); ImGui::Checkbox("##Cast shadows", &bCastShadows); - DirectionalLight->SetCastShadows(bCastShadows); + LightComponent.SetCastShadows(bCastShadows); ShowToolTip("Will this light cast shadows."); - if (!DirectionalLight->IsCastShadows()) + if (!LightComponent.IsCastShadows()) ImGui::BeginDisabled(); ImGui::Text("Number of cascades :"); ImGui::SameLine(); ImGui::SetNextItemWidth(200); - int cascades = DirectionalLight->GetActiveCascades(); - ImGui::SliderInt("##cascades", &cascades, 1, 4); - DirectionalLight->SetActiveCascades(cascades); + int CascadesCount = LightComponent.GetActiveCascades(); + ImGui::SliderInt("##cascades", &CascadesCount, 1, 4); + LightComponent.SetActiveCascades(CascadesCount); ShowToolTip("How much steps of shadow quality will be used."); ImGui::Text("Shadow coverage in M :"); ImGui::SameLine(); ImGui::SetNextItemWidth(200); - float FirstCascadeSize = DirectionalLight->GetShadowCoverage(); + float FirstCascadeSize = LightComponent.GetShadowCoverage(); ImGui::DragFloat("##shadowCoverage", &FirstCascadeSize, 0.1f, 0.1f, 500.0f); - DirectionalLight->SetShadowCoverage(FirstCascadeSize); + LightComponent.SetShadowCoverage(FirstCascadeSize); ShowToolTip("Distance from camera at which shadows would be present."); ImGui::Text("Z depth of shadow map :"); ImGui::SameLine(); ImGui::SetNextItemWidth(200); - float CSMZDepth = DirectionalLight->GetCSMZDepth(); + float CSMZDepth = LightComponent.GetCSMZDepth(); ImGui::DragFloat("##CSMZDepth", &CSMZDepth, 0.01f, 0.1f, 100.0f); - DirectionalLight->SetCSMZDepth(CSMZDepth); + LightComponent.SetCSMZDepth(CSMZDepth); ShowToolTip("If you have problems with shadow disapearing when camera is at close distance to shadow reciver, tweaking this parameter could help. Otherwise this parameter should be as small as possible."); ImGui::Text("XY depth of shadow map :"); ImGui::SameLine(); ImGui::SetNextItemWidth(200); - float CSMXYDepth = DirectionalLight->GetCSMXYDepth(); + float CSMXYDepth = LightComponent.GetCSMXYDepth(); ImGui::DragFloat("##CSMXYDepth", &CSMXYDepth, 0.01f, 0.0f, 100.0f); - DirectionalLight->SetCSMXYDepth(CSMXYDepth); + LightComponent.SetCSMXYDepth(CSMXYDepth); ShowToolTip("If you have problems with shadow on edges of screen, tweaking this parameter could help. Otherwise this parameter should be as small as possible."); ImGui::Text("Shadows blur factor:"); ImGui::SameLine(); ImGui::SetNextItemWidth(200.0f); - float ShadowsBlurFactor = DirectionalLight->GetShadowBlurFactor(); + float ShadowsBlurFactor = LightComponent.GetShadowBlurFactor(); ImGui::DragFloat("##Shadows blur factor", &ShadowsBlurFactor, 0.001f, 0.0f, 10.0f); - DirectionalLight->SetShadowBlurFactor(ShadowsBlurFactor); + LightComponent.SetShadowBlurFactor(ShadowsBlurFactor); - bool bStaticShadowBias = DirectionalLight->IsStaticShadowBias(); + bool bStaticShadowBias = LightComponent.IsStaticShadowBias(); ImGui::Checkbox("Static shadow bias :", &bStaticShadowBias); - DirectionalLight->SetIsStaticShadowBias(bStaticShadowBias); + LightComponent.SetIsStaticShadowBias(bStaticShadowBias); - if (DirectionalLight->IsStaticShadowBias()) + if (LightComponent.IsStaticShadowBias()) { ImGui::Text("Static shadow bias value :"); ImGui::SameLine(); ImGui::SetNextItemWidth(200); - float ShadowBias = DirectionalLight->GetShadowBias(); + float ShadowBias = LightComponent.GetShadowBias(); ImGui::DragFloat("##shadowBias", &ShadowBias, 0.0001f, 0.00001f, 0.1f); - DirectionalLight->SetShadowBias(ShadowBias); + LightComponent.SetShadowBias(ShadowBias); } else { ImGui::Text("Intensity of variable shadow bias :"); ImGui::SameLine(); ImGui::SetNextItemWidth(200); - float ShadowBiasIntensity = DirectionalLight->GetShadowBiasVariableIntensity(); + float ShadowBiasIntensity = LightComponent.GetShadowBiasVariableIntensity(); ImGui::DragFloat("##shadowBiasIntensity", &ShadowBiasIntensity, 0.01f, 0.01f, 10.0f); - DirectionalLight->SetShadowBiasVariableIntensity(ShadowBiasIntensity); + LightComponent.SetShadowBiasVariableIntensity(ShadowBiasIntensity); } - if (!DirectionalLight->IsCastShadows()) + if (!LightComponent.IsCastShadows()) ImGui::EndDisabled(); } - else if (Light->GetType() == FE_POINT_LIGHT) + else if (LightComponent.GetType() == FE_POINT_LIGHT) { + ImGui::Text("Light range :"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + float LightRange = LightComponent.GetRange(); + ImGui::DragFloat("##LightRadius", &LightRange, 0.1f, 0.1f, 100.0f); + LightComponent.SetRange(LightRange); + } - else if (Light->GetType() == FE_SPOT_LIGHT) + else if (LightComponent.GetType() == FE_SPOT_LIGHT) { - FESpotLight* SpotLight = reinterpret_cast(Light); - glm::vec3 direction = SpotLight->GetDirection(); - ImGui::DragFloat("##x", &direction[0], 0.01f, 0.0f, 1.0f); - ImGui::DragFloat("##y", &direction[1], 0.01f, 0.0f, 1.0f); - ImGui::DragFloat("##z", &direction[2], 0.01f, 0.0f, 1.0f); - - float SpotAngle = SpotLight->GetSpotAngle(); - ImGui::SliderFloat((std::string("Inner angle##") + SpotLight->GetName()).c_str(), &SpotAngle, 0.0f, 90.0f); - SpotLight->SetSpotAngle(SpotAngle); - - float SpotAngleOuter = SpotLight->GetSpotAngleOuter(); - ImGui::SliderFloat((std::string("Outer angle ##") + SpotLight->GetName()).c_str(), &SpotAngleOuter, 0.0f, 90.0f); - SpotLight->SetSpotAngleOuter(SpotAngleOuter); + glm::vec3 Direction = LIGHT_SYSTEM.GetDirection(LightEntity); + ImGui::DragFloat("##x", &Direction[0], 0.01f, 0.0f, 1.0f); + ImGui::DragFloat("##y", &Direction[1], 0.01f, 0.0f, 1.0f); + ImGui::DragFloat("##z", &Direction[2], 0.01f, 0.0f, 1.0f); + + float SpotAngle = LightComponent.GetSpotAngle(); + ImGui::SliderFloat((std::string("Inner angle##") + LightEntity->GetName()).c_str(), &SpotAngle, 0.0f, 90.0f); + LightComponent.SetSpotAngle(SpotAngle); + + float SpotAngleOuter = LightComponent.GetSpotAngleOuter(); + ImGui::SliderFloat((std::string("Outer angle ##") + LightEntity->GetName()).c_str(), &SpotAngleOuter, 0.0f, 90.0f); + LightComponent.SetSpotAngleOuter(SpotAngleOuter); } - glm::vec3 color = Light->GetColor(); - ImGui::ColorEdit3((std::string("Color##") + Light->GetName()).c_str(), &color.x); - Light->SetColor(color); + glm::vec3 Color = LightComponent.GetColor(); + ImGui::ColorEdit3((std::string("Color##") + LightEntity->GetName()).c_str(), &Color.x); + LightComponent.SetColor(Color); - float intensity = Light->GetIntensity(); - ImGui::SliderFloat((std::string("Intensity##") + Light->GetName()).c_str(), &intensity, 0.0f, 100.0f); - Light->SetIntensity(intensity); + float Intensity = LightComponent.GetIntensity(); + ImGui::SliderFloat((std::string("Intensity##") + LightEntity->GetName()).c_str(), &Intensity, 0.0f, 100.0f); + LightComponent.SetIntensity(Intensity); } // FIX ME! @@ -403,20 +429,6 @@ void FEEditorInspectorWindow::ChangePrefabOfEntityCallBack(const std::vector LightList = SCENE.GetLightsList(); - - for (size_t i = 0; i < LightList.size(); i++) - { - if (ImGui::TreeNode(LightList[i].c_str())) - { - DisplayLightProperties(SCENE.GetLight(LightList[i])); - ImGui::TreePop(); - } - } -} - void FEEditorInspectorWindow::Render() { if (!bVisible) @@ -434,72 +446,99 @@ void FEEditorInspectorWindow::Render() FEEntity* EntitySelected = SELECTED.GetSelected(); + //auto testlist = GetAllComponentTypeInfos(); + if (EntitySelected->HasComponent()) { - FETagComponent& Tag = EntitySelected->GetComponent(); - char Buffer[256]; - memset(Buffer, 0, 256); - strcpy_s(Buffer, Tag.Tag.c_str()); - if (ImGui::InputText("Tag", Buffer, 256)) + float headerHeight = ImGui::GetFrameHeight(); + float headerWidth = ImGui::GetContentRegionAvail().x; + + float ButtonSize = ImGui::GetFrameHeight() * 0.7f; + float cursorPosX = ImGui::GetCursorPosX(); + ImVec2 PreviosCursorPos = ImGui::GetCursorPos(); + + + ImGui::SetCursorPos(ImVec2(headerWidth - ButtonSize / 8.0f - 4.0f/*- ButtonSize*/, PreviosCursorPos.y + 4.0f/*(headerHeight - ButtonSize) * 0.5f*/)); + if (ImGui::Button("x", ImVec2(ButtonSize, ButtonSize))) { - Tag.Tag = std::string(Buffer); + int y = 0; + y++; + } + + ImGui::SetCursorPos(PreviosCursorPos); + + if (ImGui::CollapsingHeader("Tag", ImGuiTreeNodeFlags_DefaultOpen)) + { + ImGui::Text("Test"); + FETagComponent& Tag = EntitySelected->GetComponent(); + char Buffer[256]; + memset(Buffer, 0, 256); + strcpy_s(Buffer, Tag.Tag.c_str()); + if (ImGui::InputText("##Tag Edit", Buffer, 256)) + { + Tag.Tag = std::string(Buffer); + } } } if (EntitySelected->HasComponent()) { - FETransformComponent& Transform = EntitySelected->GetComponent(); - ShowTransformConfiguration(EntitySelected->GetName(), &Transform); + if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen /*| ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_FramePadding*/)) + { + FETransformComponent& Transform = EntitySelected->GetComponent(); + ShowTransformConfiguration(EntitySelected->GetName(), &Transform); + } } if (EntitySelected->HasComponent()) { - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f)); - - FEGameModelComponent& GameModelComponent = EntitySelected->GetComponent(); - bool bActive = GameModelComponent.IsWireframeMode(); - ImGui::Checkbox("WireframeMode", &bActive); - GameModelComponent.SetWireframeMode(bActive); + if (ImGui::CollapsingHeader("Game Model", ImGuiTreeNodeFlags_DefaultOpen /*| ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_FramePadding*/)) + { + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f)); - ImGui::Text("Game Model : "); - FETexture* PreviewTexture = PREVIEW_MANAGER.GetGameModelPreview(GameModelComponent.GameModel->GetObjectID()); + FEGameModelComponent& GameModelComponent = EntitySelected->GetComponent(); + bool bActive = GameModelComponent.IsWireframeMode(); + ImGui::Checkbox("WireframeMode", &bActive); + GameModelComponent.SetWireframeMode(bActive); - if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - { - //EntityToModify = EntitySelected; - //SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); - } - //EntityChangePrefabTarget->StickToItem(); + ImGui::Text("Game Model : "); + FETexture* PreviewTexture = PREVIEW_MANAGER.GetGameModelPreview(GameModelComponent.GameModel->GetObjectID()); - bool bOpenContextMenu = false; - if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) - bOpenContextMenu = true; + if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + { + //EntityToModify = EntitySelected; + //SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); + } + //EntityChangePrefabTarget->StickToItem(); - if (bOpenContextMenu) - ImGui::OpenPopup("##Inspector_context_menu"); + bool bOpenContextMenu = false; + if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) + bOpenContextMenu = true; - CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = false; - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); - if (ImGui::BeginPopup("##Inspector_context_menu")) - { - CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = true; + if (bOpenContextMenu) + ImGui::OpenPopup("##Inspector_context_menu"); - if (ImGui::MenuItem("Show in folder")) + CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = false; + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); + if (ImGui::BeginPopup("##Inspector_context_menu")) { - CONTENT_BROWSER_WINDOW.OpenItemParentFolder(GameModelComponent.GameModel); - } + CONTENT_BROWSER_WINDOW.bShouldOpenContextMenu = true; - ImGui::EndPopup(); - } - ImGui::PopStyleVar(); + if (ImGui::MenuItem("Show in folder")) + { + CONTENT_BROWSER_WINDOW.OpenItemParentFolder(GameModelComponent.GameModel); + } - ImGui::Separator(); + ImGui::EndPopup(); + } + ImGui::PopStyleVar(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + } } if (EntitySelected->HasComponent()) @@ -517,8 +556,8 @@ void FEEditorInspectorWindow::Render() FETransformComponent TempTransform = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(SELECTED.InstancedSubObjectIndexSelected)); ShowTransformConfiguration("selected instance", &TempTransform); - INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(EntitySelected, SELECTED.InstancedSubObjectIndexSelected, TempTransform.GetTransformMatrix()); - //InstancedEntity->ModifyInstance(SELECTED.InstancedSubObjectIndexSelected, TempTransform.GetTransformMatrix()); + INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(EntitySelected, SELECTED.InstancedSubObjectIndexSelected, TempTransform.GetWorldMatrix()); + //InstancedEntity->ModifyInstance(SELECTED.InstancedSubObjectIndexSelected, TempTransform.GetWorldMatrix()); ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); @@ -540,7 +579,7 @@ void FEEditorInspectorWindow::Render() ImGui::Text("Snapped to: "); ImGui::SameLine(); - const std::vector TerrainList = SCENE.GetTerrainList(); + const std::vector TerrainList = SCENE.GetEntityIDListWith(); static std::string CurrentTerrain = "none"; if (InstancedComponent.GetSnappedToTerrain() == nullptr) @@ -570,9 +609,9 @@ void FEEditorInspectorWindow::Render() for (size_t i = 0; i < TerrainList.size(); i++) { const bool bIsSelected = (CurrentTerrain == TerrainList[i]); - if (ImGui::Selectable(SCENE.GetNewStyleEntity(TerrainList[i])->GetName().c_str(), bIsSelected)) + if (ImGui::Selectable(SCENE.GetEntity(TerrainList[i])->GetName().c_str(), bIsSelected)) { - TERRAIN_SYSTEM.SnapInstancedEntity(SCENE.GetNewStyleEntity(TerrainList[i]), EntitySelected); + TERRAIN_SYSTEM.SnapInstancedEntity(SCENE.GetEntity(TerrainList[i]), EntitySelected); } if (bIsSelected) @@ -795,11 +834,12 @@ void FEEditorInspectorWindow::Render() } } + if (EntitySelected->HasComponent()) + { + DisplayLightProperties(SELECTED.GetSelected()); + } + - //else if (SELECTED.GetLight() != nullptr) - //{ - // DisplayLightProperties(SELECTED.GetLight()); - //} //else if (SELECTED.GetSelected()->GetType() == FE_CAMERA) //{ // FEBasicCamera* Camera = ENGINE.GetCamera(); @@ -811,38 +851,38 @@ void FEEditorInspectorWindow::Render() // ImGui::SameLine(); // ImGui::SetNextItemWidth(90); // ImGui::DragFloat("##X pos", &CameraPosition[0], 0.1f); - // ShowToolTip("X position"); + // ShowToolTip("X Position"); // ImGui::SameLine(); // ImGui::SetNextItemWidth(90); // ImGui::DragFloat("##Y pos", &CameraPosition[1], 0.1f); - // ShowToolTip("Y position"); + // ShowToolTip("Y Position"); // ImGui::SameLine(); // ImGui::SetNextItemWidth(90); // ImGui::DragFloat("##Z pos", &CameraPosition[2], 0.1f); - // ShowToolTip("Z position"); + // ShowToolTip("Z Position"); // Camera->SetPosition(CameraPosition); // // ********* ROTATION ********* // glm::vec3 CameraRotation = glm::vec3(Camera->GetYaw(), Camera->GetPitch(), Camera->GetRoll()); - // ImGui::Text("Rotation : "); + // ImGui::Text("WorldRotation : "); // ImGui::SameLine(); // ImGui::SetNextItemWidth(90); // ImGui::DragFloat("##X rot", &CameraRotation[0], 0.1f); - // ShowToolTip("X rotation"); + // ShowToolTip("X WorldRotation"); // ImGui::SameLine(); // ImGui::SetNextItemWidth(90); // ImGui::DragFloat("##Y rot", &CameraRotation[1], 0.1f); - // ShowToolTip("Y rotation"); + // ShowToolTip("Y WorldRotation"); // ImGui::SameLine(); // ImGui::SetNextItemWidth(90); // ImGui::DragFloat("##Z rot", &CameraRotation[2], 0.1f); - // ShowToolTip("Z rotation"); + // ShowToolTip("Z WorldRotation"); // Camera->SetYaw(CameraRotation[0]); // Camera->SetPitch(CameraRotation[1]); diff --git a/EditorWindows/InspectorWindow.h b/EditorWindows/InspectorWindow.h index 8c138d7..fb958ae 100644 --- a/EditorWindows/InspectorWindow.h +++ b/EditorWindows/InspectorWindow.h @@ -12,8 +12,7 @@ class FEEditorInspectorWindow static FEEntity* EntityToModify; // Light properties - void DisplayLightProperties(FELight* Light) const; - void DisplayLightsProperties() const; + void DisplayLightProperties(FEEntity* LightEntity) const; // Terrain settings static FEEntity* TerrainToWorkWith; diff --git a/EditorWindows/PrefabEditorWindow.cpp b/EditorWindows/PrefabEditorWindow.cpp index 6458e0a..a5abc69 100644 --- a/EditorWindows/PrefabEditorWindow.cpp +++ b/EditorWindows/PrefabEditorWindow.cpp @@ -16,70 +16,71 @@ bool PrefabEditorWindow::AddGameModelTargetCallBack(FEObject* Object, void** Ent void PrefabEditorWindow::ShowTransformConfiguration(FETransformComponent* Transform, const int Index) { - // ********************* POSITION ********************* - glm::vec3 position = Transform->GetPosition(); - ImGui::Text("Position : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##X pos : ") + std::to_string(Index)).c_str(), &position[0], 0.1f); - ShowToolTip("X position"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Y pos : ") + std::to_string(Index)).c_str(), &position[1], 0.1f); - ShowToolTip("Y position"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Z pos : ") + std::to_string(Index)).c_str(), &position[2], 0.1f); - ShowToolTip("Z position"); - Transform->SetPosition(position); - - // ********************* ROTATION ********************* - glm::vec3 rotation = Transform->GetRotation(); - ImGui::Text("Rotation : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##X rot : ") + std::to_string(Index)).c_str(), &rotation[0], 0.1f, -360.0f, 360.0f); - ShowToolTip("X rotation"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Y rot : ") + std::to_string(Index)).c_str(), &rotation[1], 0.1f, -360.0f, 360.0f); - ShowToolTip("Y rotation"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Z rot : ") + std::to_string(Index)).c_str(), &rotation[2], 0.1f, -360.0f, 360.0f); - ShowToolTip("Z rotation"); - Transform->SetRotation(rotation); - - // ********************* SCALE ********************* - bool bUniformScaling = Transform->IsUniformScalingSet(); - ImGui::Checkbox("Uniform scaling", &bUniformScaling); - Transform->SetUniformScaling(bUniformScaling); - - glm::vec3 scale = Transform->GetScale(); - ImGui::Text("Scale : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##X scale : ") + std::to_string(Index)).c_str(), &scale[0], 0.01f, 0.01f, 1000.0f); - ShowToolTip("X scale"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Y scale : ") + std::to_string(Index)).c_str(), &scale[1], 0.01f, 0.01f, 1000.0f); - ShowToolTip("Y scale"); - - ImGui::SameLine(); - ImGui::SetNextItemWidth(50); - ImGui::DragFloat((std::string("##Z scale : ") + std::to_string(Index)).c_str(), &scale[2], 0.01f, 0.01f, 1000.0f); - ShowToolTip("Z scale"); - - glm::vec3 OldScale = Transform->GetScale(); - Transform->ChangeXScaleBy(scale[0] - OldScale[0]); - Transform->ChangeYScaleBy(scale[1] - OldScale[1]); - Transform->ChangeZScaleBy(scale[2] - OldScale[2]); + // FIX ME! + //// ********************* POSITION ********************* + //glm::vec3 position = Transform->GetPosition(); + //ImGui::Text("Position : "); + //ImGui::SameLine(); + //ImGui::SetNextItemWidth(50); + //ImGui::DragFloat((std::string("##X pos : ") + std::to_string(Index)).c_str(), &position[0], 0.1f); + //ShowToolTip("X position"); + + //ImGui::SameLine(); + //ImGui::SetNextItemWidth(50); + //ImGui::DragFloat((std::string("##Y pos : ") + std::to_string(Index)).c_str(), &position[1], 0.1f); + //ShowToolTip("Y position"); + + //ImGui::SameLine(); + //ImGui::SetNextItemWidth(50); + //ImGui::DragFloat((std::string("##Z pos : ") + std::to_string(Index)).c_str(), &position[2], 0.1f); + //ShowToolTip("Z position"); + //Transform->SetPosition(position); + + //// ********************* ROTATION ********************* + //glm::vec3 rotation = Transform->GetRotation(); + //ImGui::Text("Rotation : "); + //ImGui::SameLine(); + //ImGui::SetNextItemWidth(50); + //ImGui::DragFloat((std::string("##X rot : ") + std::to_string(Index)).c_str(), &rotation[0], 0.1f, -360.0f, 360.0f); + //ShowToolTip("X rotation"); + + //ImGui::SameLine(); + //ImGui::SetNextItemWidth(50); + //ImGui::DragFloat((std::string("##Y rot : ") + std::to_string(Index)).c_str(), &rotation[1], 0.1f, -360.0f, 360.0f); + //ShowToolTip("Y rotation"); + + //ImGui::SameLine(); + //ImGui::SetNextItemWidth(50); + //ImGui::DragFloat((std::string("##Z rot : ") + std::to_string(Index)).c_str(), &rotation[2], 0.1f, -360.0f, 360.0f); + //ShowToolTip("Z rotation"); + //Transform->SetRotation(rotation); + + //// ********************* SCALE ********************* + //bool bUniformScaling = Transform->IsUniformScalingSet(); + //ImGui::Checkbox("Uniform scaling", &bUniformScaling); + //Transform->SetUniformScaling(bUniformScaling); + + //glm::vec3 scale = Transform->GetScale(); + //ImGui::Text("Scale : "); + //ImGui::SameLine(); + //ImGui::SetNextItemWidth(50); + //ImGui::DragFloat((std::string("##X scale : ") + std::to_string(Index)).c_str(), &scale[0], 0.01f, 0.01f, 1000.0f); + //ShowToolTip("X scale"); + + //ImGui::SameLine(); + //ImGui::SetNextItemWidth(50); + //ImGui::DragFloat((std::string("##Y scale : ") + std::to_string(Index)).c_str(), &scale[1], 0.01f, 0.01f, 1000.0f); + //ShowToolTip("Y scale"); + + //ImGui::SameLine(); + //ImGui::SetNextItemWidth(50); + //ImGui::DragFloat((std::string("##Z scale : ") + std::to_string(Index)).c_str(), &scale[2], 0.01f, 0.01f, 1000.0f); + //ShowToolTip("Z scale"); + + //glm::vec3 OldScale = Transform->GetScale(); + //Transform->ChangeXScaleBy(scale[0] - OldScale[0]); + //Transform->ChangeYScaleBy(scale[1] - OldScale[1]); + //Transform->ChangeZScaleBy(scale[2] - OldScale[2]); } void PrefabEditorWindow::AddNewGameModelCallBack(const std::vector SelectionsResult) diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 8e77b93..e65fd56 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -74,7 +74,7 @@ void FEEditorSceneGraphWindow::PopCorrectItemColor(FEObject* SceneObject) } } -static void CreateNewInstancedEntityCallBack(const std::vector SelectionsResult) +static void CreateInstancedEntityCallBack(const std::vector SelectionsResult) { if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) { @@ -82,17 +82,17 @@ static void CreateNewInstancedEntityCallBack(const std::vector Select if (SelectedPrefab == nullptr) return; - FEEntity* NewEntity = SCENE.AddNewStyleEntity(); - NewEntity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - NewEntity->AddComponent(SelectedPrefab->GetComponent(0)->GameModel); - NewEntity->AddComponent(); - SELECTED.SetSelected(NewEntity); + FEEntity* Entity = SCENE.AddEntity(); + Entity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + Entity->AddComponent(SelectedPrefab->GetComponent(0)->GameModel); + Entity->AddComponent(); + SELECTED.SetSelected(Entity); PROJECT_MANAGER.GetCurrent()->SetModified(true); } } -static void CreateNewEntityCallBack(const std::vector SelectionsResult) +static void CreateEntityCallBack(const std::vector SelectionsResult) { if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) { @@ -100,9 +100,9 @@ static void CreateNewEntityCallBack(const std::vector SelectionsResul if (SelectedPrefab == nullptr) return; - FEEntity* NewEntity = SCENE.AddNewStyleEntity(); - NewEntity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - SELECTED.SetSelected(NewEntity); + FEEntity* Entity = SCENE.AddEntity(); + Entity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + SELECTED.SetSelected(Entity); PROJECT_MANAGER.GetCurrent()->SetModified(true); } @@ -182,15 +182,7 @@ void FEEditorSceneGraphWindow::DrawCorrectIcon(const FEObject* SceneObject) cons DragAndDropTarget* FEEditorSceneGraphWindow::GetSceneNodeDragAndDropTarget(FENaiveSceneGraphNode* NodeToFind) { int64_t UniqueID = 0; - //// If it is Root. - //if (NodeToFind->GetOldStyleEntity() == nullptr) - //{ - // UniqueID = 1; - //} - //else - //{ - UniqueID = static_cast(std::hash{}(NodeToFind->GetNewStyleEntity()->GetObjectID().c_str())); - //} + UniqueID = static_cast(std::hash{}(NodeToFind->GetEntity()->GetObjectID().c_str())); if (SceneNodeDragAndDropTargets.find(UniqueID) == SceneNodeDragAndDropTargets.end()) { @@ -210,23 +202,15 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) ImGuiTreeNodeFlags NodeFlags = bIsLeaf ? ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen : ImGuiTreeNodeFlags_OpenOnArrow; std::string Name = SubTreeRoot->GetParent() == nullptr ? PROJECT_MANAGER.GetCurrent()->GetName() : SubTreeRoot->GetName(); - if (SELECTED.GetSelected() != nullptr && SubTreeRoot->GetNewStyleEntity() != nullptr) + if (SELECTED.GetSelected() != nullptr && SubTreeRoot->GetEntity() != nullptr) { - if (SELECTED.GetSelected()->GetObjectID() == SubTreeRoot->GetNewStyleEntity()->GetObjectID()) + if (SELECTED.GetSelected()->GetObjectID() == SubTreeRoot->GetEntity()->GetObjectID()) { NodeFlags |= ImGuiTreeNodeFlags_Selected; } } - // If it is Root. - /*if (SubTreeRoot->GetOldStyleEntity() == nullptr) - { - UniqueID = 1; - } - else - {*/ - UniqueID = static_cast(std::hash{}(SubTreeRoot->GetNewStyleEntity()->GetObjectID().c_str())); - //} + UniqueID = static_cast(std::hash{}(SubTreeRoot->GetEntity()->GetObjectID().c_str())); bool bOpened = ImGui::TreeNodeEx((void*)UniqueID, NodeFlags, Name.c_str(), 0); GetSceneNodeDragAndDropTarget(SubTreeRoot)->StickToItem(); @@ -235,7 +219,7 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) { if (SubTreeRoot->GetParent() != nullptr) { - SELECTED.SetSelected(SubTreeRoot->GetNewStyleEntity()); + SELECTED.SetSelected(SubTreeRoot->GetEntity()); SELECTED.SetDirtyFlag(false); } } @@ -330,13 +314,7 @@ void FEEditorSceneGraphWindow::Render() // SceneObjectsList.push_back(EntityList[i]); //} - const std::vector LightList = SCENE.GetLightsList(); - for (size_t i = 0; i < LightList.size(); i++) - { - SceneObjectsList.push_back(LightList[i]); - } - - const std::vector TerrainList = SCENE.GetTerrainList(); + const std::vector TerrainList = SCENE.GetEntityIDListWith(); for (size_t i = 0; i < TerrainList.size(); i++) { SceneObjectsList.push_back(TerrainList[i]); @@ -392,8 +370,8 @@ void FEEditorSceneGraphWindow::Render() if (ImGui::IsItemClicked()) { // FIX ME! - //FEEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])->GetObjectID()); - //SELECTED.SetSelected(NewNewEntity); + /*FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[i]); + SELECTED.SetSelected(Entity);*/ SELECTED.SetDirtyFlag(false); } @@ -422,45 +400,19 @@ void FEEditorSceneGraphWindow::Render() { if (ImGui::MenuItem("Entity")) { - SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, CreateNewEntityCallBack); - //selectGameModelPopUp::getInstance().show(nullptr, true); + SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, CreateEntityCallBack); } if (ImGui::MenuItem("Instanced entity")) { - SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, CreateNewInstancedEntityCallBack); - //selectGameModelPopUp::getInstance().show(nullptr, true, true); + SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, CreateInstancedEntityCallBack); } if (ImGui::MenuItem("Terrain")) { - /*const std::vector TerrainList = SCENE.GetTerrainList(); - const size_t NextId = TerrainList.size(); - size_t index = 0; - std::string NewName = "terrain_" + std::to_string(NextId + index); - - while (true) - { - bool bCorrectName = true; - for (size_t i = 0; i < TerrainList.size(); i++) - { - if (TerrainList[i] == NewName) - { - bCorrectName = false; - break; - } - } - - if (bCorrectName) - break; - - index++; - NewName = "terrain_" + std::to_string(NextId + index); - }*/ - - FEEntity* NewEntity = SCENE.AddNewStyleEntity("Unnamed terrain"); - FETransformComponent& TransformComponent = NewEntity->GetComponent(); - FETerrainComponent& TerrainComponent = NewEntity->AddComponent(); + FEEntity* Entity = SCENE.AddEntity("Unnamed terrain"); + FETransformComponent& TransformComponent = Entity->GetComponent(); + FETerrainComponent& TerrainComponent = Entity->AddComponent(); TerrainComponent.HeightMap = RESOURCE_MANAGER.CreateBlankHightMapTexture(); PROJECT_MANAGER.GetCurrent()->SetModified(true); @@ -468,7 +420,7 @@ void FEEditorSceneGraphWindow::Render() if (ImGui::BeginMenu("Light")) { - if (ImGui::MenuItem("Directional")) + /*if (ImGui::MenuItem("Directional")) { SCENE.AddLight(FE_DIRECTIONAL_LIGHT, ""); } @@ -481,7 +433,7 @@ void FEEditorSceneGraphWindow::Render() if (ImGui::MenuItem("Point")) { SCENE.AddLight(FE_POINT_LIGHT, ""); - } + }*/ ImGui::EndMenu(); } @@ -493,21 +445,21 @@ void FEEditorSceneGraphWindow::Render() { if (ImGui::MenuItem("Rename")) { - if (SCENE.GetNewStyleEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) + if (SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) { - RenamePopUp::getInstance().Show(SCENE.GetNewStyleEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex])); + RenamePopUp::getInstance().Show(SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex])); } } if (ImGui::MenuItem("Delete")) { - FEEntity* Entity = SCENE.GetNewStyleEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); + FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); if (Entity != nullptr) { if (SELECTED.GetSelected() == Entity) SELECTED.Clear(); - SCENE.DeleteNewEntity(Entity); + SCENE.DeleteEntity(Entity); } // FIX ME! @@ -632,7 +584,7 @@ void FEEditorSceneGraphWindow::Render() if (SELECTED.GetSelected()->HasComponent()) { FEGameModel* GameModel = SELECTED.GetSelected()->GetComponent().GameModel; - FEAABB SelectedAABB = GameModel->GetMesh()->GetAABB().Transform(SELECTED.GetSelected()->GetComponent().GetTransformMatrix()); + FEAABB SelectedAABB = GameModel->GetMesh()->GetAABB().Transform(SELECTED.GetSelected()->GetComponent().GetWorldMatrix()); RENDERER.DrawAABB(SelectedAABB); diff --git a/EditorWindows/ShaderEditorWindow.cpp b/EditorWindows/ShaderEditorWindow.cpp index 2c17796..7051f17 100644 --- a/EditorWindows/ShaderEditorWindow.cpp +++ b/EditorWindows/ShaderEditorWindow.cpp @@ -466,10 +466,10 @@ void ShaderEditorWindow::ReplaceShader(FEShader* OldShader, FEShader* NewShader) } } - const std::vector TerrainList = SCENE.GetTerrainList(); + const std::vector TerrainList = SCENE.GetEntityIDListWith(); for (size_t i = 0; i < TerrainList.size(); i++) { - FEEntity* TempTerrain = SCENE.GetNewStyleEntity(TerrainList[i]); + FEEntity* TempTerrain = SCENE.GetEntity(TerrainList[i]); FETerrainComponent& TerrainComponent = TempTerrain->GetComponent(); if (TerrainComponent.Shader->GetNameHash() == OldShader->GetNameHash()) { diff --git a/FEEditor.cpp b/FEEditor.cpp index 5c62538..3147149 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -9,28 +9,15 @@ bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) { FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())->GetComponent(0)->GameModel; - FEEntity* NewNewEntity = SCENE.AddNewStyleEntity(Object->GetName()); - NewNewEntity->GetComponent().GameModel = GameModel; - NewNewEntity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - SELECTED.SetSelected(NewNewEntity); + FEEntity* Entity = SCENE.AddEntity(Object->GetName()); + Entity->GetComponent().GameModel = GameModel; + Entity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + SELECTED.SetSelected(Entity); PROJECT_MANAGER.GetCurrent()->SetModified(true); return true; } - // FIX ME! - //if (Object->GetType() == FE_PREFAB) - //{ - // FEEntity* NewEntity = SCENE.AddEntity(RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())); - // FEEntity* NewNewEntity = SCENE.GetNewStyleEntityByOldStyleID(NewEntity->GetObjectID()); - // NewNewEntity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - // //NewEntity->Transform.SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - // SELECTED.SetSelected(NewNewEntity); - // PROJECT_MANAGER.GetCurrent()->SetModified(true); - - // return true; - //} - return false; } @@ -181,7 +168,7 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) } else { - SCENE.DeleteNewEntity(SELECTED.GetSelected()); + SCENE.DeleteEntity(SELECTED.GetSelected()); } SELECTED.Clear(); @@ -200,17 +187,16 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) if (!EDITOR.GetSceneEntityIDInClipboard().empty()) { // FIX ME! - // There should be proper FEScene::DuplicateNewStyleEntity that will duplicate the entity and all its components + // There should be proper FEScene::DuplicateEntity that will duplicate the entity and all its components // Also place it in same scene graph node as the original entity ? - FEEntity* EntityToCopy = SCENE.GetNewStyleEntity(EDITOR.GetSceneEntityIDInClipboard()); - FEEntity* NewNewEntity = SCENE.AddNewStyleEntity(EntityToCopy->GetName() + "_Copy"); - NewNewEntity->GetComponent() = EntityToCopy->GetComponent(); - NewNewEntity->GetComponent().SetPosition(EntityToCopy->GetComponent().GetPosition() * 1.1f); + FEEntity* EntityToCopy = SCENE.GetEntity(EDITOR.GetSceneEntityIDInClipboard()); + FEEntity* Entity = SCENE.AddEntity(EntityToCopy->GetName() + "_Copy"); + Entity->GetComponent() = EntityToCopy->GetComponent(); + Entity->GetComponent().SetPosition(EntityToCopy->GetComponent().GetPosition() * 1.1f); if (EntityToCopy->HasComponent()) - NewNewEntity->AddComponent(EntityToCopy->GetComponent().GameModel); - + Entity->AddComponent(EntityToCopy->GetComponent().GameModel); - SELECTED.SetSelected(NewNewEntity); + SELECTED.SetSelected(Entity); } } diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index e01d86d..9c426c7 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -12,7 +12,7 @@ void GizmoManager::InitializeResources() FEMesh* TransformationGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "45191B6F172E3B531978692E.model").c_str(), "transformationGizmoMesh"); RESOURCE_MANAGER.MakeMeshStandard(TransformationGizmoMesh); - ParentGizmoEntity = SCENE.AddNewStyleEntity("ParentGizmoEntity"); + ParentGizmoEntity = SCENE.AddEntity("ParentGizmoEntity"); FENaiveSceneGraphNode* ParentGizmoGraphNode = SCENE.SceneGraph.GetNodeByEntityID(ParentGizmoEntity->GetObjectID()); // TransformationXGizmo @@ -21,7 +21,7 @@ void GizmoManager::InitializeResources() CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationXGizmoEntity = SCENE.AddNewStyleEntity("TransformationXGizmoEntity"); + TransformationXGizmoEntity = SCENE.AddEntity("TransformationXGizmoEntity"); //TransformationXGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM"), "TransformationXGizmoEntity")); TransformationXGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM")); TransformationXGizmoEntity->SetName("TransformationXGizmoEntity"); @@ -41,7 +41,7 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationYGizmoEntity = SCENE.AddNewStyleEntity("TransformationYGizmoEntity"); + TransformationYGizmoEntity = SCENE.AddEntity("TransformationYGizmoEntity"); //TransformationYGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"), "TransformationYGizmoEntity")); TransformationYGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM")); TransformationYGizmoEntity->SetName("TransformationYGizmoEntity"); @@ -68,7 +68,7 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationZGizmoEntity = SCENE.AddNewStyleEntity("TransformationZGizmoEntity"); + TransformationZGizmoEntity = SCENE.AddEntity("TransformationZGizmoEntity"); //TransformationZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"), "TransformationZGizmoEntity")); TransformationZGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM")); TransformationYGizmoEntity->SetName("TransformationZGizmoEntity"); @@ -95,7 +95,7 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationXYGizmoEntity = SCENE.AddNewStyleEntity("TransformationXYGizmoEntity"); + TransformationXYGizmoEntity = SCENE.AddEntity("TransformationXYGizmoEntity"); //TransformationXYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"), "TransformationXYGizmoEntity")); TransformationXYGizmoEntity->AddComponent(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM")); TransformationXYGizmoEntity->SetName("TransformationXYGizmoEntity"); @@ -123,7 +123,7 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationYZGizmoEntity = SCENE.AddNewStyleEntity("TransformationYZGizmoEntity"); + TransformationYZGizmoEntity = SCENE.AddEntity("TransformationYZGizmoEntity"); //TransformationYZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"), "TransformationYZGizmoEntity")); TransformationYZGizmoEntity->AddComponent(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM")); TransformationYZGizmoEntity->SetName("TransformationYZGizmoEntity"); @@ -151,7 +151,7 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationXZGizmoEntity = SCENE.AddNewStyleEntity("TransformationXZGizmoEntity"); + TransformationXZGizmoEntity = SCENE.AddEntity("TransformationXZGizmoEntity"); //TransformationXZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"), "TransformationXZGizmoEntity")); TransformationXZGizmoEntity->SetName("TransformationXZGizmoEntity"); TransformationXZGizmoEntity->AddComponent(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM")); @@ -184,7 +184,7 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - ScaleXGizmoEntity = SCENE.AddNewStyleEntity("ScaleXGizmoEntity"); + ScaleXGizmoEntity = SCENE.AddEntity("ScaleXGizmoEntity"); //ScaleXGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM"), "ScaleXGizmoEntity")); ScaleXGizmoEntity->AddComponent(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM")); ScaleXGizmoEntity->SetName("ScaleXGizmoEntity"); @@ -211,7 +211,7 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - ScaleYGizmoEntity = SCENE.AddNewStyleEntity("ScaleYGizmoEntity"); + ScaleYGizmoEntity = SCENE.AddEntity("ScaleYGizmoEntity"); //ScaleYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM"), "ScaleYGizmoEntity")); ScaleYGizmoEntity->AddComponent(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM")); ScaleYGizmoEntity->SetName("ScaleYGizmoEntity"); @@ -238,7 +238,7 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - ScaleZGizmoEntity = SCENE.AddNewStyleEntity("ScaleZGizmoEntity"); + ScaleZGizmoEntity = SCENE.AddEntity("ScaleZGizmoEntity"); //ScaleZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM"), "ScaleZGizmoEntity")); ScaleZGizmoEntity->AddComponent(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM")); ScaleZGizmoEntity->SetName("ScaleZGizmoEntity"); @@ -258,7 +258,7 @@ void GizmoManager::InitializeResources() // Temporary overly complicated solution, because of new and old entity system. SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); - // Rotate gizmos + // RotateAroundAxis gizmos FEMesh* RotateGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "19622421516E5B317E1B5360.model").c_str(), "rotateGizmoMesh"); RESOURCE_MANAGER.MakeMeshStandard(RotateGizmoMesh); @@ -269,7 +269,7 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - RotateXGizmoEntity = SCENE.AddNewStyleEntity("RotateXGizmoEntity"); + RotateXGizmoEntity = SCENE.AddEntity("RotateXGizmoEntity"); //RotateXGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM"), "RotateXGizmoEntity")); RotateXGizmoEntity->AddComponent(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM")); RotateXGizmoEntity->SetName("RotateXGizmoEntity"); @@ -296,7 +296,7 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - RotateYGizmoEntity = SCENE.AddNewStyleEntity("RotateYGizmoEntity"); + RotateYGizmoEntity = SCENE.AddEntity("RotateYGizmoEntity"); //RotateYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM"), "RotateYGizmoEntity")); RotateYGizmoEntity->AddComponent(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM")); RotateYGizmoEntity->SetName("RotateYGizmoEntity"); @@ -323,7 +323,7 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - RotateZGizmoEntity = SCENE.AddNewStyleEntity("RotateZGizmoEntity"); + RotateZGizmoEntity = SCENE.AddEntity("RotateZGizmoEntity"); //RotateZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM"), "RotateZGizmoEntity")); RotateZGizmoEntity->AddComponent(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM")); RotateZGizmoEntity->SetName("RotateZGizmoEntity"); @@ -470,7 +470,7 @@ void GizmoManager::Render() } FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); - const glm::vec3 ObjectSpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); + const glm::vec3 ObjectSpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); glm::vec3 ToObject = ObjectSpaceOriginInWorldSpace - ENGINE.GetCamera()->GetPosition(); ToObject = glm::normalize(ToObject); @@ -660,7 +660,7 @@ bool GizmoManager::WasSelected(int Index) glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal) { FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); - const glm::vec3 EntitySpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); + const glm::vec3 EntitySpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); @@ -688,7 +688,7 @@ glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal) glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, glm::vec3& LastMousePointOnPlane) { FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); - const glm::vec3 EntitySpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); + const glm::vec3 EntitySpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); @@ -724,9 +724,8 @@ void GizmoManager::MoveSelectedEntityAlongAxis(const glm::vec3& AxisOfMovement, { if (SceneGraphParentEntity->GetParent() != SCENE.SceneGraph.GetRoot()) { - FETransformComponent& ParentTransform = SceneGraphParentEntity->GetParent()->GetNewStyleEntity()->GetComponent(); - //FEEntity* ParentEntity = reinterpret_cast(SceneGraphParentEntity->GetParent()->GetOldStyleEntity()); - LocalAlternativeAxis = glm::inverse(ParentTransform.WorldSpaceMatrix) * glm::vec4(AxisOfMovement, 0.0f); + FETransformComponent& ParentTransform = SceneGraphParentEntity->GetParent()->GetEntity()->GetComponent(); + LocalAlternativeAxis = glm::inverse(ParentTransform.GetWorldMatrix()) * glm::vec4(AxisOfMovement, 0.0f); } NewPosition += LocalAlternativeAxis; @@ -734,44 +733,6 @@ void GizmoManager::MoveSelectedEntityAlongAxis(const glm::vec3& AxisOfMovement, } } -#include -void GizmoManager::RotateSelectedEntity(const glm::vec3& AxisOfRotation, FETransformComponent& ObjectTransform, const float& RotationAmount) -{ - glm::vec3 LocalAlternativeAxis = AxisOfRotation; - - FENaiveSceneGraphNode* SceneGraphParentEntity = SCENE.SceneGraph.GetNodeByEntityID(SELECTED.GetSelected()->GetObjectID()); - if (SceneGraphParentEntity != nullptr) - { - if (SceneGraphParentEntity->GetParent() != SCENE.SceneGraph.GetRoot()) - { - FETransformComponent& ParentTransform = SceneGraphParentEntity->GetParent()->GetNewStyleEntity()->GetComponent(); - //FEEntity* ParentEntity = reinterpret_cast(SceneGraphParentEntity->GetParent()->GetOldStyleEntity()); - //LocalAlternativeAxis = glm::inverse(ParentEntity->Transform.GetQuaternion()) * glm::vec3(AxisOfRotation); - - glm::dvec3 DoubleScale; - glm::dquat DoubleRotation; - glm::dvec3 DoubleTranslation; - glm::dvec3 DoubleSkew; - glm::dvec4 DoublePerspective; - glm::dmat4 DoubleNewChildLocalMatrix = ParentTransform.WorldSpaceMatrix; - bool Success = glm::decompose(DoubleNewChildLocalMatrix, DoubleScale, DoubleRotation, DoubleTranslation, DoubleSkew, DoublePerspective); - if (Success) - { - LocalAlternativeAxis = glm::inverse(glm::quat(DoubleRotation)) * glm::vec3(AxisOfRotation); - } - - //LocalAlternativeAxis = glm::quat(glm::inverse(ParentEntity->Transform.WorldSpaceMatrix)) * glm::vec4(AxisOfRotation, 1.0f); - } - - glm::quat RotationQuaternion = glm::quat(cos(RotationAmount * ANGLE_TORADIANS_COF / 2), - LocalAlternativeAxis.x * sin(RotationAmount * ANGLE_TORADIANS_COF / 2), - LocalAlternativeAxis.y * sin(RotationAmount * ANGLE_TORADIANS_COF / 2), - LocalAlternativeAxis.z * sin(RotationAmount * ANGLE_TORADIANS_COF / 2)); - - ObjectTransform.RotateByQuaternion(RotationQuaternion); - } -} - void GizmoManager::MouseMoveTransformationGizmos() { FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); @@ -788,19 +749,27 @@ void GizmoManager::MouseMoveTransformationGizmos() { const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), LastMouseRayVector, - glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f), + glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f), LastFrameMouseRayParametricIntersection, LastFrameGizmoRayParametricIntersection); const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), MouseRayVector, - glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f), + glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f), MouseRayParametricIntersection, GizmoRayParametricIntersection); const float Difference = GizmoRayParametricIntersection - LastFrameGizmoRayParametricIntersection; if (abs(Difference) > FLT_EPSILON) { + //float OldY = ObjTransform.GetPosition(false)[1]; bAppliedSomeChanges = true; - MoveSelectedEntityAlongAxis(glm::vec3(Difference, 0.0f, 0.0f), ObjTransform); + + + + //ObjTransform.SetPosition(ObjTransform.GetPosition(false) + glm::vec3(Difference, 0.0f, 0.0f), false); + + ObjTransform.SetPosition(ObjTransform.GetPosition(false) + glm::vec3(Difference, 0.0f, 0.0f), false); + + //MoveAlongAxis(glm::vec3(Difference, 0.0f, 0.0f), ObjTransform); } } @@ -808,12 +777,12 @@ void GizmoManager::MouseMoveTransformationGizmos() { const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), LastMouseRayVector, - glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 1.0f, 0.0f), + glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 1.0f, 0.0f), LastFrameMouseRayParametricIntersection, LastFrameGizmoRayParametricIntersection); const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), MouseRayVector, - glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 1.0f, 0.0f), + glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 1.0f, 0.0f), MouseRayParametricIntersection, GizmoRayParametricIntersection); const float Difference = GizmoRayParametricIntersection - LastFrameGizmoRayParametricIntersection; @@ -828,12 +797,12 @@ void GizmoManager::MouseMoveTransformationGizmos() { const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), LastMouseRayVector, - glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 0.0f, 1.0f), + glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 0.0f, 1.0f), LastFrameMouseRayParametricIntersection, LastFrameGizmoRayParametricIntersection); const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), MouseRayVector, - glm::vec3(ObjTransform.GetTransformMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 0.0f, 1.0f), + glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 0.0f, 1.0f), MouseRayParametricIntersection, GizmoRayParametricIntersection); const float Difference = GizmoRayParametricIntersection - LastFrameGizmoRayParametricIntersection; @@ -953,7 +922,7 @@ void GizmoManager::MouseMoveRotateGizmos() if (GIZMO_MANAGER.bRotateZGizmoActive) AxisOfRotation = glm::vec3(0.0f, 0.0f, 1.0f); - RotateSelectedEntity(AxisOfRotation, ObjTransform, Difference); + ObjTransform.RotateAroundAxis(AxisOfRotation, Difference, false); ApplyChangesToSelectedObject(ObjTransform); } @@ -1068,7 +1037,7 @@ void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent Changes) if (SELECTED.InstancedSubObjectIndexSelected != -1) { - INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(SELECTED.GetSelected(), SELECTED.InstancedSubObjectIndexSelected, Changes.GetTransformMatrix()); + INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(SELECTED.GetSelected(), SELECTED.InstancedSubObjectIndexSelected, Changes.GetWorldMatrix()); } else { @@ -1083,7 +1052,7 @@ void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent Changes) { if (SELECTED.InstancedSubObjectIndexSelected != -1) { - reinterpret_cast(SELECTED.GetEntity())->ModifyInstance(SELECTED.InstancedSubObjectIndexSelected, Changes.GetTransformMatrix()); + reinterpret_cast(SELECTED.GetEntity())->ModifyInstance(SELECTED.InstancedSubObjectIndexSelected, Changes.GetWorldMatrix()); } else { @@ -1102,11 +1071,11 @@ void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent Changes) void GizmoManager::ReInitializeEntities() { - ParentGizmoEntity = SCENE.AddNewStyleEntity("ParentGizmoEntity"); + ParentGizmoEntity = SCENE.AddEntity("ParentGizmoEntity"); ParentGizmoGraphNode = SCENE.SceneGraph.GetNodeByEntityID(ParentGizmoEntity->GetObjectID()); // TransformationXGizmo - TransformationXGizmoEntity = SCENE.AddNewStyleEntity("TransformationXGizmoEntity"); + TransformationXGizmoEntity = SCENE.AddEntity("TransformationXGizmoEntity"); TransformationXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXGizmoGM")[0]); TransformationXGizmoEntity->SetName("TransformationXGizmoEntity"); TransformationXGizmoEntity->GetComponent().SetCastShadows(false); @@ -1118,7 +1087,7 @@ void GizmoManager::ReInitializeEntities() SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // TransformationYGizmo - TransformationYGizmoEntity = SCENE.AddNewStyleEntity("TransformationYGizmoEntity"); + TransformationYGizmoEntity = SCENE.AddEntity("TransformationYGizmoEntity"); TransformationYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYGizmoGM")[0]); TransformationYGizmoEntity->SetName("TransformationYGizmoEntity"); TransformationYGizmoEntity->GetComponent().SetCastShadows(false); @@ -1130,7 +1099,7 @@ void GizmoManager::ReInitializeEntities() SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // TransformationZGizmo - TransformationZGizmoEntity = SCENE.AddNewStyleEntity("TransformationZGizmoEntity"); + TransformationZGizmoEntity = SCENE.AddEntity("TransformationZGizmoEntity"); TransformationZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationZGizmoGM")[0]); TransformationZGizmoEntity->SetName("TransformationZGizmoEntity"); TransformationZGizmoEntity->GetComponent().SetCastShadows(false); @@ -1141,7 +1110,7 @@ void GizmoManager::ReInitializeEntities() SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // Plane gizmos - TransformationXYGizmoEntity = SCENE.AddNewStyleEntity("TransformationXYGizmoEntity"); + TransformationXYGizmoEntity = SCENE.AddEntity("TransformationXYGizmoEntity"); TransformationXYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXYGizmoGM")[0]); TransformationXYGizmoEntity->SetName("TransformationXYGizmoEntity"); TransformationXYGizmoEntity->GetComponent().SetCastShadows(false); @@ -1153,7 +1122,7 @@ void GizmoManager::ReInitializeEntities() // Temporary overly complicated solution, because of new and old entity system. SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); - TransformationYZGizmoEntity = SCENE.AddNewStyleEntity("TransformationYZGizmoEntity"); + TransformationYZGizmoEntity = SCENE.AddEntity("TransformationYZGizmoEntity"); TransformationYZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYZGizmoGM")[0]); TransformationYZGizmoEntity->SetName("TransformationYZGizmoEntity"); TransformationYZGizmoEntity->GetComponent().SetCastShadows(false); @@ -1165,7 +1134,7 @@ void GizmoManager::ReInitializeEntities() // Temporary overly complicated solution, because of new and old entity system. SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); - TransformationXZGizmoEntity = SCENE.AddNewStyleEntity("TransformationXZGizmoEntity"); + TransformationXZGizmoEntity = SCENE.AddEntity("TransformationXZGizmoEntity"); TransformationXZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXZGizmoGM")[0]); TransformationXZGizmoEntity->SetName("TransformationXZGizmoEntity"); TransformationXZGizmoEntity->GetComponent().SetCastShadows(false); @@ -1178,7 +1147,7 @@ void GizmoManager::ReInitializeEntities() SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // ScaleXGizmo - ScaleXGizmoEntity = SCENE.AddNewStyleEntity("ScaleXGizmoEntity"); + ScaleXGizmoEntity = SCENE.AddEntity("ScaleXGizmoEntity"); ScaleXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleXGizmoGM")[0]); ScaleXGizmoEntity->SetName("ScaleXGizmoEntity"); ScaleXGizmoEntity->GetComponent().SetCastShadows(false); @@ -1190,7 +1159,7 @@ void GizmoManager::ReInitializeEntities() SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // ScaleYGizmo - ScaleYGizmoEntity = SCENE.AddNewStyleEntity("ScaleYGizmoEntity"); + ScaleYGizmoEntity = SCENE.AddEntity("ScaleYGizmoEntity"); ScaleYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleYGizmoGM")[0]); ScaleYGizmoEntity->SetName("ScaleYGizmoEntity"); ScaleYGizmoEntity->GetComponent().SetCastShadows(false); @@ -1202,7 +1171,7 @@ void GizmoManager::ReInitializeEntities() SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // ScaleZGizmo - ScaleZGizmoEntity = SCENE.AddNewStyleEntity("ScaleZGizmoEntity"); + ScaleZGizmoEntity = SCENE.AddEntity("ScaleZGizmoEntity"); ScaleZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleZGizmoGM")[0]); ScaleZGizmoEntity->SetName("ScaleZGizmoEntity"); ScaleZGizmoEntity->GetComponent().SetCastShadows(false); @@ -1214,7 +1183,7 @@ void GizmoManager::ReInitializeEntities() SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // RotateXGizmo - RotateXGizmoEntity = SCENE.AddNewStyleEntity("RotateXGizmoEntity"); + RotateXGizmoEntity = SCENE.AddEntity("RotateXGizmoEntity"); RotateXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateXGizmoGM")[0]); RotateXGizmoEntity->SetName("RotateXGizmoEntity"); RotateXGizmoEntity->GetComponent().SetCastShadows(false); @@ -1226,7 +1195,7 @@ void GizmoManager::ReInitializeEntities() SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // RotateYGizmo - RotateYGizmoEntity = SCENE.AddNewStyleEntity("RotateYGizmoEntity"); + RotateYGizmoEntity = SCENE.AddEntity("RotateYGizmoEntity"); RotateYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateYGizmoGM")[0]); RotateYGizmoEntity->SetName("RotateYGizmoEntity"); RotateYGizmoEntity->GetComponent().SetCastShadows(false); @@ -1238,7 +1207,7 @@ void GizmoManager::ReInitializeEntities() SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); // RotateZGizmo - RotateZGizmoEntity = SCENE.AddNewStyleEntity("RotateZGizmoEntity"); + RotateZGizmoEntity = SCENE.AddEntity("RotateZGizmoEntity"); RotateZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateZGizmoGM")[0]); RotateZGizmoEntity->SetName("RotateZGizmoEntity"); RotateZGizmoEntity->GetComponent().SetCastShadows(false); diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index 1971ac8..d947aa0 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -19,7 +19,7 @@ void FEEditorPreviewManager::InitializeResources() PreviewFB = RESOURCE_MANAGER.CreateFramebuffer(FE_COLOR_ATTACHMENT | FE_DEPTH_ATTACHMENT, 128, 128); PreviewGameModel = new FEGameModel(nullptr, nullptr, "editorPreviewGameModel"); PreviewPrefab = new FEPrefab(PreviewGameModel, "editorPreviewPrefab"); - PreviewEntity = SCENE.AddNewStyleEntity("editorPreviewEntity"); + PreviewEntity = SCENE.AddEntity("editorPreviewEntity"); PreviewEntity->AddComponent(PreviewGameModel).SetVisibility(false); MeshPreviewMaterial = RESOURCE_MANAGER.CreateMaterial("meshPreviewMaterial"); RESOURCE_MANAGER.MakeMaterialStandard(MeshPreviewMaterial); @@ -32,12 +32,22 @@ void FEEditorPreviewManager::InitializeResources() "607A53601357077F03770357"/*"FEMeshPreviewShader"*/); RESOURCE_MANAGER.MakeShaderStandard(MeshPreviewMaterial->Shader); + + //LocalLightEntity = SCENE.AddEntity("EditorPreview LightEntity"); + //FELightComponent& LightComponent = LocalLightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); + //LocalLightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); + //LightComponent.SetIntensity(10.0f); } void FEEditorPreviewManager::ReInitializeEntities() { - PreviewEntity = SCENE.AddNewStyleEntity("editorPreviewEntity"); + PreviewEntity = SCENE.AddEntity("editorPreviewEntity"); PreviewEntity->AddComponent(PreviewGameModel).SetVisibility(false); + + /*LocalLightEntity = SCENE.AddEntity("EditorPreview LightEntity"); + FELightComponent& LightComponent = LocalLightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); + LocalLightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); + LightComponent.SetIntensity(10.0f);*/ } void FEEditorPreviewManager::UpdateAll() @@ -96,6 +106,37 @@ void FEEditorPreviewManager::BeforePreviewActions() ENGINE.GetCamera()->SetYaw(0.0f); PreviewEntity->GetComponent().SetVisibility(true); + + FEEntity* CurrentLightEntity = nullptr; + std::vector< std::string> LightsIDList = SCENE.GetEntityIDListWith(); + for (size_t i = 0; i < LightsIDList.size(); i++) + { + FEEntity* LightEntity = SCENE.GetEntity(LightsIDList[i]); + FETransformComponent& TransformComponent = LightEntity->GetComponent(); + FELightComponent& LightComponent = LightEntity->GetComponent(); + + if (LightComponent.GetType() == FE_DIRECTIONAL_LIGHT) + { + CurrentLightEntity = LightEntity; + break; + } + } + FETransformComponent& TransformComponent = CurrentLightEntity->GetComponent(); + FELightComponent& LightComponent = CurrentLightEntity->GetComponent(); + + RegularLightWorldMatrix = TransformComponent.GetWorldMatrix(); + + RegularLightRotation = TransformComponent.GetRotation(); + TransformComponent.SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); + TransformComponent.ForceSetWorldMatrix(TransformComponent.GetLocalMatrix()); + + RegularLightIntensity = LightComponent.GetIntensity(); + LightComponent.SetIntensity(10.0f); + + //LocalLightEntity->GetComponent().SetLightEnabled(true); + + bIsRegularFogEnabled = RENDERER.IsDistanceFogEnabled(); + RENDERER.SetDistanceFogEnabled(false); } void FEEditorPreviewManager::AfterPreviewActions() @@ -114,6 +155,30 @@ void FEEditorPreviewManager::AfterPreviewActions() ENGINE.SetClearColor(OriginalClearColor); PreviewEntity->GetComponent().SetVisibility(false); + //LocalLightEntity->GetComponent().SetLightEnabled(false); + + FEEntity* CurrentLightEntity = nullptr; + std::vector< std::string> LightsIDList = SCENE.GetEntityIDListWith(); + for (size_t i = 0; i < LightsIDList.size(); i++) + { + FEEntity* LightEntity = SCENE.GetEntity(LightsIDList[i]); + FETransformComponent& TransformComponent = LightEntity->GetComponent(); + FELightComponent& LightComponent = LightEntity->GetComponent(); + + if (LightComponent.GetType() == FE_DIRECTIONAL_LIGHT) + { + CurrentLightEntity = LightEntity; + break; + } + } + FETransformComponent& TransformComponent = CurrentLightEntity->GetComponent(); + FELightComponent& LightComponent = CurrentLightEntity->GetComponent(); + + TransformComponent.SetRotation(RegularLightRotation); + TransformComponent.ForceSetWorldMatrix(RegularLightWorldMatrix); + LightComponent.SetIntensity(RegularLightIntensity); + + RENDERER.SetDistanceFogEnabled(bIsRegularFogEnabled); } void FEEditorPreviewManager::CreateMeshPreview(const std::string MeshID) @@ -127,9 +192,8 @@ void FEEditorPreviewManager::CreateMeshPreview(const std::string MeshID) BeforePreviewActions(); - //FEAABB MeshAABB = PreviewEntity->GetAABB(); FEAABB MeshAABB = PreviewEntity->GetComponent().GameModel->Mesh->GetAABB(); - MeshAABB.Transform(PreviewEntity->GetComponent().GetTransformMatrix()); + MeshAABB.Transform(PreviewEntity->GetComponent().GetWorldMatrix()); const glm::vec3 Min = MeshAABB.GetMin(); const glm::vec3 Max = MeshAABB.GetMax(); @@ -137,22 +201,6 @@ void FEEditorPreviewManager::CreateMeshPreview(const std::string MeshID) const float YSize = sqrt((Max.y - Min.y) * (Max.y - Min.y)); const float ZSize = sqrt((Max.z - Min.z) * (Max.z - Min.z)); - FEDirectionalLight* CurrentDirectionalLight = nullptr; - const std::vector LightList = SCENE.GetLightsList(); - for (size_t i = 0; i < LightList.size(); i++) - { - if (SCENE.GetLight(LightList[i])->GetType() == FE_DIRECTIONAL_LIGHT) - { - CurrentDirectionalLight = reinterpret_cast(SCENE.GetLight(LightList[i])); - break; - } - } - const glm::vec3 RegularLightRotation = CurrentDirectionalLight->Transform.GetRotation(); - CurrentDirectionalLight->Transform.SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); - - const float RegularLightIntensity = CurrentDirectionalLight->GetIntensity(); - CurrentDirectionalLight->SetIntensity(10.0f); - // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. PreviewEntity->GetComponent().SetPosition(-glm::vec3(Max.x - XSize / 2.0f, Max.y - YSize / 2.0f, Max.z - ZSize / 2.0f)); ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); @@ -160,9 +208,6 @@ void FEEditorPreviewManager::CreateMeshPreview(const std::string MeshID) // Rendering mesh to texture. RENDERER.RenderGameModelComponent(PreviewEntity->GetComponent(), PreviewEntity->GetComponent(), ENGINE.GetCamera()); - CurrentDirectionalLight->Transform.SetRotation(RegularLightRotation); - CurrentDirectionalLight->SetIntensity(RegularLightIntensity); - AfterPreviewActions(); // if we are updating preview we should delete old texture. @@ -210,22 +255,6 @@ void FEEditorPreviewManager::CreateMaterialPreview(const std::string MaterialID) if (PreviewMaterial == nullptr) return; - FEDirectionalLight* CurrentDirectionalLight = nullptr; - const std::vector LightList = SCENE.GetLightsList(); - for (size_t i = 0; i < LightList.size(); i++) - { - if (SCENE.GetLight(LightList[i])->GetType() == FE_DIRECTIONAL_LIGHT) - { - CurrentDirectionalLight = reinterpret_cast(SCENE.GetLight(LightList[i])); - break; - } - } - const glm::vec3 RegularLightRotation = CurrentDirectionalLight->Transform.GetRotation(); - CurrentDirectionalLight->Transform.SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); - - const float RegularLightIntensity = CurrentDirectionalLight->GetIntensity(); - CurrentDirectionalLight->SetIntensity(10.0f); - PreviewGameModel->Mesh = RESOURCE_MANAGER.GetMesh("7F251E3E0D08013E3579315F"/*"sphere"*/); PreviewGameModel->Material = PreviewMaterial; PreviewEntity->GetComponent().SetReceivingShadows(false); @@ -236,9 +265,6 @@ void FEEditorPreviewManager::CreateMaterialPreview(const std::string MaterialID) // Rendering material to texture RENDERER.RenderGameModelComponentForward(PreviewEntity->GetComponent(), PreviewEntity->GetComponent(), ENGINE.GetCamera(), true); - CurrentDirectionalLight->Transform.SetRotation(RegularLightRotation); - CurrentDirectionalLight->SetIntensity(RegularLightIntensity); - AfterPreviewActions(); // if we are updating preview we should delete old texture. @@ -316,25 +342,6 @@ void FEEditorPreviewManager::CreateGameModelPreview(const std::string GameModelI if (GameModel == nullptr) return; - FEDirectionalLight* CurrentDirectionalLight = nullptr; - const std::vector LightList = SCENE.GetLightsList(); - for (size_t i = 0; i < LightList.size(); i++) - { - if (SCENE.GetLight(LightList[i])->GetType() == FE_DIRECTIONAL_LIGHT) - { - CurrentDirectionalLight = reinterpret_cast(SCENE.GetLight(LightList[i])); - break; - } - } - const glm::vec3 RegularLightRotation = CurrentDirectionalLight->Transform.GetRotation(); - CurrentDirectionalLight->Transform.SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); - - const float RegularLightIntensity = CurrentDirectionalLight->GetIntensity(); - CurrentDirectionalLight->SetIntensity(10.0f); - - const bool RegularFog = RENDERER.IsDistanceFogEnabled(); - RENDERER.SetDistanceFogEnabled(false); - PreviewGameModel->Mesh = GameModel->Mesh; PreviewGameModel->Material = GameModel->Material; PreviewEntity->GetComponent().SetReceivingShadows(false); @@ -342,7 +349,7 @@ void FEEditorPreviewManager::CreateGameModelPreview(const std::string GameModelI //FEAABB MeshAABB = PreviewEntity->GetAABB(); FEAABB MeshAABB = PreviewEntity->GetComponent().GameModel->Mesh->GetAABB(); - MeshAABB.Transform(PreviewEntity->GetComponent().GetTransformMatrix()); + MeshAABB.Transform(PreviewEntity->GetComponent().GetWorldMatrix()); const glm::vec3 min = MeshAABB.GetMin(); const glm::vec3 max = MeshAABB.GetMax(); @@ -357,11 +364,6 @@ void FEEditorPreviewManager::CreateGameModelPreview(const std::string GameModelI // rendering game model to texture RENDERER.RenderGameModelComponentForward(PreviewEntity->GetComponent(), PreviewEntity->GetComponent(), ENGINE.GetCamera(), true); - CurrentDirectionalLight->Transform.SetRotation(RegularLightRotation); - CurrentDirectionalLight->SetIntensity(RegularLightIntensity); - - RENDERER.SetDistanceFogEnabled(RegularFog); - AfterPreviewActions(); // if we are updating preview we should delete old texture. @@ -377,22 +379,6 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel if (GameModel == nullptr) return; - FEDirectionalLight* CurrentDirectionalLight = nullptr; - const std::vector LightList = SCENE.GetLightsList(); - for (size_t i = 0; i < LightList.size(); i++) - { - if (SCENE.GetLight(LightList[i])->GetType() == FE_DIRECTIONAL_LIGHT) - { - CurrentDirectionalLight = reinterpret_cast(SCENE.GetLight(LightList[i])); - break; - } - } - const glm::vec3 RegularLightRotation = CurrentDirectionalLight->Transform.GetRotation(); - CurrentDirectionalLight->Transform.SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); - - const float RegularLightIntensity = CurrentDirectionalLight->GetIntensity(); - CurrentDirectionalLight->SetIntensity(10.0f); - PreviewGameModel->Mesh = GameModel->Mesh; PreviewGameModel->Material = GameModel->Material; PreviewEntity->GetComponent().SetReceivingShadows(false); @@ -405,7 +391,7 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel //FEAABB MeshAABB = PreviewEntity->GetAABB(); FEAABB MeshAABB = PreviewEntity->GetComponent().GameModel->Mesh->GetAABB(); - MeshAABB.Transform(PreviewEntity->GetComponent().GetTransformMatrix()); + MeshAABB.Transform(PreviewEntity->GetComponent().GetWorldMatrix()); const glm::vec3 min = MeshAABB.GetMin(); const glm::vec3 max = MeshAABB.GetMax(); @@ -420,9 +406,6 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel // rendering game model to texture RENDERER.RenderGameModelComponentForward(PreviewEntity->GetComponent(), PreviewEntity->GetComponent(), ENGINE.GetCamera(), true); - CurrentDirectionalLight->Transform.SetRotation(RegularLightRotation); - CurrentDirectionalLight->SetIntensity(RegularLightIntensity); - AfterPreviewActions(); PreviewFB->SetColorAttachment(TempTexture); @@ -481,25 +464,6 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) if (GameModel == nullptr) return; - FEDirectionalLight* CurrentDirectionalLight = nullptr; - const std::vector LightList = SCENE.GetLightsList(); - for (size_t i = 0; i < LightList.size(); i++) - { - if (SCENE.GetLight(LightList[i])->GetType() == FE_DIRECTIONAL_LIGHT) - { - CurrentDirectionalLight = reinterpret_cast(SCENE.GetLight(LightList[i])); - break; - } - } - const glm::vec3 RegularLightRotation = CurrentDirectionalLight->Transform.GetRotation(); - CurrentDirectionalLight->Transform.SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); - - const float RegularLightIntensity = CurrentDirectionalLight->GetIntensity(); - CurrentDirectionalLight->SetIntensity(10.0f); - - const bool RegularFog = RENDERER.IsDistanceFogEnabled(); - RENDERER.SetDistanceFogEnabled(false); - //Fix ME! //PreviewEntity->Prefab = Prefab; PreviewEntity->GetComponent().GameModel = GameModel; @@ -509,7 +473,7 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) //PreviewEntity->SetDirtyFlag(true); //FEAABB MeshAABB = PreviewEntity->GetAABB(); FEAABB MeshAABB = PreviewEntity->GetComponent().GameModel->Mesh->GetAABB(); - MeshAABB.Transform(PreviewEntity->GetComponent().GetTransformMatrix()); + MeshAABB.Transform(PreviewEntity->GetComponent().GetWorldMatrix()); const glm::vec3 min = MeshAABB.GetMin(); const glm::vec3 max = MeshAABB.GetMax(); @@ -527,11 +491,6 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) //PreviewEntity->Prefab = PreviewPrefab; PreviewEntity->GetComponent().GameModel = PreviewGameModel; - CurrentDirectionalLight->Transform.SetRotation(RegularLightRotation); - CurrentDirectionalLight->SetIntensity(RegularLightIntensity); - - RENDERER.SetDistanceFogEnabled(RegularFog); - AfterPreviewActions(); // if we are updating preview we should delete old texture. @@ -586,27 +545,27 @@ FETexture* FEEditorPreviewManager::GetPrefabPreview(const std::string PrefabID) void FEEditorPreviewManager::Clear() { - auto iterator = MeshPreviewTextures.begin(); - while (iterator != MeshPreviewTextures.end()) + auto MeshIterator = MeshPreviewTextures.begin(); + while (MeshIterator != MeshPreviewTextures.end()) { - delete iterator->second; - iterator++; + delete MeshIterator->second; + MeshIterator++; } MeshPreviewTextures.clear(); - iterator = MaterialPreviewTextures.begin(); - while (iterator != MaterialPreviewTextures.end()) + auto MaterialIterator = MaterialPreviewTextures.begin(); + while (MaterialIterator != MaterialPreviewTextures.end()) { - delete iterator->second; - iterator++; + delete MaterialIterator->second; + MaterialIterator++; } MaterialPreviewTextures.clear(); - iterator = GameModelPreviewTextures.begin(); - while (iterator != GameModelPreviewTextures.end()) + auto GameModelIterator = GameModelPreviewTextures.begin(); + while (GameModelIterator != GameModelPreviewTextures.end()) { - delete iterator->second; - iterator++; + delete GameModelIterator->second; + GameModelIterator++; } GameModelPreviewTextures.clear(); } diff --git a/FEEditorPreviewManager.h b/FEEditorPreviewManager.h index 459df4b..dd1beec 100644 --- a/FEEditorPreviewManager.h +++ b/FEEditorPreviewManager.h @@ -35,6 +35,16 @@ class FEEditorPreviewManager FEGameModel* PreviewGameModel; FEMaterial* MeshPreviewMaterial; + // FIX ME! Make it work. + // Local directional entity + //FEEntity* LocalLightEntity; + + // Saved scene settings + glm::vec3 RegularLightRotation = glm::vec3(0.0f, 0.0f, 0.0f); + float RegularLightIntensity = 0.0f; + glm::mat4 RegularLightWorldMatrix = glm::identity(); + bool bIsRegularFogEnabled = false; + std::unordered_map MeshPreviewTextures; std::unordered_map MaterialPreviewTextures; std::unordered_map GameModelPreviewTextures; diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index 70a681c..4e35d7e 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -39,7 +39,7 @@ void FEEditorSelectedObject::InitializeResources() const FEShaderParam ColorParam(glm::vec3(0.0f, 0.0f, 0.0f), "baseColor"); PixelAccurateSelectionMaterial->AddParameter(ColorParam); - DummyEntity = SCENE.AddNewStyleEntity("Editor_Selection_Dummy_Entity"); + DummyEntity = SCENE.AddEntity("Editor_Selection_Dummy_Entity"); } void FEEditorSelectedObject::ReInitializeResources() @@ -52,7 +52,7 @@ void FEEditorSelectedObject::ReInitializeResources() PixelAccurateSelectionFB->SetColorAttachment(RESOURCE_MANAGER.CreateTexture(GL_RGB, GL_RGB, ENGINE.GetRenderTargetWidth(), ENGINE.GetRenderTargetHeight())); if (SCENE.GetEntityByName("Editor_Selection_Dummy_Entity").empty()) - DummyEntity = SCENE.AddNewStyleEntity("Editor_Selection_Dummy_Entity"); + DummyEntity = SCENE.AddEntity("Editor_Selection_Dummy_Entity"); } void FEEditorSelectedObject::SetOnUpdateFunc(void(*Func)()) @@ -127,65 +127,50 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons SELECTED.InstancedSubObjectsInfo.clear(); const glm::vec3 MouseRayVector = MouseRay(MouseX, MouseY); - const std::vector EntityList = SCENE.GetNewEntityList(); + const std::vector EntityList = SCENE.GetEntityIDList(); for (size_t i = 0; i < EntityList.size(); i++) { float Distance = 0; - FEEntity* NewStyleEntity = SCENE.GetNewStyleEntity(EntityList[i]); - if (NewStyleEntity != nullptr /*&& Entity->HasComponent()*/) + FEEntity* CurrentEntity = SCENE.GetEntity(EntityList[i]); + if (CurrentEntity != nullptr) { - //FEGameModelComponent& GameModelComponent = Entity->GetComponent(); - FEAABB Box; - if (NewStyleEntity->HasComponent() && !NewStyleEntity->HasComponent()) + if (CurrentEntity->HasComponent() && !CurrentEntity->HasComponent()) { - Box = NewStyleEntity->GetComponent().GameModel->GetMesh()->GetAABB().Transform(NewStyleEntity->GetComponent().GetTransformMatrix()); + Box = CurrentEntity->GetComponent().GameModel->GetMesh()->GetAABB().Transform(CurrentEntity->GetComponent().GetWorldMatrix()); } - else if (NewStyleEntity->HasComponent() && NewStyleEntity->HasComponent()) + else if (CurrentEntity->HasComponent() && CurrentEntity->HasComponent()) { - Box = INSTANCED_RENDERING_SYSTEM.GetAABB(NewStyleEntity); + Box = INSTANCED_RENDERING_SYSTEM.GetAABB(CurrentEntity); } - else if (NewStyleEntity->HasComponent()) + else if (CurrentEntity->HasComponent()) { - Box = TERRAIN_SYSTEM.GetAABB(NewStyleEntity); + Box = TERRAIN_SYSTEM.GetAABB(CurrentEntity); } if (Box.RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) { - if (NewStyleEntity->HasComponent()) + if (CurrentEntity->HasComponent()) { - FEInstancedComponent& InstancedComponent = NewStyleEntity->GetComponent(); - if (INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(NewStyleEntity)) + FEInstancedComponent& InstancedComponent = CurrentEntity->GetComponent(); + if (INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(CurrentEntity)) { - // Check ME! - InstancedSubObjectsInfo[NewStyleEntity] = std::vector(); + InstancedSubObjectsInfo[CurrentEntity] = std::vector(); for (size_t j = 0; j < InstancedComponent.IndividualInstancedAABB.size(); j++) { if (InstancedComponent.IndividualInstancedAABB[j].RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) { - InstancedSubObjectsInfo[NewStyleEntity].push_back(static_cast(j)); + InstancedSubObjectsInfo[CurrentEntity].push_back(static_cast(j)); } } } } - SELECTED.SceneEntitiesUnderMouse.push_back(NewStyleEntity); + SELECTED.SceneEntitiesUnderMouse.push_back(CurrentEntity); } } } - - // FIX ME! - /*const std::vector TerrainList = SCENE.GetTerrainList(); - for (size_t i = 0; i < TerrainList.size(); i++) - { - float Distance = 0; - FEAABB Box = SCENE.GetTerrain(TerrainList[i])->GetAABB(); - if (Box.RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) - { - SELECTED.SceneEntitiesUnderMouse.push_back(SCENE.GetTerrain(TerrainList[i])); - } - }*/ } int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, const double MouseY) @@ -279,7 +264,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons int g = ((LastColorShiftIndex + 1) >> 8) & 255; int b = ((LastColorShiftIndex + 1) >> 16) & 255; - static FEEntity* DummyEntity = SCENE.AddNewStyleEntity("DummyEntity"); + static FEEntity* DummyEntity = SCENE.AddEntity("DummyEntity"); if (!DummyEntity->HasComponent()) DummyEntity->AddComponent(); @@ -506,17 +491,4 @@ void FEEditorSelectedObject::SetSelectedByIndex(const size_t Index) Container = SceneEntitiesUnderMouse[Index]; if (OnUpdateFunc != nullptr) OnUpdateFunc(); -} - -FELight* FEEditorSelectedObject::GetLight() const -{ - if (Container == nullptr) - return nullptr; - - if (Container->GetType() == FE_DIRECTIONAL_LIGHT || Container->GetType() == FE_SPOT_LIGHT || Container->GetType() == FE_POINT_LIGHT) - { - return SCENE.GetLight(Container->GetObjectID()); - } - - return nullptr; } \ No newline at end of file diff --git a/FEEditorSelectedObject.h b/FEEditorSelectedObject.h index bd385f4..9329dcf 100644 --- a/FEEditorSelectedObject.h +++ b/FEEditorSelectedObject.h @@ -19,7 +19,6 @@ class FEEditorSelectedObject void SetOnUpdateFunc(void(*Func)()); FEEntity* GetSelected() const; - FELight* GetLight() const; bool GetDirtyFlag() const; void SetDirtyFlag(bool NewValue); diff --git a/FEProject.cpp b/FEProject.cpp index da33abc..bf2fd45 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -674,11 +674,11 @@ void FEProject::SaveScene(bool bFullSave) //Root["entities"] = EntityData; // Saving Terrains. - std::vector TerrainList = SCENE.GetTerrainList(); + std::vector TerrainList = SCENE.GetEntityIDListWith(); Json::Value TerrainData; for (size_t i = 0; i < TerrainList.size(); i++) { - FEEntity* Terrain = SCENE.GetNewStyleEntity(TerrainList[i]); + FEEntity* Terrain = SCENE.GetEntity(TerrainList[i]); FETerrainComponent& TerrainComponent = Terrain->GetComponent(); TerrainData[Terrain->GetObjectID()]["ID"] = Terrain->GetObjectID(); @@ -730,60 +730,60 @@ void FEProject::SaveScene(bool bFullSave) } Root["terrains"] = TerrainData; - // Saving Lights. - std::vector LightList = SCENE.GetLightsList(); - Json::Value LightData; - for (size_t i = 0; i < LightList.size(); i++) - { - FELight* Light = SCENE.GetLight(LightList[i]); - - // general light information - LightData[Light->GetObjectID()]["ID"] = Light->GetObjectID(); - LightData[Light->GetObjectID()]["type"] = Light->GetType(); - LightData[Light->GetObjectID()]["name"] = Light->GetName(); - LightData[Light->GetObjectID()]["intensity"] = Light->GetIntensity(); - WriteTransformToJson(LightData[Light->GetObjectID()]["transformation"], &Light->Transform); - LightData[Light->GetObjectID()]["castShadows"] = Light->IsCastShadows(); - LightData[Light->GetObjectID()]["enabled"] = Light->IsLightEnabled(); - LightData[Light->GetObjectID()]["color"]["R"] = Light->GetColor()[0]; - LightData[Light->GetObjectID()]["color"]["G"] = Light->GetColor()[1]; - LightData[Light->GetObjectID()]["color"]["B"] = Light->GetColor()[2]; - LightData[Light->GetObjectID()]["staticShadowBias"] = Light->IsStaticShadowBias(); - LightData[Light->GetObjectID()]["shadowBias"] = Light->GetShadowBias(); - LightData[Light->GetObjectID()]["shadowBiasVariableIntensity"] = Light->GetShadowBiasVariableIntensity(); - LightData[Light->GetObjectID()]["shadowBlurFactor"] = Light->GetShadowBlurFactor(); - - // Type specific information. - if (Light->GetType() == FE_DIRECTIONAL_LIGHT) - { - FEDirectionalLight* DirectionalLight = reinterpret_cast(Light); - - LightData[DirectionalLight->GetObjectID()]["direction"]["X"] = DirectionalLight->GetDirection()[0]; - LightData[DirectionalLight->GetObjectID()]["direction"]["Y"] = DirectionalLight->GetDirection()[1]; - LightData[DirectionalLight->GetObjectID()]["direction"]["Z"] = DirectionalLight->GetDirection()[2]; - LightData[DirectionalLight->GetObjectID()]["CSM"]["activeCascades"] = DirectionalLight->GetActiveCascades(); - LightData[DirectionalLight->GetObjectID()]["CSM"]["shadowCoverage"] = DirectionalLight->GetShadowCoverage(); - LightData[DirectionalLight->GetObjectID()]["CSM"]["CSMZDepth"] = DirectionalLight->GetCSMZDepth(); - LightData[DirectionalLight->GetObjectID()]["CSM"]["CSMXYDepth"] = DirectionalLight->GetCSMXYDepth(); - } - else if (Light->GetType() == FE_SPOT_LIGHT) - { - FESpotLight* SpotLight = reinterpret_cast(Light); + //// Saving Lights. + //std::vector LightList = SCENE.GetLightsList(); + //Json::Value LightData; + //for (size_t i = 0; i < LightList.size(); i++) + //{ + // FELight* Light = SCENE.GetLight(LightList[i]); + + // // general light information + // LightData[Light->GetObjectID()]["ID"] = Light->GetObjectID(); + // LightData[Light->GetObjectID()]["type"] = Light->GetType(); + // LightData[Light->GetObjectID()]["name"] = Light->GetName(); + // LightData[Light->GetObjectID()]["intensity"] = Light->GetIntensity(); + // WriteTransformToJson(LightData[Light->GetObjectID()]["transformation"], &Light->Transform); + // LightData[Light->GetObjectID()]["castShadows"] = Light->IsCastShadows(); + // LightData[Light->GetObjectID()]["enabled"] = Light->IsLightEnabled(); + // LightData[Light->GetObjectID()]["color"]["R"] = Light->GetColor()[0]; + // LightData[Light->GetObjectID()]["color"]["G"] = Light->GetColor()[1]; + // LightData[Light->GetObjectID()]["color"]["B"] = Light->GetColor()[2]; + // LightData[Light->GetObjectID()]["staticShadowBias"] = Light->IsStaticShadowBias(); + // LightData[Light->GetObjectID()]["shadowBias"] = Light->GetShadowBias(); + // LightData[Light->GetObjectID()]["shadowBiasVariableIntensity"] = Light->GetShadowBiasVariableIntensity(); + // LightData[Light->GetObjectID()]["shadowBlurFactor"] = Light->GetShadowBlurFactor(); + + // // Type specific information. + // if (Light->GetType() == FE_DIRECTIONAL_LIGHT) + // { + // FEDirectionalLight* DirectionalLight = reinterpret_cast(Light); + + // LightData[DirectionalLight->GetObjectID()]["direction"]["X"] = DirectionalLight->GetDirection()[0]; + // LightData[DirectionalLight->GetObjectID()]["direction"]["Y"] = DirectionalLight->GetDirection()[1]; + // LightData[DirectionalLight->GetObjectID()]["direction"]["Z"] = DirectionalLight->GetDirection()[2]; + // LightData[DirectionalLight->GetObjectID()]["CSM"]["activeCascades"] = DirectionalLight->GetActiveCascades(); + // LightData[DirectionalLight->GetObjectID()]["CSM"]["shadowCoverage"] = DirectionalLight->GetShadowCoverage(); + // LightData[DirectionalLight->GetObjectID()]["CSM"]["CSMZDepth"] = DirectionalLight->GetCSMZDepth(); + // LightData[DirectionalLight->GetObjectID()]["CSM"]["CSMXYDepth"] = DirectionalLight->GetCSMXYDepth(); + // } + // else if (Light->GetType() == FE_SPOT_LIGHT) + // { + // FESpotLight* SpotLight = reinterpret_cast(Light); - LightData[SpotLight->GetObjectID()]["spotAngle"] = SpotLight->GetSpotAngle(); - LightData[SpotLight->GetObjectID()]["spotAngleOuter"] = SpotLight->GetSpotAngleOuter(); - LightData[SpotLight->GetObjectID()]["direction"]["X"] = SpotLight->GetDirection()[0]; - LightData[SpotLight->GetObjectID()]["direction"]["Y"] = SpotLight->GetDirection()[1]; - LightData[SpotLight->GetObjectID()]["direction"]["Z"] = SpotLight->GetDirection()[2]; - } - else if (Light->GetType() == FE_POINT_LIGHT) - { - FEPointLight* PointLight = reinterpret_cast(Light); + // LightData[SpotLight->GetObjectID()]["spotAngle"] = SpotLight->GetSpotAngle(); + // LightData[SpotLight->GetObjectID()]["spotAngleOuter"] = SpotLight->GetSpotAngleOuter(); + // LightData[SpotLight->GetObjectID()]["direction"]["X"] = SpotLight->GetDirection()[0]; + // LightData[SpotLight->GetObjectID()]["direction"]["Y"] = SpotLight->GetDirection()[1]; + // LightData[SpotLight->GetObjectID()]["direction"]["Z"] = SpotLight->GetDirection()[2]; + // } + // else if (Light->GetType() == FE_POINT_LIGHT) + // { + // FEPointLight* PointLight = reinterpret_cast(Light); - LightData[PointLight->GetObjectID()]["range"] = PointLight->GetRange(); - } - } - Root["lights"] = LightData; + // LightData[PointLight->GetObjectID()]["range"] = PointLight->GetRange(); + // } + //} + //Root["lights"] = LightData; // Saving Effects settings. Json::Value EffectsData; @@ -1046,10 +1046,10 @@ void FEProject::LoadScene() std::vector TerrainList = Root["terrains"].getMemberNames(); for (size_t i = 0; i < TerrainList.size(); i++) { - FEEntity* NewEntity = SCENE.AddNewStyleEntity(Root["terrains"][TerrainList[i]]["name"].asString(), Root["terrains"][TerrainList[i]]["ID"].asString()); - FETransformComponent& TransformComponent = NewEntity->GetComponent(); - FETerrainComponent& TerrainComponent = NewEntity->AddComponent(); - TERRAIN_SYSTEM.LoadHeightMap((ProjectFolder + Root["terrains"][TerrainList[i]]["heightMap"]["fileName"].asCString()).c_str(), NewEntity); + FEEntity* Entity = SCENE.AddEntity(Root["terrains"][TerrainList[i]]["name"].asString(), Root["terrains"][TerrainList[i]]["ID"].asString()); + FETransformComponent& TransformComponent = Entity->GetComponent(); + FETerrainComponent& TerrainComponent = Entity->AddComponent(); + TERRAIN_SYSTEM.LoadHeightMap((ProjectFolder + Root["terrains"][TerrainList[i]]["heightMap"]["fileName"].asCString()).c_str(), Entity); TerrainComponent.SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); TerrainComponent.SetDisplacementScale(Root["terrains"][TerrainList[i]]["displacementScale"].asFloat()); @@ -1078,7 +1078,7 @@ void FEProject::LoadScene() { if (Root["terrains"][TerrainList[i]]["layers"][j]["acive"].asBool()) { - TERRAIN_SYSTEM.ActivateVacantLayerSlot(NewEntity, RESOURCE_MANAGER.GetMaterial(Root["terrains"][TerrainList[i]]["layers"][j]["materialID"].asCString())); + TERRAIN_SYSTEM.ActivateVacantLayerSlot(Entity, RESOURCE_MANAGER.GetMaterial(Root["terrains"][TerrainList[i]]["layers"][j]["materialID"].asCString())); TerrainComponent.GetLayerInSlot(j)->SetName(Root["terrains"][TerrainList[i]]["layers"][j]["name"].asCString()); } } @@ -1089,96 +1089,111 @@ void FEProject::LoadScene() std::vector EntityList = Root["entities"].getMemberNames(); for (size_t i = 0; i < EntityList.size(); i++) { - FEEntity* NewEntity = SCENE.AddNewStyleEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + FEEntity* Entity = SCENE.AddEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); if (Root["entities"][EntityList[i]].isMember("type")) { if (Root["entities"][EntityList[i]]["type"] == "FE_ENTITY_INSTANCED") { - FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString())->GetComponent(0)->GameModel; - FEGameModelComponent& GameModelComponent = NewEntity->AddComponent(GameModel); - FEInstancedComponent& InstancedComponent = NewEntity->AddComponent(); - - if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) - GameModelComponent.SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); - - ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &NewEntity->GetComponent()); - - FESpawnInfo SpawnInfo; - SpawnInfo.Seed = Root["entities"][EntityList[i]]["spawnInfo"]["seed"].asInt(); - SpawnInfo.ObjectCount = Root["entities"][EntityList[i]]["spawnInfo"]["objectCount"].asInt(); - SpawnInfo.Radius = Root["entities"][EntityList[i]]["spawnInfo"]["radius"].asFloat(); - SpawnInfo.SetMinScale(Root["entities"][EntityList[i]]["spawnInfo"]["minScale"].asFloat()); - SpawnInfo.SetMaxScale(Root["entities"][EntityList[i]]["spawnInfo"]["maxScale"].asFloat()); - SpawnInfo.RotationDeviation.x = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.x"].asFloat(); - SpawnInfo.RotationDeviation.y = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.y"].asFloat(); - SpawnInfo.RotationDeviation.z = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.z"].asFloat(); - - if (Root["entities"][EntityList[i]]["snappedToTerrain"].asString() != "none") + // FIX ME! Converting Prefab to GameModels. + FEEntity* EntityWithFirstPrefab = Entity; + FEPrefab* OldPrefab = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()); + for (size_t c = 0; c < OldPrefab->ComponentsCount(); c++) { - FEEntity* TerrainEntity = SCENE.GetNewStyleEntity(Root["entities"][EntityList[i]]["snappedToTerrain"].asString()); - TERRAIN_SYSTEM.SnapInstancedEntity(TerrainEntity, NewEntity); - - if (Root["entities"][EntityList[i]].isMember("terrainLayer")) + if (c > 0) + { + Entity = SCENE.AddEntity(Root["entities"][EntityList[i]]["name"].asString() + "_Prefabs_" + std::to_string(c)); + } + FEPrefabComponent* CurrentComponent = OldPrefab->GetComponent(static_cast(c)); + FEGameModel* GameModel = CurrentComponent->GameModel; + + //FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString())->GetComponent(0)->GameModel; + FEGameModelComponent& GameModelComponent = Entity->AddComponent(GameModel); + FEInstancedComponent& InstancedComponent = Entity->AddComponent(); + + if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) + GameModelComponent.SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); + + ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &Entity->GetComponent()); + // FIX ME! + Entity->GetComponent().Combine(CurrentComponent->Transform); + + FESpawnInfo SpawnInfo; + SpawnInfo.Seed = Root["entities"][EntityList[i]]["spawnInfo"]["seed"].asInt(); + SpawnInfo.ObjectCount = Root["entities"][EntityList[i]]["spawnInfo"]["objectCount"].asInt(); + SpawnInfo.Radius = Root["entities"][EntityList[i]]["spawnInfo"]["radius"].asFloat(); + SpawnInfo.SetMinScale(Root["entities"][EntityList[i]]["spawnInfo"]["minScale"].asFloat()); + SpawnInfo.SetMaxScale(Root["entities"][EntityList[i]]["spawnInfo"]["maxScale"].asFloat()); + SpawnInfo.RotationDeviation.x = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.x"].asFloat(); + SpawnInfo.RotationDeviation.y = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.y"].asFloat(); + SpawnInfo.RotationDeviation.z = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.z"].asFloat(); + + if (Root["entities"][EntityList[i]]["snappedToTerrain"].asString() != "none") { - if (Root["entities"][EntityList[i]]["terrainLayer"].asInt() != -1) + FEEntity* TerrainEntity = SCENE.GetEntity(Root["entities"][EntityList[i]]["snappedToTerrain"].asString()); + TERRAIN_SYSTEM.SnapInstancedEntity(TerrainEntity, Entity); + + if (Root["entities"][EntityList[i]].isMember("terrainLayer")) { - TERRAIN_SYSTEM.ConnectInstancedEntityToLayer(TerrainEntity, NewEntity, Root["entities"][EntityList[i]]["terrainLayer"].asInt()); - } + if (Root["entities"][EntityList[i]]["terrainLayer"].asInt() != -1) + { + TERRAIN_SYSTEM.ConnectInstancedEntityToLayer(TerrainEntity, Entity, Root["entities"][EntityList[i]]["terrainLayer"].asInt()); + } - InstancedComponent.SetMinimalLayerIntensityToSpawn(Root["entities"][EntityList[i]]["minimalLayerIntensity"].asFloat()); + InstancedComponent.SetMinimalLayerIntensityToSpawn(Root["entities"][EntityList[i]]["minimalLayerIntensity"].asFloat()); + } } - } - INSTANCED_RENDERING_SYSTEM.PopulateInstance(NewEntity, SpawnInfo); + INSTANCED_RENDERING_SYSTEM.PopulateInstance(Entity, SpawnInfo); - if (Root["entities"][EntityList[i]]["modificationsToSpawn"].asBool()) - { - std::ifstream InfoFile; - InfoFile.open(ProjectFolder + NewEntity->GetObjectID() + ".txt"); + if (Root["entities"][EntityList[i]]["modificationsToSpawn"].asBool()) + { + std::ifstream InfoFile; + InfoFile.open(ProjectFolder + EntityWithFirstPrefab->GetObjectID() + ".txt"); - std::string InfoFileData((std::istreambuf_iterator(InfoFile)), std::istreambuf_iterator()); + std::string InfoFileData((std::istreambuf_iterator(InfoFile)), std::istreambuf_iterator()); - Json::Value EntityFileRoot; - JSONCPP_STRING Err; - Json::CharReaderBuilder Builder; + Json::Value EntityFileRoot; + JSONCPP_STRING Err; + Json::CharReaderBuilder Builder; - const std::unique_ptr Reader(Builder.newCharReader()); - if (!Reader->parse(InfoFileData.c_str(), InfoFileData.c_str() + InfoFileData.size(), &EntityFileRoot, &Err)) - return; + const std::unique_ptr Reader(Builder.newCharReader()); + if (!Reader->parse(InfoFileData.c_str(), InfoFileData.c_str() + InfoFileData.size(), &EntityFileRoot, &Err)) + return; - size_t Count = EntityFileRoot["modifications"].size(); - for (int j = 0; j < Count; j++) - { - if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_DELETED) - { - INSTANCED_RENDERING_SYSTEM.DeleteIndividualInstance(NewEntity, EntityFileRoot["modifications"][j]["index"].asInt()); - } - else if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_MODIFIED) + size_t Count = EntityFileRoot["modifications"].size(); + for (int j = 0; j < Count; j++) { - glm::mat4 ModifedMatrix; - for (int k = 0; k < 4; k++) + if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_DELETED) + { + INSTANCED_RENDERING_SYSTEM.DeleteIndividualInstance(Entity, EntityFileRoot["modifications"][j]["index"].asInt()); + } + else if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_MODIFIED) { - for (int p = 0; p < 4; p++) + glm::mat4 ModifedMatrix; + for (int k = 0; k < 4; k++) { - ModifedMatrix[k][p] = EntityFileRoot["modifications"][j]["modification"][k][p].asFloat(); + for (int p = 0; p < 4; p++) + { + ModifedMatrix[k][p] = EntityFileRoot["modifications"][j]["modification"][k][p].asFloat(); + } } - } - INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(NewEntity, EntityFileRoot["modifications"][j]["index"].asInt(), ModifedMatrix); - } - else if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_ADDED) - { - glm::mat4 ModifedMatrix; - for (int k = 0; k < 4; k++) + INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(Entity, EntityFileRoot["modifications"][j]["index"].asInt(), ModifedMatrix); + } + else if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_ADDED) { - for (int p = 0; p < 4; p++) + glm::mat4 ModifedMatrix; + for (int k = 0; k < 4; k++) { - ModifedMatrix[k][p] = EntityFileRoot["modifications"][j]["modification"][k][p].asFloat(); + for (int p = 0; p < 4; p++) + { + ModifedMatrix[k][p] = EntityFileRoot["modifications"][j]["modification"][k][p].asFloat(); + } } - } - INSTANCED_RENDERING_SYSTEM.AddIndividualInstance(NewEntity, ModifedMatrix); + INSTANCED_RENDERING_SYSTEM.AddIndividualInstance(Entity, ModifedMatrix); + } } } } @@ -1192,7 +1207,7 @@ void FEProject::LoadScene() //SCENE.AddEntity(TempPrefab, Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); FEGameModel* GameModel = RESOURCE_MANAGER.GetGameModel(Root["entities"][EntityList[i]]["gameModel"].asCString()); - NewEntity->AddComponent(GameModel); + Entity->AddComponent(GameModel); } else { @@ -1201,31 +1216,31 @@ void FEProject::LoadScene() Root["entities"][EntityList[i]]["ID"].asString());*/ FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString())->GetComponent(0)->GameModel; - NewEntity->AddComponent(GameModel); + Entity->AddComponent(GameModel); } if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) { //SCENE.GetEntity(EntityList[i])->SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); - NewEntity->GetComponent().SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); + Entity->GetComponent().SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); } - ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &NewEntity->GetComponent()); + ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &Entity->GetComponent()); /*ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(EntityList[i])->Transform); - FEEntity* NewEntity = SCENE.GetNewStyleEntityByOldStyleID(EntityList[i]); - if (NewEntity != nullptr) + FEEntity* Entity = SCENE.GetNewStyleEntityByOldStyleID(EntityList[i]); + if (Entity != nullptr) { - NewEntity->GetComponent() = SCENE.GetEntity(EntityList[i])->Transform; + Entity->GetComponent() = SCENE.GetEntity(EntityList[i])->Transform; }*/ } } // For compatibility with old projects. else { - //FEEntity* NewEntity = SCENE.AddNewStyleEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + //FEEntity* Entity = SCENE.AddEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString())->GetComponent(0)->GameModel; - NewEntity->AddComponent(GameModel); - ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &NewEntity->GetComponent()); + Entity->AddComponent(GameModel); + ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &Entity->GetComponent()); /*SCENE.AddEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), EntityList[i], @@ -1236,58 +1251,63 @@ void FEProject::LoadScene() if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) { - int y = 0; - y++; // Loading scene hierarchy. SCENE.SceneGraph.FromJson(Root["sceneHierarchy"]); } - // loading Lights + // Loading Lights. std::vector LightList = Root["lights"].getMemberNames(); for (size_t i = 0; i < LightList.size(); i++) { - SCENE.AddLight(static_cast(Root["lights"][LightList[i]]["type"].asInt()), Root["lights"][LightList[i]]["name"].asCString(), Root["lights"][LightList[i]]["ID"].asCString()); - FELight* Light = SCENE.GetLight(LightList[i]); - - // general light information - Light->SetIntensity(Root["lights"][LightList[i]]["intensity"].asFloat()); - ReadTransformToJson(Root["lights"][LightList[i]]["transformation"], &Light->Transform); - Light->SetCastShadows(Root["lights"][LightList[i]]["castShadows"].asBool()); - Light->SetLightEnabled(Root["lights"][LightList[i]]["enabled"].asBool()); - Light->SetColor(glm::vec3(Root["lights"][LightList[i]]["color"]["R"].asFloat(), - Root["lights"][LightList[i]]["color"]["G"].asFloat(), - Root["lights"][LightList[i]]["color"]["B"].asFloat())); - Light->SetIsStaticShadowBias(Root["lights"][LightList[i]]["staticShadowBias"].asBool()); - Light->SetShadowBias(Root["lights"][LightList[i]]["shadowBias"].asFloat()); - Light->SetShadowBiasVariableIntensity(Root["lights"][LightList[i]]["shadowBiasVariableIntensity"].asFloat()); + FEEntity* Entity = SCENE.AddEntity("Light Entity"); + auto OldType = static_cast(Root["lights"][LightList[i]]["type"].asInt()); + FE_LIGHT_TYPE NewType = FE_DIRECTIONAL_LIGHT; + if (OldType == FE_POINT_LIGHT_DEPRECATED) + { + NewType = FE_POINT_LIGHT; + } + else if (OldType == FE_SPOT_LIGHT_DEPRECATED) + { + NewType = FE_SPOT_LIGHT; + } + FELightComponent& LightComponent = Entity->AddComponent(NewType); + + LightComponent.SetIntensity(Root["lights"][LightList[i]]["intensity"].asFloat()); + ReadTransformToJson(Root["lights"][LightList[i]]["transformation"], &Entity->GetComponent()); + LightComponent.SetCastShadows(Root["lights"][LightList[i]]["castShadows"].asBool()); + LightComponent.SetLightEnabled(Root["lights"][LightList[i]]["enabled"].asBool()); + LightComponent.SetColor(glm::vec3(Root["lights"][LightList[i]]["color"]["R"].asFloat(), + Root["lights"][LightList[i]]["color"]["G"].asFloat(), + Root["lights"][LightList[i]]["color"]["B"].asFloat())); + LightComponent.SetIsStaticShadowBias(Root["lights"][LightList[i]]["staticShadowBias"].asBool()); + LightComponent.SetShadowBias(Root["lights"][LightList[i]]["shadowBias"].asFloat()); + LightComponent.SetShadowBiasVariableIntensity(Root["lights"][LightList[i]]["shadowBiasVariableIntensity"].asFloat()); if (ProjectVersion >= 0.02f && Root["lights"][LightList[i]].isMember("shadowBlurFactor")) - Light->SetShadowBlurFactor(Root["lights"][LightList[i]]["shadowBlurFactor"].asFloat()); + LightComponent.SetShadowBlurFactor(Root["lights"][LightList[i]]["shadowBlurFactor"].asFloat()); - if (Light->GetType() == FE_POINT_LIGHT) + if (LightComponent.GetType() == FE_POINT_LIGHT) { - reinterpret_cast(Light)->SetRange(Root["lights"][LightList[i]]["range"].asFloat()); + LightComponent.SetRange(Root["lights"][LightList[i]]["range"].asFloat()); } - else if (Light->GetType() == FE_SPOT_LIGHT) + else if (LightComponent.GetType() == FE_SPOT_LIGHT) { - reinterpret_cast(Light)->SetSpotAngle(Root["lights"][LightList[i]]["spotAngle"].asFloat()); - reinterpret_cast(Light)->SetSpotAngleOuter(Root["lights"][LightList[i]]["spotAngleOuter"].asFloat()); + LightComponent.SetSpotAngle(Root["lights"][LightList[i]]["spotAngle"].asFloat()); + LightComponent.SetSpotAngleOuter(Root["lights"][LightList[i]]["spotAngleOuter"].asFloat()); - reinterpret_cast(Light)->SetDirection(glm::vec3(Root["lights"][LightList[i]]["direction"]["X"].asFloat(), - Root["lights"][LightList[i]]["direction"]["Y"].asFloat(), - Root["lights"][LightList[i]]["direction"]["Z"].asFloat())); + LightComponent.SetSpotAngle(Root["lights"][LightList[i]]["spotAngle"].asFloat()); + LightComponent.SetSpotAngleOuter(Root["lights"][LightList[i]]["spotAngleOuter"].asFloat()); } - else if (Light->GetType() == FE_DIRECTIONAL_LIGHT) + else if (LightComponent.GetType() == FE_DIRECTIONAL_LIGHT) { - FEDirectionalLight* DirectionalLight = reinterpret_cast(Light); - - DirectionalLight->SetDirection(glm::vec3(Root["lights"][LightList[i]]["direction"]["X"].asFloat(), - Root["lights"][LightList[i]]["direction"]["Y"].asFloat(), - Root["lights"][LightList[i]]["direction"]["Z"].asFloat())); - - DirectionalLight->SetActiveCascades(Root["lights"][LightList[i]]["CSM"]["activeCascades"].asInt()); - DirectionalLight->SetShadowCoverage(Root["lights"][LightList[i]]["CSM"]["shadowCoverage"].asFloat()); - DirectionalLight->SetCSMZDepth(Root["lights"][LightList[i]]["CSM"]["CSMZDepth"].asFloat()); - DirectionalLight->SetCSMXYDepth(Root["lights"][LightList[i]]["CSM"]["CSMXYDepth"].asFloat()); + LightComponent.SetActiveCascades(Root["lights"][LightList[i]]["CSM"]["activeCascades"].asInt()); + LightComponent.SetShadowCoverage(Root["lights"][LightList[i]]["CSM"]["shadowCoverage"].asFloat()); + LightComponent.SetCSMZDepth(Root["lights"][LightList[i]]["CSM"]["CSMZDepth"].asFloat()); + LightComponent.SetCSMXYDepth(Root["lights"][LightList[i]]["CSM"]["CSMXYDepth"].asFloat()); + + LightComponent.SetActiveCascades(Root["lights"][LightList[i]]["CSM"]["activeCascades"].asInt()); + LightComponent.SetShadowCoverage(Root["lights"][LightList[i]]["CSM"]["shadowCoverage"].asFloat()); + LightComponent.SetCSMZDepth(Root["lights"][LightList[i]]["CSM"]["CSMZDepth"].asFloat()); + LightComponent.SetCSMXYDepth(Root["lights"][LightList[i]]["CSM"]["CSMXYDepth"].asFloat()); } } @@ -1325,7 +1345,7 @@ void FEProject::LoadScene() //SKY_DOME_SYSTEM.SetEnabled(Root["effects"]["Sky"]["Enabled"].asFloat() > 0.0f ? true : false); //SKY_DOME_SYSTEM.SetDistanceToSky(Root["effects"]["Sky"]["Sphere size"].asFloat()); //Fix Me! - FEEntity* SkyDome = SCENE.AddNewStyleEntity("SkyDome"); + FEEntity* SkyDome = SCENE.AddEntity("SkyDome"); SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); SKY_DOME_SYSTEM.AddToEntity(SkyDome); @@ -1488,11 +1508,11 @@ void FEProject::AddUnSavedObject(FEObject* Object) bool FEProject::ShouldIncludeInSceneFile(const FETexture* Texture) { // Terrain should manage it's textures in a different way. - const std::vector TerrainList = SCENE.GetTerrainList(); + const std::vector TerrainList = SCENE.GetEntityIDListWith(); Json::Value TerrainData; for (size_t i = 0; i < TerrainList.size(); i++) { - FEEntity* Terrain = SCENE.GetNewStyleEntity(TerrainList[i]); + FEEntity* Terrain = SCENE.GetEntity(TerrainList[i]); FETerrainComponent& TerrainComponent = Terrain->GetComponent(); if (TerrainComponent.HeightMap->GetObjectID() == Texture->GetObjectID()) diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index efc44af..30f9263 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit efc44af57aa8b7be945f4d8246a4dbf523ce79f2 +Subproject commit 30f92638da7e731d37927f3184de2307c2bb4b09 From dfc204a9344a1be137fe0e5ab32575a0adfdc2c1 Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Thu, 11 Jul 2024 21:42:31 -0400 Subject: [PATCH 18/46] Engine update; Cleaned up old code from FEEditorGizmoManager; Added structure to the components view in the inspector window; Introduced a new 'Add Component' button to add components to an entity, this is the first iteration of this functionality. --- EditorWindows/InspectorWindow.cpp | 535 +++++++++++++++++------------ EditorWindows/InspectorWindow.h | 7 + EditorWindows/SceneGraphWindow.cpp | 79 +++-- FEEditorGizmoManager.cpp | 139 ++------ FEEditorPreviewManager.cpp | 6 +- FEEditorSelectedObject.cpp | 20 +- FEProject.cpp | 20 +- SubSystems/FocalEngine | 2 +- 8 files changed, 416 insertions(+), 392 deletions(-) diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index 7356ebc..df4089b 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -6,7 +6,10 @@ FEEntity* FEEditorInspectorWindow::TerrainToWorkWith = nullptr; FEEditorInspectorWindow::FEEditorInspectorWindow() { - + auto RegisteredComponentList = COMPONENTS_TOOL.GetComponentInfoList(); + + + AddComponentHandlers[typeid(FELightComponent)] = &FEEditorInspectorWindow::AddLightComponent; } void FEEditorInspectorWindow::InitializeResources() @@ -299,9 +302,6 @@ void FEEditorInspectorWindow::DisplayLightProperties(FEEntity* LightEntity) cons if (LightComponent.GetType() == FE_DIRECTIONAL_LIGHT) { - ImGui::Separator(); - ImGui::Text("-------------Shadow settings--------------"); - ImGui::Text("Cast shadows:"); ImGui::SameLine(); ImGui::SetNextItemWidth(200); @@ -429,6 +429,56 @@ void FEEditorInspectorWindow::ChangePrefabOfEntityCallBack(const std::vectorAddComponent(FE_POINT_LIGHT); +} + +std::vector FEEditorInspectorWindow::GetAvailableComponentsToAdd(FEEntity* Entity) const +{ + std::vector Result; + if (Entity == nullptr) + return Result; + + auto RegisteredComponentList = COMPONENTS_TOOL.GetComponentInfoList(); + auto EntityComponents = Entity->GetComponentsInfoList(); + + for (size_t i = 0; i < RegisteredComponentList.size(); i++) + { + if (RegisteredComponentList[i].IsCompatible(EntityComponents)) + Result.push_back(RegisteredComponentList[i].Name); + } + + return Result; +} + +bool FEEditorInspectorWindow::AddComponent(FEEntity* Entity, std::string ComponentName) +{ + auto RegisteredComponentList = COMPONENTS_TOOL.GetComponentInfoList(); + + for (size_t j = 0; j < RegisteredComponentList.size(); j++) + { + if (RegisteredComponentList[j].Name == ComponentName) + { + auto ComponentHashCode = RegisteredComponentList[j].Type->hash_code(); + + auto ComponentIterator = AddComponentHandlers.begin(); + while (ComponentIterator != AddComponentHandlers.end()) + { + if (ComponentIterator->first.hash_code() == ComponentHashCode) + { + ComponentIterator->second(Entity); + return true; + } + + ComponentIterator++; + } + } + } + + return false; +} + void FEEditorInspectorWindow::Render() { if (!bVisible) @@ -446,6 +496,10 @@ void FEEditorInspectorWindow::Render() FEEntity* EntitySelected = SELECTED.GetSelected(); + ImGui::Text("ID : %s", EntitySelected->GetObjectID().c_str()); + ImGui::Text("Name : %s", EntitySelected->GetName().c_str()); + + //auto testlist = GetAllComponentTypeInfos(); if (EntitySelected->HasComponent()) @@ -469,7 +523,6 @@ void FEEditorInspectorWindow::Render() if (ImGui::CollapsingHeader("Tag", ImGuiTreeNodeFlags_DefaultOpen)) { - ImGui::Text("Test"); FETagComponent& Tag = EntitySelected->GetComponent(); char Buffer[256]; memset(Buffer, 0, 256); @@ -543,124 +596,77 @@ void FEEditorInspectorWindow::Render() if (EntitySelected->HasComponent()) { - FEInstancedComponent& InstancedComponent = EntitySelected->GetComponent(); - - if (SELECTED.InstancedSubObjectIndexSelected != -1) + if (ImGui::CollapsingHeader("Instanced", ImGuiTreeNodeFlags_DefaultOpen)) { - std::string InstancedSubObjectInfo = "index: "; - - ImGui::Text("Selected instance info:"); - InstancedSubObjectInfo = "index: " + std::to_string(SELECTED.InstancedSubObjectIndexSelected); - ImGui::Text(InstancedSubObjectInfo.c_str()); + FEInstancedComponent& InstancedComponent = EntitySelected->GetComponent(); - FETransformComponent TempTransform = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(SELECTED.InstancedSubObjectIndexSelected)); - ShowTransformConfiguration("selected instance", &TempTransform); + if (SELECTED.InstancedSubObjectIndexSelected != -1) + { + std::string InstancedSubObjectInfo = "index: "; - INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(EntitySelected, SELECTED.InstancedSubObjectIndexSelected, TempTransform.GetWorldMatrix()); - //InstancedEntity->ModifyInstance(SELECTED.InstancedSubObjectIndexSelected, TempTransform.GetWorldMatrix()); + ImGui::Text("Selected instance info:"); + InstancedSubObjectInfo = "index: " + std::to_string(SELECTED.InstancedSubObjectIndexSelected); + ImGui::Text(InstancedSubObjectInfo.c_str()); - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + FETransformComponent TempTransform = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(SELECTED.InstancedSubObjectIndexSelected)); + TempTransform.SetSceneIndependent(true); + ShowTransformConfiguration("Selected instance", &TempTransform); - if (ImGui::ImageButton((void*)(intptr_t)ArrowToGroundIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - { - INSTANCED_RENDERING_SYSTEM.TryToSnapIndividualInstance(EntitySelected, SELECTED.InstancedSubObjectIndexSelected); - //InstancedEntity->TryToSnapInstance(SELECTED.InstancedSubObjectIndexSelected); - } - ShowToolTip("Selected instance will attempt to snap to the terrain."); + INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(EntitySelected, SELECTED.InstancedSubObjectIndexSelected, TempTransform.GetWorldMatrix()); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - } - else - { - ImGui::Text("Snapped to: "); - ImGui::SameLine(); + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - const std::vector TerrainList = SCENE.GetEntityIDListWith(); - static std::string CurrentTerrain = "none"; + if (ImGui::ImageButton((void*)(intptr_t)ArrowToGroundIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + { + INSTANCED_RENDERING_SYSTEM.TryToSnapIndividualInstance(EntitySelected, SELECTED.InstancedSubObjectIndexSelected); + } + ShowToolTip("Selected instance will attempt to snap to the terrain."); - if (InstancedComponent.GetSnappedToTerrain() == nullptr) - { - CurrentTerrain = "none"; + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); } else { - CurrentTerrain = InstancedComponent.GetSnappedToTerrain()->GetName(); - } + ImGui::Text("Snapped to: "); + ImGui::SameLine(); - ImGui::SetNextItemWidth(220); - if (ImGui::BeginCombo("##Terrain", CurrentTerrain.c_str(), ImGuiWindowFlags_None)) - { - const bool bIsSelected = (CurrentTerrain == "none"); - if (ImGui::Selectable("none", bIsSelected)) + const std::vector TerrainList = SCENE.GetEntityIDListWith(); + static std::string CurrentTerrain = "none"; + + if (InstancedComponent.GetSnappedToTerrain() == nullptr) { - if (InstancedComponent.GetSnappedToTerrain() != nullptr) - { - TERRAIN_SYSTEM.UnSnapInstancedEntity(InstancedComponent.GetSnappedToTerrain(), EntitySelected); - } + CurrentTerrain = "none"; } - - if (bIsSelected) - ImGui::SetItemDefaultFocus(); - - for (size_t i = 0; i < TerrainList.size(); i++) + else { - const bool bIsSelected = (CurrentTerrain == TerrainList[i]); - if (ImGui::Selectable(SCENE.GetEntity(TerrainList[i])->GetName().c_str(), bIsSelected)) - { - TERRAIN_SYSTEM.SnapInstancedEntity(SCENE.GetEntity(TerrainList[i]), EntitySelected); - } - - if (bIsSelected) - ImGui::SetItemDefaultFocus(); + CurrentTerrain = InstancedComponent.GetSnappedToTerrain()->GetName(); } - ImGui::EndCombo(); - } - - if (InstancedComponent.GetSnappedToTerrain() != nullptr) - { - ImGui::Text("Terrain layer: "); - ImGui::SameLine(); - - const int CurrentLayer = InstancedComponent.GetTerrainLayer(); - FEEntity* TerrainEntity = InstancedComponent.GetSnappedToTerrain(); - FETerrainComponent& TerrainComponent = TerrainEntity->GetComponent(); - - std::string Caption = "none"; - FETerrainLayer* Layer = TerrainComponent.GetLayerInSlot(CurrentLayer); - if (Layer != nullptr) - Caption = Layer->GetName(); ImGui::SetNextItemWidth(220); - if (ImGui::BeginCombo("##TerrainLayers", Caption.c_str(), ImGuiWindowFlags_None)) + if (ImGui::BeginCombo("##Terrain", CurrentTerrain.c_str(), ImGuiWindowFlags_None)) { - const bool bIsSelected = (CurrentLayer == -1); - ImGui::PushID("none_TerrainLayers_entity"); + const bool bIsSelected = (CurrentTerrain == "none"); if (ImGui::Selectable("none", bIsSelected)) { - TERRAIN_SYSTEM.UnConnectInstancedEntityFromLayer(EntitySelected); + if (InstancedComponent.GetSnappedToTerrain() != nullptr) + { + TERRAIN_SYSTEM.UnSnapInstancedEntity(InstancedComponent.GetSnappedToTerrain(), EntitySelected); + } } - ImGui::PopID(); if (bIsSelected) ImGui::SetItemDefaultFocus(); - for (size_t i = 0; i < FE_TERRAIN_MAX_LAYERS; i++) + for (size_t i = 0; i < TerrainList.size(); i++) { - FETerrainLayer* Layer = TerrainComponent.GetLayerInSlot(i); - if (Layer == nullptr) - break; - - const bool bIsSelected = (CurrentLayer == i); - ImGui::PushID(/*Layer->GetObjectID().c_str()*/static_cast(i)); - if (ImGui::Selectable(Layer->GetName().c_str(), bIsSelected)) + const bool bIsSelected = (CurrentTerrain == TerrainList[i]); + if (ImGui::Selectable(SCENE.GetEntity(TerrainList[i])->GetName().c_str(), bIsSelected)) { - TERRAIN_SYSTEM.ConnectInstancedEntityToLayer(TerrainEntity, EntitySelected, static_cast(i)); + TERRAIN_SYSTEM.SnapInstancedEntity(SCENE.GetEntity(TerrainList[i]), EntitySelected); } - ImGui::PopID(); if (bIsSelected) ImGui::SetItemDefaultFocus(); @@ -668,175 +674,250 @@ void FEEditorInspectorWindow::Render() ImGui::EndCombo(); } - if (CurrentLayer != -1) + if (InstancedComponent.GetSnappedToTerrain() != nullptr) { - ImGui::Text("Minimal layer intensity to spawn:"); - float MinLevel = InstancedComponent.GetMinimalLayerIntensityToSpawn(); + ImGui::Text("Terrain layer: "); ImGui::SameLine(); - ImGui::SetNextItemWidth(80); - ImGui::DragFloat("##minLevel", &MinLevel); - InstancedComponent.SetMinimalLayerIntensityToSpawn(MinLevel); - } - } - ImGui::Separator(); + const int CurrentLayer = InstancedComponent.GetTerrainLayer(); + FEEntity* TerrainEntity = InstancedComponent.GetSnappedToTerrain(); + FETerrainComponent& TerrainComponent = TerrainEntity->GetComponent(); - ImGui::Text("Seed:"); - int seed = InstancedComponent.SpawnInfo.Seed; - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - ImGui::DragInt("##Seed", &seed); - InstancedComponent.SpawnInfo.Seed = seed; + std::string Caption = "none"; + FETerrainLayer* Layer = TerrainComponent.GetLayerInSlot(CurrentLayer); + if (Layer != nullptr) + Caption = Layer->GetName(); - ImGui::Text("Object count:"); - int ObjectCount = InstancedComponent.SpawnInfo.ObjectCount; - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - ImGui::DragInt("##Object count", &ObjectCount); - if (ObjectCount <= 0) - ObjectCount = 1; - InstancedComponent.SpawnInfo.ObjectCount = ObjectCount; + ImGui::SetNextItemWidth(220); + if (ImGui::BeginCombo("##TerrainLayers", Caption.c_str(), ImGuiWindowFlags_None)) + { + const bool bIsSelected = (CurrentLayer == -1); + ImGui::PushID("none_TerrainLayers_entity"); + if (ImGui::Selectable("none", bIsSelected)) + { + TERRAIN_SYSTEM.UnConnectInstancedEntityFromLayer(EntitySelected); + } + ImGui::PopID(); - ImGui::Text("Radius:"); - float radius = InstancedComponent.SpawnInfo.Radius; - ImGui::SameLine(); - ImGui::SetNextItemWidth(200); - ImGui::DragFloat("##Radius", &radius); - if (radius < 0.0f) - radius = 0.1f; - InstancedComponent.SpawnInfo.Radius = radius; + if (bIsSelected) + ImGui::SetItemDefaultFocus(); - // Scale deviation. - ImGui::Text("Scale: "); + for (size_t i = 0; i < FE_TERRAIN_MAX_LAYERS; i++) + { + FETerrainLayer* Layer = TerrainComponent.GetLayerInSlot(i); + if (Layer == nullptr) + break; - ImGui::SameLine(); - ImGui::Text("min "); + const bool bIsSelected = (CurrentLayer == i); + ImGui::PushID(/*Layer->GetObjectID().c_str()*/static_cast(i)); + if (ImGui::Selectable(Layer->GetName().c_str(), bIsSelected)) + { + TERRAIN_SYSTEM.ConnectInstancedEntityToLayer(TerrainEntity, EntitySelected, static_cast(i)); + } + ImGui::PopID(); - ImGui::SameLine(); - ImGui::SetNextItemWidth(100); - float MinScale = InstancedComponent.SpawnInfo.GetMinScale(); - ImGui::DragFloat("##minScale", &MinScale, 0.01f); - InstancedComponent.SpawnInfo.SetMinScale(MinScale); + if (bIsSelected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } - ImGui::SameLine(); - ImGui::Text("max "); + if (CurrentLayer != -1) + { + ImGui::Text("Minimal layer intensity to spawn:"); + float MinLevel = InstancedComponent.GetMinimalLayerIntensityToSpawn(); + ImGui::SameLine(); + ImGui::SetNextItemWidth(80); + ImGui::DragFloat("##minLevel", &MinLevel); + InstancedComponent.SetMinimalLayerIntensityToSpawn(MinLevel); + } + } - ImGui::SameLine(); - float MaxScale = InstancedComponent.SpawnInfo.GetMaxScale(); - ImGui::SetNextItemWidth(100); - ImGui::DragFloat("##maxScale", &MaxScale, 0.01f); - InstancedComponent.SpawnInfo.SetMaxScale(MaxScale); - - ImGui::Text("Rotation deviation:"); - float RotationDeviationX = InstancedComponent.SpawnInfo.RotationDeviation.x; - ImGui::Text("X:"); - ImGui::SameLine(); - ImGui::DragFloat("##Rotation deviation X", &RotationDeviationX, 0.01f); - if (RotationDeviationX < 0.01f) - RotationDeviationX = 0.01f; - if (RotationDeviationX > 1.0f) - RotationDeviationX = 1.0f; - InstancedComponent.SpawnInfo.RotationDeviation.x = RotationDeviationX; - - float RotationDeviationY = InstancedComponent.SpawnInfo.RotationDeviation.y; - ImGui::Text("Y:"); - ImGui::SameLine(); - ImGui::DragFloat("##Rotation deviation Y", &RotationDeviationY, 0.01f); - if (RotationDeviationY < 0.01f) - RotationDeviationY = 0.01f; - if (RotationDeviationY > 1.0f) - RotationDeviationY = 1.0f; - InstancedComponent.SpawnInfo.RotationDeviation.y = RotationDeviationY; - - float RotationDeviationZ = InstancedComponent.SpawnInfo.RotationDeviation.z; - ImGui::Text("Z:"); - ImGui::SameLine(); - ImGui::DragFloat("##Rotation deviation z", &RotationDeviationZ, 0.01f); - if (RotationDeviationZ < 0.01f) - RotationDeviationZ = 0.01f; - if (RotationDeviationZ > 1.0f) - RotationDeviationZ = 1.0f; - InstancedComponent.SpawnInfo.RotationDeviation.z = RotationDeviationZ; - - if (ImGui::Button("Spawn/Re-Spawn")) - { - INSTANCED_RENDERING_SYSTEM.ClearInstance(EntitySelected); - INSTANCED_RENDERING_SYSTEM.PopulateInstance(EntitySelected, InstancedComponent.SpawnInfo); - } + ImGui::Separator(); - if (ImGui::Button("Add instance")) - { - glm::mat4 NewInstanceMatrix = glm::identity(); - NewInstanceMatrix = glm::translate(NewInstanceMatrix, ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - INSTANCED_RENDERING_SYSTEM.AddIndividualInstance(EntitySelected, NewInstanceMatrix); + ImGui::Text("Seed:"); + int seed = InstancedComponent.SpawnInfo.Seed; + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + ImGui::DragInt("##Seed", &seed); + InstancedComponent.SpawnInfo.Seed = seed; - PROJECT_MANAGER.GetCurrent()->SetModified(true); - } + ImGui::Text("Object count:"); + int ObjectCount = InstancedComponent.SpawnInfo.ObjectCount; + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + ImGui::DragInt("##Object count", &ObjectCount); + if (ObjectCount <= 0) + ObjectCount = 1; + InstancedComponent.SpawnInfo.ObjectCount = ObjectCount; + + ImGui::Text("Radius:"); + float radius = InstancedComponent.SpawnInfo.Radius; + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + ImGui::DragFloat("##Radius", &radius); + if (radius < 0.0f) + radius = 0.1f; + InstancedComponent.SpawnInfo.Radius = radius; - if (INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(EntitySelected)) - { - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.0f, 0.75f, 0.0f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); - } - else - { - ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); - } + // Scale deviation. + ImGui::Text("Scale: "); - ImGui::Separator(); - if (ImGui::ImageButton((void*)(intptr_t)MouseCursorIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - { - INSTANCED_RENDERING_SYSTEM.SetIndividualSelectMode(EntitySelected, !INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(EntitySelected)); - if (!INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(EntitySelected)) + ImGui::SameLine(); + ImGui::Text("min "); + + ImGui::SameLine(); + ImGui::SetNextItemWidth(100); + float MinScale = InstancedComponent.SpawnInfo.GetMinScale(); + ImGui::DragFloat("##minScale", &MinScale, 0.01f); + InstancedComponent.SpawnInfo.SetMinScale(MinScale); + + ImGui::SameLine(); + ImGui::Text("max "); + + ImGui::SameLine(); + float MaxScale = InstancedComponent.SpawnInfo.GetMaxScale(); + ImGui::SetNextItemWidth(100); + ImGui::DragFloat("##maxScale", &MaxScale, 0.01f); + InstancedComponent.SpawnInfo.SetMaxScale(MaxScale); + + ImGui::Text("Rotation deviation:"); + float RotationDeviationX = InstancedComponent.SpawnInfo.RotationDeviation.x; + ImGui::Text("X:"); + ImGui::SameLine(); + ImGui::DragFloat("##Rotation deviation X", &RotationDeviationX, 0.01f); + if (RotationDeviationX < 0.01f) + RotationDeviationX = 0.01f; + if (RotationDeviationX > 1.0f) + RotationDeviationX = 1.0f; + InstancedComponent.SpawnInfo.RotationDeviation.x = RotationDeviationX; + + float RotationDeviationY = InstancedComponent.SpawnInfo.RotationDeviation.y; + ImGui::Text("Y:"); + ImGui::SameLine(); + ImGui::DragFloat("##Rotation deviation Y", &RotationDeviationY, 0.01f); + if (RotationDeviationY < 0.01f) + RotationDeviationY = 0.01f; + if (RotationDeviationY > 1.0f) + RotationDeviationY = 1.0f; + InstancedComponent.SpawnInfo.RotationDeviation.y = RotationDeviationY; + + float RotationDeviationZ = InstancedComponent.SpawnInfo.RotationDeviation.z; + ImGui::Text("Z:"); + ImGui::SameLine(); + ImGui::DragFloat("##Rotation deviation z", &RotationDeviationZ, 0.01f); + if (RotationDeviationZ < 0.01f) + RotationDeviationZ = 0.01f; + if (RotationDeviationZ > 1.0f) + RotationDeviationZ = 1.0f; + InstancedComponent.SpawnInfo.RotationDeviation.z = RotationDeviationZ; + + if (ImGui::Button("Spawn/Re-Spawn")) { - SELECTED.Clear(); - SELECTED.SetSelected(EntitySelected); + INSTANCED_RENDERING_SYSTEM.ClearInstance(EntitySelected); + INSTANCED_RENDERING_SYSTEM.PopulateInstance(EntitySelected, InstancedComponent.SpawnInfo); } - } - ShowToolTip("Individual selection mode - Used to select individual instances."); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); + if (ImGui::Button("Add instance")) + { + glm::mat4 NewInstanceMatrix = glm::identity(); + NewInstanceMatrix = glm::translate(NewInstanceMatrix, ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + INSTANCED_RENDERING_SYSTEM.AddIndividualInstance(EntitySelected, NewInstanceMatrix); + + PROJECT_MANAGER.GetCurrent()->SetModified(true); + } + + if (INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(EntitySelected)) + { + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.0f, 0.75f, 0.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.0f, 1.0f, 0.0f)); + } + else + { + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); + } + + ImGui::Separator(); + if (ImGui::ImageButton((void*)(intptr_t)MouseCursorIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + { + INSTANCED_RENDERING_SYSTEM.SetIndividualSelectMode(EntitySelected, !INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(EntitySelected)); + if (!INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(EntitySelected)) + { + SELECTED.Clear(); + SELECTED.SetSelected(EntitySelected); + } + } + ShowToolTip("Individual selection mode - Used to select individual instances."); + + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + } } } if (EntitySelected->HasComponent()) { - FETerrainComponent& TerrainComponent = EntitySelected->GetComponent(); - DisplayTerrainSettings(EntitySelected); - - if (TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE) + if (ImGui::CollapsingHeader("Terrain", ImGuiTreeNodeFlags_DefaultOpen)) { - // To hide gizmos. - SELECTED.SetSelected(EntitySelected); - - TERRAIN_SYSTEM.SetBrushActive(EntitySelected, bLeftMousePressed); + FETerrainComponent& TerrainComponent = EntitySelected->GetComponent(); + DisplayTerrainSettings(EntitySelected); - if (bShiftPressed) + if (TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE) { - if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW) - TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED); + // To hide gizmos. + SELECTED.SetSelected(EntitySelected); + + TERRAIN_SYSTEM.SetBrushActive(EntitySelected, bLeftMousePressed); + + if (bShiftPressed) + { + if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW) + TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED); + } + else + { + if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) + TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); + } } else { - if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) - TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); + // To show gizmos. + SELECTED.SetSelected(EntitySelected); } } - else + } + + if (EntitySelected->HasComponent()) + { + if (ImGui::CollapsingHeader("Light", ImGuiTreeNodeFlags_DefaultOpen)) { - // To show gizmos. - SELECTED.SetSelected(EntitySelected); + DisplayLightProperties(SELECTED.GetSelected()); } } - if (EntitySelected->HasComponent()) + std::vector AvailableComponentTypes = GetAvailableComponentsToAdd(EntitySelected); + + ImGui::SetNextItemWidth(220.0f); + ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 6.0f); + + float RegionWidth = ImGui::GetContentRegionAvail().x; + ImGui::SetCursorPosX(RegionWidth * 0.5f - 220.0f / 2.0f + 20.0f); + + if (ImGui::BeginCombo("##Add Component", " Add Component", ImGuiComboFlags_NoArrowButton)) { - DisplayLightProperties(SELECTED.GetSelected()); + for (size_t i = 0; i < AvailableComponentTypes.size(); i++) + { + if (ImGui::Selectable(AvailableComponentTypes[i].c_str(), false)) + { + AddComponent(EntitySelected, AvailableComponentTypes[i]); + } + } + ImGui::EndCombo(); } diff --git a/EditorWindows/InspectorWindow.h b/EditorWindows/InspectorWindow.h index fb958ae..1e72119 100644 --- a/EditorWindows/InspectorWindow.h +++ b/EditorWindows/InspectorWindow.h @@ -58,6 +58,13 @@ class FEEditorInspectorWindow void Clear(); void InitializeResources(); + std::vector GetAvailableComponentsToAdd(FEEntity* Entity) const; + + bool AddComponent(FEEntity* Entity, std::string ComponentName); + std::unordered_map> AddComponentHandlers; + + static void AddLightComponent(FEEntity* Entity); + public: SINGLETON_PUBLIC_PART(FEEditorInspectorWindow) }; diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index e65fd56..33b5f12 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -398,45 +398,52 @@ void FEEditorSceneGraphWindow::Render() { if (ImGui::BeginMenu("Add")) { - if (ImGui::MenuItem("Entity")) + if (ImGui::MenuItem("Empty entity")) { - SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, CreateEntityCallBack); + SCENE.AddEntity("Unnamed entity"); } - if (ImGui::MenuItem("Instanced entity")) - { - SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, CreateInstancedEntityCallBack); - } - - if (ImGui::MenuItem("Terrain")) - { - FEEntity* Entity = SCENE.AddEntity("Unnamed terrain"); - FETransformComponent& TransformComponent = Entity->GetComponent(); - FETerrainComponent& TerrainComponent = Entity->AddComponent(); - TerrainComponent.HeightMap = RESOURCE_MANAGER.CreateBlankHightMapTexture(); - - PROJECT_MANAGER.GetCurrent()->SetModified(true); - } - - if (ImGui::BeginMenu("Light")) - { - /*if (ImGui::MenuItem("Directional")) - { - SCENE.AddLight(FE_DIRECTIONAL_LIGHT, ""); - } - - if (ImGui::MenuItem("Spot")) - { - SCENE.AddLight(FE_SPOT_LIGHT, ""); - } - - if (ImGui::MenuItem("Point")) - { - SCENE.AddLight(FE_POINT_LIGHT, ""); - }*/ - - ImGui::EndMenu(); - } + // FIX ME! + //if (ImGui::MenuItem("Entity")) + //{ + // SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, CreateEntityCallBack); + //} + + //if (ImGui::MenuItem("Instanced entity")) + //{ + // SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, CreateInstancedEntityCallBack); + //} + + //if (ImGui::MenuItem("Terrain")) + //{ + // FEEntity* Entity = SCENE.AddEntity("Unnamed terrain"); + // FETransformComponent& TransformComponent = Entity->GetComponent(); + // Entity->AddComponent(); + // FETerrainComponent& TerrainComponent = Entity->GetComponent(); + // TerrainComponent.HeightMap = RESOURCE_MANAGER.CreateBlankHightMapTexture(); + + // PROJECT_MANAGER.GetCurrent()->SetModified(true); + //} + + //if (ImGui::BeginMenu("Light")) + //{ + // /*if (ImGui::MenuItem("Directional")) + // { + // SCENE.AddLight(FE_DIRECTIONAL_LIGHT, ""); + // } + + // if (ImGui::MenuItem("Spot")) + // { + // SCENE.AddLight(FE_SPOT_LIGHT, ""); + // } + + // if (ImGui::MenuItem("Point")) + // { + // SCENE.AddLight(FE_POINT_LIGHT, ""); + // }*/ + + // ImGui::EndMenu(); + //} ImGui::EndMenu(); } diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index 9c426c7..c813cf6 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -32,7 +32,7 @@ void GizmoManager::InitializeResources() TransformationXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); TransformationXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // TransformationYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYGizmoMaterial"); @@ -59,7 +59,7 @@ void GizmoManager::InitializeResources() TransformationYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); TransformationYGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // TransformationZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationZGizmoMaterial"); @@ -86,7 +86,7 @@ void GizmoManager::InitializeResources() TransformationZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); TransformationZGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // Plane gizmos CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXYGizmoMaterial"); @@ -115,7 +115,7 @@ void GizmoManager::InitializeResources() //TransformationXYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); //TransformationXYGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); @@ -143,7 +143,7 @@ void GizmoManager::InitializeResources() //TransformationYZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); //TransformationYZGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); @@ -171,7 +171,7 @@ void GizmoManager::InitializeResources() //TransformationXZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); //TransformationXZGizmoEntity->SetIsPostprocessApplied(false); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // Scale gizmos. FEMesh* ScaleGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "637C784B2E5E5C6548190E1B.model").c_str(), "scaleGizmoMesh"); @@ -202,7 +202,7 @@ void GizmoManager::InitializeResources() ScaleXGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); ScaleXGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // ScaleYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleYGizmoMaterial"); @@ -229,7 +229,7 @@ void GizmoManager::InitializeResources() ScaleYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); ScaleYGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // ScaleZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleZGizmoMaterial"); @@ -256,7 +256,7 @@ void GizmoManager::InitializeResources() ScaleZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); ScaleZGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // RotateAroundAxis gizmos FEMesh* RotateGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "19622421516E5B317E1B5360.model").c_str(), "rotateGizmoMesh"); @@ -287,7 +287,7 @@ void GizmoManager::InitializeResources() RotateXGizmoEntity->Transform.SetRotation(RotateXStandardRotation); RotateXGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // RotateYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateYGizmoMaterial"); @@ -314,7 +314,7 @@ void GizmoManager::InitializeResources() RotateYGizmoEntity->Transform.SetRotation(RotateYStandardRotation); RotateYGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // RotateZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateZGizmoMaterial"); @@ -341,7 +341,7 @@ void GizmoManager::InitializeResources() RotateZGizmoEntity->Transform.SetRotation(RotateZStandardRotation); RotateZGizmoEntity->SetIsPostprocessApplied(false);*/ // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); TransformationGizmoIcon = RESOURCE_MANAGER.LoadFETexture((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "456A31026A1C3152181A6064.texture").c_str(), "transformationGizmoIcon"); RESOURCE_MANAGER.MakeTextureStandard(TransformationGizmoIcon); @@ -714,25 +714,6 @@ glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, return PointOnPlane; } -void GizmoManager::MoveSelectedEntityAlongAxis(const glm::vec3& AxisOfMovement, FETransformComponent& ObjectTransform) -{ - glm::vec3 NewPosition = ObjectTransform.GetPosition(); - glm::vec3 LocalAlternativeAxis = AxisOfMovement; - - FENaiveSceneGraphNode* SceneGraphParentEntity = SCENE.SceneGraph.GetNodeByEntityID(SELECTED.GetSelected()->GetObjectID()); - if (SceneGraphParentEntity != nullptr) - { - if (SceneGraphParentEntity->GetParent() != SCENE.SceneGraph.GetRoot()) - { - FETransformComponent& ParentTransform = SceneGraphParentEntity->GetParent()->GetEntity()->GetComponent(); - LocalAlternativeAxis = glm::inverse(ParentTransform.GetWorldMatrix()) * glm::vec4(AxisOfMovement, 0.0f); - } - - NewPosition += LocalAlternativeAxis; - ObjectTransform.SetPosition(NewPosition); - } -} - void GizmoManager::MouseMoveTransformationGizmos() { FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); @@ -760,16 +741,8 @@ void GizmoManager::MouseMoveTransformationGizmos() const float Difference = GizmoRayParametricIntersection - LastFrameGizmoRayParametricIntersection; if (abs(Difference) > FLT_EPSILON) { - //float OldY = ObjTransform.GetPosition(false)[1]; bAppliedSomeChanges = true; - - - - //ObjTransform.SetPosition(ObjTransform.GetPosition(false) + glm::vec3(Difference, 0.0f, 0.0f), false); - ObjTransform.SetPosition(ObjTransform.GetPosition(false) + glm::vec3(Difference, 0.0f, 0.0f), false); - - //MoveAlongAxis(glm::vec3(Difference, 0.0f, 0.0f), ObjTransform); } } @@ -789,7 +762,7 @@ void GizmoManager::MouseMoveTransformationGizmos() if (abs(Difference) > FLT_EPSILON) { bAppliedSomeChanges = true; - MoveSelectedEntityAlongAxis(glm::vec3(0.0f, Difference, 0.0f), ObjTransform); + ObjTransform.SetPosition(ObjTransform.GetPosition(false) + glm::vec3(0.0f, Difference, 0.0f), false); } } @@ -809,7 +782,7 @@ void GizmoManager::MouseMoveTransformationGizmos() if (abs(Difference) > FLT_EPSILON) { bAppliedSomeChanges = true; - MoveSelectedEntityAlongAxis(glm::vec3(0.0f, 0.0f, Difference), ObjTransform); + ObjTransform.SetPosition(ObjTransform.GetPosition(false) + glm::vec3(0.0f, 0.0f, Difference), false); } } @@ -819,7 +792,7 @@ void GizmoManager::MouseMoveTransformationGizmos() if (!GEOMETRY.IsEpsilonEqual(Difference, glm::vec3(0.0f))) { bAppliedSomeChanges = true; - MoveSelectedEntityAlongAxis(Difference, ObjTransform); + ObjTransform.SetPosition(ObjTransform.GetPosition(false) + Difference, false); } } @@ -829,7 +802,7 @@ void GizmoManager::MouseMoveTransformationGizmos() if (!GEOMETRY.IsEpsilonEqual(Difference, glm::vec3(0.0f))) { bAppliedSomeChanges = true; - MoveSelectedEntityAlongAxis(Difference, ObjTransform); + ObjTransform.SetPosition(ObjTransform.GetPosition(false) + Difference, false); } } @@ -839,7 +812,7 @@ void GizmoManager::MouseMoveTransformationGizmos() if (!GEOMETRY.IsEpsilonEqual(Difference, glm::vec3(0.0f))) { bAppliedSomeChanges = true; - MoveSelectedEntityAlongAxis(Difference, ObjTransform); + ObjTransform.SetPosition(ObjTransform.GetPosition(false) + Difference, false); } } @@ -996,38 +969,14 @@ FETransformComponent GizmoManager::GetTransformComponentOfSelectedObject() if (SELECTED.InstancedSubObjectIndexSelected != -1 && SELECTED.GetSelected()->HasComponent()) { FEInstancedComponent& InstancedComponent = SELECTED.GetSelected()->GetComponent(); - return InstancedComponent.GetTransformedInstancedMatrix(SELECTED.InstancedSubObjectIndexSelected); + FETransformComponent& DummyTransform = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(SELECTED.InstancedSubObjectIndexSelected)); + DummyTransform.SetSceneIndependent(true); + return DummyTransform; } else { return SELECTED.GetSelected()->GetComponent(); } - - /*if (SELECTED.GetSelected()->GetType() == FE_ENTITY) - { - return SELECTED.GetEntity()->Transform; - } - else if (SELECTED.GetSelected()->GetType() == FE_ENTITY_INSTANCED) - { - if (SELECTED.InstancedSubObjectIndexSelected != -1) - { - return reinterpret_cast(SELECTED.GetEntity())->GetTransformedInstancedMatrix(SELECTED.InstancedSubObjectIndexSelected); - } - else - { - return SELECTED.GetEntity()->Transform; - } - } - else if (SELECTED.GetSelected()->GetType() == FE_TERRAIN) - { - return SELECTED.GetTerrain()->Transform; - } - else if (SELECTED.GetSelected()->GetType() == FE_DIRECTIONAL_LIGHT || SELECTED.GetSelected()->GetType() == FE_SPOT_LIGHT || SELECTED.GetSelected()->GetType() == FE_POINT_LIGHT) - { - return SELECTED.GetLight()->Transform; - } - - return FETransformComponent();*/ } void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent Changes) @@ -1043,30 +992,6 @@ void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent Changes) { SELECTED.GetSelected()->GetComponent() = Changes; } - - /*if (SELECTED.GetSelected()->GetType() == FE_ENTITY) - { - SELECTED.GetEntity()->Transform = Changes; - } - else if (SELECTED.GetSelected()->GetType() == FE_ENTITY_INSTANCED) - { - if (SELECTED.InstancedSubObjectIndexSelected != -1) - { - reinterpret_cast(SELECTED.GetEntity())->ModifyInstance(SELECTED.InstancedSubObjectIndexSelected, Changes.GetWorldMatrix()); - } - else - { - SELECTED.GetEntity()->Transform = Changes; - } - } - else if (SELECTED.GetSelected()->GetType() == FE_TERRAIN) - { - SELECTED.GetTerrain()->Transform = Changes; - } - else if (SELECTED.GetSelected()->GetType() == FE_DIRECTIONAL_LIGHT || SELECTED.GetSelected()->GetType() == FE_SPOT_LIGHT || SELECTED.GetSelected()->GetType() == FE_POINT_LIGHT) - { - SELECTED.GetLight()->Transform = Changes; - }*/ } void GizmoManager::ReInitializeEntities() @@ -1084,7 +1009,7 @@ void GizmoManager::ReInitializeEntities() TransformationXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); TransformationXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // TransformationYGizmo TransformationYGizmoEntity = SCENE.AddEntity("TransformationYGizmoEntity"); @@ -1096,7 +1021,7 @@ void GizmoManager::ReInitializeEntities() TransformationYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); TransformationYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // TransformationZGizmo TransformationZGizmoEntity = SCENE.AddEntity("TransformationZGizmoEntity"); @@ -1107,7 +1032,7 @@ void GizmoManager::ReInitializeEntities() TransformationZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); TransformationZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); TransformationZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // Plane gizmos TransformationXYGizmoEntity = SCENE.AddEntity("TransformationXYGizmoEntity"); @@ -1120,7 +1045,7 @@ void GizmoManager::ReInitializeEntities() TransformationXYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); TransformationXYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); TransformationYZGizmoEntity = SCENE.AddEntity("TransformationYZGizmoEntity"); TransformationYZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYZGizmoGM")[0]); @@ -1132,7 +1057,7 @@ void GizmoManager::ReInitializeEntities() TransformationYZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); TransformationYZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); TransformationXZGizmoEntity = SCENE.AddEntity("TransformationXZGizmoEntity"); TransformationXZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXZGizmoGM")[0]); @@ -1144,7 +1069,7 @@ void GizmoManager::ReInitializeEntities() TransformationXZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); TransformationXZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // ScaleXGizmo ScaleXGizmoEntity = SCENE.AddEntity("ScaleXGizmoEntity"); @@ -1156,7 +1081,7 @@ void GizmoManager::ReInitializeEntities() ScaleXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); ScaleXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // ScaleYGizmo ScaleYGizmoEntity = SCENE.AddEntity("ScaleYGizmoEntity"); @@ -1168,7 +1093,7 @@ void GizmoManager::ReInitializeEntities() ScaleYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); ScaleYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // ScaleZGizmo ScaleZGizmoEntity = SCENE.AddEntity("ScaleZGizmoEntity"); @@ -1180,7 +1105,7 @@ void GizmoManager::ReInitializeEntities() ScaleZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); ScaleZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // RotateXGizmo RotateXGizmoEntity = SCENE.AddEntity("RotateXGizmoEntity"); @@ -1192,7 +1117,7 @@ void GizmoManager::ReInitializeEntities() RotateXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); RotateXGizmoEntity->GetComponent().SetRotation(RotateXStandardRotation); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // RotateYGizmo RotateYGizmoEntity = SCENE.AddEntity("RotateYGizmoEntity"); @@ -1204,7 +1129,7 @@ void GizmoManager::ReInitializeEntities() RotateYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); RotateYGizmoEntity->GetComponent().SetRotation(RotateYStandardRotation); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // RotateZGizmo RotateZGizmoEntity = SCENE.AddEntity("RotateZGizmoEntity"); @@ -1216,5 +1141,5 @@ void GizmoManager::ReInitializeEntities() RotateZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); RotateZGizmoEntity->GetComponent().SetRotation(RotateZStandardRotation); // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID()); + SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); } \ No newline at end of file diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index d947aa0..959a09f 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -20,7 +20,8 @@ void FEEditorPreviewManager::InitializeResources() PreviewGameModel = new FEGameModel(nullptr, nullptr, "editorPreviewGameModel"); PreviewPrefab = new FEPrefab(PreviewGameModel, "editorPreviewPrefab"); PreviewEntity = SCENE.AddEntity("editorPreviewEntity"); - PreviewEntity->AddComponent(PreviewGameModel).SetVisibility(false); + PreviewEntity->AddComponent(PreviewGameModel); + PreviewEntity->GetComponent().SetVisibility(false); MeshPreviewMaterial = RESOURCE_MANAGER.CreateMaterial("meshPreviewMaterial"); RESOURCE_MANAGER.MakeMaterialStandard(MeshPreviewMaterial); MeshPreviewMaterial->Shader = RESOURCE_MANAGER.CreateShader("FEMeshPreviewShader", RESOURCE_MANAGER.LoadGLSL("Resources//Materials//FE_MeshPreview_VS.glsl").c_str(), @@ -42,7 +43,8 @@ void FEEditorPreviewManager::InitializeResources() void FEEditorPreviewManager::ReInitializeEntities() { PreviewEntity = SCENE.AddEntity("editorPreviewEntity"); - PreviewEntity->AddComponent(PreviewGameModel).SetVisibility(false); + PreviewEntity->AddComponent(PreviewGameModel); + PreviewEntity->GetComponent().SetVisibility(false); /*LocalLightEntity = SCENE.AddEntity("EditorPreview LightEntity"); FELightComponent& LightComponent = LocalLightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index 4e35d7e..7766723 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -220,7 +220,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons else if (PotentiallySelectedEntity->HasComponent()) { // Render instanced object only if it is not in individual select mode - if (/*InstancedSubObjectsInfo.find(PotentiallySelectedEntity) == InstancedSubObjectsInfo.end()*/!INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(PotentiallySelectedEntity)) + if (!INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(PotentiallySelectedEntity)) { PixelAccurateSelectionMaterial->Shader = FEPixelAccurateInstancedSelection; FEMaterial* RegularBillboardMaterials = GameModelComponent.GameModel->GetBillboardMaterial(); @@ -275,7 +275,8 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons DummyGameModelComponent.SetVisibility(true); FEInstancedComponent& InstancedComponent = it->first->GetComponent(); - DummyEntity->GetComponent() = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(it->second[j])); + FETransformComponent& DummyTransformComponent = DummyEntity->GetComponent(); + DummyTransformComponent = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(it->second[j])); FEMaterial* RegularMaterial = OriginalGameModelComponent.GameModel->Material; DummyGameModelComponent.GameModel->Material = PixelAccurateSelectionMaterial; @@ -284,10 +285,9 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - RENDERER.RenderGameModelComponent(DummyGameModelComponent, DummyEntity->GetComponent(), ENGINE.GetCamera(), false); - + RENDERER.RenderGameModelComponent(DummyGameModelComponent, DummyTransformComponent, ENGINE.GetCamera(), false); + OriginalGameModelComponent.GameModel->Material = RegularMaterial; - DummyGameModelComponent.SetVisibility(false); } it++; @@ -399,36 +399,28 @@ void FEEditorSelectedObject::OnCameraUpdate() const } else if (Container->HasComponent()) { - //FEEntityInstanced* SelectedInstancedEntity = reinterpret_cast(SelectedEntity); if (InstancedSubObjectIndexSelected != -1) { - // FIX ME! - //static FEEntity* DummyEntity = SCENE.AddEntity(SelectedInstancedEntity->Prefab, "dummyEntity"); if (!DummyEntity->HasComponent()) DummyEntity->AddComponent(); + FEGameModelComponent& DummyGameModelComponent = DummyEntity->GetComponent(); DummyGameModelComponent.GameModel = GameModelComponent.GameModel; DummyGameModelComponent.SetVisibility(true); - //DummyEntity->Prefab = SelectedInstancedEntity->Prefab; FEInstancedComponent& InstancedComponent = Container->GetComponent(); DummyEntity->GetComponent() = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(InstancedSubObjectIndexSelected)); - //FETransformComponent(SelectedInstancedEntity->GetTransformedInstancedMatrix(InstancedSubObjectIndexSelected)); FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; - DummyGameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; HALO_SELECTION_EFFECT.HaloMaterial->SetBaseColor(glm::vec3(0.61f, 0.86f, 1.0f)); HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - //RENDERER.RenderEntity(DummyEntity, ENGINE.GetCamera(), false, i); RENDERER.RenderGameModelComponent(DummyGameModelComponent, DummyEntity->GetComponent(), ENGINE.GetCamera(), false); - //SelectedInstancedEntity->Prefab->GetComponent(i)->GameModel->Material = RegularMaterial; GameModelComponent.GameModel->Material = RegularMaterial; - DummyGameModelComponent.SetVisibility(false); } else diff --git a/FEProject.cpp b/FEProject.cpp index bf2fd45..7eec00d 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -1048,7 +1048,8 @@ void FEProject::LoadScene() { FEEntity* Entity = SCENE.AddEntity(Root["terrains"][TerrainList[i]]["name"].asString(), Root["terrains"][TerrainList[i]]["ID"].asString()); FETransformComponent& TransformComponent = Entity->GetComponent(); - FETerrainComponent& TerrainComponent = Entity->AddComponent(); + Entity->AddComponent(); + FETerrainComponent& TerrainComponent = Entity->GetComponent(); TERRAIN_SYSTEM.LoadHeightMap((ProjectFolder + Root["terrains"][TerrainList[i]]["heightMap"]["fileName"].asCString()).c_str(), Entity); TerrainComponent.SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); @@ -1107,9 +1108,10 @@ void FEProject::LoadScene() FEPrefabComponent* CurrentComponent = OldPrefab->GetComponent(static_cast(c)); FEGameModel* GameModel = CurrentComponent->GameModel; - //FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString())->GetComponent(0)->GameModel; - FEGameModelComponent& GameModelComponent = Entity->AddComponent(GameModel); - FEInstancedComponent& InstancedComponent = Entity->AddComponent(); + Entity->AddComponent(GameModel); + FEGameModelComponent& GameModelComponent = Entity->GetComponent(); + Entity->AddComponent(); + FEInstancedComponent& InstancedComponent = Entity->GetComponent(); if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) GameModelComponent.SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); @@ -1144,6 +1146,8 @@ void FEProject::LoadScene() } } + // FIX ME! That should be done after all entities are loaded. + // And scene was updated. INSTANCED_RENDERING_SYSTEM.PopulateInstance(Entity, SpawnInfo); if (Root["entities"][EntityList[i]]["modificationsToSpawn"].asBool()) @@ -1270,7 +1274,8 @@ void FEProject::LoadScene() { NewType = FE_SPOT_LIGHT; } - FELightComponent& LightComponent = Entity->AddComponent(NewType); + Entity->AddComponent(NewType); + FELightComponent& LightComponent = Entity->GetComponent(); LightComponent.SetIntensity(Root["lights"][LightList[i]]["intensity"].asFloat()); ReadTransformToJson(Root["lights"][LightList[i]]["transformation"], &Entity->GetComponent()); @@ -1367,6 +1372,11 @@ void FEProject::LoadScene() if (ProjectVersion >= 0.02f && Root["camera"].isMember("movementSpeed")) ENGINE.GetCamera()->SetMovementSpeed(Root["camera"]["movementSpeed"].asFloat()); + // After all scene objects are loaded, we need to update all objects. + SCENE.Update(); + + // FIX ME! Only after that all systems should be updated and triggered. + // VFS if (FILE_SYSTEM.CheckFile((ProjectFolder + "VFS.txt").c_str())) { diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 30f9263..dad9c90 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 30f92638da7e731d37927f3184de2307c2bb4b09 +Subproject commit dad9c907ce5a55b925ed028c831375fa2fcad99c From 9792615c62a5b921e8a183c617ece8c2ae6cd3a7 Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Sun, 14 Jul 2024 20:18:03 -0400 Subject: [PATCH 19/46] Engine update. --- EditorWindows/SceneGraphWindow.cpp | 2 +- EditorWindows/SceneGraphWindow.h | 2 +- SubSystems/FocalEngine | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 33b5f12..d07d6f8 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -186,7 +186,7 @@ DragAndDropTarget* FEEditorSceneGraphWindow::GetSceneNodeDragAndDropTarget(FENai if (SceneNodeDragAndDropTargets.find(UniqueID) == SceneNodeDragAndDropTargets.end()) { - SceneNodeDragAndDropTargets[UniqueID] = DRAG_AND_DROP_MANAGER.AddTarget(std::vector { FE_SCENE_ENTITY }, + SceneNodeDragAndDropTargets[UniqueID] = DRAG_AND_DROP_MANAGER.AddTarget(std::vector { FE_SCENE_GRAPH_NODE }, SceneNodeDragAndDropCallback, reinterpret_cast(NodeToFind), std::vector { "Drop move to that parent" }); } diff --git a/EditorWindows/SceneGraphWindow.h b/EditorWindows/SceneGraphWindow.h index 89457b9..07a3f5e 100644 --- a/EditorWindows/SceneGraphWindow.h +++ b/EditorWindows/SceneGraphWindow.h @@ -48,7 +48,7 @@ class FEEditorSceneGraphWindow bool bSceneNodeTargetsDirty = true; static bool SceneNodeDragAndDropCallback(FEObject* Object, void** SceneNodeTarget) { - if (Object == nullptr || SceneNodeTarget == nullptr || Object->GetType() != FE_SCENE_ENTITY) + if (Object == nullptr || SceneNodeTarget == nullptr || Object->GetType() != FE_SCENE_GRAPH_NODE) return false; FENaiveSceneGraphNode* NodeTarget = reinterpret_cast(SceneNodeTarget); diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index dad9c90..0ede396 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit dad9c907ce5a55b925ed028c831375fa2fcad99c +Subproject commit 0ede3961bbb30625760fb35efbd1136951d502d7 From edfc19b68301ed6485e53ac71d01d387d2ff26e6 Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Thu, 18 Jul 2024 21:13:03 -0400 Subject: [PATCH 20/46] Engine update; Adjustments made due to engine ECS subsystem updates; Fixed terrain brush mode visualization. --- EditorWindows/ContentBrowserWindow.cpp | 18 +- EditorWindows/DeletePopups.cpp | 38 +- EditorWindows/InspectorWindow.cpp | 35 +- EditorWindows/PrefabEditorWindow.cpp | 9 + EditorWindows/SceneGraphWindow.cpp | 31 +- EditorWindows/SceneGraphWindow.h | 15 +- EditorWindows/ShaderEditorWindow.cpp | 18 +- FEEditor.cpp | 149 +++-- FEEditorGizmoManager.cpp | 884 ++++++++++++------------- FEEditorPreviewManager.cpp | 76 ++- FEEditorSelectedObject.cpp | 50 +- FEProject.cpp | 97 +-- FEProject.h | 2 + SubSystems/FocalEngine | 2 +- 14 files changed, 753 insertions(+), 671 deletions(-) diff --git a/EditorWindows/ContentBrowserWindow.cpp b/EditorWindows/ContentBrowserWindow.cpp index 86152d3..9e863fd 100644 --- a/EditorWindows/ContentBrowserWindow.cpp +++ b/EditorWindows/ContentBrowserWindow.cpp @@ -132,14 +132,20 @@ void FEEditorContentBrowserWindow::Render() FILE_SYSTEM.ShowFileOpenDialog(FilePath, ALL_IMPORT_LOAD_FILTER, 3); if (!FilePath.empty()) { - const std::vector LoadedObjects = SCENE.ImportAsset(FilePath.c_str()); - for (size_t i = 0; i < LoadedObjects.size(); i++) + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (!ActiveScenes.empty()) { - if (LoadedObjects[i] != nullptr) + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + const std::vector LoadedObjects = CurrentScene->ImportAsset(FilePath.c_str()); + for (size_t i = 0; i < LoadedObjects.size(); i++) { - VIRTUAL_FILE_SYSTEM.CreateFile(LoadedObjects[i], VIRTUAL_FILE_SYSTEM.GetCurrentPath()); - PROJECT_MANAGER.GetCurrent()->SetModified(true); - PROJECT_MANAGER.GetCurrent()->AddUnSavedObject(LoadedObjects[i]); + if (LoadedObjects[i] != nullptr) + { + VIRTUAL_FILE_SYSTEM.CreateFile(LoadedObjects[i], VIRTUAL_FILE_SYSTEM.GetCurrentPath()); + PROJECT_MANAGER.GetCurrent()->SetModified(true); + PROJECT_MANAGER.GetCurrent()->AddUnSavedObject(LoadedObjects[i]); + } } } } diff --git a/EditorWindows/DeletePopups.cpp b/EditorWindows/DeletePopups.cpp index a36b56a..4062959 100644 --- a/EditorWindows/DeletePopups.cpp +++ b/EditorWindows/DeletePopups.cpp @@ -81,15 +81,21 @@ std::vector DeleteTexturePopup::MaterialsThatUsesTexture(const FETe } } - const std::vector TerrainList = SCENE.GetEntityIDListWith(); - for (size_t i = 0; i < TerrainList.size(); i++) + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (!ActiveScenes.empty()) { - /*FEEntity* CurrentTerrain = SCENE.GetEntity(TerrainList[i]); - FETerrainComponent& TerrainComponent = CurrentTerrain->GetComponent(); - if (TerrainComponent.HeightMap != nullptr && TerrainComponent.HeightMap->GetObjectID() == Texture->GetObjectID()) + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + const std::vector TerrainList = CurrentScene->GetEntityIDListWith(); + for (size_t i = 0; i < TerrainList.size(); i++) { - Result.push_back(nullptr); - }*/ + /*FEEntity* CurrentTerrain = SCENE.GetEntity(TerrainList[i]); + FETerrainComponent& TerrainComponent = CurrentTerrain->GetComponent(); + if (TerrainComponent.HeightMap != nullptr && TerrainComponent.HeightMap->GetObjectID() == Texture->GetObjectID()) + { + Result.push_back(nullptr); + }*/ + } } return Result; @@ -321,8 +327,13 @@ void DeleteGameModelPopup::DeleteGameModel(FEGameModel* GameModel) { VIRTUAL_FILE_SYSTEM.LocateAndDeleteFile(GameModel); - std::string name = GameModel->GetName(); - SCENE.PrepareForGameModelDeletion(GameModel); + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (!ActiveScenes.empty()) + { + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + CurrentScene->PrepareForGameModelDeletion(GameModel); + } RESOURCE_MANAGER.DeleteGameModel(GameModel); PROJECT_MANAGER.GetCurrent()->SetModified(true); } @@ -411,8 +422,13 @@ void DeletePrefabPopup::DeletePrefab(FEPrefab* Prefab) { VIRTUAL_FILE_SYSTEM.LocateAndDeleteFile(Prefab); - std::string name = Prefab->GetName(); - SCENE.PrepareForPrefabDeletion(Prefab); + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (!ActiveScenes.empty()) + { + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + CurrentScene->PrepareForPrefabDeletion(Prefab); + } RESOURCE_MANAGER.DeletePrefab(Prefab); PROJECT_MANAGER.GetCurrent()->SetModified(true); } diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index df4089b..7e688f8 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -441,11 +441,9 @@ std::vector FEEditorInspectorWindow::GetAvailableComponentsToAdd(FE return Result; auto RegisteredComponentList = COMPONENTS_TOOL.GetComponentInfoList(); - auto EntityComponents = Entity->GetComponentsInfoList(); - for (size_t i = 0; i < RegisteredComponentList.size(); i++) { - if (RegisteredComponentList[i].IsCompatible(EntityComponents)) + if (RegisteredComponentList[i].IsCompatible(Entity)) Result.push_back(RegisteredComponentList[i].Name); } @@ -495,6 +493,7 @@ void FEEditorInspectorWindow::Render() } FEEntity* EntitySelected = SELECTED.GetSelected(); + FEScene* CurrentScene = EntitySelected->GetParentScene(); ImGui::Text("ID : %s", EntitySelected->GetObjectID().c_str()); ImGui::Text("Name : %s", EntitySelected->GetName().c_str()); @@ -633,7 +632,7 @@ void FEEditorInspectorWindow::Render() ImGui::Text("Snapped to: "); ImGui::SameLine(); - const std::vector TerrainList = SCENE.GetEntityIDListWith(); + const std::vector TerrainList = CurrentScene->GetEntityIDListWith(); static std::string CurrentTerrain = "none"; if (InstancedComponent.GetSnappedToTerrain() == nullptr) @@ -663,9 +662,9 @@ void FEEditorInspectorWindow::Render() for (size_t i = 0; i < TerrainList.size(); i++) { const bool bIsSelected = (CurrentTerrain == TerrainList[i]); - if (ImGui::Selectable(SCENE.GetEntity(TerrainList[i])->GetName().c_str(), bIsSelected)) + if (ImGui::Selectable(CurrentScene->GetEntity(TerrainList[i])->GetName().c_str(), bIsSelected)) { - TERRAIN_SYSTEM.SnapInstancedEntity(SCENE.GetEntity(TerrainList[i]), EntitySelected); + TERRAIN_SYSTEM.SnapInstancedEntity(CurrentScene->GetEntity(TerrainList[i]), EntitySelected); } if (bIsSelected) @@ -871,17 +870,17 @@ void FEEditorInspectorWindow::Render() // To hide gizmos. SELECTED.SetSelected(EntitySelected); - TERRAIN_SYSTEM.SetBrushActive(EntitySelected, bLeftMousePressed); + TERRAIN_SYSTEM.SetBrushActive(bLeftMousePressed); if (bShiftPressed) { if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW) - TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED); + TERRAIN_SYSTEM.SetBrushMode(EntitySelected, FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED); } else { if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) - TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); + TERRAIN_SYSTEM.SetBrushMode(EntitySelected, FE_TERRAIN_BRUSH_SCULPT_DRAW); } } else @@ -1077,8 +1076,6 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) ImGui::Text(SizeInM.c_str()); // ********************* REAL WORLD COMPARISON SCALE END ********************* - //ShowTransformConfiguration(Terrain, &TerrainComponent.Transform); - ImGui::EndTabItem(); } if (ImGui::BeginTabItem("Sculpt")) @@ -1144,11 +1141,11 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW || TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_DRAW_INVERSED) { - TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_NONE); + TERRAIN_SYSTEM.SetBrushMode(TerrainEntity, FE_TERRAIN_BRUSH_NONE); } else { - TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_DRAW); + TERRAIN_SYSTEM.SetBrushMode(TerrainEntity, FE_TERRAIN_BRUSH_SCULPT_DRAW); } } @@ -1164,11 +1161,11 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) { if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_LEVEL) { - TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_NONE); + TERRAIN_SYSTEM.SetBrushMode(TerrainEntity, FE_TERRAIN_BRUSH_NONE); } else { - TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_LEVEL); + TERRAIN_SYSTEM.SetBrushMode(TerrainEntity, FE_TERRAIN_BRUSH_SCULPT_LEVEL); } } @@ -1184,11 +1181,11 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) { if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_SCULPT_SMOOTH) { - TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_NONE); + TERRAIN_SYSTEM.SetBrushMode(TerrainEntity, FE_TERRAIN_BRUSH_NONE); } else { - TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_SCULPT_SMOOTH); + TERRAIN_SYSTEM.SetBrushMode(TerrainEntity, FE_TERRAIN_BRUSH_SCULPT_SMOOTH); } } @@ -1224,11 +1221,11 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) { if (TERRAIN_SYSTEM.GetBrushMode() == FE_TERRAIN_BRUSH_LAYER_DRAW) { - TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_NONE); + TERRAIN_SYSTEM.SetBrushMode(TerrainEntity, FE_TERRAIN_BRUSH_NONE); } else { - TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_LAYER_DRAW); + TERRAIN_SYSTEM.SetBrushMode(TerrainEntity, FE_TERRAIN_BRUSH_LAYER_DRAW); } } diff --git a/EditorWindows/PrefabEditorWindow.cpp b/EditorWindows/PrefabEditorWindow.cpp index a5abc69..dcf78d7 100644 --- a/EditorWindows/PrefabEditorWindow.cpp +++ b/EditorWindows/PrefabEditorWindow.cpp @@ -109,8 +109,17 @@ PrefabEditorWindow::~PrefabEditorWindow() delete CloseButton; } +// FIX ME! Temporary. +#include "SceneGraphWindow.h" void PrefabEditorWindow::Show(FEPrefab* Prefab) { + // FIX ME! test + if (Prefab->Scene != nullptr) + { + SCENE_MANAGER.TestScene = Prefab->Scene; + SCENE_GRAPH_WINDOW.SetScene(SCENE_MANAGER.TestScene); + } + Size = ImVec2(800, 800); Position = ImVec2(FEngine::getInstance().GetWindowWidth() / 2 - Size.x / 2, FEngine::getInstance().GetWindowHeight() / 2 - Size.y / 2); diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index d07d6f8..f84bae5 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -29,6 +29,16 @@ void FEEditorSceneGraphWindow::InitializeResources() RESOURCE_MANAGER.MakeTextureStandard(CameraIcon); } +void FEEditorSceneGraphWindow::SetScene(FEScene* Scene) +{ + CurrentScene = Scene; +} + +FEScene* FEEditorSceneGraphWindow::GetScene() +{ + return CurrentScene; +} + void FEEditorSceneGraphWindow::Clear() { strcpy_s(FilterForEntities, ""); @@ -82,7 +92,7 @@ static void CreateInstancedEntityCallBack(const std::vector Selection if (SelectedPrefab == nullptr) return; - FEEntity* Entity = SCENE.AddEntity(); + FEEntity* Entity = SCENE_GRAPH_WINDOW.GetScene()->AddEntity(); Entity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); Entity->AddComponent(SelectedPrefab->GetComponent(0)->GameModel); Entity->AddComponent(); @@ -100,7 +110,7 @@ static void CreateEntityCallBack(const std::vector SelectionsResult) if (SelectedPrefab == nullptr) return; - FEEntity* Entity = SCENE.AddEntity(); + FEEntity* Entity = SCENE_GRAPH_WINDOW.GetScene()->AddEntity(); Entity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); SELECTED.SetSelected(Entity); @@ -267,7 +277,7 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) void FEEditorSceneGraphWindow::RenderNewSceneGraph() { - FENaiveSceneGraphNode* Root = SCENE.SceneGraph.GetRoot(); + FENaiveSceneGraphNode* Root = SCENE_GRAPH_WINDOW.GetScene()->SceneGraph.GetRoot(); if (bSceneNodeTargetsDirty) SceneNodeDragAndDropTargets.clear(); @@ -284,6 +294,9 @@ void FEEditorSceneGraphWindow::Render() if (!bVisible) return; + if (CurrentScene == nullptr) + return; + static int SceneObjectHoveredIndex = -1; ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); @@ -314,7 +327,7 @@ void FEEditorSceneGraphWindow::Render() // SceneObjectsList.push_back(EntityList[i]); //} - const std::vector TerrainList = SCENE.GetEntityIDListWith(); + const std::vector TerrainList = CurrentScene->GetEntityIDListWith(); for (size_t i = 0; i < TerrainList.size(); i++) { SceneObjectsList.push_back(TerrainList[i]); @@ -400,7 +413,7 @@ void FEEditorSceneGraphWindow::Render() { if (ImGui::MenuItem("Empty entity")) { - SCENE.AddEntity("Unnamed entity"); + CurrentScene->AddEntity("Unnamed entity"); } // FIX ME! @@ -452,21 +465,21 @@ void FEEditorSceneGraphWindow::Render() { if (ImGui::MenuItem("Rename")) { - if (SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) + if (CurrentScene->GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) { - RenamePopUp::getInstance().Show(SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex])); + RenamePopUp::getInstance().Show(CurrentScene->GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex])); } } if (ImGui::MenuItem("Delete")) { - FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); + FEEntity* Entity = CurrentScene->GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); if (Entity != nullptr) { if (SELECTED.GetSelected() == Entity) SELECTED.Clear(); - SCENE.DeleteEntity(Entity); + CurrentScene->DeleteEntity(Entity); } // FIX ME! diff --git a/EditorWindows/SceneGraphWindow.h b/EditorWindows/SceneGraphWindow.h index 07a3f5e..d886c6d 100644 --- a/EditorWindows/SceneGraphWindow.h +++ b/EditorWindows/SceneGraphWindow.h @@ -7,6 +7,8 @@ class FEEditorSceneGraphWindow friend class FEEditor; SINGLETON_PRIVATE_PART(FEEditorSceneGraphWindow) + FEScene* CurrentScene = nullptr; + // Visibility bool bVisible = true; @@ -54,7 +56,15 @@ class FEEditorSceneGraphWindow FENaiveSceneGraphNode* NodeTarget = reinterpret_cast(SceneNodeTarget); FENaiveSceneGraphNode* SceneEntity = reinterpret_cast(Object); - return SCENE.SceneGraph.MoveNode(SceneEntity->GetObjectID(), NodeTarget->GetObjectID()); + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (!ActiveScenes.empty()) + { + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + return CurrentScene->SceneGraph.MoveNode(SceneEntity->GetObjectID(), NodeTarget->GetObjectID()); + } + + return false; } void UpdateSceneNodeDragAndDropTargets(); @@ -68,6 +78,9 @@ class FEEditorSceneGraphWindow public: SINGLETON_PUBLIC_PART(FEEditorSceneGraphWindow) + + void SetScene(FEScene* Scene); + FEScene* GetScene(); }; #define SCENE_GRAPH_WINDOW FEEditorSceneGraphWindow::getInstance() \ No newline at end of file diff --git a/EditorWindows/ShaderEditorWindow.cpp b/EditorWindows/ShaderEditorWindow.cpp index 7051f17..353b2bb 100644 --- a/EditorWindows/ShaderEditorWindow.cpp +++ b/EditorWindows/ShaderEditorWindow.cpp @@ -466,14 +466,20 @@ void ShaderEditorWindow::ReplaceShader(FEShader* OldShader, FEShader* NewShader) } } - const std::vector TerrainList = SCENE.GetEntityIDListWith(); - for (size_t i = 0; i < TerrainList.size(); i++) + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (!ActiveScenes.empty()) { - FEEntity* TempTerrain = SCENE.GetEntity(TerrainList[i]); - FETerrainComponent& TerrainComponent = TempTerrain->GetComponent(); - if (TerrainComponent.Shader->GetNameHash() == OldShader->GetNameHash()) + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + const std::vector TerrainList = CurrentScene->GetEntityIDListWith(); + for (size_t i = 0; i < TerrainList.size(); i++) { - TerrainComponent.Shader = NewShader; + FEEntity* TempTerrain = CurrentScene->GetEntity(TerrainList[i]); + FETerrainComponent& TerrainComponent = TempTerrain->GetComponent(); + if (TerrainComponent.Shader->GetNameHash() == OldShader->GetNameHash()) + { + TerrainComponent.Shader = NewShader; + } } } } \ No newline at end of file diff --git a/FEEditor.cpp b/FEEditor.cpp index 3147149..c6c27e4 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -9,13 +9,19 @@ bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) { FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())->GetComponent(0)->GameModel; - FEEntity* Entity = SCENE.AddEntity(Object->GetName()); - Entity->GetComponent().GameModel = GameModel; - Entity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - SELECTED.SetSelected(Entity); - PROJECT_MANAGER.GetCurrent()->SetModified(true); + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (!ActiveScenes.empty()) + { + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + FEEntity* Entity = CurrentScene->AddEntity(Object->GetName()); + Entity->GetComponent().GameModel = GameModel; + Entity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + SELECTED.SetSelected(Entity); + PROJECT_MANAGER.GetCurrent()->SetModified(true); - return true; + return true; + } } return false; @@ -168,7 +174,13 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) } else { - SCENE.DeleteEntity(SELECTED.GetSelected()); + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (!ActiveScenes.empty()) + { + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + CurrentScene->DeleteEntity(SELECTED.GetSelected()); + } } SELECTED.Clear(); @@ -186,17 +198,21 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) { if (!EDITOR.GetSceneEntityIDInClipboard().empty()) { - // FIX ME! - // There should be proper FEScene::DuplicateEntity that will duplicate the entity and all its components - // Also place it in same scene graph node as the original entity ? - FEEntity* EntityToCopy = SCENE.GetEntity(EDITOR.GetSceneEntityIDInClipboard()); - FEEntity* Entity = SCENE.AddEntity(EntityToCopy->GetName() + "_Copy"); - Entity->GetComponent() = EntityToCopy->GetComponent(); - Entity->GetComponent().SetPosition(EntityToCopy->GetComponent().GetPosition() * 1.1f); - if (EntityToCopy->HasComponent()) - Entity->AddComponent(EntityToCopy->GetComponent().GameModel); - - SELECTED.SetSelected(Entity); + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (!ActiveScenes.empty()) + { + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + + FEEntity* EntityToDuplicate = CurrentScene->GetEntity(EDITOR.GetSceneEntityIDInClipboard()); + FENaiveSceneGraphNode* NodeToDuplicate = CurrentScene->SceneGraph.GetNodeByEntityID(EntityToDuplicate->GetObjectID()); + FENaiveSceneGraphNode* DuplicatedNode = CurrentScene->SceneGraph.DuplicateNode(NodeToDuplicate->GetObjectID(), NodeToDuplicate->GetParent()->GetObjectID()); + if (DuplicatedNode != nullptr) + { + FEEntity* DuplicatedEntity = DuplicatedNode->GetEntity(); + SELECTED.SetSelected(DuplicatedEntity); + } + } } } @@ -236,39 +252,42 @@ void FEEditor::InitializeResources() // **************************** Gizmos **************************** GIZMO_MANAGER.InitializeResources(); - // hide all resources for gizmos from content browser - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("45191B6F172E3B531978692E"/*"transformationGizmoMesh"*/)); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("637C784B2E5E5C6548190E1B"/*"scaleGizmoMesh"*/)); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("19622421516E5B317E1B5360"/*"rotateGizmoMesh"*/)); - - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity); - - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleZGizmoEntity); - - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateXGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateZGizmoEntity); - - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(PREVIEW_MANAGER.PreviewEntity); + if (!SCENE_MANAGER.GetActiveScenes().empty()) + { + // hide all resources for gizmos from content browser + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("45191B6F172E3B531978692E"/*"transformationGizmoMesh"*/)); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("637C784B2E5E5C6548190E1B"/*"scaleGizmoMesh"*/)); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("19622421516E5B317E1B5360"/*"rotateGizmoMesh"*/)); + + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoEntity); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity); + + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoEntity); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleZGizmoEntity); + + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateXGizmoEntity); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateYGizmoEntity); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().GameModel); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateZGizmoEntity); + + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(PREVIEW_MANAGER.PreviewEntity); + } SCENE_GRAPH_WINDOW.InitializeResources(); CONTENT_BROWSER_WINDOW.InitializeResources(); @@ -557,20 +576,26 @@ void FEEditor::DropCallback(const int Count, const char** Paths) if (PROJECT_MANAGER.GetCurrent() != nullptr) { - std::vector LoadedObjects = SCENE.ImportAsset(Paths[i]); - for (size_t j = 0; j < LoadedObjects.size(); j++) + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (!ActiveScenes.empty()) { - if (LoadedObjects[j] != nullptr) + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + std::vector LoadedObjects = CurrentScene->ImportAsset(Paths[i]); + for (size_t j = 0; j < LoadedObjects.size(); j++) { - if (LoadedObjects[j]->GetType() == FE_ENTITY) - { - //SCENE.AddEntity(reinterpret_cast(LoadedObjects[j])); - } - else + if (LoadedObjects[j] != nullptr) { - VIRTUAL_FILE_SYSTEM.CreateFile(LoadedObjects[j], VIRTUAL_FILE_SYSTEM.GetCurrentPath()); - PROJECT_MANAGER.GetCurrent()->SetModified(true); - PROJECT_MANAGER.GetCurrent()->AddUnSavedObject(LoadedObjects[j]); + if (LoadedObjects[j]->GetType() == FE_ENTITY) + { + //SCENE.AddEntity(reinterpret_cast(LoadedObjects[j])); + } + else + { + VIRTUAL_FILE_SYSTEM.CreateFile(LoadedObjects[j], VIRTUAL_FILE_SYSTEM.GetCurrentPath()); + PROJECT_MANAGER.GetCurrent()->SetModified(true); + PROJECT_MANAGER.GetCurrent()->AddUnSavedObject(LoadedObjects[j]); + } } } } diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index c813cf6..bdfdf86 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -12,336 +12,263 @@ void GizmoManager::InitializeResources() FEMesh* TransformationGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "45191B6F172E3B531978692E.model").c_str(), "transformationGizmoMesh"); RESOURCE_MANAGER.MakeMeshStandard(TransformationGizmoMesh); - ParentGizmoEntity = SCENE.AddEntity("ParentGizmoEntity"); - FENaiveSceneGraphNode* ParentGizmoGraphNode = SCENE.SceneGraph.GetNodeByEntityID(ParentGizmoEntity->GetObjectID()); - - // TransformationXGizmo - FEMaterial* CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - TransformationXGizmoEntity = SCENE.AddEntity("TransformationXGizmoEntity"); - //TransformationXGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM"), "TransformationXGizmoEntity")); - TransformationXGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM")); - TransformationXGizmoEntity->SetName("TransformationXGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationXGizmoEntity->GetComponent().GameModel); - TransformationXGizmoEntity->GetComponent().SetCastShadows(false); - TransformationXGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - TransformationXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - TransformationXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // TransformationYGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - TransformationYGizmoEntity = SCENE.AddEntity("TransformationYGizmoEntity"); - //TransformationYGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"), "TransformationYGizmoEntity")); - TransformationYGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM")); - TransformationYGizmoEntity->SetName("TransformationYGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationYGizmoEntity->GetComponent().GameModel); - TransformationYGizmoEntity->GetComponent().SetCastShadows(false); - TransformationYGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - TransformationYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); - TransformationYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - /*TransformationYGizmoEntity = SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"), "transformationYGizmoEntity"); - RESOURCE_MANAGER.MakePrefabStandard(TransformationYGizmoEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationYGizmoEntity->Prefab->GetComponent(0)->GameModel); - TransformationYGizmoEntity->SetCastShadows(false); - TransformationYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); - TransformationYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); - TransformationYGizmoEntity->SetIsPostprocessApplied(false);*/ - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // TransformationZGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationZGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - TransformationZGizmoEntity = SCENE.AddEntity("TransformationZGizmoEntity"); - //TransformationZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"), "TransformationZGizmoEntity")); - TransformationZGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM")); - TransformationYGizmoEntity->SetName("TransformationZGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationZGizmoEntity->GetComponent().GameModel); - TransformationZGizmoEntity->GetComponent().SetCastShadows(false); - TransformationZGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - TransformationZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - TransformationZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - /*TransformationZGizmoEntity = SCENE.AddEntity(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"), "transformationZGizmoEntity"); - RESOURCE_MANAGER.MakePrefabStandard(TransformationZGizmoEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationZGizmoEntity->Prefab->GetComponent(0)->GameModel); - TransformationZGizmoEntity->SetCastShadows(false); - TransformationZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); - TransformationZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - TransformationZGizmoEntity->SetIsPostprocessApplied(false);*/ - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // Plane gizmos - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXYGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - TransformationXYGizmoEntity = SCENE.AddEntity("TransformationXYGizmoEntity"); - //TransformationXYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"), "TransformationXYGizmoEntity")); - TransformationXYGizmoEntity->AddComponent(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM")); - TransformationXYGizmoEntity->SetName("TransformationXYGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationXYGizmoEntity->GetComponent().GameModel); - TransformationXYGizmoEntity->GetComponent().SetCastShadows(false); - TransformationXYGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationXYGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); - TransformationXYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); - TransformationXYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - TransformationXYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - //TransformationXYGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"), "transformationXYGizmoEntity"); - //RESOURCE_MANAGER.MakePrefabStandard(TransformationXYGizmoEntity->Prefab); - //RESOURCE_MANAGER.MakeGameModelStandard(TransformationXYGizmoEntity->Prefab->GetComponent(0)->GameModel); - //TransformationXYGizmoEntity->SetCastShadows(false); - //TransformationXYGizmoEntity->Transform.SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); - //TransformationXYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); - //TransformationXYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - //TransformationXYGizmoEntity->SetIsPostprocessApplied(false); - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYZGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - TransformationYZGizmoEntity = SCENE.AddEntity("TransformationYZGizmoEntity"); - //TransformationYZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"), "TransformationYZGizmoEntity")); - TransformationYZGizmoEntity->AddComponent(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM")); - TransformationYZGizmoEntity->SetName("TransformationYZGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationYZGizmoEntity->GetComponent().GameModel); - TransformationYZGizmoEntity->GetComponent().SetCastShadows(false); - TransformationYZGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationYZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); - TransformationYZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); - TransformationYZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - TransformationYZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - //TransformationYZGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"), "transformationYZGizmoEntity"); - //RESOURCE_MANAGER.MakePrefabStandard(TransformationYZGizmoEntity->Prefab); - //RESOURCE_MANAGER.MakeGameModelStandard(TransformationYZGizmoEntity->Prefab->GetComponent(0)->GameModel); - //TransformationYZGizmoEntity->SetCastShadows(false); - //TransformationYZGizmoEntity->Transform.SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); - //TransformationYZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); - //TransformationYZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - //TransformationYZGizmoEntity->SetIsPostprocessApplied(false); - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXZGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - TransformationXZGizmoEntity = SCENE.AddEntity("TransformationXZGizmoEntity"); - //TransformationXZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"), "TransformationXZGizmoEntity")); - TransformationXZGizmoEntity->SetName("TransformationXZGizmoEntity"); - TransformationXZGizmoEntity->AddComponent(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM")); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationXZGizmoEntity->GetComponent().GameModel); - TransformationXZGizmoEntity->GetComponent().SetCastShadows(false); - TransformationXZGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationXZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); - TransformationXZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); - TransformationXZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - TransformationXZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - //TransformationXZGizmoEntity = SCENE.AddEntity(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"), "transformationXZGizmoEntity"); - //RESOURCE_MANAGER.MakePrefabStandard(TransformationXZGizmoEntity->Prefab); - //RESOURCE_MANAGER.MakeGameModelStandard(TransformationXZGizmoEntity->Prefab->GetComponent(0)->GameModel); - //TransformationXZGizmoEntity->SetCastShadows(false); - //TransformationXZGizmoEntity->Transform.SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); - //TransformationXZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); - //TransformationXZGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - //TransformationXZGizmoEntity->SetIsPostprocessApplied(false); - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // Scale gizmos. - FEMesh* ScaleGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "637C784B2E5E5C6548190E1B.model").c_str(), "scaleGizmoMesh"); - RESOURCE_MANAGER.MakeMeshStandard(ScaleGizmoMesh); - - // ScaleXGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleXGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - ScaleXGizmoEntity = SCENE.AddEntity("ScaleXGizmoEntity"); - //ScaleXGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM"), "ScaleXGizmoEntity")); - ScaleXGizmoEntity->AddComponent(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM")); - ScaleXGizmoEntity->SetName("ScaleXGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(ScaleXGizmoEntity->GetComponent().GameModel); - ScaleXGizmoEntity->GetComponent().SetCastShadows(false); - ScaleXGizmoEntity->GetComponent().SetReceivingShadows(false); - ScaleXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - ScaleXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - ScaleXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - /*ScaleXGizmoEntity = SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "scaleXGizmoGM"), "scaleXGizmoEntity"); - RESOURCE_MANAGER.MakePrefabStandard(ScaleXGizmoEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(ScaleXGizmoEntity->Prefab->GetComponent(0)->GameModel); - ScaleXGizmoEntity->SetCastShadows(false); - ScaleXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); - ScaleXGizmoEntity->Transform.SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - ScaleXGizmoEntity->SetIsPostprocessApplied(false);*/ - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // ScaleYGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleYGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - ScaleYGizmoEntity = SCENE.AddEntity("ScaleYGizmoEntity"); - //ScaleYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM"), "ScaleYGizmoEntity")); - ScaleYGizmoEntity->AddComponent(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM")); - ScaleYGizmoEntity->SetName("ScaleYGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(ScaleYGizmoEntity->GetComponent().GameModel); - ScaleYGizmoEntity->GetComponent().SetCastShadows(false); - ScaleYGizmoEntity->GetComponent().SetReceivingShadows(false); - ScaleYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - ScaleYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); - ScaleYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - /*ScaleYGizmoEntity = SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "scaleYGizmoGM"), "scaleYGizmoEntity"); - RESOURCE_MANAGER.MakePrefabStandard(ScaleYGizmoEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(ScaleYGizmoEntity->Prefab->GetComponent(0)->GameModel); - ScaleYGizmoEntity->SetCastShadows(false); - ScaleYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); - ScaleYGizmoEntity->Transform.SetRotation(glm::vec3(0.0f)); - ScaleYGizmoEntity->SetIsPostprocessApplied(false);*/ - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // ScaleZGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleZGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - ScaleZGizmoEntity = SCENE.AddEntity("ScaleZGizmoEntity"); - //ScaleZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM"), "ScaleZGizmoEntity")); - ScaleZGizmoEntity->AddComponent(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM")); - ScaleZGizmoEntity->SetName("ScaleZGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(ScaleZGizmoEntity->GetComponent().GameModel); - ScaleZGizmoEntity->GetComponent().SetCastShadows(false); - ScaleZGizmoEntity->GetComponent().SetReceivingShadows(false); - ScaleZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - ScaleZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - ScaleZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - /*ScaleZGizmoEntity = SCENE.AddEntity(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "scaleZGizmoGM"), "scaleZGizmoEntity"); - RESOURCE_MANAGER.MakePrefabStandard(ScaleZGizmoEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(ScaleZGizmoEntity->Prefab->GetComponent(0)->GameModel); - ScaleZGizmoEntity->SetCastShadows(false); - ScaleZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale)); - ScaleZGizmoEntity->Transform.SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - ScaleZGizmoEntity->SetIsPostprocessApplied(false);*/ - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // RotateAroundAxis gizmos - FEMesh* RotateGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "19622421516E5B317E1B5360.model").c_str(), "rotateGizmoMesh"); - RESOURCE_MANAGER.MakeMeshStandard(RotateGizmoMesh); - - // RotateXGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateXGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - RotateXGizmoEntity = SCENE.AddEntity("RotateXGizmoEntity"); - //RotateXGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM"), "RotateXGizmoEntity")); - RotateXGizmoEntity->AddComponent(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM")); - RotateXGizmoEntity->SetName("RotateXGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(RotateXGizmoEntity->GetComponent().GameModel); - RotateXGizmoEntity->GetComponent().SetCastShadows(false); - RotateXGizmoEntity->GetComponent().SetReceivingShadows(false); - RotateXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateXGizmoEntity->GetComponent().SetRotation(RotateXStandardRotation); - RotateXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - /*RotateXGizmoEntity = SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "rotateXGizmoGM"), "rotateXGizmoEntity"); - RESOURCE_MANAGER.MakePrefabStandard(RotateXGizmoEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(RotateXGizmoEntity->Prefab->GetComponent(0)->GameModel); - RotateXGizmoEntity->SetCastShadows(false); - RotateXGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateXGizmoEntity->Transform.SetRotation(RotateXStandardRotation); - RotateXGizmoEntity->SetIsPostprocessApplied(false);*/ - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // RotateYGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateYGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - RotateYGizmoEntity = SCENE.AddEntity("RotateYGizmoEntity"); - //RotateYGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM"), "RotateYGizmoEntity")); - RotateYGizmoEntity->AddComponent(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM")); - RotateYGizmoEntity->SetName("RotateYGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(RotateYGizmoEntity->GetComponent().GameModel); - RotateYGizmoEntity->GetComponent().SetCastShadows(false); - RotateYGizmoEntity->GetComponent().SetReceivingShadows(false); - RotateYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateYGizmoEntity->GetComponent().SetRotation(RotateYStandardRotation); - RotateYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - /*RotateYGizmoEntity = SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "rotateYGizmoGM"), "rotateYGizmoEntity"); - RESOURCE_MANAGER.MakePrefabStandard(RotateYGizmoEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(RotateYGizmoEntity->Prefab->GetComponent(0)->GameModel); - RotateYGizmoEntity->SetCastShadows(false); - RotateYGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateYGizmoEntity->Transform.SetRotation(RotateYStandardRotation); - RotateYGizmoEntity->SetIsPostprocessApplied(false);*/ - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // RotateZGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateZGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - RotateZGizmoEntity = SCENE.AddEntity("RotateZGizmoEntity"); - //RotateZGizmoEntity->AddComponent(SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM"), "RotateZGizmoEntity")); - RotateZGizmoEntity->AddComponent(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM")); - RotateZGizmoEntity->SetName("RotateZGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(RotateZGizmoEntity->GetComponent().GameModel); - RotateZGizmoEntity->GetComponent().SetCastShadows(false); - RotateZGizmoEntity->GetComponent().SetReceivingShadows(false); - RotateZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateZGizmoEntity->GetComponent().SetRotation(RotateZStandardRotation); - RotateZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - /*RotateZGizmoEntity = SCENE.AddEntity(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "rotateZGizmoGM"), "rotateZGizmoEntity"); - RESOURCE_MANAGER.MakePrefabStandard(RotateZGizmoEntity->Prefab); - RESOURCE_MANAGER.MakeGameModelStandard(RotateZGizmoEntity->Prefab->GetComponent(0)->GameModel); - RotateZGizmoEntity->SetCastShadows(false); - RotateZGizmoEntity->Transform.SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateZGizmoEntity->Transform.SetRotation(RotateZStandardRotation); - RotateZGizmoEntity->SetIsPostprocessApplied(false);*/ - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + // FIX ME! Temporary solution, only supports one scene + //std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + //if (!ActiveScenes.empty()) + //{ + //FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + //ParentGizmoEntity = CurrentScene->AddEntity("ParentGizmoEntity"); + //FENaiveSceneGraphNode* ParentGizmoGraphNode = CurrentScene->SceneGraph.GetNodeByEntityID(ParentGizmoEntity->GetObjectID()); + + // TransformationXGizmo + FEMaterial* CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + FEGameModel* CurrentModel = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + //TransformationXGizmoEntity = CurrentScene->AddEntity("TransformationXGizmoEntity"); + //TransformationXGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM")); + //TransformationXGizmoEntity->SetName("TransformationXGizmoEntity"); + //RESOURCE_MANAGER.MakeGameModelStandard(TransformationXGizmoEntity->GetComponent().GameModel); + /*TransformationXGizmoEntity->GetComponent().SetCastShadows(false); + TransformationXGizmoEntity->GetComponent().SetReceivingShadows(false); + TransformationXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + TransformationXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + TransformationXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ + + // TransformationYGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + //TransformationYGizmoEntity = CurrentScene->AddEntity("TransformationYGizmoEntity"); + //TransformationYGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM")); + //TransformationYGizmoEntity->SetName("TransformationYGizmoEntity"); + /*RESOURCE_MANAGER.MakeGameModelStandard(TransformationYGizmoEntity->GetComponent().GameModel); + TransformationYGizmoEntity->GetComponent().SetCastShadows(false); + TransformationYGizmoEntity->GetComponent().SetReceivingShadows(false); + TransformationYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + TransformationYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); + TransformationYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ + + // TransformationZGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationZGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + /*TransformationZGizmoEntity = CurrentScene->AddEntity("TransformationZGizmoEntity"); + TransformationZGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM")); + TransformationYGizmoEntity->SetName("TransformationZGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationZGizmoEntity->GetComponent().GameModel); + TransformationZGizmoEntity->GetComponent().SetCastShadows(false); + TransformationZGizmoEntity->GetComponent().SetReceivingShadows(false); + TransformationZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + TransformationZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); + TransformationZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ + + // Plane gizmos + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXYGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + //TransformationXYGizmoEntity = CurrentScene->AddEntity("TransformationXYGizmoEntity"); + //TransformationXYGizmoEntity->AddComponent(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM")); + //TransformationXYGizmoEntity->SetName("TransformationXYGizmoEntity"); + //RESOURCE_MANAGER.MakeGameModelStandard(TransformationXYGizmoEntity->GetComponent().GameModel); + //TransformationXYGizmoEntity->GetComponent().SetCastShadows(false); + //TransformationXYGizmoEntity->GetComponent().SetReceivingShadows(false); + //TransformationXYGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); + //TransformationXYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); + //TransformationXYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + //TransformationXYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + //CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYZGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + //TransformationYZGizmoEntity = CurrentScene->AddEntity("TransformationYZGizmoEntity"); + //TransformationYZGizmoEntity->AddComponent(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM")); + //TransformationYZGizmoEntity->SetName("TransformationYZGizmoEntity"); + //RESOURCE_MANAGER.MakeGameModelStandard(TransformationYZGizmoEntity->GetComponent().GameModel); + //TransformationYZGizmoEntity->GetComponent().SetCastShadows(false); + //TransformationYZGizmoEntity->GetComponent().SetReceivingShadows(false); + //TransformationYZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); + //TransformationYZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); + //TransformationYZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + //TransformationYZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + //CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXZGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + //TransformationXZGizmoEntity = CurrentScene->AddEntity("TransformationXZGizmoEntity"); + //TransformationXZGizmoEntity->SetName("TransformationXZGizmoEntity"); + //TransformationXZGizmoEntity->AddComponent(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM")); + //RESOURCE_MANAGER.MakeGameModelStandard(TransformationXZGizmoEntity->GetComponent().GameModel); + //TransformationXZGizmoEntity->GetComponent().SetCastShadows(false); + //TransformationXZGizmoEntity->GetComponent().SetReceivingShadows(false); + //TransformationXZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); + //TransformationXZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); + //TransformationXZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + //TransformationXZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + //CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + + // Scale gizmos. + FEMesh* ScaleGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "637C784B2E5E5C6548190E1B.model").c_str(), "scaleGizmoMesh"); + RESOURCE_MANAGER.MakeMeshStandard(ScaleGizmoMesh); + + // ScaleXGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleXGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + /*ScaleXGizmoEntity = CurrentScene->AddEntity("ScaleXGizmoEntity"); + ScaleXGizmoEntity->AddComponent(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM")); + ScaleXGizmoEntity->SetName("ScaleXGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(ScaleXGizmoEntity->GetComponent().GameModel); + ScaleXGizmoEntity->GetComponent().SetCastShadows(false); + ScaleXGizmoEntity->GetComponent().SetReceivingShadows(false); + ScaleXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + ScaleXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + ScaleXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ + + // ScaleYGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleYGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + /*ScaleYGizmoEntity = CurrentScene->AddEntity("ScaleYGizmoEntity"); + ScaleYGizmoEntity->AddComponent(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM")); + ScaleYGizmoEntity->SetName("ScaleYGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(ScaleYGizmoEntity->GetComponent().GameModel); + ScaleYGizmoEntity->GetComponent().SetCastShadows(false); + ScaleYGizmoEntity->GetComponent().SetReceivingShadows(false); + ScaleYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + ScaleYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); + ScaleYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ + + // ScaleZGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleZGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + /*ScaleZGizmoEntity = CurrentScene->AddEntity("ScaleZGizmoEntity"); + ScaleZGizmoEntity->AddComponent(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM")); + ScaleZGizmoEntity->SetName("ScaleZGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(ScaleZGizmoEntity->GetComponent().GameModel); + ScaleZGizmoEntity->GetComponent().SetCastShadows(false); + ScaleZGizmoEntity->GetComponent().SetReceivingShadows(false); + ScaleZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + ScaleZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); + ScaleZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ + + // RotateAroundAxis gizmos + FEMesh* RotateGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "19622421516E5B317E1B5360.model").c_str(), "rotateGizmoMesh"); + RESOURCE_MANAGER.MakeMeshStandard(RotateGizmoMesh); + + // RotateXGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateXGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + /*RotateXGizmoEntity = CurrentScene->AddEntity("RotateXGizmoEntity"); + RotateXGizmoEntity->AddComponent(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM")); + RotateXGizmoEntity->SetName("RotateXGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(RotateXGizmoEntity->GetComponent().GameModel); + RotateXGizmoEntity->GetComponent().SetCastShadows(false); + RotateXGizmoEntity->GetComponent().SetReceivingShadows(false); + RotateXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); + RotateXGizmoEntity->GetComponent().SetRotation(RotateXStandardRotation); + RotateXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ + + // RotateYGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateYGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + /*RotateYGizmoEntity = CurrentScene->AddEntity("RotateYGizmoEntity"); + RotateYGizmoEntity->AddComponent(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM")); + RotateYGizmoEntity->SetName("RotateYGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(RotateYGizmoEntity->GetComponent().GameModel); + RotateYGizmoEntity->GetComponent().SetCastShadows(false); + RotateYGizmoEntity->GetComponent().SetReceivingShadows(false); + RotateYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); + RotateYGizmoEntity->GetComponent().SetRotation(RotateYStandardRotation); + RotateYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ + + // RotateZGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateZGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + /*RotateZGizmoEntity = CurrentScene->AddEntity("RotateZGizmoEntity"); + RotateZGizmoEntity->AddComponent(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM")); + RotateZGizmoEntity->SetName("RotateZGizmoEntity"); + RESOURCE_MANAGER.MakeGameModelStandard(RotateZGizmoEntity->GetComponent().GameModel); + RotateZGizmoEntity->GetComponent().SetCastShadows(false); + RotateZGizmoEntity->GetComponent().SetReceivingShadows(false); + RotateZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); + RotateZGizmoEntity->GetComponent().SetRotation(RotateZStandardRotation); + RotateZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ + //} TransformationGizmoIcon = RESOURCE_MANAGER.LoadFETexture((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "456A31026A1C3152181A6064.texture").c_str(), "transformationGizmoIcon"); RESOURCE_MANAGER.MakeTextureStandard(TransformationGizmoIcon); @@ -459,8 +386,14 @@ void GizmoManager::DeactivateAllGizmo() void GizmoManager::Render() { + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (ActiveScenes.empty()) + return; + + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; // If we cleared the scene, we should not render gizmos. - if (SCENE.GetEntityByName("TransformationXGizmoEntity").empty() || SCENE.GetEntityByName("TransformationXGizmoEntity")[0] == nullptr) + if (CurrentScene->GetEntityByName("TransformationXGizmoEntity").empty() || CurrentScene->GetEntityByName("TransformationXGizmoEntity")[0] == nullptr) return; if (SELECTED.GetSelected() == nullptr || SELECTED.GetSelected()->GetType() == FE_CAMERA) @@ -996,150 +929,147 @@ void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent Changes) void GizmoManager::ReInitializeEntities() { - ParentGizmoEntity = SCENE.AddEntity("ParentGizmoEntity"); - ParentGizmoGraphNode = SCENE.SceneGraph.GetNodeByEntityID(ParentGizmoEntity->GetObjectID()); - - // TransformationXGizmo - TransformationXGizmoEntity = SCENE.AddEntity("TransformationXGizmoEntity"); - TransformationXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXGizmoGM")[0]); - TransformationXGizmoEntity->SetName("TransformationXGizmoEntity"); - TransformationXGizmoEntity->GetComponent().SetCastShadows(false); - TransformationXGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - TransformationXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - TransformationXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // TransformationYGizmo - TransformationYGizmoEntity = SCENE.AddEntity("TransformationYGizmoEntity"); - TransformationYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYGizmoGM")[0]); - TransformationYGizmoEntity->SetName("TransformationYGizmoEntity"); - TransformationYGizmoEntity->GetComponent().SetCastShadows(false); - TransformationYGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - TransformationYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - TransformationYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // TransformationZGizmo - TransformationZGizmoEntity = SCENE.AddEntity("TransformationZGizmoEntity"); - TransformationZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationZGizmoGM")[0]); - TransformationZGizmoEntity->SetName("TransformationZGizmoEntity"); - TransformationZGizmoEntity->GetComponent().SetCastShadows(false); - TransformationZGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - TransformationZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - TransformationZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // Plane gizmos - TransformationXYGizmoEntity = SCENE.AddEntity("TransformationXYGizmoEntity"); - TransformationXYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXYGizmoGM")[0]); - TransformationXYGizmoEntity->SetName("TransformationXYGizmoEntity"); - TransformationXYGizmoEntity->GetComponent().SetCastShadows(false); - TransformationXYGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationXYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - TransformationXYGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); - TransformationXYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); - TransformationXYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - TransformationYZGizmoEntity = SCENE.AddEntity("TransformationYZGizmoEntity"); - TransformationYZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYZGizmoGM")[0]); - TransformationYZGizmoEntity->SetName("TransformationYZGizmoEntity"); - TransformationYZGizmoEntity->GetComponent().SetCastShadows(false); - TransformationYZGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationYZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - TransformationYZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); - TransformationYZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); - TransformationYZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - TransformationXZGizmoEntity = SCENE.AddEntity("TransformationXZGizmoEntity"); - TransformationXZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXZGizmoGM")[0]); - TransformationXZGizmoEntity->SetName("TransformationXZGizmoEntity"); - TransformationXZGizmoEntity->GetComponent().SetCastShadows(false); - TransformationXZGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationXZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - TransformationXZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); - TransformationXZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); - TransformationXZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // ScaleXGizmo - ScaleXGizmoEntity = SCENE.AddEntity("ScaleXGizmoEntity"); - ScaleXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleXGizmoGM")[0]); - ScaleXGizmoEntity->SetName("ScaleXGizmoEntity"); - ScaleXGizmoEntity->GetComponent().SetCastShadows(false); - ScaleXGizmoEntity->GetComponent().SetReceivingShadows(false); - ScaleXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - ScaleXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - ScaleXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // ScaleYGizmo - ScaleYGizmoEntity = SCENE.AddEntity("ScaleYGizmoEntity"); - ScaleYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleYGizmoGM")[0]); - ScaleYGizmoEntity->SetName("ScaleYGizmoEntity"); - ScaleYGizmoEntity->GetComponent().SetCastShadows(false); - ScaleYGizmoEntity->GetComponent().SetReceivingShadows(false); - ScaleYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - ScaleYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - ScaleYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // ScaleZGizmo - ScaleZGizmoEntity = SCENE.AddEntity("ScaleZGizmoEntity"); - ScaleZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleZGizmoGM")[0]); - ScaleZGizmoEntity->SetName("ScaleZGizmoEntity"); - ScaleZGizmoEntity->GetComponent().SetCastShadows(false); - ScaleZGizmoEntity->GetComponent().SetReceivingShadows(false); - ScaleZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - ScaleZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - ScaleZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // RotateXGizmo - RotateXGizmoEntity = SCENE.AddEntity("RotateXGizmoEntity"); - RotateXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateXGizmoGM")[0]); - RotateXGizmoEntity->SetName("RotateXGizmoEntity"); - RotateXGizmoEntity->GetComponent().SetCastShadows(false); - RotateXGizmoEntity->GetComponent().SetReceivingShadows(false); - RotateXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - RotateXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateXGizmoEntity->GetComponent().SetRotation(RotateXStandardRotation); - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // RotateYGizmo - RotateYGizmoEntity = SCENE.AddEntity("RotateYGizmoEntity"); - RotateYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateYGizmoGM")[0]); - RotateYGizmoEntity->SetName("RotateYGizmoEntity"); - RotateYGizmoEntity->GetComponent().SetCastShadows(false); - RotateYGizmoEntity->GetComponent().SetReceivingShadows(false); - RotateYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - RotateYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateYGizmoEntity->GetComponent().SetRotation(RotateYStandardRotation); - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // RotateZGizmo - RotateZGizmoEntity = SCENE.AddEntity("RotateZGizmoEntity"); - RotateZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateZGizmoGM")[0]); - RotateZGizmoEntity->SetName("RotateZGizmoEntity"); - RotateZGizmoEntity->GetComponent().SetCastShadows(false); - RotateZGizmoEntity->GetComponent().SetReceivingShadows(false); - RotateZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - RotateZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateZGizmoEntity->GetComponent().SetRotation(RotateZStandardRotation); - // Temporary overly complicated solution, because of new and old entity system. - SCENE.SceneGraph.MoveNode(SCENE.SceneGraph.GetNodeByEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (!ActiveScenes.empty()) + { + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + ParentGizmoEntity = CurrentScene->AddEntity("ParentGizmoEntity"); + ParentGizmoGraphNode = CurrentScene->SceneGraph.GetNodeByEntityID(ParentGizmoEntity->GetObjectID()); + + // TransformationXGizmo + TransformationXGizmoEntity = CurrentScene->AddEntity("TransformationXGizmoEntity"); + TransformationXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXGizmoGM")[0]); + TransformationXGizmoEntity->SetName("TransformationXGizmoEntity"); + TransformationXGizmoEntity->GetComponent().SetCastShadows(false); + TransformationXGizmoEntity->GetComponent().SetReceivingShadows(false); + TransformationXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + TransformationXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + TransformationXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + + // TransformationYGizmo + TransformationYGizmoEntity = CurrentScene->AddEntity("TransformationYGizmoEntity"); + TransformationYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYGizmoGM")[0]); + TransformationYGizmoEntity->SetName("TransformationYGizmoEntity"); + TransformationYGizmoEntity->GetComponent().SetCastShadows(false); + TransformationYGizmoEntity->GetComponent().SetReceivingShadows(false); + TransformationYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + TransformationYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + TransformationYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + + // TransformationZGizmo + TransformationZGizmoEntity = CurrentScene->AddEntity("TransformationZGizmoEntity"); + TransformationZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationZGizmoGM")[0]); + TransformationZGizmoEntity->SetName("TransformationZGizmoEntity"); + TransformationZGizmoEntity->GetComponent().SetCastShadows(false); + TransformationZGizmoEntity->GetComponent().SetReceivingShadows(false); + TransformationZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + TransformationZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + TransformationZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + + // Plane gizmos + TransformationXYGizmoEntity = CurrentScene->AddEntity("TransformationXYGizmoEntity"); + TransformationXYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXYGizmoGM")[0]); + TransformationXYGizmoEntity->SetName("TransformationXYGizmoEntity"); + TransformationXYGizmoEntity->GetComponent().SetCastShadows(false); + TransformationXYGizmoEntity->GetComponent().SetReceivingShadows(false); + TransformationXYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + TransformationXYGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); + TransformationXYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); + TransformationXYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + + TransformationYZGizmoEntity = CurrentScene->AddEntity("TransformationYZGizmoEntity"); + TransformationYZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYZGizmoGM")[0]); + TransformationYZGizmoEntity->SetName("TransformationYZGizmoEntity"); + TransformationYZGizmoEntity->GetComponent().SetCastShadows(false); + TransformationYZGizmoEntity->GetComponent().SetReceivingShadows(false); + TransformationYZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + TransformationYZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); + TransformationYZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); + TransformationYZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + + TransformationXZGizmoEntity = CurrentScene->AddEntity("TransformationXZGizmoEntity"); + TransformationXZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXZGizmoGM")[0]); + TransformationXZGizmoEntity->SetName("TransformationXZGizmoEntity"); + TransformationXZGizmoEntity->GetComponent().SetCastShadows(false); + TransformationXZGizmoEntity->GetComponent().SetReceivingShadows(false); + TransformationXZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + TransformationXZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); + TransformationXZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); + TransformationXZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + + // ScaleXGizmo + ScaleXGizmoEntity = CurrentScene->AddEntity("ScaleXGizmoEntity"); + ScaleXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleXGizmoGM")[0]); + ScaleXGizmoEntity->SetName("ScaleXGizmoEntity"); + ScaleXGizmoEntity->GetComponent().SetCastShadows(false); + ScaleXGizmoEntity->GetComponent().SetReceivingShadows(false); + ScaleXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + ScaleXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + ScaleXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + + // ScaleYGizmo + ScaleYGizmoEntity = CurrentScene->AddEntity("ScaleYGizmoEntity"); + ScaleYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleYGizmoGM")[0]); + ScaleYGizmoEntity->SetName("ScaleYGizmoEntity"); + ScaleYGizmoEntity->GetComponent().SetCastShadows(false); + ScaleYGizmoEntity->GetComponent().SetReceivingShadows(false); + ScaleYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + ScaleYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + ScaleYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + + // ScaleZGizmo + ScaleZGizmoEntity = CurrentScene->AddEntity("ScaleZGizmoEntity"); + ScaleZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleZGizmoGM")[0]); + ScaleZGizmoEntity->SetName("ScaleZGizmoEntity"); + ScaleZGizmoEntity->GetComponent().SetCastShadows(false); + ScaleZGizmoEntity->GetComponent().SetReceivingShadows(false); + ScaleZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + ScaleZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + ScaleZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + + // RotateXGizmo + RotateXGizmoEntity = CurrentScene->AddEntity("RotateXGizmoEntity"); + RotateXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateXGizmoGM")[0]); + RotateXGizmoEntity->SetName("RotateXGizmoEntity"); + RotateXGizmoEntity->GetComponent().SetCastShadows(false); + RotateXGizmoEntity->GetComponent().SetReceivingShadows(false); + RotateXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + RotateXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); + RotateXGizmoEntity->GetComponent().SetRotation(RotateXStandardRotation); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + + // RotateYGizmo + RotateYGizmoEntity = CurrentScene->AddEntity("RotateYGizmoEntity"); + RotateYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateYGizmoGM")[0]); + RotateYGizmoEntity->SetName("RotateYGizmoEntity"); + RotateYGizmoEntity->GetComponent().SetCastShadows(false); + RotateYGizmoEntity->GetComponent().SetReceivingShadows(false); + RotateYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + RotateYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); + RotateYGizmoEntity->GetComponent().SetRotation(RotateYStandardRotation); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + + // RotateZGizmo + RotateZGizmoEntity = CurrentScene->AddEntity("RotateZGizmoEntity"); + RotateZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateZGizmoGM")[0]); + RotateZGizmoEntity->SetName("RotateZGizmoEntity"); + RotateZGizmoEntity->GetComponent().SetCastShadows(false); + RotateZGizmoEntity->GetComponent().SetReceivingShadows(false); + RotateZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + RotateZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); + RotateZGizmoEntity->GetComponent().SetRotation(RotateZStandardRotation); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + } } \ No newline at end of file diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index 959a09f..4bb26c0 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -19,9 +19,7 @@ void FEEditorPreviewManager::InitializeResources() PreviewFB = RESOURCE_MANAGER.CreateFramebuffer(FE_COLOR_ATTACHMENT | FE_DEPTH_ATTACHMENT, 128, 128); PreviewGameModel = new FEGameModel(nullptr, nullptr, "editorPreviewGameModel"); PreviewPrefab = new FEPrefab(PreviewGameModel, "editorPreviewPrefab"); - PreviewEntity = SCENE.AddEntity("editorPreviewEntity"); - PreviewEntity->AddComponent(PreviewGameModel); - PreviewEntity->GetComponent().SetVisibility(false); + MeshPreviewMaterial = RESOURCE_MANAGER.CreateMaterial("meshPreviewMaterial"); RESOURCE_MANAGER.MakeMaterialStandard(MeshPreviewMaterial); MeshPreviewMaterial->Shader = RESOURCE_MANAGER.CreateShader("FEMeshPreviewShader", RESOURCE_MANAGER.LoadGLSL("Resources//Materials//FE_MeshPreview_VS.glsl").c_str(), @@ -34,22 +32,38 @@ void FEEditorPreviewManager::InitializeResources() RESOURCE_MANAGER.MakeShaderStandard(MeshPreviewMaterial->Shader); - //LocalLightEntity = SCENE.AddEntity("EditorPreview LightEntity"); - //FELightComponent& LightComponent = LocalLightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); - //LocalLightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); - //LightComponent.SetIntensity(10.0f); + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (!ActiveScenes.empty()) + { + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + PreviewEntity = CurrentScene->AddEntity("editorPreviewEntity"); + PreviewEntity->AddComponent(PreviewGameModel); + PreviewEntity->GetComponent().SetVisibility(false); + + //LocalLightEntity = SCENE.AddEntity("EditorPreview LightEntity"); + //FELightComponent& LightComponent = LocalLightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); + //LocalLightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); + //LightComponent.SetIntensity(10.0f); + } } void FEEditorPreviewManager::ReInitializeEntities() { - PreviewEntity = SCENE.AddEntity("editorPreviewEntity"); - PreviewEntity->AddComponent(PreviewGameModel); - PreviewEntity->GetComponent().SetVisibility(false); - - /*LocalLightEntity = SCENE.AddEntity("EditorPreview LightEntity"); - FELightComponent& LightComponent = LocalLightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); - LocalLightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); - LightComponent.SetIntensity(10.0f);*/ + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (!ActiveScenes.empty()) + { + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + PreviewEntity = CurrentScene->AddEntity("editorPreviewEntity"); + PreviewEntity->AddComponent(PreviewGameModel); + PreviewEntity->GetComponent().SetVisibility(false); + + /*LocalLightEntity = SCENE.AddEntity("EditorPreview LightEntity"); + FELightComponent& LightComponent = LocalLightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); + LocalLightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); + LightComponent.SetIntensity(10.0f);*/ + } } void FEEditorPreviewManager::UpdateAll() @@ -77,6 +91,13 @@ void FEEditorPreviewManager::UpdateAll() void FEEditorPreviewManager::BeforePreviewActions() { + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (ActiveScenes.empty()) + return; + + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + PreviewFB->Bind(); // We use these values even with the deferred renderer because the final image will not undergo gamma correction. Therefore, values exceeding 1.0f will not function correctly. OriginalClearColor = ENGINE.GetClearColor(); @@ -110,10 +131,10 @@ void FEEditorPreviewManager::BeforePreviewActions() PreviewEntity->GetComponent().SetVisibility(true); FEEntity* CurrentLightEntity = nullptr; - std::vector< std::string> LightsIDList = SCENE.GetEntityIDListWith(); + std::vector< std::string> LightsIDList = CurrentScene->GetEntityIDListWith(); for (size_t i = 0; i < LightsIDList.size(); i++) { - FEEntity* LightEntity = SCENE.GetEntity(LightsIDList[i]); + FEEntity* LightEntity = CurrentScene->GetEntity(LightsIDList[i]); FETransformComponent& TransformComponent = LightEntity->GetComponent(); FELightComponent& LightComponent = LightEntity->GetComponent(); @@ -143,6 +164,13 @@ void FEEditorPreviewManager::BeforePreviewActions() void FEEditorPreviewManager::AfterPreviewActions() { + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (ActiveScenes.empty()) + return; + + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + // We are reversing all of our previously applied transformations. PreviewEntity->GetComponent() = OriginalTransform; @@ -160,10 +188,10 @@ void FEEditorPreviewManager::AfterPreviewActions() //LocalLightEntity->GetComponent().SetLightEnabled(false); FEEntity* CurrentLightEntity = nullptr; - std::vector< std::string> LightsIDList = SCENE.GetEntityIDListWith(); + std::vector< std::string> LightsIDList = CurrentScene->GetEntityIDListWith(); for (size_t i = 0; i < LightsIDList.size(); i++) { - FEEntity* LightEntity = SCENE.GetEntity(LightsIDList[i]); + FEEntity* LightEntity = CurrentScene->GetEntity(LightsIDList[i]); FETransformComponent& TransformComponent = LightEntity->GetComponent(); FELightComponent& LightComponent = LightEntity->GetComponent(); @@ -208,7 +236,7 @@ void FEEditorPreviewManager::CreateMeshPreview(const std::string MeshID) ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); // Rendering mesh to texture. - RENDERER.RenderGameModelComponent(PreviewEntity->GetComponent(), PreviewEntity->GetComponent(), ENGINE.GetCamera()); + RENDERER.RenderGameModelComponent(PreviewEntity, ENGINE.GetCamera()); AfterPreviewActions(); @@ -265,7 +293,7 @@ void FEEditorPreviewManager::CreateMaterialPreview(const std::string MaterialID) ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, 70.0f)); // Rendering material to texture - RENDERER.RenderGameModelComponentForward(PreviewEntity->GetComponent(), PreviewEntity->GetComponent(), ENGINE.GetCamera(), true); + RENDERER.RenderGameModelComponentForward(PreviewEntity, ENGINE.GetCamera(), true); AfterPreviewActions(); @@ -364,7 +392,7 @@ void FEEditorPreviewManager::CreateGameModelPreview(const std::string GameModelI ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); // rendering game model to texture - RENDERER.RenderGameModelComponentForward(PreviewEntity->GetComponent(), PreviewEntity->GetComponent(), ENGINE.GetCamera(), true); + RENDERER.RenderGameModelComponentForward(PreviewEntity, ENGINE.GetCamera(), true); AfterPreviewActions(); @@ -406,7 +434,7 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); // rendering game model to texture - RENDERER.RenderGameModelComponentForward(PreviewEntity->GetComponent(), PreviewEntity->GetComponent(), ENGINE.GetCamera(), true); + RENDERER.RenderGameModelComponentForward(PreviewEntity, ENGINE.GetCamera(), true); AfterPreviewActions(); @@ -488,7 +516,7 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); // rendering game model to texture - RENDERER.RenderGameModelComponentForward(PreviewEntity->GetComponent(), PreviewEntity->GetComponent(), ENGINE.GetCamera(), true); + RENDERER.RenderGameModelComponentForward(PreviewEntity, ENGINE.GetCamera(), true); //PreviewEntity->Prefab = PreviewPrefab; PreviewEntity->GetComponent().GameModel = PreviewGameModel; diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index 7766723..1c40647 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -39,7 +39,13 @@ void FEEditorSelectedObject::InitializeResources() const FEShaderParam ColorParam(glm::vec3(0.0f, 0.0f, 0.0f), "baseColor"); PixelAccurateSelectionMaterial->AddParameter(ColorParam); - DummyEntity = SCENE.AddEntity("Editor_Selection_Dummy_Entity"); + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (!ActiveScenes.empty()) + { + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + DummyEntity = CurrentScene->AddEntity("Editor_Selection_Dummy_Entity"); + } } void FEEditorSelectedObject::ReInitializeResources() @@ -51,8 +57,14 @@ void FEEditorSelectedObject::ReInitializeResources() delete PixelAccurateSelectionFB->GetColorAttachment(); PixelAccurateSelectionFB->SetColorAttachment(RESOURCE_MANAGER.CreateTexture(GL_RGB, GL_RGB, ENGINE.GetRenderTargetWidth(), ENGINE.GetRenderTargetHeight())); - if (SCENE.GetEntityByName("Editor_Selection_Dummy_Entity").empty()) - DummyEntity = SCENE.AddEntity("Editor_Selection_Dummy_Entity"); + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (!ActiveScenes.empty()) + { + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + if (CurrentScene->GetEntityByName("Editor_Selection_Dummy_Entity").empty()) + DummyEntity = CurrentScene->AddEntity("Editor_Selection_Dummy_Entity"); + } } void FEEditorSelectedObject::SetOnUpdateFunc(void(*Func)()) @@ -81,7 +93,7 @@ void FEEditorSelectedObject::SetSelected(FEEntity* SelectedObject) return; if (Container != nullptr && Container->HasComponent() && Container != SelectedObject) - TERRAIN_SYSTEM.SetBrushMode(FE_TERRAIN_BRUSH_NONE); + TERRAIN_SYSTEM.SetBrushMode(Container, FE_TERRAIN_BRUSH_NONE); if (Container != SelectedObject) bDirtyFlag = true; @@ -101,8 +113,10 @@ void FEEditorSelectedObject::Clear() InstancedSubObjectIndexSelected = -1; Container = nullptr; bDirtyFlag = true; - if (OnUpdateFunc != nullptr) - OnUpdateFunc(); + + if (!SCENE_MANAGER.GetActiveScenes().empty()) + if (OnUpdateFunc != nullptr) + OnUpdateFunc(); } glm::dvec3 FEEditorSelectedObject::MouseRay(const double MouseX, const double MouseY) const @@ -126,13 +140,16 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons SELECTED.SceneEntitiesUnderMouse.clear(); SELECTED.InstancedSubObjectsInfo.clear(); + // FIX ME! Temporary solution, only supports one scene + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + const glm::vec3 MouseRayVector = MouseRay(MouseX, MouseY); - const std::vector EntityList = SCENE.GetEntityIDList(); + const std::vector EntityList = CurrentScene->GetEntityIDList(); for (size_t i = 0; i < EntityList.size(); i++) { float Distance = 0; - FEEntity* CurrentEntity = SCENE.GetEntity(EntityList[i]); + FEEntity* CurrentEntity = CurrentScene->GetEntity(EntityList[i]); if (CurrentEntity != nullptr) { FEAABB Box; @@ -215,7 +232,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons if (!PotentiallySelectedEntity->HasComponent()) { - RENDERER.RenderGameModelComponent(GameModelComponent, PotentiallySelectedEntity->GetComponent(), ENGINE.GetCamera(), false); + RENDERER.RenderGameModelComponent(PotentiallySelectedEntity, ENGINE.GetCamera(), false); } else if (PotentiallySelectedEntity->HasComponent()) { @@ -227,7 +244,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons GameModelComponent.GameModel->SetBillboardMaterial(PixelAccurateSelectionMaterial); FEInstancedComponent& InstancedComponent = PotentiallySelectedEntity->GetComponent(); - RENDERER.RenderGameModelComponentWithInstanced(PotentiallySelectedEntity->GetComponent(), GameModelComponent, InstancedComponent, ENGINE.GetCamera(), nullptr, false, false); + RENDERER.RenderGameModelComponentWithInstanced(PotentiallySelectedEntity, ENGINE.GetCamera(), nullptr, false, false); PixelAccurateSelectionMaterial->Shader = FEPixelAccurateSelection; GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterials); @@ -254,6 +271,9 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons int LastColorShiftIndex = static_cast(SELECTED.SceneEntitiesUnderMouse.size() - 1); + // FIX ME! Temporary solution, only supports one scene + FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + auto it = InstancedSubObjectsInfo.begin(); while (it != InstancedSubObjectsInfo.end()) { @@ -264,7 +284,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons int g = ((LastColorShiftIndex + 1) >> 8) & 255; int b = ((LastColorShiftIndex + 1) >> 16) & 255; - static FEEntity* DummyEntity = SCENE.AddEntity("DummyEntity"); + static FEEntity* DummyEntity = CurrentScene->AddEntity("DummyEntity"); if (!DummyEntity->HasComponent()) DummyEntity->AddComponent(); @@ -285,7 +305,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - RENDERER.RenderGameModelComponent(DummyGameModelComponent, DummyTransformComponent, ENGINE.GetCamera(), false); + RENDERER.RenderGameModelComponent(DummyEntity/*DummyGameModelComponent, DummyTransformComponent*/, ENGINE.GetCamera(), false); OriginalGameModelComponent.GameModel->Material = RegularMaterial; DummyGameModelComponent.SetVisibility(false); @@ -395,7 +415,7 @@ void FEEditorSelectedObject::OnCameraUpdate() const if (!Container->HasComponent()) { - RENDERER.RenderGameModelComponent(GameModelComponent, Container->GetComponent(), ENGINE.GetCamera(), false); + RENDERER.RenderGameModelComponent(Container, ENGINE.GetCamera(), false); } else if (Container->HasComponent()) { @@ -418,7 +438,7 @@ void FEEditorSelectedObject::OnCameraUpdate() const HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - RENDERER.RenderGameModelComponent(DummyGameModelComponent, DummyEntity->GetComponent(), ENGINE.GetCamera(), false); + RENDERER.RenderGameModelComponent(DummyEntity, ENGINE.GetCamera(), false); GameModelComponent.GameModel->Material = RegularMaterial; DummyGameModelComponent.SetVisibility(false); @@ -429,7 +449,7 @@ void FEEditorSelectedObject::OnCameraUpdate() const FEMaterial* RegularBillboardMaterial = GameModelComponent.GameModel->GetBillboardMaterial(); GameModelComponent.GameModel->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); - RENDERER.RenderGameModelComponentWithInstanced(Container->GetComponent(), GameModelComponent, Container->GetComponent(), ENGINE.GetCamera(), nullptr, false, false); + RENDERER.RenderGameModelComponentWithInstanced(Container, ENGINE.GetCamera(), nullptr, false, false); HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterial); diff --git a/FEProject.cpp b/FEProject.cpp index 7eec00d..e63b449 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -46,29 +46,33 @@ void FEProjectManager::CloseCurrentProject() WindowsManager::getInstance().CloseAllPopups(); SELECTED.Clear(); + PREVIEW_MANAGER.Clear(); + SCENE_MANAGER.DeleteScene(PROJECT_MANAGER.GetCurrent()->ProjectScene); for (size_t i = 0; i < List.size(); i++) { delete List[i]; } List.clear(); PROJECT_MANAGER.SetCurrent(nullptr); - PREVIEW_MANAGER.Clear(); - LoadProjectList(); VIRTUAL_FILE_SYSTEM.SetCurrentPath("/"); } +// FIX ME! Temporary. +#include "EditorWindows/SceneGraphWindow.h" void FEProjectManager::OpenProject(const int ProjectIndex) { - SCENE.Clear(); - PROJECT_MANAGER.SetCurrent(List[ProjectIndex]); + PROJECT_MANAGER.GetCurrent()->ProjectScene = SCENE_MANAGER.AddScene(); PROJECT_MANAGER.GetCurrent()->LoadScene(); + // FIX ME! Temporary. + SCENE_GRAPH_WINDOW.SetScene(PROJECT_MANAGER.GetCurrent()->ProjectScene); IndexChosen = -1; GIZMO_MANAGER.ReInitializeEntities(); + // FIX ME! Entities should just have special tag, not be in the list. EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoEntity); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity); @@ -93,7 +97,7 @@ void FEProjectManager::OpenProject(const int ProjectIndex) while (it != EDITOR_INTERNAL_RESOURCES.InternalEditorObjects.end()) { if (it->second->GetType() == FE_ENTITY) - SCENE.AddEntity(reinterpret_cast(it->second)); + ProjectScene->AddEntity(reinterpret_cast(it->second)); it++; }*/ @@ -103,10 +107,10 @@ void FEProjectManager::OpenProject(const int ProjectIndex) SELECTED.Clear(); // Cleaning dirty flag of entities. - //const std::vector EntityList = SCENE.GetEntityList(); + //const std::vector EntityList = ProjectScene->GetEntityList(); //for (size_t i = 0; i < EntityList.size(); i++) //{ - // FEEntity* Entity = SCENE.GetEntity(EntityList[i]); + // FEEntity* Entity = ProjectScene->GetEntity(EntityList[i]); // // But before that update AABB. // Entity->GetAABB(); // Entity->Transform.SetDirtyFlag(false); @@ -275,9 +279,9 @@ void FEProjectManager::DisplayProjectSelection() FILE_SYSTEM.CreateDirectory((std::string(PROJECTS_FOLDER) + std::string("/") + ProjectName + "/").c_str()); List.push_back(new FEProject(ProjectName, std::string(PROJECTS_FOLDER) + std::string("/") + ProjectName + "/")); List.back()->CreateDummyScreenshot(); - //SCENE.addLight(FE_DIRECTIONAL_LIGHT, "sun"); + //ProjectScene->addLight(FE_DIRECTIONAL_LIGHT, "sun"); std::fstream File; - File.open((std::string(PROJECTS_FOLDER) + std::string("/") + ProjectName + "/" + "scene.txt").c_str(), std::ios::out); + File.open((std::string(PROJECTS_FOLDER) + std::string("/") + ProjectName + "/" + "ProjectScene->txt").c_str(), std::ios::out); File.write(BASIC_SCENE, strlen(BASIC_SCENE)); File.close(); @@ -356,7 +360,7 @@ FEProject::~FEProject() delete SceneScreenshot; EDITOR_INTERNAL_RESOURCES.ClearListByType(FE_ENTITY); - SCENE.Clear(); + //ProjectScene->Clear(); RESOURCE_MANAGER.Clear(); ENGINE.ResetCamera(); VIRTUAL_FILE_SYSTEM.Clear(); @@ -399,7 +403,7 @@ void FEProject::SaveScene(bool bFullSave) Root["version"] = PROJECTS_FILE_VER; // Saving scene hierarchy. - Json::Value SceneHierarchy = SCENE.SceneGraph.ToJson(); + Json::Value SceneHierarchy = ProjectScene->SceneGraph.ToJson(); std::vector KeysToDelete; Json::Value& SceneNodes = SceneHierarchy["Nodes"]; @@ -579,11 +583,11 @@ void FEProject::SaveScene(bool bFullSave) Root["prefabs"] = PrefabData; // Saving Entities. - //std::vector EntityList = SCENE.GetEntityList(); + //std::vector EntityList = ProjectScene->GetEntityList(); //Json::Value EntityData; //for (size_t i = 0; i < EntityList.size(); i++) //{ - // FEEntity* Entity = SCENE.GetEntity(EntityList[i]); + // FEEntity* Entity = ProjectScene->GetEntity(EntityList[i]); // if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(Entity)) // continue; @@ -674,11 +678,11 @@ void FEProject::SaveScene(bool bFullSave) //Root["entities"] = EntityData; // Saving Terrains. - std::vector TerrainList = SCENE.GetEntityIDListWith(); + std::vector TerrainList = ProjectScene->GetEntityIDListWith(); Json::Value TerrainData; for (size_t i = 0; i < TerrainList.size(); i++) { - FEEntity* Terrain = SCENE.GetEntity(TerrainList[i]); + FEEntity* Terrain = ProjectScene->GetEntity(TerrainList[i]); FETerrainComponent& TerrainComponent = Terrain->GetComponent(); TerrainData[Terrain->GetObjectID()]["ID"] = Terrain->GetObjectID(); @@ -731,11 +735,11 @@ void FEProject::SaveScene(bool bFullSave) Root["terrains"] = TerrainData; //// Saving Lights. - //std::vector LightList = SCENE.GetLightsList(); + //std::vector LightList = ProjectScene->GetLightsList(); //Json::Value LightData; //for (size_t i = 0; i < LightList.size(); i++) //{ - // FELight* Light = SCENE.GetLight(LightList[i]); + // FELight* Light = ProjectScene->GetLight(LightList[i]); // // general light information // LightData[Light->GetObjectID()]["ID"] = Light->GetObjectID(); @@ -839,7 +843,7 @@ void FEProject::SaveScene(bool bFullSave) Json::StreamWriterBuilder Builder; const std::string JsonFile = Json::writeString(Builder, Root); - SceneFile.open(ProjectFolder + "scene.txt"); + SceneFile.open(ProjectFolder + "ProjectScene->txt"); SceneFile << JsonFile; SceneFile.close(); @@ -874,7 +878,7 @@ void FEProject::ReadTransformToJson(Json::Value& Root, FETransformComponent* Tra void FEProject::LoadScene() { std::ifstream SceneFile; - SceneFile.open(ProjectFolder + "scene.txt"); + SceneFile.open(ProjectFolder + "Scene.txt"); std::string FileData((std::istreambuf_iterator(SceneFile)), std::istreambuf_iterator()); SceneFile.close(); @@ -1046,7 +1050,7 @@ void FEProject::LoadScene() std::vector TerrainList = Root["terrains"].getMemberNames(); for (size_t i = 0; i < TerrainList.size(); i++) { - FEEntity* Entity = SCENE.AddEntity(Root["terrains"][TerrainList[i]]["name"].asString(), Root["terrains"][TerrainList[i]]["ID"].asString()); + FEEntity* Entity = ProjectScene->AddEntity(Root["terrains"][TerrainList[i]]["name"].asString(), Root["terrains"][TerrainList[i]]["ID"].asString()); FETransformComponent& TransformComponent = Entity->GetComponent(); Entity->AddComponent(); FETerrainComponent& TerrainComponent = Entity->GetComponent(); @@ -1090,7 +1094,7 @@ void FEProject::LoadScene() std::vector EntityList = Root["entities"].getMemberNames(); for (size_t i = 0; i < EntityList.size(); i++) { - FEEntity* Entity = SCENE.AddEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + FEEntity* Entity = ProjectScene->AddEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); if (Root["entities"][EntityList[i]].isMember("type")) { @@ -1099,11 +1103,19 @@ void FEProject::LoadScene() // FIX ME! Converting Prefab to GameModels. FEEntity* EntityWithFirstPrefab = Entity; FEPrefab* OldPrefab = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()); + + if (OldPrefab->ComponentsCount() > 1) + { + OldPrefab->Scene = SCENE_MANAGER.AddScene(false, OldPrefab->GetName()); + //OldPrefab->Scene->ImportEntity(Entity); + } + for (size_t c = 0; c < OldPrefab->ComponentsCount(); c++) { if (c > 0) { - Entity = SCENE.AddEntity(Root["entities"][EntityList[i]]["name"].asString() + "_Prefabs_" + std::to_string(c)); + Entity = ProjectScene->AddEntity(Root["entities"][EntityList[i]]["name"].asString() + "_Prefabs_" + std::to_string(c)); + //OldPrefab->Scene->ImportEntity(Entity); } FEPrefabComponent* CurrentComponent = OldPrefab->GetComponent(static_cast(c)); FEGameModel* GameModel = CurrentComponent->GameModel; @@ -1132,7 +1144,7 @@ void FEProject::LoadScene() if (Root["entities"][EntityList[i]]["snappedToTerrain"].asString() != "none") { - FEEntity* TerrainEntity = SCENE.GetEntity(Root["entities"][EntityList[i]]["snappedToTerrain"].asString()); + FEEntity* TerrainEntity = ProjectScene->GetEntity(Root["entities"][EntityList[i]]["snappedToTerrain"].asString()); TERRAIN_SYSTEM.SnapInstancedEntity(TerrainEntity, Entity); if (Root["entities"][EntityList[i]].isMember("terrainLayer")) @@ -1200,6 +1212,11 @@ void FEProject::LoadScene() } } } + + if (OldPrefab->ComponentsCount() > 1) + { + OldPrefab->Scene->ImportEntity(Entity); + } } } else @@ -1208,14 +1225,14 @@ void FEProject::LoadScene() if (Root["entities"][EntityList[i]].isMember("gameModel")) { //FEPrefab* TempPrefab = RESOURCE_MANAGER.CreatePrefab(RESOURCE_MANAGER.GetGameModel(Root["entities"][EntityList[i]]["gameModel"].asCString())); - //SCENE.AddEntity(TempPrefab, Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + //ProjectScene->AddEntity(TempPrefab, Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); FEGameModel* GameModel = RESOURCE_MANAGER.GetGameModel(Root["entities"][EntityList[i]]["gameModel"].asCString()); Entity->AddComponent(GameModel); } else { - /*SCENE.AddEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), + /*ProjectScene->AddEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString());*/ @@ -1225,45 +1242,45 @@ void FEProject::LoadScene() if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) { - //SCENE.GetEntity(EntityList[i])->SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); + //ProjectScene->GetEntity(EntityList[i])->SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); Entity->GetComponent().SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); } ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &Entity->GetComponent()); - /*ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(EntityList[i])->Transform); - FEEntity* Entity = SCENE.GetNewStyleEntityByOldStyleID(EntityList[i]); + /*ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &ProjectScene->GetEntity(EntityList[i])->Transform); + FEEntity* Entity = ProjectScene->GetNewStyleEntityByOldStyleID(EntityList[i]); if (Entity != nullptr) { - Entity->GetComponent() = SCENE.GetEntity(EntityList[i])->Transform; + Entity->GetComponent() = ProjectScene->GetEntity(EntityList[i])->Transform; }*/ } } // For compatibility with old projects. else { - //FEEntity* Entity = SCENE.AddEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + //FEEntity* Entity = ProjectScene->AddEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString())->GetComponent(0)->GameModel; Entity->AddComponent(GameModel); ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &Entity->GetComponent()); - /*SCENE.AddEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), + /*ProjectScene->AddEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), EntityList[i], Root["entities"][EntityList[i]]["ID"].asString()); - ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &SCENE.GetEntity(EntityList[i])->Transform);*/ + ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &ProjectScene->GetEntity(EntityList[i])->Transform);*/ } } if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) { // Loading scene hierarchy. - SCENE.SceneGraph.FromJson(Root["sceneHierarchy"]); + ProjectScene->SceneGraph.FromJson(Root["sceneHierarchy"]); } // Loading Lights. std::vector LightList = Root["lights"].getMemberNames(); for (size_t i = 0; i < LightList.size(); i++) { - FEEntity* Entity = SCENE.AddEntity("Light Entity"); + FEEntity* Entity = ProjectScene->AddEntity("Light Entity"); auto OldType = static_cast(Root["lights"][LightList[i]]["type"].asInt()); FE_LIGHT_TYPE NewType = FE_DIRECTIONAL_LIGHT; if (OldType == FE_POINT_LIGHT_DEPRECATED) @@ -1350,7 +1367,7 @@ void FEProject::LoadScene() //SKY_DOME_SYSTEM.SetEnabled(Root["effects"]["Sky"]["Enabled"].asFloat() > 0.0f ? true : false); //SKY_DOME_SYSTEM.SetDistanceToSky(Root["effects"]["Sky"]["Sphere size"].asFloat()); //Fix Me! - FEEntity* SkyDome = SCENE.AddEntity("SkyDome"); + FEEntity* SkyDome = ProjectScene->AddEntity("SkyDome"); SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); SKY_DOME_SYSTEM.AddToEntity(SkyDome); @@ -1373,7 +1390,7 @@ void FEProject::LoadScene() ENGINE.GetCamera()->SetMovementSpeed(Root["camera"]["movementSpeed"].asFloat()); // After all scene objects are loaded, we need to update all objects. - SCENE.Update(); + ProjectScene->Update(); // FIX ME! Only after that all systems should be updated and triggered. @@ -1443,10 +1460,10 @@ void FEProject::LoadScene() //if (textureToAdd->getInternalFormat() == GL_R16) //{ // // Potentially it could be texture hight map. - // std::vector terrainList = SCENE.getTerrainList(); + // std::vector terrainList = ProjectScene->getTerrainList(); // for (size_t j = 0; j < terrainList.size(); j++) // { - // if (SCENE.getTerrain(terrainList[j])->heightMap == textureToAdd) + // if (ProjectScene->getTerrain(terrainList[j])->heightMap == textureToAdd) // { // shouldAdd = false; // break; @@ -1518,11 +1535,11 @@ void FEProject::AddUnSavedObject(FEObject* Object) bool FEProject::ShouldIncludeInSceneFile(const FETexture* Texture) { // Terrain should manage it's textures in a different way. - const std::vector TerrainList = SCENE.GetEntityIDListWith(); + const std::vector TerrainList = ProjectScene->GetEntityIDListWith(); Json::Value TerrainData; for (size_t i = 0; i < TerrainList.size(); i++) { - FEEntity* Terrain = SCENE.GetEntity(TerrainList[i]); + FEEntity* Terrain = ProjectScene->GetEntity(TerrainList[i]); FETerrainComponent& TerrainComponent = Terrain->GetComponent(); if (TerrainComponent.HeightMap->GetObjectID() == Texture->GetObjectID()) diff --git a/FEProject.h b/FEProject.h index 0293a88..3781ca8 100644 --- a/FEProject.h +++ b/FEProject.h @@ -10,6 +10,7 @@ class FEProject { + friend class FEProjectManager; public: FEProject(std::string Name, std::string ProjectFolder); ~FEProject(); @@ -32,6 +33,7 @@ class FEProject void AddUnSavedObject(FEObject* Object); private: + FEScene* ProjectScene = nullptr; std::string Name; std::string ProjectFolder; bool bModified = false; diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 0ede396..bd54e47 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 0ede3961bbb30625760fb35efbd1136951d502d7 +Subproject commit bd54e4716b6e5c06d22de53d63abb6bdf08dfcf6 From f8c03763b5a4c8138df7a0376467e0b56feda731 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Fri, 19 Jul 2024 12:27:45 -0400 Subject: [PATCH 21/46] Engine update. --- EditorWindows/SceneGraphWindow.cpp | 8 +- FEEditor.cpp | 4 +- FEEditorGizmoManager.cpp | 408 ++++++++++------------------- FEEditorPreviewManager.cpp | 33 ++- FEEditorPreviewManager.h | 4 +- FEEditorSelectedObject.cpp | 6 +- FEProject.cpp | 24 +- SubSystems/FocalEngine | 2 +- 8 files changed, 187 insertions(+), 302 deletions(-) diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index f84bae5..55b36e7 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -92,7 +92,7 @@ static void CreateInstancedEntityCallBack(const std::vector Selection if (SelectedPrefab == nullptr) return; - FEEntity* Entity = SCENE_GRAPH_WINDOW.GetScene()->AddEntity(); + FEEntity* Entity = SCENE_GRAPH_WINDOW.GetScene()->CreateEntity(); Entity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); Entity->AddComponent(SelectedPrefab->GetComponent(0)->GameModel); Entity->AddComponent(); @@ -110,7 +110,7 @@ static void CreateEntityCallBack(const std::vector SelectionsResult) if (SelectedPrefab == nullptr) return; - FEEntity* Entity = SCENE_GRAPH_WINDOW.GetScene()->AddEntity(); + FEEntity* Entity = SCENE_GRAPH_WINDOW.GetScene()->CreateEntity(); Entity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); SELECTED.SetSelected(Entity); @@ -413,7 +413,7 @@ void FEEditorSceneGraphWindow::Render() { if (ImGui::MenuItem("Empty entity")) { - CurrentScene->AddEntity("Unnamed entity"); + CurrentScene->CreateEntity("Unnamed entity"); } // FIX ME! @@ -429,7 +429,7 @@ void FEEditorSceneGraphWindow::Render() //if (ImGui::MenuItem("Terrain")) //{ - // FEEntity* Entity = SCENE.AddEntity("Unnamed terrain"); + // FEEntity* Entity = SCENE.CreateEntity("Unnamed terrain"); // FETransformComponent& TransformComponent = Entity->GetComponent(); // Entity->AddComponent(); // FETerrainComponent& TerrainComponent = Entity->GetComponent(); diff --git a/FEEditor.cpp b/FEEditor.cpp index c6c27e4..24c186a 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -14,7 +14,7 @@ bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) if (!ActiveScenes.empty()) { FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - FEEntity* Entity = CurrentScene->AddEntity(Object->GetName()); + FEEntity* Entity = CurrentScene->CreateEntity(Object->GetName()); Entity->GetComponent().GameModel = GameModel; Entity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); SELECTED.SetSelected(Entity); @@ -588,7 +588,7 @@ void FEEditor::DropCallback(const int Count, const char** Paths) { if (LoadedObjects[j]->GetType() == FE_ENTITY) { - //SCENE.AddEntity(reinterpret_cast(LoadedObjects[j])); + //SCENE.CreateEntity(reinterpret_cast(LoadedObjects[j])); } else { diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index bdfdf86..5632eb7 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -12,263 +12,131 @@ void GizmoManager::InitializeResources() FEMesh* TransformationGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "45191B6F172E3B531978692E.model").c_str(), "transformationGizmoMesh"); RESOURCE_MANAGER.MakeMeshStandard(TransformationGizmoMesh); - // FIX ME! Temporary solution, only supports one scene - //std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - //if (!ActiveScenes.empty()) - //{ - //FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - //ParentGizmoEntity = CurrentScene->AddEntity("ParentGizmoEntity"); - //FENaiveSceneGraphNode* ParentGizmoGraphNode = CurrentScene->SceneGraph.GetNodeByEntityID(ParentGizmoEntity->GetObjectID()); - - // TransformationXGizmo - FEMaterial* CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - FEGameModel* CurrentModel = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); - //TransformationXGizmoEntity = CurrentScene->AddEntity("TransformationXGizmoEntity"); - //TransformationXGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM")); - //TransformationXGizmoEntity->SetName("TransformationXGizmoEntity"); - //RESOURCE_MANAGER.MakeGameModelStandard(TransformationXGizmoEntity->GetComponent().GameModel); - /*TransformationXGizmoEntity->GetComponent().SetCastShadows(false); - TransformationXGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - TransformationXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - TransformationXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ - - // TransformationYGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - CurrentModel = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); - //TransformationYGizmoEntity = CurrentScene->AddEntity("TransformationYGizmoEntity"); - //TransformationYGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM")); - //TransformationYGizmoEntity->SetName("TransformationYGizmoEntity"); - /*RESOURCE_MANAGER.MakeGameModelStandard(TransformationYGizmoEntity->GetComponent().GameModel); - TransformationYGizmoEntity->GetComponent().SetCastShadows(false); - TransformationYGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - TransformationYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); - TransformationYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ - - // TransformationZGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationZGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - CurrentModel = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); - /*TransformationZGizmoEntity = CurrentScene->AddEntity("TransformationZGizmoEntity"); - TransformationZGizmoEntity->AddComponent(new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM")); - TransformationYGizmoEntity->SetName("TransformationZGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationZGizmoEntity->GetComponent().GameModel); - TransformationZGizmoEntity->GetComponent().SetCastShadows(false); - TransformationZGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - TransformationZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - TransformationZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ - - // Plane gizmos - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXYGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - CurrentModel = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); - //TransformationXYGizmoEntity = CurrentScene->AddEntity("TransformationXYGizmoEntity"); - //TransformationXYGizmoEntity->AddComponent(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM")); - //TransformationXYGizmoEntity->SetName("TransformationXYGizmoEntity"); - //RESOURCE_MANAGER.MakeGameModelStandard(TransformationXYGizmoEntity->GetComponent().GameModel); - //TransformationXYGizmoEntity->GetComponent().SetCastShadows(false); - //TransformationXYGizmoEntity->GetComponent().SetReceivingShadows(false); - //TransformationXYGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); - //TransformationXYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); - //TransformationXYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - //TransformationXYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - //CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYZGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - CurrentModel = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); - //TransformationYZGizmoEntity = CurrentScene->AddEntity("TransformationYZGizmoEntity"); - //TransformationYZGizmoEntity->AddComponent(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM")); - //TransformationYZGizmoEntity->SetName("TransformationYZGizmoEntity"); - //RESOURCE_MANAGER.MakeGameModelStandard(TransformationYZGizmoEntity->GetComponent().GameModel); - //TransformationYZGizmoEntity->GetComponent().SetCastShadows(false); - //TransformationYZGizmoEntity->GetComponent().SetReceivingShadows(false); - //TransformationYZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); - //TransformationYZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); - //TransformationYZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - //TransformationYZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - //CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXZGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - CurrentModel = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); - //TransformationXZGizmoEntity = CurrentScene->AddEntity("TransformationXZGizmoEntity"); - //TransformationXZGizmoEntity->SetName("TransformationXZGizmoEntity"); - //TransformationXZGizmoEntity->AddComponent(new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM")); - //RESOURCE_MANAGER.MakeGameModelStandard(TransformationXZGizmoEntity->GetComponent().GameModel); - //TransformationXZGizmoEntity->GetComponent().SetCastShadows(false); - //TransformationXZGizmoEntity->GetComponent().SetReceivingShadows(false); - //TransformationXZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); - //TransformationXZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); - //TransformationXZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - //TransformationXZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - //CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // Scale gizmos. - FEMesh* ScaleGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "637C784B2E5E5C6548190E1B.model").c_str(), "scaleGizmoMesh"); - RESOURCE_MANAGER.MakeMeshStandard(ScaleGizmoMesh); - - // ScaleXGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleXGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - CurrentModel = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); - /*ScaleXGizmoEntity = CurrentScene->AddEntity("ScaleXGizmoEntity"); - ScaleXGizmoEntity->AddComponent(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM")); - ScaleXGizmoEntity->SetName("ScaleXGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(ScaleXGizmoEntity->GetComponent().GameModel); - ScaleXGizmoEntity->GetComponent().SetCastShadows(false); - ScaleXGizmoEntity->GetComponent().SetReceivingShadows(false); - ScaleXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - ScaleXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - ScaleXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ - - // ScaleYGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleYGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - CurrentModel = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); - /*ScaleYGizmoEntity = CurrentScene->AddEntity("ScaleYGizmoEntity"); - ScaleYGizmoEntity->AddComponent(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM")); - ScaleYGizmoEntity->SetName("ScaleYGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(ScaleYGizmoEntity->GetComponent().GameModel); - ScaleYGizmoEntity->GetComponent().SetCastShadows(false); - ScaleYGizmoEntity->GetComponent().SetReceivingShadows(false); - ScaleYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - ScaleYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); - ScaleYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ - - // ScaleZGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleZGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - CurrentModel = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); - /*ScaleZGizmoEntity = CurrentScene->AddEntity("ScaleZGizmoEntity"); - ScaleZGizmoEntity->AddComponent(new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM")); - ScaleZGizmoEntity->SetName("ScaleZGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(ScaleZGizmoEntity->GetComponent().GameModel); - ScaleZGizmoEntity->GetComponent().SetCastShadows(false); - ScaleZGizmoEntity->GetComponent().SetReceivingShadows(false); - ScaleZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - ScaleZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - ScaleZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ - - // RotateAroundAxis gizmos - FEMesh* RotateGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "19622421516E5B317E1B5360.model").c_str(), "rotateGizmoMesh"); - RESOURCE_MANAGER.MakeMeshStandard(RotateGizmoMesh); - - // RotateXGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateXGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - CurrentModel = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); - /*RotateXGizmoEntity = CurrentScene->AddEntity("RotateXGizmoEntity"); - RotateXGizmoEntity->AddComponent(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM")); - RotateXGizmoEntity->SetName("RotateXGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(RotateXGizmoEntity->GetComponent().GameModel); - RotateXGizmoEntity->GetComponent().SetCastShadows(false); - RotateXGizmoEntity->GetComponent().SetReceivingShadows(false); - RotateXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateXGizmoEntity->GetComponent().SetRotation(RotateXStandardRotation); - RotateXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ - - // RotateYGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateYGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - CurrentModel = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); - /*RotateYGizmoEntity = CurrentScene->AddEntity("RotateYGizmoEntity"); - RotateYGizmoEntity->AddComponent(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM")); - RotateYGizmoEntity->SetName("RotateYGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(RotateYGizmoEntity->GetComponent().GameModel); - RotateYGizmoEntity->GetComponent().SetCastShadows(false); - RotateYGizmoEntity->GetComponent().SetReceivingShadows(false); - RotateYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateYGizmoEntity->GetComponent().SetRotation(RotateYStandardRotation); - RotateYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ - - // RotateZGizmo - CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateZGizmoMaterial"); - CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); - CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - - CurrentModel = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); - /*RotateZGizmoEntity = CurrentScene->AddEntity("RotateZGizmoEntity"); - RotateZGizmoEntity->AddComponent(new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM")); - RotateZGizmoEntity->SetName("RotateZGizmoEntity"); - RESOURCE_MANAGER.MakeGameModelStandard(RotateZGizmoEntity->GetComponent().GameModel); - RotateZGizmoEntity->GetComponent().SetCastShadows(false); - RotateZGizmoEntity->GetComponent().SetReceivingShadows(false); - RotateZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateZGizmoEntity->GetComponent().SetRotation(RotateZStandardRotation); - RotateZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false);*/ - //} + // TransformationXGizmo + FEMaterial* CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + FEGameModel* CurrentModel = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + + // TransformationYGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + + // TransformationZGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationZGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + + // Plane gizmos + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXYGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYZGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXZGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + + // Scale gizmos. + FEMesh* ScaleGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "637C784B2E5E5C6548190E1B.model").c_str(), "scaleGizmoMesh"); + RESOURCE_MANAGER.MakeMeshStandard(ScaleGizmoMesh); + + // ScaleXGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleXGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + + // ScaleYGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleYGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + + // ScaleZGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleZGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + + // RotateAroundAxis gizmos + FEMesh* RotateGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "19622421516E5B317E1B5360.model").c_str(), "rotateGizmoMesh"); + RESOURCE_MANAGER.MakeMeshStandard(RotateGizmoMesh); + + // RotateXGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateXGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + + // RotateYGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateYGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + + // RotateZGizmo + CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateZGizmoMaterial"); + CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); + CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); + CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); + RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + + CurrentModel = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); TransformationGizmoIcon = RESOURCE_MANAGER.LoadFETexture((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "456A31026A1C3152181A6064.texture").c_str(), "transformationGizmoIcon"); RESOURCE_MANAGER.MakeTextureStandard(TransformationGizmoIcon); @@ -934,11 +802,11 @@ void GizmoManager::ReInitializeEntities() if (!ActiveScenes.empty()) { FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - ParentGizmoEntity = CurrentScene->AddEntity("ParentGizmoEntity"); + ParentGizmoEntity = CurrentScene->CreateEntity("ParentGizmoEntity"); ParentGizmoGraphNode = CurrentScene->SceneGraph.GetNodeByEntityID(ParentGizmoEntity->GetObjectID()); // TransformationXGizmo - TransformationXGizmoEntity = CurrentScene->AddEntity("TransformationXGizmoEntity"); + TransformationXGizmoEntity = CurrentScene->CreateEntity("TransformationXGizmoEntity"); TransformationXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXGizmoGM")[0]); TransformationXGizmoEntity->SetName("TransformationXGizmoEntity"); TransformationXGizmoEntity->GetComponent().SetCastShadows(false); @@ -949,7 +817,7 @@ void GizmoManager::ReInitializeEntities() CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // TransformationYGizmo - TransformationYGizmoEntity = CurrentScene->AddEntity("TransformationYGizmoEntity"); + TransformationYGizmoEntity = CurrentScene->CreateEntity("TransformationYGizmoEntity"); TransformationYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYGizmoGM")[0]); TransformationYGizmoEntity->SetName("TransformationYGizmoEntity"); TransformationYGizmoEntity->GetComponent().SetCastShadows(false); @@ -960,7 +828,7 @@ void GizmoManager::ReInitializeEntities() CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // TransformationZGizmo - TransformationZGizmoEntity = CurrentScene->AddEntity("TransformationZGizmoEntity"); + TransformationZGizmoEntity = CurrentScene->CreateEntity("TransformationZGizmoEntity"); TransformationZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationZGizmoGM")[0]); TransformationZGizmoEntity->SetName("TransformationZGizmoEntity"); TransformationZGizmoEntity->GetComponent().SetCastShadows(false); @@ -971,7 +839,7 @@ void GizmoManager::ReInitializeEntities() CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // Plane gizmos - TransformationXYGizmoEntity = CurrentScene->AddEntity("TransformationXYGizmoEntity"); + TransformationXYGizmoEntity = CurrentScene->CreateEntity("TransformationXYGizmoEntity"); TransformationXYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXYGizmoGM")[0]); TransformationXYGizmoEntity->SetName("TransformationXYGizmoEntity"); TransformationXYGizmoEntity->GetComponent().SetCastShadows(false); @@ -983,7 +851,7 @@ void GizmoManager::ReInitializeEntities() CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - TransformationYZGizmoEntity = CurrentScene->AddEntity("TransformationYZGizmoEntity"); + TransformationYZGizmoEntity = CurrentScene->CreateEntity("TransformationYZGizmoEntity"); TransformationYZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYZGizmoGM")[0]); TransformationYZGizmoEntity->SetName("TransformationYZGizmoEntity"); TransformationYZGizmoEntity->GetComponent().SetCastShadows(false); @@ -995,7 +863,7 @@ void GizmoManager::ReInitializeEntities() CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - TransformationXZGizmoEntity = CurrentScene->AddEntity("TransformationXZGizmoEntity"); + TransformationXZGizmoEntity = CurrentScene->CreateEntity("TransformationXZGizmoEntity"); TransformationXZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXZGizmoGM")[0]); TransformationXZGizmoEntity->SetName("TransformationXZGizmoEntity"); TransformationXZGizmoEntity->GetComponent().SetCastShadows(false); @@ -1007,7 +875,7 @@ void GizmoManager::ReInitializeEntities() CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // ScaleXGizmo - ScaleXGizmoEntity = CurrentScene->AddEntity("ScaleXGizmoEntity"); + ScaleXGizmoEntity = CurrentScene->CreateEntity("ScaleXGizmoEntity"); ScaleXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleXGizmoGM")[0]); ScaleXGizmoEntity->SetName("ScaleXGizmoEntity"); ScaleXGizmoEntity->GetComponent().SetCastShadows(false); @@ -1018,7 +886,7 @@ void GizmoManager::ReInitializeEntities() CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // ScaleYGizmo - ScaleYGizmoEntity = CurrentScene->AddEntity("ScaleYGizmoEntity"); + ScaleYGizmoEntity = CurrentScene->CreateEntity("ScaleYGizmoEntity"); ScaleYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleYGizmoGM")[0]); ScaleYGizmoEntity->SetName("ScaleYGizmoEntity"); ScaleYGizmoEntity->GetComponent().SetCastShadows(false); @@ -1029,7 +897,7 @@ void GizmoManager::ReInitializeEntities() CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // ScaleZGizmo - ScaleZGizmoEntity = CurrentScene->AddEntity("ScaleZGizmoEntity"); + ScaleZGizmoEntity = CurrentScene->CreateEntity("ScaleZGizmoEntity"); ScaleZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleZGizmoGM")[0]); ScaleZGizmoEntity->SetName("ScaleZGizmoEntity"); ScaleZGizmoEntity->GetComponent().SetCastShadows(false); @@ -1040,7 +908,7 @@ void GizmoManager::ReInitializeEntities() CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // RotateXGizmo - RotateXGizmoEntity = CurrentScene->AddEntity("RotateXGizmoEntity"); + RotateXGizmoEntity = CurrentScene->CreateEntity("RotateXGizmoEntity"); RotateXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateXGizmoGM")[0]); RotateXGizmoEntity->SetName("RotateXGizmoEntity"); RotateXGizmoEntity->GetComponent().SetCastShadows(false); @@ -1051,7 +919,7 @@ void GizmoManager::ReInitializeEntities() CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // RotateYGizmo - RotateYGizmoEntity = CurrentScene->AddEntity("RotateYGizmoEntity"); + RotateYGizmoEntity = CurrentScene->CreateEntity("RotateYGizmoEntity"); RotateYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateYGizmoGM")[0]); RotateYGizmoEntity->SetName("RotateYGizmoEntity"); RotateYGizmoEntity->GetComponent().SetCastShadows(false); @@ -1062,7 +930,7 @@ void GizmoManager::ReInitializeEntities() CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); // RotateZGizmo - RotateZGizmoEntity = CurrentScene->AddEntity("RotateZGizmoEntity"); + RotateZGizmoEntity = CurrentScene->CreateEntity("RotateZGizmoEntity"); RotateZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateZGizmoGM")[0]); RotateZGizmoEntity->SetName("RotateZGizmoEntity"); RotateZGizmoEntity->GetComponent().SetCastShadows(false); diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index 4bb26c0..7cc184a 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -16,6 +16,8 @@ float FEEditorPreviewManager::OriginalExposure = 0.0f; void FEEditorPreviewManager::InitializeResources() { + //PreviewScene = SCENE_MANAGER.CreateScene("EditorPreviewScene"); + PreviewFB = RESOURCE_MANAGER.CreateFramebuffer(FE_COLOR_ATTACHMENT | FE_DEPTH_ATTACHMENT, 128, 128); PreviewGameModel = new FEGameModel(nullptr, nullptr, "editorPreviewGameModel"); PreviewPrefab = new FEPrefab(PreviewGameModel, "editorPreviewPrefab"); @@ -32,19 +34,31 @@ void FEEditorPreviewManager::InitializeResources() RESOURCE_MANAGER.MakeShaderStandard(MeshPreviewMaterial->Shader); + + /*PreviewEntity = PreviewScene->CreateEntity("editorPreviewEntity"); + PreviewEntity->AddComponent(PreviewGameModel); + PreviewEntity->GetComponent().SetVisibility(false); + + LocalSunEntity = PreviewScene->CreateEntity("EditorPreview LightEntity"); + LocalSunEntity->AddComponent(FE_DIRECTIONAL_LIGHT); + FELightComponent& LightComponent = LocalSunEntity->GetComponent(); + LocalSunEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); + LightComponent.SetIntensity(10.0f);*/ + // FIX ME! Temporary solution, only supports one scene std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); if (!ActiveScenes.empty()) { FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - PreviewEntity = CurrentScene->AddEntity("editorPreviewEntity"); + PreviewEntity = PreviewScene->CreateEntity("editorPreviewEntity"); PreviewEntity->AddComponent(PreviewGameModel); PreviewEntity->GetComponent().SetVisibility(false); - //LocalLightEntity = SCENE.AddEntity("EditorPreview LightEntity"); - //FELightComponent& LightComponent = LocalLightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); - //LocalLightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); - //LightComponent.SetIntensity(10.0f); + /*LocalSunEntity = PreviewScene->CreateEntity("EditorPreview LightEntity"); + LocalSunEntity->AddComponent(FE_DIRECTIONAL_LIGHT); + FELightComponent& LightComponent = LocalSunEntity->GetComponent(); + LocalSunEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); + LightComponent.SetIntensity(10.0f);*/ } } @@ -55,11 +69,11 @@ void FEEditorPreviewManager::ReInitializeEntities() if (!ActiveScenes.empty()) { FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - PreviewEntity = CurrentScene->AddEntity("editorPreviewEntity"); + PreviewEntity = CurrentScene->CreateEntity("editorPreviewEntity"); PreviewEntity->AddComponent(PreviewGameModel); PreviewEntity->GetComponent().SetVisibility(false); - /*LocalLightEntity = SCENE.AddEntity("EditorPreview LightEntity"); + /*LocalLightEntity = SCENE.CreateEntity("EditorPreview LightEntity"); FELightComponent& LightComponent = LocalLightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); LocalLightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); LightComponent.SetIntensity(10.0f);*/ @@ -105,6 +119,7 @@ void FEEditorPreviewManager::BeforePreviewActions() FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); + // FIX ME! Camera should be part of scene. // Saving currently used variables. OriginalCameraPosition = ENGINE.GetCamera()->GetPosition(); OriginalAspectRation = ENGINE.GetCamera()->GetAspectRatio(); @@ -156,7 +171,7 @@ void FEEditorPreviewManager::BeforePreviewActions() RegularLightIntensity = LightComponent.GetIntensity(); LightComponent.SetIntensity(10.0f); - //LocalLightEntity->GetComponent().SetLightEnabled(true); + //LocalSunEntity->GetComponent().SetLightEnabled(true); bIsRegularFogEnabled = RENDERER.IsDistanceFogEnabled(); RENDERER.SetDistanceFogEnabled(false); @@ -185,7 +200,7 @@ void FEEditorPreviewManager::AfterPreviewActions() ENGINE.SetClearColor(OriginalClearColor); PreviewEntity->GetComponent().SetVisibility(false); - //LocalLightEntity->GetComponent().SetLightEnabled(false); + //LocalSunEntity->GetComponent().SetLightEnabled(false); FEEntity* CurrentLightEntity = nullptr; std::vector< std::string> LightsIDList = CurrentScene->GetEntityIDListWith(); diff --git a/FEEditorPreviewManager.h b/FEEditorPreviewManager.h index dd1beec..46e7bc5 100644 --- a/FEEditorPreviewManager.h +++ b/FEEditorPreviewManager.h @@ -29,6 +29,8 @@ class FEEditorPreviewManager void ReInitializeEntities(); void UpdateAll(); + FEScene* PreviewScene = nullptr; + FEFramebuffer* PreviewFB; FEEntity* PreviewEntity; FEPrefab* PreviewPrefab; @@ -37,7 +39,7 @@ class FEEditorPreviewManager // FIX ME! Make it work. // Local directional entity - //FEEntity* LocalLightEntity; + FEEntity* LocalSunEntity; // Saved scene settings glm::vec3 RegularLightRotation = glm::vec3(0.0f, 0.0f, 0.0f); diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index 1c40647..b38ea5a 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -44,7 +44,7 @@ void FEEditorSelectedObject::InitializeResources() if (!ActiveScenes.empty()) { FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - DummyEntity = CurrentScene->AddEntity("Editor_Selection_Dummy_Entity"); + DummyEntity = CurrentScene->CreateEntity("Editor_Selection_Dummy_Entity"); } } @@ -63,7 +63,7 @@ void FEEditorSelectedObject::ReInitializeResources() { FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; if (CurrentScene->GetEntityByName("Editor_Selection_Dummy_Entity").empty()) - DummyEntity = CurrentScene->AddEntity("Editor_Selection_Dummy_Entity"); + DummyEntity = CurrentScene->CreateEntity("Editor_Selection_Dummy_Entity"); } } @@ -284,7 +284,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons int g = ((LastColorShiftIndex + 1) >> 8) & 255; int b = ((LastColorShiftIndex + 1) >> 16) & 255; - static FEEntity* DummyEntity = CurrentScene->AddEntity("DummyEntity"); + static FEEntity* DummyEntity = CurrentScene->CreateEntity("DummyEntity"); if (!DummyEntity->HasComponent()) DummyEntity->AddComponent(); diff --git a/FEProject.cpp b/FEProject.cpp index e63b449..f4ce427 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -64,7 +64,7 @@ void FEProjectManager::CloseCurrentProject() void FEProjectManager::OpenProject(const int ProjectIndex) { PROJECT_MANAGER.SetCurrent(List[ProjectIndex]); - PROJECT_MANAGER.GetCurrent()->ProjectScene = SCENE_MANAGER.AddScene(); + PROJECT_MANAGER.GetCurrent()->ProjectScene = SCENE_MANAGER.CreateScene(); PROJECT_MANAGER.GetCurrent()->LoadScene(); // FIX ME! Temporary. SCENE_GRAPH_WINDOW.SetScene(PROJECT_MANAGER.GetCurrent()->ProjectScene); @@ -97,7 +97,7 @@ void FEProjectManager::OpenProject(const int ProjectIndex) while (it != EDITOR_INTERNAL_RESOURCES.InternalEditorObjects.end()) { if (it->second->GetType() == FE_ENTITY) - ProjectScene->AddEntity(reinterpret_cast(it->second)); + ProjectScene->CreateEntity(reinterpret_cast(it->second)); it++; }*/ @@ -1050,7 +1050,7 @@ void FEProject::LoadScene() std::vector TerrainList = Root["terrains"].getMemberNames(); for (size_t i = 0; i < TerrainList.size(); i++) { - FEEntity* Entity = ProjectScene->AddEntity(Root["terrains"][TerrainList[i]]["name"].asString(), Root["terrains"][TerrainList[i]]["ID"].asString()); + FEEntity* Entity = ProjectScene->CreateEntity(Root["terrains"][TerrainList[i]]["name"].asString(), Root["terrains"][TerrainList[i]]["ID"].asString()); FETransformComponent& TransformComponent = Entity->GetComponent(); Entity->AddComponent(); FETerrainComponent& TerrainComponent = Entity->GetComponent(); @@ -1094,7 +1094,7 @@ void FEProject::LoadScene() std::vector EntityList = Root["entities"].getMemberNames(); for (size_t i = 0; i < EntityList.size(); i++) { - FEEntity* Entity = ProjectScene->AddEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + FEEntity* Entity = ProjectScene->CreateEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); if (Root["entities"][EntityList[i]].isMember("type")) { @@ -1106,7 +1106,7 @@ void FEProject::LoadScene() if (OldPrefab->ComponentsCount() > 1) { - OldPrefab->Scene = SCENE_MANAGER.AddScene(false, OldPrefab->GetName()); + OldPrefab->Scene = SCENE_MANAGER.CreateScene(false, OldPrefab->GetName()); //OldPrefab->Scene->ImportEntity(Entity); } @@ -1114,7 +1114,7 @@ void FEProject::LoadScene() { if (c > 0) { - Entity = ProjectScene->AddEntity(Root["entities"][EntityList[i]]["name"].asString() + "_Prefabs_" + std::to_string(c)); + Entity = ProjectScene->CreateEntity(Root["entities"][EntityList[i]]["name"].asString() + "_Prefabs_" + std::to_string(c)); //OldPrefab->Scene->ImportEntity(Entity); } FEPrefabComponent* CurrentComponent = OldPrefab->GetComponent(static_cast(c)); @@ -1225,14 +1225,14 @@ void FEProject::LoadScene() if (Root["entities"][EntityList[i]].isMember("gameModel")) { //FEPrefab* TempPrefab = RESOURCE_MANAGER.CreatePrefab(RESOURCE_MANAGER.GetGameModel(Root["entities"][EntityList[i]]["gameModel"].asCString())); - //ProjectScene->AddEntity(TempPrefab, Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + //ProjectScene->CreateEntity(TempPrefab, Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); FEGameModel* GameModel = RESOURCE_MANAGER.GetGameModel(Root["entities"][EntityList[i]]["gameModel"].asCString()); Entity->AddComponent(GameModel); } else { - /*ProjectScene->AddEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), + /*ProjectScene->CreateEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString());*/ @@ -1258,12 +1258,12 @@ void FEProject::LoadScene() // For compatibility with old projects. else { - //FEEntity* Entity = ProjectScene->AddEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); + //FEEntity* Entity = ProjectScene->CreateEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString())->GetComponent(0)->GameModel; Entity->AddComponent(GameModel); ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &Entity->GetComponent()); - /*ProjectScene->AddEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), + /*ProjectScene->CreateEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), EntityList[i], Root["entities"][EntityList[i]]["ID"].asString()); ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &ProjectScene->GetEntity(EntityList[i])->Transform);*/ @@ -1280,7 +1280,7 @@ void FEProject::LoadScene() std::vector LightList = Root["lights"].getMemberNames(); for (size_t i = 0; i < LightList.size(); i++) { - FEEntity* Entity = ProjectScene->AddEntity("Light Entity"); + FEEntity* Entity = ProjectScene->CreateEntity("Light Entity"); auto OldType = static_cast(Root["lights"][LightList[i]]["type"].asInt()); FE_LIGHT_TYPE NewType = FE_DIRECTIONAL_LIGHT; if (OldType == FE_POINT_LIGHT_DEPRECATED) @@ -1367,7 +1367,7 @@ void FEProject::LoadScene() //SKY_DOME_SYSTEM.SetEnabled(Root["effects"]["Sky"]["Enabled"].asFloat() > 0.0f ? true : false); //SKY_DOME_SYSTEM.SetDistanceToSky(Root["effects"]["Sky"]["Sphere size"].asFloat()); //Fix Me! - FEEntity* SkyDome = ProjectScene->AddEntity("SkyDome"); + FEEntity* SkyDome = ProjectScene->CreateEntity("SkyDome"); SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); SKY_DOME_SYSTEM.AddToEntity(SkyDome); diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index bd54e47..4638858 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit bd54e4716b6e5c06d22de53d63abb6bdf08dfcf6 +Subproject commit 4638858d8731bea6d165055254c7eb28251e0a09 From d012b7b1cc3c155d0d27cef29ecd6f4a70e0799c Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Sun, 21 Jul 2024 21:05:12 -0400 Subject: [PATCH 22/46] Engine update; Adjustments made due to the introduction of the new camera system; Initial attempts to improve editor scene management. --- EditorWindows/InspectorWindow.cpp | 153 +++++++++++++++-------------- EditorWindows/InspectorWindow.h | 5 +- EditorWindows/SceneGraphWindow.cpp | 32 +++--- FEEditor.cpp | 122 +++++++++++++---------- FEEditor.h | 10 +- FEEditorGizmoManager.cpp | 61 ++++++------ FEEditorPreviewManager.cpp | 84 ++++++++-------- FEEditorPreviewManager.h | 7 +- FEEditorSelectedObject.cpp | 37 ++++--- FEProject.cpp | 47 +++++++-- FEProject.h | 3 + SubSystems/FocalEngine | 2 +- 12 files changed, 319 insertions(+), 244 deletions(-) diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index 7e688f8..ead8eb1 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -1,4 +1,6 @@ #include "InspectorWindow.h" +#include "../FEEditor.h" + FEEditorInspectorWindow* FEEditorInspectorWindow::Instance = nullptr; FEEntity* FEEditorInspectorWindow::EntityToModify = nullptr; @@ -6,10 +8,9 @@ FEEntity* FEEditorInspectorWindow::TerrainToWorkWith = nullptr; FEEditorInspectorWindow::FEEditorInspectorWindow() { - auto RegisteredComponentList = COMPONENTS_TOOL.GetComponentInfoList(); - - + std::vector RegisteredComponentList = COMPONENTS_TOOL.GetComponentInfoList(); AddComponentHandlers[typeid(FELightComponent)] = &FEEditorInspectorWindow::AddLightComponent; + AddComponentHandlers[typeid(FECameraComponent)] = &FEEditorInspectorWindow::AddCameraComponent; } void FEEditorInspectorWindow::InitializeResources() @@ -120,7 +121,7 @@ void FEEditorInspectorWindow::ShowTransformConfiguration(const std::string Name, bModified = false; // ********************* WORLD POSITION ********************* - glm::vec3 WorldPosition = Transform->GetPosition(false); + glm::vec3 WorldPosition = Transform->GetPosition(FE_WORLD_SPACE); ImGui::Text("World Position : "); ImGui::SameLine(); ImGui::SetNextItemWidth(EditWidth); @@ -141,7 +142,7 @@ void FEEditorInspectorWindow::ShowTransformConfiguration(const std::string Name, ShowToolTip("Z position"); if (bModified) - Transform->SetPosition(WorldPosition, false); + Transform->SetPosition(WorldPosition, FE_WORLD_SPACE); bModified = false; @@ -172,7 +173,7 @@ void FEEditorInspectorWindow::ShowTransformConfiguration(const std::string Name, bModified = false; // ********************* WORLD ROTATION ********************* - glm::vec3 WorldRotation = Transform->GetRotation(false); + glm::vec3 WorldRotation = Transform->GetRotation(FE_WORLD_SPACE); ImGui::Text("World Rotation : "); ImGui::SameLine(); ImGui::SetNextItemWidth(EditWidth); @@ -193,7 +194,7 @@ void FEEditorInspectorWindow::ShowTransformConfiguration(const std::string Name, ShowToolTip("Z rotation"); if (bModified) - Transform->SetRotation(WorldRotation, false); + Transform->SetRotation(WorldRotation, FE_WORLD_SPACE); bModified = false; @@ -250,7 +251,7 @@ void FEEditorInspectorWindow::ShowTransformConfiguration(const std::string Name, bModified = false; // ********************* WORLD SCALE ********************* - glm::vec3 WorldScale = Transform->GetScale(false); + glm::vec3 WorldScale = Transform->GetScale(FE_WORLD_SPACE); ScaleChangeSpeed = WorldScale.x * 0.01f; ImGui::Text("World Scale : "); ImGui::SameLine(); @@ -293,7 +294,7 @@ void FEEditorInspectorWindow::ShowTransformConfiguration(const std::string Name, ShowToolTip("Z scale"); if (bModified) - Transform->SetScale(WorldScale, false); + Transform->SetScale(WorldScale, FE_WORLD_SPACE); } void FEEditorInspectorWindow::DisplayLightProperties(FEEntity* LightEntity) const @@ -413,6 +414,57 @@ void FEEditorInspectorWindow::DisplayLightProperties(FEEntity* LightEntity) cons LightComponent.SetIntensity(Intensity); } +void FEEditorInspectorWindow::DisplayCameraProperties(FEEntity* CameraEntity) const +{ + FECameraComponent& CameraComponent = CameraEntity->GetComponent(); + + bool bIsMainCamera = CameraComponent.IsMainCamera(); + ImGui::Checkbox("Main camera", &bIsMainCamera); + CAMERA_SYSTEM.SetMainCamera(CameraEntity); + + float CameraSpeed = CameraComponent.GetMovementSpeed(); + ImGui::Text("Camera speed in m/s : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(70); + ImGui::DragFloat("##Camera_speed", &CameraSpeed, 0.01f, 0.01f, 100.0f); + CameraComponent.SetMovementSpeed(CameraSpeed); + + float FOV = CameraComponent.GetFOV(); + ImGui::Text("Field of view : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(70); + ImGui::DragFloat("##FOV", &FOV, 0.1f, 1.0f, 179.0f); + CameraComponent.SetFOV(FOV); + + float NearPlane = CameraComponent.GetNearPlane(); + ImGui::Text("Near plane : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(70); + ImGui::DragFloat("##NearPlane", &NearPlane, 0.1f, 0.01f, 1000.0f); + CameraComponent.SetNearPlane(NearPlane); + + float FarPlane = CameraComponent.GetFarPlane(); + ImGui::Text("Far plane : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(70); + ImGui::DragFloat("##FarPlane", &FarPlane, 0.1f, 0.01f, 10000.0f); + CameraComponent.SetFarPlane(FarPlane); + + float Gamma = CameraComponent.GetGamma(); + ImGui::Text("Gamma : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(70); + ImGui::DragFloat("##Gamma", &Gamma, 0.1f, 0.1f, 10.0f); + CameraComponent.SetGamma(Gamma); + + float Exposure = CameraComponent.GetExposure(); + ImGui::Text("Exposure : "); + ImGui::SameLine(); + ImGui::SetNextItemWidth(70); + ImGui::DragFloat("##Exposure", &Exposure, 0.1f, 0.1f, 10.0f); + CameraComponent.SetExposure(Exposure); +} + // FIX ME! void FEEditorInspectorWindow::ChangePrefabOfEntityCallBack(const std::vector SelectionsResult) { @@ -434,6 +486,11 @@ void FEEditorInspectorWindow::AddLightComponent(FEEntity* Entity) Entity->AddComponent(FE_POINT_LIGHT); } +void FEEditorInspectorWindow::AddCameraComponent(FEEntity* Entity) +{ + Entity->AddComponent(); +} + std::vector FEEditorInspectorWindow::GetAvailableComponentsToAdd(FEEntity* Entity) const { std::vector Result; @@ -454,11 +511,11 @@ bool FEEditorInspectorWindow::AddComponent(FEEntity* Entity, std::string Compone { auto RegisteredComponentList = COMPONENTS_TOOL.GetComponentInfoList(); - for (size_t j = 0; j < RegisteredComponentList.size(); j++) + for (size_t i = 0; i < RegisteredComponentList.size(); i++) { - if (RegisteredComponentList[j].Name == ComponentName) + if (RegisteredComponentList[i].Name == ComponentName) { - auto ComponentHashCode = RegisteredComponentList[j].Type->hash_code(); + auto ComponentHashCode = RegisteredComponentList[i].Type->hash_code(); auto ComponentIterator = AddComponentHandlers.begin(); while (ComponentIterator != AddComponentHandlers.end()) @@ -498,9 +555,6 @@ void FEEditorInspectorWindow::Render() ImGui::Text("ID : %s", EntitySelected->GetObjectID().c_str()); ImGui::Text("Name : %s", EntitySelected->GetName().c_str()); - - //auto testlist = GetAllComponentTypeInfos(); - if (EntitySelected->HasComponent()) { float headerHeight = ImGui::GetFrameHeight(); @@ -820,7 +874,9 @@ void FEEditorInspectorWindow::Render() if (ImGui::Button("Add instance")) { glm::mat4 NewInstanceMatrix = glm::identity(); - NewInstanceMatrix = glm::translate(NewInstanceMatrix, ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); + FECameraComponent& CameraComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); + NewInstanceMatrix = glm::translate(NewInstanceMatrix, CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); INSTANCED_RENDERING_SYSTEM.AddIndividualInstance(EntitySelected, NewInstanceMatrix); PROJECT_MANAGER.GetCurrent()->SetModified(true); @@ -899,6 +955,14 @@ void FEEditorInspectorWindow::Render() } } + if (EntitySelected->HasComponent()) + { + if (ImGui::CollapsingHeader("Camera", ImGuiTreeNodeFlags_DefaultOpen)) + { + DisplayCameraProperties(SELECTED.GetSelected()); + } + } + std::vector AvailableComponentTypes = GetAvailableComponentsToAdd(EntitySelected); ImGui::SetNextItemWidth(220.0f); @@ -919,63 +983,6 @@ void FEEditorInspectorWindow::Render() ImGui::EndCombo(); } - - //else if (SELECTED.GetSelected()->GetType() == FE_CAMERA) - //{ - // FEBasicCamera* Camera = ENGINE.GetCamera(); - - // // ********* POSITION ********* - // glm::vec3 CameraPosition = Camera->GetPosition(); - - // ImGui::Text("Position : "); - // ImGui::SameLine(); - // ImGui::SetNextItemWidth(90); - // ImGui::DragFloat("##X pos", &CameraPosition[0], 0.1f); - // ShowToolTip("X Position"); - - // ImGui::SameLine(); - // ImGui::SetNextItemWidth(90); - // ImGui::DragFloat("##Y pos", &CameraPosition[1], 0.1f); - // ShowToolTip("Y Position"); - - // ImGui::SameLine(); - // ImGui::SetNextItemWidth(90); - // ImGui::DragFloat("##Z pos", &CameraPosition[2], 0.1f); - // ShowToolTip("Z Position"); - - // Camera->SetPosition(CameraPosition); - - // // ********* ROTATION ********* - // glm::vec3 CameraRotation = glm::vec3(Camera->GetYaw(), Camera->GetPitch(), Camera->GetRoll()); - - // ImGui::Text("WorldRotation : "); - // ImGui::SameLine(); - // ImGui::SetNextItemWidth(90); - // ImGui::DragFloat("##X rot", &CameraRotation[0], 0.1f); - // ShowToolTip("X WorldRotation"); - - // ImGui::SameLine(); - // ImGui::SetNextItemWidth(90); - // ImGui::DragFloat("##Y rot", &CameraRotation[1], 0.1f); - // ShowToolTip("Y WorldRotation"); - - // ImGui::SameLine(); - // ImGui::SetNextItemWidth(90); - // ImGui::DragFloat("##Z rot", &CameraRotation[2], 0.1f); - // ShowToolTip("Z WorldRotation"); - - // Camera->SetYaw(CameraRotation[0]); - // Camera->SetPitch(CameraRotation[1]); - // Camera->SetRoll(CameraRotation[2]); - - // float CameraSpeed = Camera->GetMovementSpeed(); - // ImGui::Text("Camera speed in m/s : "); - // ImGui::SameLine(); - // ImGui::SetNextItemWidth(70); - // ImGui::DragFloat("##Camera_speed", &CameraSpeed, 0.01f, 0.01f, 100.0f); - // Camera->SetMovementSpeed(CameraSpeed); - //} - ImGui::PopStyleVar(); ImGui::End(); } diff --git a/EditorWindows/InspectorWindow.h b/EditorWindows/InspectorWindow.h index 1e72119..a970956 100644 --- a/EditorWindows/InspectorWindow.h +++ b/EditorWindows/InspectorWindow.h @@ -4,6 +4,7 @@ class FEEditorInspectorWindow { + friend class FEEditorSceneGraphWindow; friend class FEEditor; SINGLETON_PRIVATE_PART(FEEditorInspectorWindow) @@ -11,8 +12,8 @@ class FEEditorInspectorWindow bool bVisible = true; static FEEntity* EntityToModify; - // Light properties void DisplayLightProperties(FEEntity* LightEntity) const; + void DisplayCameraProperties(FEEntity* CameraEntity) const; // Terrain settings static FEEntity* TerrainToWorkWith; @@ -64,7 +65,7 @@ class FEEditorInspectorWindow std::unordered_map> AddComponentHandlers; static void AddLightComponent(FEEntity* Entity); - + static void AddCameraComponent(FEEntity* Entity); public: SINGLETON_PUBLIC_PART(FEEditorInspectorWindow) }; diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 55b36e7..94606da 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -1,4 +1,5 @@ #include "SceneGraphWindow.h" +#include "../FEEditor.h" FEEditorSceneGraphWindow* FEEditorSceneGraphWindow::Instance = nullptr; FEEntity* FEEditorSceneGraphWindow::EntityToModify = nullptr; @@ -56,7 +57,7 @@ void FEEditorSceneGraphWindow::SetCorrectItemColor(FEObject* SceneObject) const { ImGui::PushStyleColor(ImGuiCol_Text, CameraItemColor); } - else if (SceneObject->GetType() == FE_TERRAIN) + else if (SceneObject->GetType() == FE_TERRAIN_DEPRECATED) { ImGui::PushStyleColor(ImGuiCol_Text, TerrainItemColor); } @@ -64,7 +65,7 @@ void FEEditorSceneGraphWindow::SetCorrectItemColor(FEObject* SceneObject) const { ImGui::PushStyleColor(ImGuiCol_Text, EntityItemColor); } - else if (SceneObject->GetType() == FE_ENTITY_INSTANCED) + else if (SceneObject->GetType() == FE_ENTITY_INSTANCED_DEPRECATED) { ImGui::PushStyleColor(ImGuiCol_Text, InstancedEntityItemColor); } @@ -76,9 +77,9 @@ void FEEditorSceneGraphWindow::PopCorrectItemColor(FEObject* SceneObject) SceneObject->GetType() == FE_SPOT_LIGHT || SceneObject->GetType() == FE_POINT_LIGHT || SceneObject->GetType() == FE_CAMERA || - SceneObject->GetType() == FE_TERRAIN || + SceneObject->GetType() == FE_TERRAIN_DEPRECATED || SceneObject->GetType() == FE_ENTITY || - SceneObject->GetType() == FE_ENTITY_INSTANCED) + SceneObject->GetType() == FE_ENTITY_INSTANCED_DEPRECATED) { ImGui::PopStyleColor(); } @@ -92,8 +93,10 @@ static void CreateInstancedEntityCallBack(const std::vector Selection if (SelectedPrefab == nullptr) return; + FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); + FECameraComponent& CameraComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); FEEntity* Entity = SCENE_GRAPH_WINDOW.GetScene()->CreateEntity(); - Entity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); Entity->AddComponent(SelectedPrefab->GetComponent(0)->GameModel); Entity->AddComponent(); SELECTED.SetSelected(Entity); @@ -110,8 +113,10 @@ static void CreateEntityCallBack(const std::vector SelectionsResult) if (SelectedPrefab == nullptr) return; + FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); + FECameraComponent& CameraComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); FEEntity* Entity = SCENE_GRAPH_WINDOW.GetScene()->CreateEntity(); - Entity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); + Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); SELECTED.SetSelected(Entity); PROJECT_MANAGER.GetCurrent()->SetModified(true); @@ -139,14 +144,14 @@ void FEEditorSceneGraphWindow::DrawCorrectIcon(const FEObject* SceneObject) cons ImGui::SetCursorPosX(20); // FIX ME! - /*if (SceneObject->GetType() == FE_ENTITY || SceneObject->GetType() == FE_ENTITY_INSTANCED) + /*if (SceneObject->GetType() == FE_ENTITY || SceneObject->GetType() == FE_ENTITY_INSTANCED_DEPRECATED) { const FEEntity* entity = SCENE.GetEntity(SceneObject->GetObjectID()); if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(entity)) return; - if (entity->GetType() == FE_ENTITY_INSTANCED) + if (entity->GetType() == FE_ENTITY_INSTANCED_DEPRECATED) { ImGui::Image((void*)(intptr_t)InstancedEntityIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); @@ -175,7 +180,7 @@ void FEEditorSceneGraphWindow::DrawCorrectIcon(const FEObject* SceneObject) cons } - if (SceneObject->GetType() == FE_TERRAIN) + if (SceneObject->GetType() == FE_TERRAIN_DEPRECATED) { ImGui::Image((void*)(intptr_t)TerrainIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); } @@ -289,6 +294,8 @@ void FEEditorSceneGraphWindow::RenderNewSceneGraph() bSceneNodeTargetsDirty = false; } +//FIX ME! +#include "InspectorWindow.h" void FEEditorSceneGraphWindow::Render() { if (!bVisible) @@ -333,7 +340,7 @@ void FEEditorSceneGraphWindow::Render() SceneObjectsList.push_back(TerrainList[i]); } - SceneObjectsList.push_back(ENGINE.GetCamera()->GetObjectID()); + //SceneObjectsList.push_back(ENGINE.GetCamera()->GetObjectID()); // Filtering. ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5.0f); @@ -527,7 +534,10 @@ void FEEditorSceneGraphWindow::Render() ImGui::EndPopup(); } - // It should not be here. + //FEBasicCamera* Camera = ENGINE.GetCamera(); + //INSPECTOR_WINDOW.ShowTransformConfiguration("Camera", & Camera->TestTransform); + + // FIX ME! It should not be here. static bool bDisplayGrid = true; ImGui::Checkbox("Display grid", &bDisplayGrid); diff --git a/FEEditor.cpp b/FEEditor.cpp index 24c186a..5352c9a 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -9,19 +9,17 @@ bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) { FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())->GetComponent(0)->GameModel; - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (!ActiveScenes.empty()) - { - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - FEEntity* Entity = CurrentScene->CreateEntity(Object->GetName()); - Entity->GetComponent().GameModel = GameModel; - Entity->GetComponent().SetPosition(ENGINE.GetCamera()->GetPosition() + ENGINE.GetCamera()->GetForward() * 10.0f); - SELECTED.SetSelected(Entity); - PROJECT_MANAGER.GetCurrent()->SetModified(true); + FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); + FECameraComponent& CameraComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); - return true; - } + FEEntity* Entity = EDITOR.GetCurrentEditorScene()->CreateEntity(Object->GetName()); + Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); + Entity->AddComponent(GameModel); + + SELECTED.SetSelected(Entity); + PROJECT_MANAGER.GetCurrent()->SetModified(true); + + return true; } return false; @@ -110,6 +108,11 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) { EDITOR.bIsCameraInputActive = false; ENGINE.GetCamera()->SetIsInputActive(false); + if (PROJECT_MANAGER.GetCurrent() != nullptr && PROJECT_MANAGER.GetCurrent()->ProjectScene != nullptr) + { + FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(PROJECT_MANAGER.GetCurrent()->ProjectScene); + CAMERA_SYSTEM.SetIsIndividualInputActive(MainCamera, false); + } return; } @@ -139,12 +142,22 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_PRESS) { EDITOR.bIsCameraInputActive = true; - ENGINE.GetCamera()->SetIsInputActive(true); + //ENGINE.GetCamera()->SetIsInputActive(true); + if (PROJECT_MANAGER.GetCurrent() != nullptr && PROJECT_MANAGER.GetCurrent()->ProjectScene != nullptr) + { + FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(PROJECT_MANAGER.GetCurrent()->ProjectScene); + CAMERA_SYSTEM.SetIsIndividualInputActive(MainCamera, true); + } } else if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_RELEASE) { EDITOR.bIsCameraInputActive = false; ENGINE.GetCamera()->SetIsInputActive(false); + if (PROJECT_MANAGER.GetCurrent() != nullptr && PROJECT_MANAGER.GetCurrent()->ProjectScene != nullptr) + { + FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(PROJECT_MANAGER.GetCurrent()->ProjectScene); + CAMERA_SYSTEM.SetIsIndividualInputActive(MainCamera, false); + } } } @@ -244,6 +257,11 @@ void FEEditor::InitializeResources() SELECTED.InitializeResources(); ENGINE.GetCamera()->SetIsInputActive(bIsCameraInputActive); + if (PROJECT_MANAGER.GetCurrent() != nullptr && PROJECT_MANAGER.GetCurrent()->ProjectScene != nullptr) + { + FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(PROJECT_MANAGER.GetCurrent()->ProjectScene); + CAMERA_SYSTEM.SetIsIndividualInputActive(MainCamera, bIsCameraInputActive); + } PROJECT_MANAGER.InitializeResources(); PREVIEW_MANAGER.InitializeResources(); DRAG_AND_DROP_MANAGER.InitializeResources(); @@ -293,7 +311,7 @@ void FEEditor::InitializeResources() CONTENT_BROWSER_WINDOW.InitializeResources(); INSPECTOR_WINDOW.InitializeResources(); - ENGINE.GetCamera()->SetOnUpdate(OnCameraUpdate); + ENGINE.AddOnAfterUpdateCallback(AfterEngineUpdate); ENGINE.AddWindowCloseCallback(CloseWindowCallBack); SetUpImgui(); @@ -321,7 +339,7 @@ void FEEditor::MouseMoveCallback(double Xpos, double Ypos) } } -void FEEditor::OnCameraUpdate(FEBasicCamera* Camera) +void FEEditor::AfterEngineUpdate() { SELECTED.OnCameraUpdate(); GIZMO_MANAGER.Render(); @@ -329,6 +347,19 @@ void FEEditor::OnCameraUpdate(FEBasicCamera* Camera) void FEEditor::Render() { + // FIX ME! Temporary solution, only supports one scene + std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + if (ActiveScenes.empty()) + { + CurrentEditorScene = nullptr; + CurrentEditorCameraEntity = nullptr; + } + else + { + CurrentEditorScene = SCENE_MANAGER.GetActiveScenes()[0]; + CurrentEditorCameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(CurrentEditorScene); + } + DRAG_AND_DROP_MANAGER.Render(); if (PROJECT_MANAGER.GetCurrent()) @@ -367,9 +398,7 @@ void FEEditor::Render() } else { - PROJECT_MANAGER.CloseCurrentProject(); - CONTENT_BROWSER_WINDOW.Clear(); - SCENE_GRAPH_WINDOW.Clear(); + OnProjectClose(); ImGui::PopStyleVar(); ImGui::EndMenu(); @@ -388,7 +417,7 @@ void FEEditor::Render() } else { - PROJECT_MANAGER.CloseCurrentProject(); + OnProjectClose(); ENGINE.Terminate(); return; } @@ -549,7 +578,7 @@ void FEEditor::CloseWindowCallBack() } else { - PROJECT_MANAGER.CloseCurrentProject(); + EDITOR.OnProjectClose(); ENGINE.Terminate(); return; } @@ -645,39 +674,6 @@ void FEEditor::DisplayEffectsWindow() const bFirstCall = false; } - if (ImGui::CollapsingHeader("Gamma Correction & Exposure", 0)) - { - ImGui::Text("Gamma Correction:"); - float Gamma = ENGINE.GetCamera()->GetGamma(); - ImGui::SetNextItemWidth(FieldWidth); - ImGui::DragFloat("##Gamma Correction", &Gamma, 0.01f, 0.001f, 10.0f); - ENGINE.GetCamera()->SetGamma(Gamma); - - ImGui::PushID(GUIID++); - ImGui::SameLine(); - ResetButton->Render(); - if (ResetButton->IsClicked()) - { - ENGINE.GetCamera()->SetGamma(2.2f); - } - ImGui::PopID(); - - ImGui::Text("Exposure:"); - float Exposure = ENGINE.GetCamera()->GetExposure(); - ImGui::SetNextItemWidth(FieldWidth); - ImGui::DragFloat("##Exposure", &Exposure, 0.01f, 0.001f, 100.0f); - ENGINE.GetCamera()->SetExposure(Exposure); - - ImGui::PushID(GUIID++); - ImGui::SameLine(); - ResetButton->Render(); - if (ResetButton->IsClicked()) - { - ENGINE.GetCamera()->SetExposure(1.0f); - } - ImGui::PopID(); - } - if (ImGui::CollapsingHeader("Anti-Aliasing(FXAA)", 0)) { static const char* options[5] = { "none", "1x", "2x", "4x", "8x" }; @@ -1210,4 +1206,24 @@ void FEEditor::SetUpImgui() ImGui::StyleColorsDark(); SetImguiStyle(); +} + +FEScene* FEEditor::GetCurrentEditorScene() const +{ + return CurrentEditorScene; +} + +FEEntity* FEEditor::GetCurrentEditorCameraEntity() const +{ + return CurrentEditorCameraEntity; +} + +void FEEditor::OnProjectClose() +{ + CurrentEditorScene = nullptr; + CurrentEditorCameraEntity = nullptr; + + PROJECT_MANAGER.CloseCurrentProject(); + CONTENT_BROWSER_WINDOW.Clear(); + SCENE_GRAPH_WINDOW.Clear(); } \ No newline at end of file diff --git a/FEEditor.h b/FEEditor.h index 7d55b8f..0b9f7f6 100644 --- a/FEEditor.h +++ b/FEEditor.h @@ -26,6 +26,9 @@ class FEEditor // Clipboard std::string GetSceneEntityIDInClipboard(); void SetSceneEntityIDInClipboard(std::string NewValue); + + FEScene* GetCurrentEditorScene() const; + FEEntity* GetCurrentEditorCameraEntity() const; private: SINGLETON_PRIVATE_PART(FEEditor) @@ -35,6 +38,9 @@ class FEEditor bool bSceneWindowHovered; bool bIsCameraInputActive = false; + FEScene* CurrentEditorScene = nullptr; + FEEntity* CurrentEditorCameraEntity = nullptr; + // Clipboard std::string SceneEntityIDInClipboard; @@ -45,7 +51,7 @@ class FEEditor DragAndDropTarget* SceneWindowTarget = nullptr; // Callbacks - static void OnCameraUpdate(FEBasicCamera* Camera); + static void AfterEngineUpdate(); static void MouseButtonCallback(int Button, int Action, int Mods); static void MouseMoveCallback(double Xpos, double Ypos); static void KeyButtonCallback(int Key, int Scancode, int Action, int Mods); @@ -80,6 +86,8 @@ class FEEditor // ImGui setup void SetUpImgui(); void SetImguiStyle(); + + void OnProjectClose(); }; #define EDITOR FEEditor::getInstance() \ No newline at end of file diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index 5632eb7..868f857 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -1,5 +1,6 @@ #include "FEEditorGizmoManager.h" using namespace FocalEngine; +#include "FEEditor.h" //using namespace GizmoManager; GizmoManager* GizmoManager::Instance = nullptr; @@ -254,14 +255,11 @@ void GizmoManager::DeactivateAllGizmo() void GizmoManager::Render() { - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (ActiveScenes.empty()) + if (EDITOR.GetCurrentEditorScene() == nullptr) return; - - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + // If we cleared the scene, we should not render gizmos. - if (CurrentScene->GetEntityByName("TransformationXGizmoEntity").empty() || CurrentScene->GetEntityByName("TransformationXGizmoEntity")[0] == nullptr) + if (EDITOR.GetCurrentEditorScene()->GetEntityByName("TransformationXGizmoEntity").empty() || EDITOR.GetCurrentEditorScene()->GetEntityByName("TransformationXGizmoEntity")[0] == nullptr) return; if (SELECTED.GetSelected() == nullptr || SELECTED.GetSelected()->GetType() == FE_CAMERA) @@ -270,20 +268,15 @@ void GizmoManager::Render() return; } + FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); const glm::vec3 ObjectSpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); - glm::vec3 ToObject = ObjectSpaceOriginInWorldSpace - ENGINE.GetCamera()->GetPosition(); + glm::vec3 ToObject = ObjectSpaceOriginInWorldSpace - CameraTransformComponent.GetPosition(FE_WORLD_SPACE); ToObject = glm::normalize(ToObject); - // This will center gizmos in AABB center, but it will produce bug while moving object under some circumstances. - /*if (SELECTED.getEntity() != nullptr && SELECTED.getEntity()->getType() == FE_ENTITY_INSTANCED && SELECTED.instancedSubObjectIndexSelected == -1) - { - FEAABB AABB = SELECTED.getEntity()->getAABB(); - glm::vec3 center = AABB.getMin() + ((AABB.getMax() - AABB.getMin()) / 2.0f); - toObject = glm::normalize(center - ENGINE.getCamera()->getPosition()); - }*/ - - ParentGizmoEntity->GetComponent().SetPosition((ENGINE.GetCamera()->GetPosition() + ToObject * 0.15f)); + ParentGizmoEntity->GetComponent().SetPosition((CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + ToObject * 0.15f)); + //ParentGizmoEntity->GetComponent().Update(); + //ParentGizmoEntity->GetComponent().ForceSetWorldMatrix(ParentGizmoEntity->GetComponent().GetLocalMatrix()); if (GIZMO_MANAGER.GizmosState == TRANSFORM_GIZMOS) { // X Gizmos @@ -460,13 +453,14 @@ bool GizmoManager::WasSelected(int Index) glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal) { + FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); const glm::vec3 EntitySpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); - const glm::vec3 CameraPosition = ENGINE.GetCamera()->GetPosition(); + const glm::vec3 CameraPosition = CameraTransformComponent.GetPosition(FE_WORLD_SPACE); const float SignedDistanceToOrigin = glm::dot(PlaneNormal, EntitySpaceOriginInWorldSpace); @@ -488,13 +482,14 @@ glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal) glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, glm::vec3& LastMousePointOnPlane) { + FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); const glm::vec3 EntitySpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); - const glm::vec3 CameraPosition = ENGINE.GetCamera()->GetPosition(); + const glm::vec3 CameraPosition = CameraTransformComponent.GetPosition(FE_WORLD_SPACE); const float SignedDistanceToOrigin = glm::dot(PlaneNormal, EntitySpaceOriginInWorldSpace); @@ -517,6 +512,7 @@ glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, void GizmoManager::MouseMoveTransformationGizmos() { + FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); float MouseRayParametricIntersection = 0.0f; @@ -530,12 +526,12 @@ void GizmoManager::MouseMoveTransformationGizmos() if (GIZMO_MANAGER.bTransformationXGizmoActive) { const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); - GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), LastMouseRayVector, + GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), LastMouseRayVector, glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f), LastFrameMouseRayParametricIntersection, LastFrameGizmoRayParametricIntersection); const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); - GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), MouseRayVector, + GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRayVector, glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f), MouseRayParametricIntersection, GizmoRayParametricIntersection); @@ -543,19 +539,19 @@ void GizmoManager::MouseMoveTransformationGizmos() if (abs(Difference) > FLT_EPSILON) { bAppliedSomeChanges = true; - ObjTransform.SetPosition(ObjTransform.GetPosition(false) + glm::vec3(Difference, 0.0f, 0.0f), false); + ObjTransform.SetPosition(ObjTransform.GetPosition(FE_WORLD_SPACE) + glm::vec3(Difference, 0.0f, 0.0f), FE_WORLD_SPACE); } } if (GIZMO_MANAGER.bTransformationYGizmoActive) { const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); - GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), LastMouseRayVector, + GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), LastMouseRayVector, glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 1.0f, 0.0f), LastFrameMouseRayParametricIntersection, LastFrameGizmoRayParametricIntersection); const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); - GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), MouseRayVector, + GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRayVector, glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 1.0f, 0.0f), MouseRayParametricIntersection, GizmoRayParametricIntersection); @@ -563,19 +559,19 @@ void GizmoManager::MouseMoveTransformationGizmos() if (abs(Difference) > FLT_EPSILON) { bAppliedSomeChanges = true; - ObjTransform.SetPosition(ObjTransform.GetPosition(false) + glm::vec3(0.0f, Difference, 0.0f), false); + ObjTransform.SetPosition(ObjTransform.GetPosition(FE_WORLD_SPACE) + glm::vec3(0.0f, Difference, 0.0f), FE_WORLD_SPACE); } } if (GIZMO_MANAGER.bTransformationZGizmoActive) { const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); - GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), LastMouseRayVector, + GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), LastMouseRayVector, glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 0.0f, 1.0f), LastFrameMouseRayParametricIntersection, LastFrameGizmoRayParametricIntersection); const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); - GEOMETRY.RaysIntersection(ENGINE.GetCamera()->GetPosition(), MouseRayVector, + GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRayVector, glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 0.0f, 1.0f), MouseRayParametricIntersection, GizmoRayParametricIntersection); @@ -583,7 +579,7 @@ void GizmoManager::MouseMoveTransformationGizmos() if (abs(Difference) > FLT_EPSILON) { bAppliedSomeChanges = true; - ObjTransform.SetPosition(ObjTransform.GetPosition(false) + glm::vec3(0.0f, 0.0f, Difference), false); + ObjTransform.SetPosition(ObjTransform.GetPosition(FE_WORLD_SPACE) + glm::vec3(0.0f, 0.0f, Difference), FE_WORLD_SPACE); } } @@ -593,7 +589,7 @@ void GizmoManager::MouseMoveTransformationGizmos() if (!GEOMETRY.IsEpsilonEqual(Difference, glm::vec3(0.0f))) { bAppliedSomeChanges = true; - ObjTransform.SetPosition(ObjTransform.GetPosition(false) + Difference, false); + ObjTransform.SetPosition(ObjTransform.GetPosition(FE_WORLD_SPACE) + Difference, FE_WORLD_SPACE); } } @@ -603,7 +599,7 @@ void GizmoManager::MouseMoveTransformationGizmos() if (!GEOMETRY.IsEpsilonEqual(Difference, glm::vec3(0.0f))) { bAppliedSomeChanges = true; - ObjTransform.SetPosition(ObjTransform.GetPosition(false) + Difference, false); + ObjTransform.SetPosition(ObjTransform.GetPosition(FE_WORLD_SPACE) + Difference, FE_WORLD_SPACE); } } @@ -613,7 +609,7 @@ void GizmoManager::MouseMoveTransformationGizmos() if (!GEOMETRY.IsEpsilonEqual(Difference, glm::vec3(0.0f))) { bAppliedSomeChanges = true; - ObjTransform.SetPosition(ObjTransform.GetPosition(false) + Difference, false); + ObjTransform.SetPosition(ObjTransform.GetPosition(FE_WORLD_SPACE) + Difference, FE_WORLD_SPACE); } } @@ -623,11 +619,12 @@ void GizmoManager::MouseMoveTransformationGizmos() void GizmoManager::MouseMoveScaleGizmos() { + FECameraComponent& CameraComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); if (GIZMO_MANAGER.bScaleXGizmoActive && GIZMO_MANAGER.bScaleYGizmoActive && GIZMO_MANAGER.bScaleZGizmoActive) { - const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(-ENGINE.GetCamera()->GetForward()); + const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(-CameraComponent.GetForward()); float Magnitude = Difference.x + Difference.y + Difference.z; glm::vec3 EntityScale = ObjTransform.GetScale(); @@ -696,7 +693,7 @@ void GizmoManager::MouseMoveRotateGizmos() if (GIZMO_MANAGER.bRotateZGizmoActive) AxisOfRotation = glm::vec3(0.0f, 0.0f, 1.0f); - ObjTransform.RotateAroundAxis(AxisOfRotation, Difference, false); + ObjTransform.RotateAroundAxis(AxisOfRotation, Difference, FE_WORLD_SPACE); ApplyChangesToSelectedObject(ObjTransform); } diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index 7cc184a..ace4e31 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -7,16 +7,10 @@ FEEditorPreviewManager::~FEEditorPreviewManager() {} glm::vec4 FEEditorPreviewManager::OriginalClearColor = glm::vec4(); FETransformComponent FEEditorPreviewManager::OriginalTransform = FETransformComponent(); -glm::vec3 FEEditorPreviewManager::OriginalCameraPosition = glm::vec3(); -float FEEditorPreviewManager::OriginalAspectRation = 0.0f; -float FEEditorPreviewManager::OriginalCameraPitch = 0.0f; -float FEEditorPreviewManager::OriginalCameraRoll = 0.0f; -float FEEditorPreviewManager::OriginalCameraYaw = 0.0f; -float FEEditorPreviewManager::OriginalExposure = 0.0f; void FEEditorPreviewManager::InitializeResources() { - //PreviewScene = SCENE_MANAGER.CreateScene("EditorPreviewScene"); + PreviewScene = SCENE_MANAGER.CreateScene("EditorPreviewScene", "", false); PreviewFB = RESOURCE_MANAGER.CreateFramebuffer(FE_COLOR_ATTACHMENT | FE_DEPTH_ATTACHMENT, 128, 128); PreviewGameModel = new FEGameModel(nullptr, nullptr, "editorPreviewGameModel"); @@ -35,11 +29,17 @@ void FEEditorPreviewManager::InitializeResources() RESOURCE_MANAGER.MakeShaderStandard(MeshPreviewMaterial->Shader); - /*PreviewEntity = PreviewScene->CreateEntity("editorPreviewEntity"); + PreviewEntity = PreviewScene->CreateEntity("EditorPreviewEntity"); PreviewEntity->AddComponent(PreviewGameModel); PreviewEntity->GetComponent().SetVisibility(false); - LocalSunEntity = PreviewScene->CreateEntity("EditorPreview LightEntity"); + LocalCameraEntity = PreviewScene->CreateEntity("EditorPreview CameraEntity"); + LocalCameraEntity->AddComponent(); + FECameraComponent& CameraComponent = LocalCameraEntity->GetComponent(); + CameraComponent.SetIsUsingDefaultRenderTargetSize(false); + CameraComponent.SetRenderTargetSize(128, 128); + + /*LocalSunEntity = PreviewScene->CreateEntity("EditorPreview LightEntity"); LocalSunEntity->AddComponent(FE_DIRECTIONAL_LIGHT); FELightComponent& LightComponent = LocalSunEntity->GetComponent(); LocalSunEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); @@ -50,7 +50,7 @@ void FEEditorPreviewManager::InitializeResources() if (!ActiveScenes.empty()) { FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - PreviewEntity = PreviewScene->CreateEntity("editorPreviewEntity"); + PreviewEntity = PreviewScene->CreateEntity("EditorPreviewEntity"); PreviewEntity->AddComponent(PreviewGameModel); PreviewEntity->GetComponent().SetVisibility(false); @@ -69,7 +69,7 @@ void FEEditorPreviewManager::ReInitializeEntities() if (!ActiveScenes.empty()) { FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - PreviewEntity = CurrentScene->CreateEntity("editorPreviewEntity"); + PreviewEntity = CurrentScene->CreateEntity("EditorPreviewEntity"); PreviewEntity->AddComponent(PreviewGameModel); PreviewEntity->GetComponent().SetVisibility(false); @@ -119,16 +119,6 @@ void FEEditorPreviewManager::BeforePreviewActions() FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); - // FIX ME! Camera should be part of scene. - // Saving currently used variables. - OriginalCameraPosition = ENGINE.GetCamera()->GetPosition(); - OriginalAspectRation = ENGINE.GetCamera()->GetAspectRatio(); - OriginalCameraPitch = ENGINE.GetCamera()->GetPitch(); - OriginalCameraRoll = ENGINE.GetCamera()->GetRoll(); - OriginalCameraYaw = ENGINE.GetCamera()->GetYaw(); - OriginalExposure = ENGINE.GetCamera()->GetExposure(); - ENGINE.GetCamera()->SetExposure(1.0f); - OriginalTransform = PreviewEntity->GetComponent(); // The transform impacts the AABB. Therefore, the necessary values must be set prior to any calculations. @@ -136,13 +126,9 @@ void FEEditorPreviewManager::BeforePreviewActions() PreviewEntity->GetComponent().SetScale(glm::vec3(1.0, 1.0, 1.0)); PreviewEntity->GetComponent().SetRotation(glm::vec3(15.0, -15.0, 0.0)); - ENGINE.GetCamera()->SetAspectRatio(1.0f); + //CameraComponent.SetAspectRatio(1.0f); FE_GL_ERROR(glViewport(0, 0, 128, 128)); - ENGINE.GetCamera()->SetPitch(0.0f); - ENGINE.GetCamera()->SetRoll(0.0f); - ENGINE.GetCamera()->SetYaw(0.0f); - PreviewEntity->GetComponent().SetVisibility(true); FEEntity* CurrentLightEntity = nullptr; @@ -189,12 +175,6 @@ void FEEditorPreviewManager::AfterPreviewActions() // We are reversing all of our previously applied transformations. PreviewEntity->GetComponent() = OriginalTransform; - ENGINE.GetCamera()->SetPosition(OriginalCameraPosition); - ENGINE.GetCamera()->SetAspectRatio(OriginalAspectRation); - ENGINE.GetCamera()->SetPitch(OriginalCameraPitch); - ENGINE.GetCamera()->SetRoll(OriginalCameraRoll); - ENGINE.GetCamera()->SetYaw(OriginalCameraYaw); - PreviewFB->UnBind(); ENGINE.SetClearColor(OriginalClearColor); @@ -248,10 +228,14 @@ void FEEditorPreviewManager::CreateMeshPreview(const std::string MeshID) // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. PreviewEntity->GetComponent().SetPosition(-glm::vec3(Max.x - XSize / 2.0f, Max.y - YSize / 2.0f, Max.z - ZSize / 2.0f)); - ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); + // FIX ME! Temporary solution + LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); + LocalCameraEntity->GetComponent().Update(); + LocalCameraEntity->GetComponent().ForceSetWorldMatrix(LocalCameraEntity->GetComponent().GetLocalMatrix()); + CAMERA_SYSTEM.IndividualUpdate(LocalCameraEntity, 0.0); // Rendering mesh to texture. - RENDERER.RenderGameModelComponent(PreviewEntity, ENGINE.GetCamera()); + RENDERER.RenderGameModelComponent(PreviewEntity, LocalCameraEntity); AfterPreviewActions(); @@ -305,10 +289,14 @@ void FEEditorPreviewManager::CreateMaterialPreview(const std::string MaterialID) PreviewEntity->GetComponent().SetReceivingShadows(false); BeforePreviewActions(); - ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, 70.0f)); + // FIX ME! Temporary solution + LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, 70.0f)); + LocalCameraEntity->GetComponent().Update(); + LocalCameraEntity->GetComponent().ForceSetWorldMatrix(LocalCameraEntity->GetComponent().GetLocalMatrix()); + CAMERA_SYSTEM.IndividualUpdate(LocalCameraEntity, 0.0); // Rendering material to texture - RENDERER.RenderGameModelComponentForward(PreviewEntity, ENGINE.GetCamera(), true); + RENDERER.RenderGameModelComponentForward(PreviewEntity, LocalCameraEntity, true); AfterPreviewActions(); @@ -404,10 +392,14 @@ void FEEditorPreviewManager::CreateGameModelPreview(const std::string GameModelI // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. PreviewEntity->GetComponent().SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); - ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); + // FIX ME! Temporary solution + LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); + LocalCameraEntity->GetComponent().Update(); + LocalCameraEntity->GetComponent().ForceSetWorldMatrix(LocalCameraEntity->GetComponent().GetLocalMatrix()); + CAMERA_SYSTEM.IndividualUpdate(LocalCameraEntity, 0.0); // rendering game model to texture - RENDERER.RenderGameModelComponentForward(PreviewEntity, ENGINE.GetCamera(), true); + RENDERER.RenderGameModelComponentForward(PreviewEntity, LocalCameraEntity, true); AfterPreviewActions(); @@ -446,10 +438,14 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. PreviewEntity->GetComponent().SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); - ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); + // FIX ME! Temporary solution + LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); + LocalCameraEntity->GetComponent().Update(); + LocalCameraEntity->GetComponent().ForceSetWorldMatrix(LocalCameraEntity->GetComponent().GetLocalMatrix()); + CAMERA_SYSTEM.IndividualUpdate(LocalCameraEntity, 0.0); // rendering game model to texture - RENDERER.RenderGameModelComponentForward(PreviewEntity, ENGINE.GetCamera(), true); + RENDERER.RenderGameModelComponentForward(PreviewEntity, LocalCameraEntity, true); AfterPreviewActions(); @@ -528,10 +524,14 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. PreviewEntity->GetComponent().SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); - ENGINE.GetCamera()->SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); + // FIX ME! Temporary solution + LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); + LocalCameraEntity->GetComponent().Update(); + LocalCameraEntity->GetComponent().ForceSetWorldMatrix(LocalCameraEntity->GetComponent().GetLocalMatrix()); + CAMERA_SYSTEM.IndividualUpdate(LocalCameraEntity, 0.0); // rendering game model to texture - RENDERER.RenderGameModelComponentForward(PreviewEntity, ENGINE.GetCamera(), true); + RENDERER.RenderGameModelComponentForward(PreviewEntity, LocalCameraEntity, true); //PreviewEntity->Prefab = PreviewPrefab; PreviewEntity->GetComponent().GameModel = PreviewGameModel; diff --git a/FEEditorPreviewManager.h b/FEEditorPreviewManager.h index 46e7bc5..3aa0fe4 100644 --- a/FEEditorPreviewManager.h +++ b/FEEditorPreviewManager.h @@ -40,6 +40,7 @@ class FEEditorPreviewManager // FIX ME! Make it work. // Local directional entity FEEntity* LocalSunEntity; + FEEntity* LocalCameraEntity; // Saved scene settings glm::vec3 RegularLightRotation = glm::vec3(0.0f, 0.0f, 0.0f); @@ -54,12 +55,6 @@ class FEEditorPreviewManager static glm::vec4 OriginalClearColor; static FETransformComponent OriginalTransform; - static glm::vec3 OriginalCameraPosition; - static float OriginalAspectRation; - static float OriginalCameraPitch; - static float OriginalCameraRoll; - static float OriginalCameraYaw; - static float OriginalExposure; void BeforePreviewActions(); void AfterPreviewActions(); diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index b38ea5a..e56d966 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -1,4 +1,5 @@ #include "FEEditorSelectedObject.h" +#include "FEProject.h" using namespace FocalEngine; FEEditorSelectedObject* FEEditorSelectedObject::Instance = nullptr; @@ -121,15 +122,18 @@ void FEEditorSelectedObject::Clear() glm::dvec3 FEEditorSelectedObject::MouseRay(const double MouseX, const double MouseY) const { + FEEntity* MainCameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(PROJECT_MANAGER.GetCurrent()->GetScene()); + FECameraComponent& CameraComponent = MainCameraEntity->GetComponent(); + glm::dvec2 NormalizedMouseCoords; NormalizedMouseCoords.x = (2.0f * MouseX) / ENGINE.GetRenderTargetWidth() - 1; NormalizedMouseCoords.y = 1.0f - (2.0f * (MouseY)) / ENGINE.GetRenderTargetHeight(); const glm::dvec4 ClipCoords = glm::dvec4(NormalizedMouseCoords.x, NormalizedMouseCoords.y, -1.0, 1.0); - glm::dvec4 EyeCoords = glm::inverse(ENGINE.GetCamera()->GetProjectionMatrix()) * ClipCoords; + glm::dvec4 EyeCoords = glm::inverse(CameraComponent.GetProjectionMatrix()) * ClipCoords; EyeCoords.z = -1.0f; EyeCoords.w = 0.0f; - glm::dvec3 WorldRay = glm::inverse(ENGINE.GetCamera()->GetViewMatrix()) * EyeCoords; + glm::dvec3 WorldRay = glm::inverse(CameraComponent.GetViewMatrix()) * EyeCoords; WorldRay = glm::normalize(WorldRay); return WorldRay; @@ -143,6 +147,11 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons // FIX ME! Temporary solution, only supports one scene FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + // FIX ME! Temporary solution + FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(CurrentScene); + FETransformComponent& CameraTransformComponent = MainCamera->GetComponent(); + FECameraComponent& CameraComponent = MainCamera->GetComponent(); + const glm::vec3 MouseRayVector = MouseRay(MouseX, MouseY); const std::vector EntityList = CurrentScene->GetEntityIDList(); for (size_t i = 0; i < EntityList.size(); i++) @@ -166,7 +175,7 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons Box = TERRAIN_SYSTEM.GetAABB(CurrentEntity); } - if (Box.RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) + if (Box.RayIntersect(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRayVector, Distance)) { if (CurrentEntity->HasComponent()) { @@ -176,7 +185,7 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons InstancedSubObjectsInfo[CurrentEntity] = std::vector(); for (size_t j = 0; j < InstancedComponent.IndividualInstancedAABB.size(); j++) { - if (InstancedComponent.IndividualInstancedAABB[j].RayIntersect(ENGINE.GetCamera()->GetPosition(), MouseRayVector, Distance)) + if (InstancedComponent.IndividualInstancedAABB[j].RayIntersect(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRayVector, Distance)) { InstancedSubObjectsInfo[CurrentEntity].push_back(static_cast(j)); } @@ -232,7 +241,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons if (!PotentiallySelectedEntity->HasComponent()) { - RENDERER.RenderGameModelComponent(PotentiallySelectedEntity, ENGINE.GetCamera(), false); + RENDERER.RenderGameModelComponent(PotentiallySelectedEntity); } else if (PotentiallySelectedEntity->HasComponent()) { @@ -244,7 +253,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons GameModelComponent.GameModel->SetBillboardMaterial(PixelAccurateSelectionMaterial); FEInstancedComponent& InstancedComponent = PotentiallySelectedEntity->GetComponent(); - RENDERER.RenderGameModelComponentWithInstanced(PotentiallySelectedEntity, ENGINE.GetCamera(), nullptr, false, false); + RENDERER.RenderGameModelComponentWithInstanced(PotentiallySelectedEntity, nullptr); PixelAccurateSelectionMaterial->Shader = FEPixelAccurateSelection; GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterials); @@ -263,7 +272,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); - RENDERER.RenderTerrainComponent(PotentiallySelectedEntity, ENGINE.GetCamera()); + RENDERER.RenderTerrainComponent(PotentiallySelectedEntity); TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); } @@ -305,7 +314,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - RENDERER.RenderGameModelComponent(DummyEntity/*DummyGameModelComponent, DummyTransformComponent*/, ENGINE.GetCamera(), false); + RENDERER.RenderGameModelComponent(DummyEntity); OriginalGameModelComponent.GameModel->Material = RegularMaterial; DummyGameModelComponent.SetVisibility(false); @@ -391,10 +400,9 @@ void FEEditorSelectedObject::OnCameraUpdate() const FE_GL_ERROR(glViewport(0, 0, RENDERER.SceneToTextureFB->GetWidth(), RENDERER.SceneToTextureFB->GetHeight())); glm::vec4 OriginalClearColor = ENGINE.GetClearColor(); ENGINE.SetClearColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.0f)); - //FE_GL_ERROR(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT)); - if (Container == nullptr /*|| !Container->HasComponent()*/) + if (Container == nullptr) { HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); ENGINE.SetClearColor(OriginalClearColor); @@ -405,7 +413,6 @@ void FEEditorSelectedObject::OnCameraUpdate() const if (Container->HasComponent()) { - FEGameModelComponent& GameModelComponent = Container->GetComponent(); FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; @@ -415,7 +422,7 @@ void FEEditorSelectedObject::OnCameraUpdate() const if (!Container->HasComponent()) { - RENDERER.RenderGameModelComponent(Container, ENGINE.GetCamera(), false); + RENDERER.RenderGameModelComponent(Container); } else if (Container->HasComponent()) { @@ -438,7 +445,7 @@ void FEEditorSelectedObject::OnCameraUpdate() const HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - RENDERER.RenderGameModelComponent(DummyEntity, ENGINE.GetCamera(), false); + RENDERER.RenderGameModelComponent(DummyEntity); GameModelComponent.GameModel->Material = RegularMaterial; DummyGameModelComponent.SetVisibility(false); @@ -449,7 +456,7 @@ void FEEditorSelectedObject::OnCameraUpdate() const FEMaterial* RegularBillboardMaterial = GameModelComponent.GameModel->GetBillboardMaterial(); GameModelComponent.GameModel->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); - RENDERER.RenderGameModelComponentWithInstanced(Container, ENGINE.GetCamera(), nullptr, false, false); + RENDERER.RenderGameModelComponentWithInstanced(Container, nullptr); HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterial); @@ -466,7 +473,7 @@ void FEEditorSelectedObject::OnCameraUpdate() const const float RegularLODLevel = TerrainComponent.GetLODLevel(); TerrainComponent.SetLODLevel(0.0f); - RENDERER.RenderTerrainComponent(Container, ENGINE.GetCamera()); + RENDERER.RenderTerrainComponent(Container); TerrainComponent.SetLODLevel(RegularLODLevel); TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); diff --git a/FEProject.cpp b/FEProject.cpp index f4ce427..aad2832 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -408,7 +408,8 @@ void FEProject::SaveScene(bool bFullSave) std::vector KeysToDelete; Json::Value& SceneNodes = SceneHierarchy["Nodes"]; - std::vector ListOfOmitedObjects = { "gizmo", "Gizmo", "editorPreviewEntity" }; + // FIX ME! Temporary. + std::vector ListOfOmitedObjects = { "gizmo", "Gizmo", "EditorPreviewEntity" }; // Parsing scene hierarchy to delete all internal editor objects. for (auto it = SceneNodes.begin(); it != SceneNodes.end(); it++) { @@ -619,7 +620,7 @@ void FEProject::SaveScene(bool bFullSave) // } // //WriteTransformToJson(EntityData[Entity->GetObjectID()]["transformation"], &Entity->Transform); - // //if (Entity->GetType() == FE_ENTITY_INSTANCED) + // //if (Entity->GetType() == FE_ENTITY_INSTANCED_DEPRECATED) // //{ // // FEEntityInstanced* InstancedEntity = reinterpret_cast(Entity); // // EntityData[Entity->GetObjectID()]["modificationsToSpawn"] = InstancedEntity->GetSpawnModificationCount() == 0 ? false : true; @@ -1371,20 +1372,45 @@ void FEProject::LoadScene() SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); SKY_DOME_SYSTEM.AddToEntity(SkyDome); - // loading Camera settings - ENGINE.GetCamera()->SetPosition(glm::vec3(Root["camera"]["position"]["X"].asFloat(), + // Loading Camera. + FEEntity* Entity = ProjectScene->CreateEntity("Camera Entity"); + Entity->AddComponent(); + FECameraComponent& CameraComponent = Entity->GetComponent(); + // Will work in future. + //ReadTransformToJson(Root["camera"]["transformation"], &Entity->GetComponent()); + + glm::vec3 CameraPosition = glm::vec3(Root["camera"]["position"]["X"].asFloat(), Root["camera"]["position"]["Y"].asFloat(), - Root["camera"]["position"]["Z"].asFloat())); + Root["camera"]["position"]["Z"].asFloat()); + + Entity->GetComponent().SetPosition(CameraPosition); + + ENGINE.GetCamera()->SetPosition(CameraPosition); ENGINE.GetCamera()->SetFov(Root["camera"]["fov"].asFloat()); + CameraComponent.SetFOV(50.680f); ENGINE.GetCamera()->SetNearPlane(Root["camera"]["nearPlane"].asFloat()); + CameraComponent.SetNearPlane(Root["camera"]["nearPlane"].asFloat()); ENGINE.GetCamera()->SetFarPlane(Root["camera"]["farPlane"].asFloat()); + CameraComponent.SetFarPlane(Root["camera"]["farPlane"].asFloat()); + + glm::vec3 CameraRotation = glm::vec3(Root["camera"]["yaw"].asFloat(), + Root["camera"]["pitch"].asFloat(), + Root["camera"]["roll"].asFloat()); - ENGINE.GetCamera()->SetYaw(Root["camera"]["yaw"].asFloat()); - ENGINE.GetCamera()->SetPitch(Root["camera"]["pitch"].asFloat()); - ENGINE.GetCamera()->SetRoll(Root["camera"]["roll"].asFloat()); + Entity->GetComponent().SetRotation(glm::vec3(-CameraRotation.y, -CameraRotation.x, CameraRotation.z)); + // FIX ME! This is temporary solution. + CameraComponent.CurrentMouseXAngle = -CameraRotation.x; + CameraComponent.CurrentMouseYAngle = -CameraRotation.y; + + ENGINE.GetCamera()->SetYaw(CameraRotation.x); + ENGINE.GetCamera()->SetPitch(CameraRotation.y); + ENGINE.GetCamera()->SetRoll(CameraRotation.z); ENGINE.GetCamera()->SetAspectRatio(Root["camera"]["aspectRatio"].asFloat()); + CameraComponent.SetAspectRatio(Root["camera"]["aspectRatio"].asFloat()); + + CAMERA_SYSTEM.SetMainCamera(Entity); if (ProjectVersion >= 0.02f && Root["camera"].isMember("movementSpeed")) ENGINE.GetCamera()->SetMovementSpeed(Root["camera"]["movementSpeed"].asFloat()); @@ -1571,4 +1597,9 @@ void FEProject::SaveSceneTo(const std::string NewPath) SetProjectFolder(NewPath); ENGINE.TakeScreenshot((GetProjectFolder() + "projectScreenShot.texture").c_str()); SaveScene(true); +} + +FEScene* FEProject::GetScene() +{ + return ProjectScene; } \ No newline at end of file diff --git a/FEProject.h b/FEProject.h index 3781ca8..243711c 100644 --- a/FEProject.h +++ b/FEProject.h @@ -11,6 +11,7 @@ class FEProject { friend class FEProjectManager; + friend class FEEditor; public: FEProject(std::string Name, std::string ProjectFolder); ~FEProject(); @@ -32,6 +33,8 @@ class FEProject void SetModified(bool NewValue); void AddUnSavedObject(FEObject* Object); + + FEScene* GetScene(); private: FEScene* ProjectScene = nullptr; std::string Name; diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 4638858..2c2b1bf 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 4638858d8731bea6d165055254c7eb28251e0a09 +Subproject commit 2c2b1bf60a434e9de150cf4c6257ce0dfd2146b2 From a17a3d8557435edae131738183d262a73ab50c33 Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Mon, 29 Jul 2024 21:38:52 -0400 Subject: [PATCH 23/46] Engine update; Major overhaul of the editor due to changes in the engine; Editor changes to enable working with multiple scenes; Rewrote selection system, halo effect system, and gizmos to support multiple scenes; FEEditorPreviewManager now uses a custom scene to create preview thumbnails; Project loading/saving is still not ready, but many changes have been made to prepare for fixing it. --- CMakeLists.txt | 1 + .../CombineChannelsToTexturePopUp.cpp | 2 +- EditorWindows/ContentBrowserWindow.cpp | 8 +- EditorWindows/DebugTextureViewWindow.cpp | 2 +- EditorWindows/DeletePopups.cpp | 34 +- EditorWindows/EditPopups.cpp | 4 +- EditorWindows/GyzmosSettingsWindow.cpp | 104 ++ EditorWindows/GyzmosSettingsWindow.h | 97 +- EditorWindows/InspectorWindow.cpp | 440 ++++++- EditorWindows/LogWindow.cpp | 2 +- EditorWindows/PrefabEditorWindow.cpp | 127 +- EditorWindows/PrefabEditorWindow.h | 3 + EditorWindows/ProjectWasModifiedPopUp.cpp | 2 +- EditorWindows/RenamePopups.cpp | 4 +- EditorWindows/ResizeTexturePopup.cpp | 2 +- EditorWindows/SceneGraphWindow.cpp | 72 +- EditorWindows/SceneGraphWindow.h | 20 +- EditorWindows/SelectPopups.cpp | 2 +- EditorWindows/ShaderEditorWindow.cpp | 7 +- FEDearImguiWrapper/FEDearImguiWrapper.cpp | 7 +- FEDearImguiWrapper/FEDearImguiWrapper.h | 2 + FEEditor.cpp | 853 ++++--------- FEEditor.h | 36 +- FEEditorGizmoManager.cpp | 1070 ++++++++++------- FEEditorGizmoManager.h | 92 +- FEEditorHaloSelectionEffect.cpp | 218 ++-- FEEditorHaloSelectionEffect.h | 32 +- FEEditorPreviewManager.cpp | 276 ++--- FEEditorPreviewManager.h | 7 - FEEditorSelectedObject.cpp | 546 +++++---- FEEditorSelectedObject.h | 89 +- FEProject.cpp | 155 ++- Resources/imgui.ini | 10 +- SubSystems/FocalEngine | 2 +- main.cpp | 32 +- 35 files changed, 2318 insertions(+), 2042 deletions(-) create mode 100644 EditorWindows/GyzmosSettingsWindow.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f44c462..cd84fde 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,7 @@ file(GLOB EditorWindows_SRC "EditorWindows/EditPopups.cpp" "EditorWindows/EditPopups.h" "EditorWindows/GyzmosSettingsWindow.h" + "EditorWindows/GyzmosSettingsWindow.cpp" "EditorWindows/CombineChannelsToTexturePopUp.cpp" "EditorWindows/CombineChannelsToTexturePopUp.h" "EditorWindows/ProjectWasModifiedPopUp.cpp" diff --git a/EditorWindows/CombineChannelsToTexturePopUp.cpp b/EditorWindows/CombineChannelsToTexturePopUp.cpp index b6986ff..d2f8ec4 100644 --- a/EditorWindows/CombineChannelsToTexturePopUp.cpp +++ b/EditorWindows/CombineChannelsToTexturePopUp.cpp @@ -23,7 +23,7 @@ CombineChannelsToTexturePopUp::~CombineChannelsToTexturePopUp() void CombineChannelsToTexturePopUp::Show() { Size = ImVec2(800, 800); - Position = ImVec2(FEngine::getInstance().GetWindowWidth() / 2 - Size.x / 2, FEngine::getInstance().GetWindowHeight() / 2 - Size.y / 2); + Position = ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2 - Size.x / 2, APPLICATION.GetMainWindow()->GetHeight() / 2 - Size.y / 2); Flags = ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse; diff --git a/EditorWindows/ContentBrowserWindow.cpp b/EditorWindows/ContentBrowserWindow.cpp index 9e863fd..2d3ec22 100644 --- a/EditorWindows/ContentBrowserWindow.cpp +++ b/EditorWindows/ContentBrowserWindow.cpp @@ -1,4 +1,5 @@ #include "ContentBrowserWindow.h" +#include "../FEEditor.h" using namespace FocalEngine; FEEditorContentBrowserWindow* FEEditorContentBrowserWindow::Instance = nullptr; @@ -132,12 +133,9 @@ void FEEditorContentBrowserWindow::Render() FILE_SYSTEM.ShowFileOpenDialog(FilePath, ALL_IMPORT_LOAD_FILTER, 3); if (!FilePath.empty()) { - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (!ActiveScenes.empty()) + if (EDITOR.GetFocusedScene() != nullptr) { - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - const std::vector LoadedObjects = CurrentScene->ImportAsset(FilePath.c_str()); + const std::vector LoadedObjects = EDITOR.GetFocusedScene()->ImportAsset(FilePath.c_str()); for (size_t i = 0; i < LoadedObjects.size(); i++) { if (LoadedObjects[i] != nullptr) diff --git a/EditorWindows/DebugTextureViewWindow.cpp b/EditorWindows/DebugTextureViewWindow.cpp index 99fb395..6c11919 100644 --- a/EditorWindows/DebugTextureViewWindow.cpp +++ b/EditorWindows/DebugTextureViewWindow.cpp @@ -8,7 +8,7 @@ DebugTextureViewWindow::DebugTextureViewWindow(std::function Func strcpy_s(Caption, tempCaption.size() + 1, tempCaption.c_str()); Size = ImVec2(800, 800); - Position = ImVec2(FEngine::getInstance().GetWindowWidth() / 2 - Size.x / 2, FEngine::getInstance().GetWindowHeight() / 2 - Size.y / 2); + Position = ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2 - Size.x / 2, APPLICATION.GetMainWindow()->GetHeight() / 2 - Size.y / 2); Flags = ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse; diff --git a/EditorWindows/DeletePopups.cpp b/EditorWindows/DeletePopups.cpp index 4062959..8664e8c 100644 --- a/EditorWindows/DeletePopups.cpp +++ b/EditorWindows/DeletePopups.cpp @@ -1,4 +1,5 @@ #include "DeletePopups.h" +#include "../FEEditor.h" DeleteTexturePopup* DeleteTexturePopup::Instance = nullptr; @@ -28,7 +29,7 @@ void DeleteTexturePopup::Render() return; } - ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); + ImGui::SetWindowPos(ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, APPLICATION.GetMainWindow()->GetHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); // check if this texture is used in some materials // to-do: should be done through counter, not by searching each time. const std::vector MaterialsThatUseTexture = MaterialsThatUsesTexture(ObjToWorkWith); @@ -81,12 +82,9 @@ std::vector DeleteTexturePopup::MaterialsThatUsesTexture(const FETe } } - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (!ActiveScenes.empty()) + if (EDITOR.GetFocusedScene() != nullptr) { - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - const std::vector TerrainList = CurrentScene->GetEntityIDListWith(); + const std::vector TerrainList = EDITOR.GetFocusedScene()->GetEntityIDListWith(); for (size_t i = 0; i < TerrainList.size(); i++) { /*FEEntity* CurrentTerrain = SCENE.GetEntity(TerrainList[i]); @@ -164,7 +162,7 @@ void DeleteMeshPopup::Render() return; } - ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); + ImGui::SetWindowPos(ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, APPLICATION.GetMainWindow()->GetHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); // check if this mesh is used in some game model // to-do: should be done through counter, not by searching each time. const int Result = TimesMeshUsed(ObjToWorkWith); @@ -270,7 +268,7 @@ void DeleteGameModelPopup::Render() return; } - ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); + ImGui::SetWindowPos(ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, APPLICATION.GetMainWindow()->GetHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); // check if this game model is used in some prefabs // to-do: should be done through counter, not by searching each time. const int Result = TimesGameModelUsed(ObjToWorkWith); @@ -327,12 +325,9 @@ void DeleteGameModelPopup::DeleteGameModel(FEGameModel* GameModel) { VIRTUAL_FILE_SYSTEM.LocateAndDeleteFile(GameModel); - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (!ActiveScenes.empty()) + if (EDITOR.GetFocusedScene() != nullptr) { - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - CurrentScene->PrepareForGameModelDeletion(GameModel); + EDITOR.GetFocusedScene()->PrepareForGameModelDeletion(GameModel); } RESOURCE_MANAGER.DeleteGameModel(GameModel); PROJECT_MANAGER.GetCurrent()->SetModified(true); @@ -367,7 +362,7 @@ void DeletePrefabPopup::Render() return; } - ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); + ImGui::SetWindowPos(ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, APPLICATION.GetMainWindow()->GetHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); // check if this prefab is used in some entities // to-do: should be done through counter, not by searching each time. const int Result = TimesPrefabUsed(ObjToWorkWith); @@ -422,12 +417,9 @@ void DeletePrefabPopup::DeletePrefab(FEPrefab* Prefab) { VIRTUAL_FILE_SYSTEM.LocateAndDeleteFile(Prefab); - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (!ActiveScenes.empty()) + if (EDITOR.GetFocusedScene() != nullptr) { - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - CurrentScene->PrepareForPrefabDeletion(Prefab); + EDITOR.GetFocusedScene()->PrepareForPrefabDeletion(Prefab); } RESOURCE_MANAGER.DeletePrefab(Prefab); PROJECT_MANAGER.GetCurrent()->SetModified(true); @@ -461,7 +453,7 @@ void DeleteMaterialPopup::Render() return; } - ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); + ImGui::SetWindowPos(ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, APPLICATION.GetMainWindow()->GetHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); // check if this material is used in some game model // to-do: should be done through counter, not by searching each time. const int Result = TimesMaterialUsed(ObjToWorkWith); @@ -611,7 +603,7 @@ void DeleteDirectoryPopup::Render() ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); if (ImGui::BeginPopupModal(PopupCaption.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); + ImGui::SetWindowPos(ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, APPLICATION.GetMainWindow()->GetHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); ImGui::Text(("Do you want to delete \"" + ObjToWorkWith + "\" folder ?").c_str()); ImGui::Text("It is not empty !"); diff --git a/EditorWindows/EditPopups.cpp b/EditorWindows/EditPopups.cpp index 3547a78..d722d2a 100644 --- a/EditorWindows/EditPopups.cpp +++ b/EditorWindows/EditPopups.cpp @@ -145,7 +145,7 @@ void EditGameModelPopup::Show(FEGameModel* GameModel) TempCaption += " " + ObjToWorkWith->GetName(); strcpy_s(Caption, TempCaption.size() + 1, TempCaption.c_str()); - Position = ImVec2(FEngine::getInstance().GetWindowWidth() / 2 - Size.x / 2, FEngine::getInstance().GetWindowHeight() / 2 - Size.y / 2); + Position = ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2 - Size.x / 2, APPLICATION.GetMainWindow()->GetHeight() / 2 - Size.y / 2); FEImGuiWindow::Show(); PREVIEW_MANAGER.CreateGameModelPreview(TempModel, &TempPreview); @@ -761,7 +761,7 @@ void EditMaterialPopup::Show(FEMaterial* Material) #else size = ImVec2(1500.0f, 700.0f); #endif // USE_NODES - Position = ImVec2(FEngine::getInstance().GetWindowWidth() / 2 - Size.x / 2, FEngine::getInstance().GetWindowHeight() / 2 - Size.y / 2); + Position = ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2 - Size.x / 2, APPLICATION.GetMainWindow()->GetHeight() / 2 - Size.y / 2); FEImGuiWindow::Show(); IconButton = new ImGuiImageButton(nullptr); diff --git a/EditorWindows/GyzmosSettingsWindow.cpp b/EditorWindows/GyzmosSettingsWindow.cpp new file mode 100644 index 0000000..85b5a74 --- /dev/null +++ b/EditorWindows/GyzmosSettingsWindow.cpp @@ -0,0 +1,104 @@ +#include "GyzmosSettingsWindow.h" +#include "../FEEditor.h" + +GyzmosSettingsWindow::GyzmosSettingsWindow() +{ + Flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar; +} + +GyzmosSettingsWindow::~GyzmosSettingsWindow() +{ + delete TransformationGizmoButton; + delete ScaleGizmoButton; + delete RotateGizmoButton; +} + +void GyzmosSettingsWindow::Show() +{ + const std::string TempCaption = "##GizmosSettingsWindow"; + strcpy_s(Caption, TempCaption.size() + 1, TempCaption.c_str()); + Size = ImVec2(146.0f, 48.0f); + Position = ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - 150.0f / 2.0f, 10.0f); + FEImGuiWindow::Show(); + + if (TransformationGizmoButton == nullptr) + TransformationGizmoButton = new ImGuiImageButton(GIZMO_MANAGER.TransformationGizmoIcon); + + if (ScaleGizmoButton == nullptr) + ScaleGizmoButton = new ImGuiImageButton(GIZMO_MANAGER.ScaleGizmoIcon); + + if (RotateGizmoButton == nullptr) + RotateGizmoButton = new ImGuiImageButton(GIZMO_MANAGER.RotateGizmoIcon); + + float CurrentX = 5.0f; + TransformationGizmoButton->SetPosition(ImVec2(CurrentX, 5.0f)); + CurrentX += 32.0f + 16.0f; + ScaleGizmoButton->SetPosition(ImVec2(CurrentX, 5.0f)); + CurrentX += 32.0f + 16.0f; + RotateGizmoButton->SetPosition(ImVec2(CurrentX, 5.0f)); +} + +void GyzmosSettingsWindow::Render() +{ + if (!IsVisible()) + return; + + FEScene* CurrentScene = EDITOR.GetFocusedScene(); + if (CurrentScene == nullptr) + return; + + FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(CurrentScene->GetObjectID()); + return; + + FEImGuiWindow::Render(); + + GizmoSceneData->GizmosState == TRANSFORM_GIZMOS ? SetSelectedStyle(TransformationGizmoButton) : SetDefaultStyle(TransformationGizmoButton); + ImGui::PushID(0); + TransformationGizmoButton->Render(); + if (TransformationGizmoButton->IsClicked()) + { + if (GizmoSceneData->GizmosState != TRANSFORM_GIZMOS) + { + GIZMO_MANAGER.UpdateGizmoState(TRANSFORM_GIZMOS, CurrentScene); + ImGui::PopID(); + FEImGuiWindow::OnRenderEnd(); + return; + } + } + ImGui::PopID(); + ShowToolTip("Translate objects. key = shift"); + + GizmoSceneData->GizmosState == SCALE_GIZMOS ? SetSelectedStyle(ScaleGizmoButton) : SetDefaultStyle(ScaleGizmoButton); + ImGui::PushID(1); + ScaleGizmoButton->Render(); + if (ScaleGizmoButton->IsClicked()) + { + if (GizmoSceneData->GizmosState != SCALE_GIZMOS) + { + GIZMO_MANAGER.UpdateGizmoState(SCALE_GIZMOS, CurrentScene); + ImGui::PopID(); + FEImGuiWindow::OnRenderEnd(); + return; + } + } + ImGui::PopID(); + ShowToolTip("Scale objects. key = shift"); + + GizmoSceneData->GizmosState == ROTATE_GIZMOS ? SetSelectedStyle(RotateGizmoButton) : SetDefaultStyle(RotateGizmoButton); + ImGui::PushID(2); + RotateGizmoButton->Render(); + if (RotateGizmoButton->IsClicked()) + { + if (GizmoSceneData->GizmosState != ROTATE_GIZMOS) + { + GIZMO_MANAGER.UpdateGizmoState(ROTATE_GIZMOS, CurrentScene); + ImGui::PopID(); + FEImGuiWindow::OnRenderEnd(); + return; + } + } + ImGui::PopID(); + ShowToolTip("Rotate objects. key = shift"); + + FEImGuiWindow::OnRenderEnd(); +} \ No newline at end of file diff --git a/EditorWindows/GyzmosSettingsWindow.h b/EditorWindows/GyzmosSettingsWindow.h index 24a1f6b..7a8f0b6 100644 --- a/EditorWindows/GyzmosSettingsWindow.h +++ b/EditorWindows/GyzmosSettingsWindow.h @@ -8,99 +8,10 @@ class GyzmosSettingsWindow : public FEImGuiWindow ImGuiImageButton* ScaleGizmoButton = nullptr; ImGuiImageButton* RotateGizmoButton = nullptr; public: - GyzmosSettingsWindow() - { - Flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar; - } + GyzmosSettingsWindow(); + ~GyzmosSettingsWindow(); - ~GyzmosSettingsWindow() override - { - delete TransformationGizmoButton; - delete ScaleGizmoButton; - delete RotateGizmoButton; - } - - void Show() override - { - const std::string TempCaption = "##GizmosSettingsWindow"; - strcpy_s(Caption, TempCaption.size() + 1, TempCaption.c_str()); - Size = ImVec2(146.0f, 48.0f); - Position = ImVec2(FEngine::getInstance().GetWindowWidth() / 2.0f - 150.0f / 2.0f, 10.0f); - FEImGuiWindow::Show(); - - if (TransformationGizmoButton == nullptr) - TransformationGizmoButton = new ImGuiImageButton(GIZMO_MANAGER.TransformationGizmoIcon); - - if (ScaleGizmoButton == nullptr) - ScaleGizmoButton = new ImGuiImageButton(GIZMO_MANAGER.ScaleGizmoIcon); - - if (RotateGizmoButton == nullptr) - RotateGizmoButton = new ImGuiImageButton(GIZMO_MANAGER.RotateGizmoIcon); - - float CurrentX = 5.0f; - TransformationGizmoButton->SetPosition(ImVec2(CurrentX, 5.0f)); - CurrentX += 32.0f + 16.0f; - ScaleGizmoButton->SetPosition(ImVec2(CurrentX, 5.0f)); - CurrentX += 32.0f + 16.0f; - RotateGizmoButton->SetPosition(ImVec2(CurrentX, 5.0f)); - } - - void Render() override - { - FEImGuiWindow::Render(); - - if (!IsVisible()) - return; - - GIZMO_MANAGER.GizmosState == TRANSFORM_GIZMOS ? SetSelectedStyle(TransformationGizmoButton) : SetDefaultStyle(TransformationGizmoButton); - ImGui::PushID(0); - TransformationGizmoButton->Render(); - if (TransformationGizmoButton->IsClicked()) - { - if (GIZMO_MANAGER.GizmosState != TRANSFORM_GIZMOS) - { - GIZMO_MANAGER.UpdateGizmoState(TRANSFORM_GIZMOS); - ImGui::PopID(); - FEImGuiWindow::OnRenderEnd(); - return; - } - } - ImGui::PopID(); - ShowToolTip("Translate objects. key = shift"); - - GIZMO_MANAGER.GizmosState == SCALE_GIZMOS ? SetSelectedStyle(ScaleGizmoButton) : SetDefaultStyle(ScaleGizmoButton); - ImGui::PushID(1); - ScaleGizmoButton->Render(); - if (ScaleGizmoButton->IsClicked()) - { - if (GIZMO_MANAGER.GizmosState != SCALE_GIZMOS) - { - GIZMO_MANAGER.UpdateGizmoState(SCALE_GIZMOS); - ImGui::PopID(); - FEImGuiWindow::OnRenderEnd(); - return; - } - } - ImGui::PopID(); - ShowToolTip("Scale objects. key = shift"); - - GIZMO_MANAGER.GizmosState == ROTATE_GIZMOS ? SetSelectedStyle(RotateGizmoButton) : SetDefaultStyle(RotateGizmoButton); - ImGui::PushID(2); - RotateGizmoButton->Render(); - if (RotateGizmoButton->IsClicked()) - { - if (GIZMO_MANAGER.GizmosState != ROTATE_GIZMOS) - { - GIZMO_MANAGER.UpdateGizmoState(ROTATE_GIZMOS); - ImGui::PopID(); - FEImGuiWindow::OnRenderEnd(); - return; - } - } - ImGui::PopID(); - ShowToolTip("Rotate objects. key = shift"); - - FEImGuiWindow::OnRenderEnd(); - } + void Show() override; + void Render() override; }; static GyzmosSettingsWindow GyzmosSettingsWindowObject; \ No newline at end of file diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index ead8eb1..111a98a 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -1,7 +1,6 @@ #include "InspectorWindow.h" #include "../FEEditor.h" - FEEditorInspectorWindow* FEEditorInspectorWindow::Instance = nullptr; FEEntity* FEEditorInspectorWindow::EntityToModify = nullptr; FEEntity* FEEditorInspectorWindow::TerrainToWorkWith = nullptr; @@ -75,14 +74,19 @@ bool FEEditorInspectorWindow::EntityChangePrefabTargetCallBack(FEObject* Object, bool FEEditorInspectorWindow::TerrainChangeMaterialTargetCallBack(FEObject* Object, void** LayerIndex) { - if (SELECTED.GetSelected() == nullptr || !SELECTED.GetSelected()->HasComponent()) + if (EDITOR.GetFocusedScene() == nullptr) + return false; + + FEScene* CurrentScene = EDITOR.GetFocusedScene(); + + if (SELECTED.GetSelected(CurrentScene) == nullptr || !SELECTED.GetSelected(CurrentScene)->HasComponent()) return false; FEMaterial* MaterialToAssign = RESOURCE_MANAGER.GetMaterial(Object->GetObjectID()); if (!MaterialToAssign->IsCompackPacking()) return false; - FETerrainComponent& Terrain = SELECTED.GetSelected()->GetComponent(); + FETerrainComponent& Terrain = SELECTED.GetSelected(CurrentScene)->GetComponent(); const int TempLayerIndex = *(int*)LayerIndex; if (TempLayerIndex >= 0 && TempLayerIndex < FE_TERRAIN_MAX_LAYERS) Terrain.GetLayerInSlot(TempLayerIndex)->SetMaterial(MaterialToAssign); @@ -419,8 +423,8 @@ void FEEditorInspectorWindow::DisplayCameraProperties(FEEntity* CameraEntity) co FECameraComponent& CameraComponent = CameraEntity->GetComponent(); bool bIsMainCamera = CameraComponent.IsMainCamera(); - ImGui::Checkbox("Main camera", &bIsMainCamera); - CAMERA_SYSTEM.SetMainCamera(CameraEntity); + if (ImGui::Checkbox("Main camera", &bIsMainCamera)) + CAMERA_SYSTEM.SetMainCamera(CameraEntity); float CameraSpeed = CameraComponent.GetMovementSpeed(); ImGui::Text("Camera speed in m/s : "); @@ -463,6 +467,398 @@ void FEEditorInspectorWindow::DisplayCameraProperties(FEEntity* CameraEntity) co ImGui::SetNextItemWidth(70); ImGui::DragFloat("##Exposure", &Exposure, 0.1f, 0.1f, 10.0f); CameraComponent.SetExposure(Exposure); + + // *********** Bloom *********** + ImGui::Separator(); + ImGui::Text("Bloom:"); + ImGui::Text("Threshold:"); + float Threshold = CameraComponent.GetBloomThreshold(); + ImGui::SetNextItemWidth(70); + ImGui::DragFloat("##Threshold", &Threshold, 0.01f, 0.001f, 30.0f); + CameraComponent.SetBloomThreshold(Threshold); + + /*ImGui::PushID(GUIID++); + ImGui::SameLine(); + ResetButton->Render(); + if (ResetButton->IsClicked()) + { + CameraComponent.SetBloomThreshold(1.5f); + } + ImGui::PopID();*/ + + ImGui::Text("Size:"); + float Size = CameraComponent.GetBloomSize(); + ImGui::SetNextItemWidth(70); + ImGui::DragFloat("##BloomSize", &Size, 0.01f, 0.001f, 100.0f); + CameraComponent.SetBloomSize(Size); + + /*ImGui::PushID(GUIID++); + ImGui::SameLine(); + ResetButton->Render(); + if (ResetButton->IsClicked()) + { + CameraComponent.SetBloomSize(5.0f); + } + ImGui::PopID();*/ + + // *********** Anti-Aliasing(FXAA) *********** + ImGui::Separator(); + ImGui::Text("Anti-Aliasing(FXAA)"); + static const char* options[5] = { "none", "1x", "2x", "4x", "8x" }; + static std::string SelectedOption = "1x"; + + // FIX ME! Was used with one camera only. + static bool bFirstLook = true; + if (bFirstLook) + { + const float FXAASpanMax = CameraComponent.GetFXAASpanMax(); + if (FXAASpanMax == 0.0f) + { + SelectedOption = options[0]; + } + else if (FXAASpanMax > 0.1f && FXAASpanMax < 1.1f) + { + SelectedOption = options[1]; + } + else if (FXAASpanMax > 1.1f && FXAASpanMax < 2.1f) + { + SelectedOption = options[2]; + } + else if (FXAASpanMax > 2.1f && FXAASpanMax < 4.1f) + { + SelectedOption = options[3]; + } + else if (FXAASpanMax > 4.1f && FXAASpanMax < 8.1f) + { + SelectedOption = options[4]; + } + else + { + SelectedOption = options[5]; + } + + bFirstLook = false; + } + + static bool bDebugSettings = false; + if (ImGui::Checkbox("debug view", &bDebugSettings)) + { + const float FXAASpanMax = CameraComponent.GetFXAASpanMax(); + if (FXAASpanMax == 0.0f) + { + SelectedOption = options[0]; + } + else if (FXAASpanMax > 0.1f && FXAASpanMax < 1.1f) + { + SelectedOption = options[1]; + } + else if (FXAASpanMax > 1.1f && FXAASpanMax < 2.1f) + { + SelectedOption = options[2]; + } + else if (FXAASpanMax > 2.1f && FXAASpanMax < 4.1f) + { + SelectedOption = options[3]; + } + else if (FXAASpanMax > 4.1f && FXAASpanMax < 8.1f) + { + SelectedOption = options[4]; + } + else + { + SelectedOption = options[5]; + } + } + + if (!bDebugSettings) + { + ImGui::Text("Anti Aliasing Strength:"); + if (ImGui::BeginCombo("##Anti Aliasing Strength", SelectedOption.c_str(), ImGuiWindowFlags_None)) + { + for (size_t i = 0; i < 5; i++) + { + const bool is_selected = (SelectedOption == options[i]); + if (ImGui::Selectable(options[i], is_selected)) + { + CameraComponent.SetFXAASpanMax(float(pow(2.0, (i - 1)))); + if (i == 0) + CameraComponent.SetFXAASpanMax(0.0f); + SelectedOption = options[i]; + } + + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } + } + else + { + ImGui::Text("FXAASpanMax:"); + ImGui::SetNextItemWidth(70); + float FXAASpanMax = CameraComponent.GetFXAASpanMax(); + ImGui::DragFloat("##FXAASpanMax", &FXAASpanMax, 0.0f, 0.001f, 32.0f); + CameraComponent.SetFXAASpanMax(FXAASpanMax); + + /*ImGui::PushID(GUIID++); + ImGui::SameLine(); + ResetButton->Render(); + if (ResetButton->IsClicked()) + { + CameraComponent.SetFXAASpanMax(8.0f); + } + ImGui::PopID();*/ + + ImGui::Text("FXAAReduceMin:"); + ImGui::SetNextItemWidth(70); + float FXAAReduceMin = CameraComponent.GetFXAAReduceMin(); + ImGui::DragFloat("##FXAAReduceMin", &FXAAReduceMin, 0.01f, 0.001f, 100.0f); + CameraComponent.SetFXAAReduceMin(FXAAReduceMin); + + /*ImGui::PushID(GUIID++); + ImGui::SameLine(); + ResetButton->Render(); + if (ResetButton->IsClicked()) + { + CameraComponent.SetFXAAReduceMin(0.008f); + } + ImGui::PopID();*/ + + ImGui::Text("FXAAReduceMul:"); + ImGui::SetNextItemWidth(70); + float FXAAReduceMul = CameraComponent.GetFXAAReduceMul(); + ImGui::DragFloat("##FXAAReduceMul", &FXAAReduceMul, 0.01f, 0.001f, 100.0f); + CameraComponent.SetFXAAReduceMul(FXAAReduceMul); + + /*ImGui::PushID(GUIID++); + ImGui::SameLine(); + ResetButton->Render(); + if (ResetButton->IsClicked()) + { + CameraComponent.SetFXAAReduceMul(0.400f); + } + ImGui::PopID();*/ + } + + ImGui::Separator(); + ImGui::Text("Depth of Field:"); + // *********** Depth of Field *********** + ImGui::Text("Near distance:"); + ImGui::SetNextItemWidth(70); + float DepthThreshold = CameraComponent.GetDOFNearDistance(); + ImGui::DragFloat("##depthThreshold", &DepthThreshold, 0.0f, 0.001f, 100.0f); + CameraComponent.SetDOFNearDistance(DepthThreshold); + + ImGui::Text("Far distance:"); + ImGui::SetNextItemWidth(70); + float DepthThresholdFar = CameraComponent.GetDOFFarDistance(); + ImGui::DragFloat("##depthThresholdFar", &DepthThresholdFar, 0.0f, 0.001f, 100.0f); + CameraComponent.SetDOFFarDistance(DepthThresholdFar); + + ImGui::Text("Strength:"); + ImGui::SetNextItemWidth(70); + float Strength = CameraComponent.GetDOFStrength(); + ImGui::DragFloat("##Strength", &Strength, 0.0f, 0.001f, 10.0f); + CameraComponent.SetDOFStrength(Strength); + + ImGui::Text("Distance dependent strength:"); + ImGui::SetNextItemWidth(70); + float IntMult = CameraComponent.GetDOFDistanceDependentStrength(); + ImGui::DragFloat("##Distance dependent strength", &IntMult, 0.0f, 0.001f, 100.0f); + CameraComponent.SetDOFDistanceDependentStrength(IntMult); + + ImGui::Separator(); + ImGui::Text("Chromatic Aberration:"); + ImGui::Text("Shift strength:"); + ImGui::SetNextItemWidth(70); + float intensity = CameraComponent.GetChromaticAberrationIntensity(); + ImGui::DragFloat("##intensity", &intensity, 0.01f, 0.0f, 30.0f); + CameraComponent.SetChromaticAberrationIntensity(intensity); + + /*ImGui::PushID(GUIID++); + ImGui::SameLine(); + ResetButton->Render(); + if (ResetButton->IsClicked()) + { + CameraComponent.SetChromaticAberrationIntensity(1.0f); + } + ImGui::PopID();*/ + + ImGui::Separator(); + ImGui::Text("SSAO:"); + // *********** SSAO *********** + static const char* SSAO_Options[5] = { "Off", "Low", "Medium", "High", "Custom" }; + static std::string SSAO_SelectedOption = "Medium"; + + // FIX ME! Was used with one camera only. + static bool bSSAO_FirstLook = true; + if (bFirstLook) + { + const int SampleCount = CameraComponent.GetSSAOSampleCount(); + + if (!CameraComponent.IsSSAOEnabled()) + { + SSAO_SelectedOption = SSAO_Options[0]; + } + else if (SampleCount == 4) + { + SSAO_SelectedOption = SSAO_Options[1]; + } + else if (SampleCount == 16 && CameraComponent.GetSSAORadiusSmallDetails()) + { + SSAO_SelectedOption = SSAO_Options[2]; + } + else if (SampleCount == 32 && CameraComponent.GetSSAORadiusSmallDetails()) + { + SSAO_SelectedOption = SSAO_Options[3]; + } + else + { + SSAO_SelectedOption = SSAO_Options[4]; + } + + //bFirstLook = false; + } + + static bool bSSAO_DebugSettings = false; + if (ImGui::Checkbox("Debug view", &bSSAO_DebugSettings)) + { + + } + + if (!bSSAO_DebugSettings) + { + ImGui::Text("SSAO Quality:"); + ImGui::SetNextItemWidth(150); + if (ImGui::BeginCombo("##SSAO Quality", SSAO_SelectedOption.c_str(), ImGuiWindowFlags_None)) + { + for (size_t i = 0; i < 5; i++) + { + const bool is_selected = (SSAO_SelectedOption == SSAO_Options[i]); + if (ImGui::Selectable(SSAO_Options[i], is_selected)) + { + CameraComponent.SetSSAOResultBlured(true); + CameraComponent.SetSSAOBias(0.013f); + CameraComponent.SetSSAORadius(10.0f); + CameraComponent.SetSSAORadiusSmallDetails(0.4f); + CameraComponent.SetSSAOSmallDetailsWeight(0.2f); + + if (i == 0) + { + CameraComponent.SetSSAOEnabled(false); + } + else if (i == 1) + { + CameraComponent.SetSSAOEnabled(true); + + CameraComponent.SetSSAOSampleCount(4); + CameraComponent.SetSSAOSmallDetailsEnabled(false); + } + else if (i == 2) + { + CameraComponent.SetSSAOEnabled(true); + + CameraComponent.SetSSAOSampleCount(16); + CameraComponent.SetSSAOSmallDetailsEnabled(true); + } + else if (i == 3) + { + CameraComponent.SetSSAOEnabled(true); + + CameraComponent.SetSSAOSampleCount(32); + CameraComponent.SetSSAOSmallDetailsEnabled(true); + } + + SSAO_SelectedOption = SSAO_Options[i]; + } + + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } + } + else + { + bool TempBool = CameraComponent.IsSSAOEnabled(); + ImGui::Checkbox("SSAO active", &TempBool); + CameraComponent.SetSSAOEnabled(TempBool); + + TempBool = CameraComponent.IsSSAOSmallDetailsEnabled(); + ImGui::Checkbox("SSAO small details", &TempBool); + CameraComponent.SetSSAOSmallDetailsEnabled(TempBool); + + TempBool = CameraComponent.IsSSAOResultBlured(); + ImGui::Checkbox("SSAO blured", &TempBool); + CameraComponent.SetSSAOResultBlured(TempBool); + + int TempInt = CameraComponent.GetSSAOSampleCount(); + ImGui::SetNextItemWidth(100); + ImGui::DragInt("SSAO sample count", &TempInt); + CameraComponent.SetSSAOSampleCount(TempInt); + + float TempFloat = CameraComponent.GetSSAOBias(); + ImGui::SetNextItemWidth(100); + ImGui::DragFloat("SSAO bias", &TempFloat, 0.1f); + CameraComponent.SetSSAOBias(TempFloat); + + TempFloat = CameraComponent.GetSSAORadius(); + ImGui::SetNextItemWidth(100); + ImGui::DragFloat("SSAO radius", &TempFloat, 0.1f); + CameraComponent.SetSSAORadius(TempFloat); + + TempFloat = CameraComponent.GetSSAORadiusSmallDetails(); + ImGui::SetNextItemWidth(100); + ImGui::DragFloat("SSAO radius small details", &TempFloat, 0.1f); + CameraComponent.SetSSAORadiusSmallDetails(TempFloat); + + TempFloat = CameraComponent.GetSSAOSmallDetailsWeight(); + ImGui::SetNextItemWidth(100); + ImGui::DragFloat("SSAO small details weight", &TempFloat, 0.01f); + CameraComponent.SetSSAOSmallDetailsWeight(TempFloat); + } + + // *********** Distance Fog *********** + ImGui::Separator(); + ImGui::Text("Distance Fog:"); + bool bEnabledFog = CameraComponent.IsDistanceFogEnabled(); + if (ImGui::Checkbox("Enable fog", &bEnabledFog)) + { + CameraComponent.SetDistanceFogEnabled(bEnabledFog); + } + + if (bEnabledFog) + { + ImGui::Text("Density:"); + ImGui::SetNextItemWidth(70); + float FogDensity = CameraComponent.GetDistanceFogDensity(); + ImGui::DragFloat("##fogDensity", &FogDensity, 0.0001f, 0.0f, 5.0f); + CameraComponent.SetDistanceFogDensity(FogDensity); + + /*ImGui::PushID(GUIID++); + ImGui::SameLine(); + ResetButton->Render(); + if (ResetButton->IsClicked()) + { + CameraComponent.SetDistanceFogDensity(0.007f); + } + ImGui::PopID();*/ + + ImGui::Text("Gradient:"); + ImGui::SetNextItemWidth(70); + float FogGradient = CameraComponent.GetDistanceFogGradient(); + ImGui::DragFloat("##fogGradient", &FogGradient, 0.001f, 0.0f, 5.0f); + CameraComponent.SetDistanceFogGradient(FogGradient); + + /*ImGui::PushID(GUIID++); + ImGui::SameLine(); + ResetButton->Render(); + if (ResetButton->IsClicked()) + { + CameraComponent.SetDistanceFogGradient(2.5f); + } + ImGui::PopID();*/ + } } // FIX ME! @@ -539,18 +935,25 @@ void FEEditorInspectorWindow::Render() if (!bVisible) return; + if (EDITOR.GetFocusedScene() == nullptr) + return; + + FEScene* CurrentScene = EDITOR.GetFocusedScene(); + FEEntity* MainCameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(CurrentScene); + if (MainCameraEntity == nullptr) + return; + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); ImGui::Begin("Inspector", nullptr, ImGuiWindowFlags_None); - if (SELECTED.GetSelected() == nullptr) + if (SELECTED.GetSelected(CurrentScene) == nullptr) { ImGui::PopStyleVar(); ImGui::End(); return; } - FEEntity* EntitySelected = SELECTED.GetSelected(); - FEScene* CurrentScene = EntitySelected->GetParentScene(); + FEEntity* EntitySelected = SELECTED.GetSelected(CurrentScene); ImGui::Text("ID : %s", EntitySelected->GetObjectID().c_str()); ImGui::Text("Name : %s", EntitySelected->GetName().c_str()); @@ -651,21 +1054,22 @@ void FEEditorInspectorWindow::Render() { if (ImGui::CollapsingHeader("Instanced", ImGuiTreeNodeFlags_DefaultOpen)) { + FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(CurrentScene->GetObjectID()); FEInstancedComponent& InstancedComponent = EntitySelected->GetComponent(); - if (SELECTED.InstancedSubObjectIndexSelected != -1) + if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1) { std::string InstancedSubObjectInfo = "index: "; ImGui::Text("Selected instance info:"); - InstancedSubObjectInfo = "index: " + std::to_string(SELECTED.InstancedSubObjectIndexSelected); + InstancedSubObjectInfo = "index: " + std::to_string(CurrentSelectionData->InstancedSubObjectIndexSelected); ImGui::Text(InstancedSubObjectInfo.c_str()); - FETransformComponent TempTransform = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(SELECTED.InstancedSubObjectIndexSelected)); + FETransformComponent TempTransform = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(CurrentSelectionData->InstancedSubObjectIndexSelected)); TempTransform.SetSceneIndependent(true); ShowTransformConfiguration("Selected instance", &TempTransform); - INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(EntitySelected, SELECTED.InstancedSubObjectIndexSelected, TempTransform.GetWorldMatrix()); + INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(EntitySelected, CurrentSelectionData->InstancedSubObjectIndexSelected, TempTransform.GetWorldMatrix()); ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.55f, 0.55f, 0.95f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.75f, 0.75f, 0.95f)); @@ -673,7 +1077,7 @@ void FEEditorInspectorWindow::Render() if (ImGui::ImageButton((void*)(intptr_t)ArrowToGroundIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) { - INSTANCED_RENDERING_SYSTEM.TryToSnapIndividualInstance(EntitySelected, SELECTED.InstancedSubObjectIndexSelected); + INSTANCED_RENDERING_SYSTEM.TryToSnapIndividualInstance(EntitySelected, CurrentSelectionData->InstancedSubObjectIndexSelected); } ShowToolTip("Selected instance will attempt to snap to the terrain."); @@ -874,8 +1278,8 @@ void FEEditorInspectorWindow::Render() if (ImGui::Button("Add instance")) { glm::mat4 NewInstanceMatrix = glm::identity(); - FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); - FECameraComponent& CameraComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); + FETransformComponent& CameraTransformComponent = MainCameraEntity->GetComponent(); + FECameraComponent& CameraComponent = MainCameraEntity->GetComponent(); NewInstanceMatrix = glm::translate(NewInstanceMatrix, CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); INSTANCED_RENDERING_SYSTEM.AddIndividualInstance(EntitySelected, NewInstanceMatrix); @@ -901,7 +1305,7 @@ void FEEditorInspectorWindow::Render() INSTANCED_RENDERING_SYSTEM.SetIndividualSelectMode(EntitySelected, !INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(EntitySelected)); if (!INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(EntitySelected)) { - SELECTED.Clear(); + SELECTED.Clear(CurrentScene); SELECTED.SetSelected(EntitySelected); } } @@ -951,7 +1355,7 @@ void FEEditorInspectorWindow::Render() { if (ImGui::CollapsingHeader("Light", ImGuiTreeNodeFlags_DefaultOpen)) { - DisplayLightProperties(SELECTED.GetSelected()); + DisplayLightProperties(SELECTED.GetSelected(CurrentScene)); } } @@ -959,7 +1363,7 @@ void FEEditorInspectorWindow::Render() { if (ImGui::CollapsingHeader("Camera", ImGuiTreeNodeFlags_DefaultOpen)) { - DisplayCameraProperties(SELECTED.GetSelected()); + DisplayCameraProperties(SELECTED.GetSelected(CurrentScene)); } } diff --git a/EditorWindows/LogWindow.cpp b/EditorWindows/LogWindow.cpp index 91e6650..17aeb8e 100644 --- a/EditorWindows/LogWindow.cpp +++ b/EditorWindows/LogWindow.cpp @@ -104,7 +104,7 @@ void FEEditor::DisplayLogWindow() const LogEditor.SetReadOnly(true); LogEditor.SetShowWhitespaces(false); LogEditor.SetText(LogMessages); - LogEditor.Render("Log messages");*/ + LogEditor.Update("Log messages");*/ static char LogMessages_[1000000]; strcpy_s(LogMessages_, LogMessages.c_str()); diff --git a/EditorWindows/PrefabEditorWindow.cpp b/EditorWindows/PrefabEditorWindow.cpp index dcf78d7..9473df8 100644 --- a/EditorWindows/PrefabEditorWindow.cpp +++ b/EditorWindows/PrefabEditorWindow.cpp @@ -1,5 +1,6 @@ #include "PrefabEditorWindow.h" - +#include "SceneGraphWindow.h" +#include "../FEEditor.h" PrefabEditorWindow* PrefabEditorWindow::Instance = nullptr; FEPrefab* PrefabEditorWindow::ObjToWorkWith = nullptr; @@ -16,71 +17,6 @@ bool PrefabEditorWindow::AddGameModelTargetCallBack(FEObject* Object, void** Ent void PrefabEditorWindow::ShowTransformConfiguration(FETransformComponent* Transform, const int Index) { - // FIX ME! - //// ********************* POSITION ********************* - //glm::vec3 position = Transform->GetPosition(); - //ImGui::Text("Position : "); - //ImGui::SameLine(); - //ImGui::SetNextItemWidth(50); - //ImGui::DragFloat((std::string("##X pos : ") + std::to_string(Index)).c_str(), &position[0], 0.1f); - //ShowToolTip("X position"); - - //ImGui::SameLine(); - //ImGui::SetNextItemWidth(50); - //ImGui::DragFloat((std::string("##Y pos : ") + std::to_string(Index)).c_str(), &position[1], 0.1f); - //ShowToolTip("Y position"); - - //ImGui::SameLine(); - //ImGui::SetNextItemWidth(50); - //ImGui::DragFloat((std::string("##Z pos : ") + std::to_string(Index)).c_str(), &position[2], 0.1f); - //ShowToolTip("Z position"); - //Transform->SetPosition(position); - - //// ********************* ROTATION ********************* - //glm::vec3 rotation = Transform->GetRotation(); - //ImGui::Text("Rotation : "); - //ImGui::SameLine(); - //ImGui::SetNextItemWidth(50); - //ImGui::DragFloat((std::string("##X rot : ") + std::to_string(Index)).c_str(), &rotation[0], 0.1f, -360.0f, 360.0f); - //ShowToolTip("X rotation"); - - //ImGui::SameLine(); - //ImGui::SetNextItemWidth(50); - //ImGui::DragFloat((std::string("##Y rot : ") + std::to_string(Index)).c_str(), &rotation[1], 0.1f, -360.0f, 360.0f); - //ShowToolTip("Y rotation"); - - //ImGui::SameLine(); - //ImGui::SetNextItemWidth(50); - //ImGui::DragFloat((std::string("##Z rot : ") + std::to_string(Index)).c_str(), &rotation[2], 0.1f, -360.0f, 360.0f); - //ShowToolTip("Z rotation"); - //Transform->SetRotation(rotation); - - //// ********************* SCALE ********************* - //bool bUniformScaling = Transform->IsUniformScalingSet(); - //ImGui::Checkbox("Uniform scaling", &bUniformScaling); - //Transform->SetUniformScaling(bUniformScaling); - - //glm::vec3 scale = Transform->GetScale(); - //ImGui::Text("Scale : "); - //ImGui::SameLine(); - //ImGui::SetNextItemWidth(50); - //ImGui::DragFloat((std::string("##X scale : ") + std::to_string(Index)).c_str(), &scale[0], 0.01f, 0.01f, 1000.0f); - //ShowToolTip("X scale"); - - //ImGui::SameLine(); - //ImGui::SetNextItemWidth(50); - //ImGui::DragFloat((std::string("##Y scale : ") + std::to_string(Index)).c_str(), &scale[1], 0.01f, 0.01f, 1000.0f); - //ShowToolTip("Y scale"); - - //ImGui::SameLine(); - //ImGui::SetNextItemWidth(50); - //ImGui::DragFloat((std::string("##Z scale : ") + std::to_string(Index)).c_str(), &scale[2], 0.01f, 0.01f, 1000.0f); - //ShowToolTip("Z scale"); - - //glm::vec3 OldScale = Transform->GetScale(); - //Transform->ChangeXScaleBy(scale[0] - OldScale[0]); - //Transform->ChangeYScaleBy(scale[1] - OldScale[1]); - //Transform->ChangeZScaleBy(scale[2] - OldScale[2]); } void PrefabEditorWindow::AddNewGameModelCallBack(const std::vector SelectionsResult) @@ -89,7 +25,7 @@ void PrefabEditorWindow::AddNewGameModelCallBack(const std::vector Se { if (SelectionsResult[i]->GetType() == FE_GAMEMODEL) ObjToWorkWith->AddComponent(reinterpret_cast(SelectionsResult[i])); - } + } } PrefabEditorWindow::PrefabEditorWindow() @@ -109,25 +45,48 @@ PrefabEditorWindow::~PrefabEditorWindow() delete CloseButton; } -// FIX ME! Temporary. -#include "SceneGraphWindow.h" void PrefabEditorWindow::Show(FEPrefab* Prefab) { - // FIX ME! test if (Prefab->Scene != nullptr) { - SCENE_MANAGER.TestScene = Prefab->Scene; - SCENE_GRAPH_WINDOW.SetScene(SCENE_MANAGER.TestScene); - } - - Size = ImVec2(800, 800); - Position = ImVec2(FEngine::getInstance().GetWindowWidth() / 2 - Size.x / 2, FEngine::getInstance().GetWindowHeight() / 2 - Size.y / 2); + if (CurrentPrefabScene != nullptr) + SCENE_MANAGER.DeleteScene(CurrentPrefabScene); + CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->Scene, "Scene: " + Prefab->GetName()); - Flags = ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse; + FEEntity* Camera = CurrentPrefabScene->CreateEntity("Prefab scene camera"); + CurrentCameraEntity = Camera; + Camera->AddComponent(); + FECameraComponent& CameraComponent = Camera->GetComponent(); + // FIX ME! It should be model camera but it is not working with transform component + CameraComponent.Type = 0; + CameraComponent.DistanceToModel = 10.0; - ObjToWorkWith = Prefab; - - FEImGuiWindow::Show(); + CAMERA_SYSTEM.SetMainCamera(Camera); + FETransformComponent& CameraTransform = Camera->GetComponent(); + CameraTransform.SetPosition(glm::vec3(0.0f, 0.0f, 30.0f)); + + FEEntity* SkyDomeEntity = CurrentPrefabScene->CreateEntity("Prefab scene skydome"); + SkyDomeEntity->GetComponent().SetScale(glm::vec3(100.0f)); + SkyDomeEntity->AddComponent(); + + FEEntity* LightEntity = CurrentPrefabScene->CreateEntity("Prefab scene light"); + LightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); + FELightComponent& LightComponent = LightEntity->GetComponent(); + LightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); + LightComponent.SetIntensity(4.3f); + LightComponent.SetCastShadows(false); + + EDITOR.AddEditorScene(CurrentPrefabScene); + + /*Size = ImVec2(800, 800); + Position = ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2 - Size.x / 2, APPLICATION.GetMainWindow()->GetHeight() / 2 - Size.y / 2); + + Flags = ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse; + + ObjToWorkWith = Prefab; + + FEImGuiWindow::Show();*/ + } } void PrefabEditorWindow::Render() @@ -251,7 +210,15 @@ void PrefabEditorWindow::Render() CloseButton->Render(); if (CloseButton->IsClicked()) + { + if (CurrentPrefabScene != nullptr) + { + SCENE_MANAGER.DeleteScene(CurrentPrefabScene); + CurrentPrefabScene = nullptr; + } + Close(); + } FEImGuiWindow::OnRenderEnd(); } \ No newline at end of file diff --git a/EditorWindows/PrefabEditorWindow.h b/EditorWindows/PrefabEditorWindow.h index 96532b4..40262ec 100644 --- a/EditorWindows/PrefabEditorWindow.h +++ b/EditorWindows/PrefabEditorWindow.h @@ -19,6 +19,9 @@ class PrefabEditorWindow : public FEImGuiWindow void ShowTransformConfiguration(FETransformComponent* Transform, int Index); static void AddNewGameModelCallBack(std::vector SelectionsResult); + + FEScene* CurrentPrefabScene = nullptr; + FEEntity* CurrentCameraEntity = nullptr; public: SINGLETON_PUBLIC_PART(PrefabEditorWindow) diff --git a/EditorWindows/ProjectWasModifiedPopUp.cpp b/EditorWindows/ProjectWasModifiedPopUp.cpp index 066c9f3..575d975 100644 --- a/EditorWindows/ProjectWasModifiedPopUp.cpp +++ b/EditorWindows/ProjectWasModifiedPopUp.cpp @@ -32,7 +32,7 @@ void ProjectWasModifiedPopUp::Render() bool ButtonPressed = false; - ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); + ImGui::SetWindowPos(ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, APPLICATION.GetMainWindow()->GetHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); ImGui::Text("Project was modified, should it be saved before exit ?"); ImGui::SetCursorPosX(ImGui::GetWindowWidth() * 0.15f - 140.0f / 2.0f); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10.0f); diff --git a/EditorWindows/RenamePopups.cpp b/EditorWindows/RenamePopups.cpp index 452fd68..961560f 100644 --- a/EditorWindows/RenamePopups.cpp +++ b/EditorWindows/RenamePopups.cpp @@ -23,7 +23,7 @@ void RenameFailedPopUp::Render() ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); if (ImGui::BeginPopupModal(PopupCaption.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove)) { - ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); + ImGui::SetWindowPos(ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, APPLICATION.GetMainWindow()->GetHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); ImGui::Text("Entered name is incorrect !"); OkButton->SetPosition(ImVec2(ImGui::GetWindowWidth() / 2.0f - 120.0f / 2.0f, ImGui::GetCursorPosY() + 10.0f)); @@ -71,7 +71,7 @@ void RenamePopUp::Render() return; } - ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); + ImGui::SetWindowPos(ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, APPLICATION.GetMainWindow()->GetHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); ImGui::Text("New object name :"); ImGui::InputText("##New object name", NewName, IM_ARRAYSIZE(NewName)); diff --git a/EditorWindows/ResizeTexturePopup.cpp b/EditorWindows/ResizeTexturePopup.cpp index 4176cb7..2db42a2 100644 --- a/EditorWindows/ResizeTexturePopup.cpp +++ b/EditorWindows/ResizeTexturePopup.cpp @@ -47,7 +47,7 @@ void ResizeTexturePopup::Render() return; } - ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); + ImGui::SetWindowPos(ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, APPLICATION.GetMainWindow()->GetHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); ImGui::SetCursorPos(ImVec2(20, 45)); ImGui::Text("Width:"); diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 94606da..35e5636 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -30,16 +30,6 @@ void FEEditorSceneGraphWindow::InitializeResources() RESOURCE_MANAGER.MakeTextureStandard(CameraIcon); } -void FEEditorSceneGraphWindow::SetScene(FEScene* Scene) -{ - CurrentScene = Scene; -} - -FEScene* FEEditorSceneGraphWindow::GetScene() -{ - return CurrentScene; -} - void FEEditorSceneGraphWindow::Clear() { strcpy_s(FilterForEntities, ""); @@ -53,7 +43,7 @@ void FEEditorSceneGraphWindow::SetCorrectItemColor(FEObject* SceneObject) const { ImGui::PushStyleColor(ImGuiCol_Text, LightItemColor); } - else if (SceneObject->GetType() == FE_CAMERA) + else if (SceneObject->GetType() == FE_CAMERA_DEPRECATED) { ImGui::PushStyleColor(ImGuiCol_Text, CameraItemColor); } @@ -76,7 +66,7 @@ void FEEditorSceneGraphWindow::PopCorrectItemColor(FEObject* SceneObject) if (SceneObject->GetType() == FE_DIRECTIONAL_LIGHT || SceneObject->GetType() == FE_SPOT_LIGHT || SceneObject->GetType() == FE_POINT_LIGHT || - SceneObject->GetType() == FE_CAMERA || + SceneObject->GetType() == FE_CAMERA_DEPRECATED || SceneObject->GetType() == FE_TERRAIN_DEPRECATED || SceneObject->GetType() == FE_ENTITY || SceneObject->GetType() == FE_ENTITY_INSTANCED_DEPRECATED) @@ -87,15 +77,18 @@ void FEEditorSceneGraphWindow::PopCorrectItemColor(FEObject* SceneObject) static void CreateInstancedEntityCallBack(const std::vector SelectionsResult) { + if (EDITOR.GetFocusedScene() == nullptr) + return; + if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) { FEPrefab* SelectedPrefab = RESOURCE_MANAGER.GetPrefab(SelectionsResult[0]->GetObjectID()); if (SelectedPrefab == nullptr) return; - FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); - FECameraComponent& CameraComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); - FEEntity* Entity = SCENE_GRAPH_WINDOW.GetScene()->CreateEntity(); + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + FEEntity* Entity = EDITOR.GetFocusedScene()->CreateEntity(); Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); Entity->AddComponent(SelectedPrefab->GetComponent(0)->GameModel); Entity->AddComponent(); @@ -107,15 +100,18 @@ static void CreateInstancedEntityCallBack(const std::vector Selection static void CreateEntityCallBack(const std::vector SelectionsResult) { + if (EDITOR.GetFocusedScene() == nullptr) + return; + if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) { FEPrefab* SelectedPrefab = RESOURCE_MANAGER.GetPrefab(SelectionsResult[0]->GetObjectID()); if (SelectedPrefab == nullptr) return; - FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); - FECameraComponent& CameraComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); - FEEntity* Entity = SCENE_GRAPH_WINDOW.GetScene()->CreateEntity(); + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + FEEntity* Entity = EDITOR.GetFocusedScene()->CreateEntity(); Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); SELECTED.SetSelected(Entity); @@ -185,7 +181,7 @@ void FEEditorSceneGraphWindow::DrawCorrectIcon(const FEObject* SceneObject) cons ImGui::Image((void*)(intptr_t)TerrainIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); } - if (SceneObject->GetType() == FE_CAMERA) + if (SceneObject->GetType() == FE_CAMERA_DEPRECATED) { ImGui::Image((void*)(intptr_t)CameraIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); } @@ -217,9 +213,9 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) ImGuiTreeNodeFlags NodeFlags = bIsLeaf ? ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen : ImGuiTreeNodeFlags_OpenOnArrow; std::string Name = SubTreeRoot->GetParent() == nullptr ? PROJECT_MANAGER.GetCurrent()->GetName() : SubTreeRoot->GetName(); - if (SELECTED.GetSelected() != nullptr && SubTreeRoot->GetEntity() != nullptr) + if (SELECTED.GetSelected(EDITOR.GetFocusedScene()) != nullptr && SubTreeRoot->GetEntity() != nullptr) { - if (SELECTED.GetSelected()->GetObjectID() == SubTreeRoot->GetEntity()->GetObjectID()) + if (SELECTED.GetSelected(EDITOR.GetFocusedScene())->GetObjectID() == SubTreeRoot->GetEntity()->GetObjectID()) { NodeFlags |= ImGuiTreeNodeFlags_Selected; } @@ -235,7 +231,7 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) if (SubTreeRoot->GetParent() != nullptr) { SELECTED.SetSelected(SubTreeRoot->GetEntity()); - SELECTED.SetDirtyFlag(false); + //SELECTED.SetDirtyFlag(false); } } @@ -282,7 +278,10 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) void FEEditorSceneGraphWindow::RenderNewSceneGraph() { - FENaiveSceneGraphNode* Root = SCENE_GRAPH_WINDOW.GetScene()->SceneGraph.GetRoot(); + if (EDITOR.GetFocusedScene() == nullptr) + return; + + FENaiveSceneGraphNode* Root = EDITOR.GetFocusedScene()->SceneGraph.GetRoot(); if (bSceneNodeTargetsDirty) SceneNodeDragAndDropTargets.clear(); @@ -294,13 +293,12 @@ void FEEditorSceneGraphWindow::RenderNewSceneGraph() bSceneNodeTargetsDirty = false; } -//FIX ME! -#include "InspectorWindow.h" void FEEditorSceneGraphWindow::Render() { if (!bVisible) return; + FEScene* CurrentScene = EDITOR.GetFocusedScene(); if (CurrentScene == nullptr) return; @@ -375,9 +373,9 @@ void FEEditorSceneGraphWindow::Render() DrawCorrectIcon(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); ImGuiTreeNodeFlags NodeFlags = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; - if (SELECTED.GetSelected() != nullptr) + if (SELECTED.GetSelected(CurrentScene) != nullptr) { - if (SELECTED.GetSelected()->GetObjectID() == FilteredSceneObjectsList[i]) + if (SELECTED.GetSelected(CurrentScene)->GetObjectID() == FilteredSceneObjectsList[i]) { NodeFlags |= ImGuiTreeNodeFlags_Selected; } @@ -392,7 +390,7 @@ void FEEditorSceneGraphWindow::Render() // FIX ME! /*FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[i]); SELECTED.SetSelected(Entity);*/ - SELECTED.SetDirtyFlag(false); + //SELECTED.SetDirtyFlag(false); } if (ImGui::IsItemHovered()) @@ -483,8 +481,8 @@ void FEEditorSceneGraphWindow::Render() FEEntity* Entity = CurrentScene->GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); if (Entity != nullptr) { - if (SELECTED.GetSelected() == Entity) - SELECTED.Clear(); + if (SELECTED.GetSelected(CurrentScene) == Entity) + SELECTED.Clear(CurrentScene); CurrentScene->DeleteEntity(Entity); } @@ -607,25 +605,25 @@ void FEEditorSceneGraphWindow::Render() ImGui::Checkbox("Display AABB of selected object", &bDisplaySelectedObjAABB); // Draw AABB - if (SELECTED.GetSelected() != nullptr && - (SELECTED.GetSelected()->HasComponent() || SELECTED.GetSelected()->HasComponent()) && + if (SELECTED.GetSelected(CurrentScene) != nullptr && + (SELECTED.GetSelected(CurrentScene)->HasComponent() || SELECTED.GetSelected(CurrentScene)->HasComponent()) && bDisplaySelectedObjAABB) { - if (SELECTED.GetSelected()->HasComponent()) + if (SELECTED.GetSelected(CurrentScene)->HasComponent()) { - FEGameModel* GameModel = SELECTED.GetSelected()->GetComponent().GameModel; - FEAABB SelectedAABB = GameModel->GetMesh()->GetAABB().Transform(SELECTED.GetSelected()->GetComponent().GetWorldMatrix()); + FEGameModel* GameModel = SELECTED.GetSelected(CurrentScene)->GetComponent().GameModel; + FEAABB SelectedAABB = GameModel->GetMesh()->GetAABB().Transform(SELECTED.GetSelected(CurrentScene)->GetComponent().GetWorldMatrix()); RENDERER.DrawAABB(SelectedAABB); - if (SELECTED.GetSelected()->HasComponent()) + if (SELECTED.GetSelected(CurrentScene)->HasComponent()) { static bool bDisplaySubObjAABB = false; ImGui::Checkbox("Display AABB of instanced entity subobjects", &bDisplaySubObjAABB); if (bDisplaySubObjAABB) { - FEInstancedComponent& InstancedComponent = SELECTED.GetSelected()->GetComponent(); + FEInstancedComponent& InstancedComponent = SELECTED.GetSelected(CurrentScene)->GetComponent(); const int MaxIterations = InstancedComponent.IndividualInstancedAABB.size() * 8 >= FE_MAX_LINES ? FE_MAX_LINES : int(InstancedComponent.IndividualInstancedAABB.size()); for (size_t j = 0; j < MaxIterations; j++) diff --git a/EditorWindows/SceneGraphWindow.h b/EditorWindows/SceneGraphWindow.h index d886c6d..1300ea8 100644 --- a/EditorWindows/SceneGraphWindow.h +++ b/EditorWindows/SceneGraphWindow.h @@ -2,13 +2,12 @@ #include "ProjectWasModifiedPopUp.h" + class FEEditorSceneGraphWindow { friend class FEEditor; SINGLETON_PRIVATE_PART(FEEditorSceneGraphWindow) - FEScene* CurrentScene = nullptr; - // Visibility bool bVisible = true; @@ -56,18 +55,11 @@ class FEEditorSceneGraphWindow FENaiveSceneGraphNode* NodeTarget = reinterpret_cast(SceneNodeTarget); FENaiveSceneGraphNode* SceneEntity = reinterpret_cast(Object); - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (!ActiveScenes.empty()) - { - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - return CurrentScene->SceneGraph.MoveNode(SceneEntity->GetObjectID(), NodeTarget->GetObjectID()); - } - - return false; + FEScene* CurrentScene = NodeTarget->GetEntity()->GetParentScene(); + return CurrentScene->SceneGraph.MoveNode(SceneEntity->GetObjectID(), NodeTarget->GetObjectID()); } - void UpdateSceneNodeDragAndDropTargets(); + //void UpdateSceneNodeDragAndDropTargets(); // Rendering and initialization void Render(); @@ -79,8 +71,8 @@ class FEEditorSceneGraphWindow public: SINGLETON_PUBLIC_PART(FEEditorSceneGraphWindow) - void SetScene(FEScene* Scene); - FEScene* GetScene(); + /*void SetScene(FEScene* Scene); + FEScene* GetScene();*/ }; #define SCENE_GRAPH_WINDOW FEEditorSceneGraphWindow::getInstance() \ No newline at end of file diff --git a/EditorWindows/SelectPopups.cpp b/EditorWindows/SelectPopups.cpp index d009e2f..e355ec0 100644 --- a/EditorWindows/SelectPopups.cpp +++ b/EditorWindows/SelectPopups.cpp @@ -125,7 +125,7 @@ void SelectFEObjectPopUp::Render() ImGui::SetNextWindowSize(ImVec2(128 * 7, 800)); if (ImGui::BeginPopupModal(PopupCaption.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove)) { - ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); + ImGui::SetWindowPos(ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, APPLICATION.GetMainWindow()->GetHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); ImGui::SetCursorPosX(10); ImGui::SetCursorPosY(40); ImGui::Text("Filter: "); diff --git a/EditorWindows/ShaderEditorWindow.cpp b/EditorWindows/ShaderEditorWindow.cpp index 353b2bb..8421747 100644 --- a/EditorWindows/ShaderEditorWindow.cpp +++ b/EditorWindows/ShaderEditorWindow.cpp @@ -1,4 +1,5 @@ #include "ShaderEditorWindow.h" +#include "../FEEditor.h" ShaderDebugWindow* ShaderDebugWindow::Instance = nullptr; @@ -466,11 +467,9 @@ void ShaderEditorWindow::ReplaceShader(FEShader* OldShader, FEShader* NewShader) } } - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (!ActiveScenes.empty()) + if (EDITOR.GetFocusedScene() != nullptr) { - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + FEScene* CurrentScene = EDITOR.GetFocusedScene(); const std::vector TerrainList = CurrentScene->GetEntityIDListWith(); for (size_t i = 0; i < TerrainList.size(); i++) { diff --git a/FEDearImguiWrapper/FEDearImguiWrapper.cpp b/FEDearImguiWrapper/FEDearImguiWrapper.cpp index 13c8683..0bd0e57 100644 --- a/FEDearImguiWrapper/FEDearImguiWrapper.cpp +++ b/FEDearImguiWrapper/FEDearImguiWrapper.cpp @@ -393,6 +393,11 @@ void FEImGuiWindow::SetCaption(const std::string NewCaption) strcpy_s(Caption, NewCaption.size() + 1, NewCaption.c_str()); } +ImGuiWindow* FEImGuiWindow::GetWindow() const +{ + return Window; +} + void FEImGuiWindow::SetVisible(bool NewValue) { bVisible = NewValue; @@ -762,7 +767,7 @@ void MessagePopUp::Render() ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); if (ImGui::BeginPopupModal(PopupCaption.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); + ImGui::SetWindowPos(ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, APPLICATION.GetMainWindow()->GetHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); ImGui::Text(Message.c_str()); ImGui::SetCursorPosX(ImGui::GetWindowWidth() / 2.0f - 120.0f / 2.0f); if (ImGui::Button("Ok", ImVec2(120, 0))) diff --git a/FEDearImguiWrapper/FEDearImguiWrapper.h b/FEDearImguiWrapper/FEDearImguiWrapper.h index 3aebf94..26525fa 100644 --- a/FEDearImguiWrapper/FEDearImguiWrapper.h +++ b/FEDearImguiWrapper/FEDearImguiWrapper.h @@ -175,6 +175,8 @@ class FEImGuiWindow bool IsMouseHovered() const; virtual void SetCaption(std::string NewCaption); + + ImGuiWindow* GetWindow() const; }; class FEArrowScroller diff --git a/FEEditor.cpp b/FEEditor.cpp index 5352c9a..2a2e6dd 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -1,18 +1,23 @@ #include "FEEditor.h" FEEditor* FEEditor::Instance = nullptr; -ImGuiWindow* FEEditor::SceneWindow = nullptr; bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) { + if (EDITOR.GetFocusedScene() == nullptr) + return false; + + if (CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene()) == nullptr) + return false; + if (Object->GetType() == FE_PREFAB) { FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())->GetComponent(0)->GameModel; - FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); - FECameraComponent& CameraComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); - FEEntity* Entity = EDITOR.GetCurrentEditorScene()->CreateEntity(Object->GetName()); + FEEntity* Entity = EDITOR.GetFocusedScene()->CreateEntity(Object->GetName()); Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); Entity->AddComponent(GameModel); @@ -27,12 +32,9 @@ bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) FEEditor::FEEditor() { - ENGINE.SetRenderTargetMode(FE_CUSTOM_MODE); - ImGuiIO& io = ImGui::GetIO(); - io.ConfigWindowsMoveFromTitleBarOnly = true; - - if (ENGINE.GetCamera()->GetCameraType() == 1) - ENGINE.RenderTargetCenterForCamera(reinterpret_cast(ENGINE.GetCamera())); + ImGuiIO& IO = ImGui::GetIO(); + IO.ConfigWindowsMoveFromTitleBarOnly = true; + ENGINE.SetVsyncEnabled(true); } FEEditor::~FEEditor() {} @@ -89,74 +91,68 @@ void FEEditor::SetSceneEntityIDInClipboard(const std::string NewValue) void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) { - if (ImGui::GetCurrentContext()->HoveredWindow != nullptr && FEEditor::SceneWindow != nullptr) - { - EDITOR.bSceneWindowHovered = ImGui::GetCurrentContext()->HoveredWindow->Name == EDITOR.SceneWindow->Name; - } - else - { - EDITOR.bSceneWindowHovered = false; - } - - if (FEEditor::SceneWindow == nullptr || !FEEditor::SceneWindow->Active) - EDITOR.bSceneWindowHovered = false; - if (Button == GLFW_MOUSE_BUTTON_1 && Action == GLFW_RELEASE) DRAG_AND_DROP_MANAGER.DropAction(); - if (ImGui::GetIO().WantCaptureMouse && !EDITOR.bSceneWindowHovered) + for (size_t i = 0; i < EDITOR.EditorScenes.size(); i++) { - EDITOR.bIsCameraInputActive = false; - ENGINE.GetCamera()->SetIsInputActive(false); - if (PROJECT_MANAGER.GetCurrent() != nullptr && PROJECT_MANAGER.GetCurrent()->ProjectScene != nullptr) + EDITOR.EditorScenes[i].bWindowHovered = false; + + if (EDITOR.EditorScenes[i].SceneWindow == nullptr) + continue; + + if (EDITOR.EditorScenes[i].Scene != EDITOR.GetFocusedScene()) + continue; + + if (ImGui::GetCurrentContext()->HoveredWindow != nullptr) + EDITOR.EditorScenes[i].bWindowHovered = ImGui::GetCurrentContext()->HoveredWindow->Name == EDITOR.EditorScenes[i].SceneWindow->Name; + + FEEntity* CurrentMainCamera = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.EditorScenes[i].Scene); + + if (ImGui::GetIO().WantCaptureMouse && !EDITOR.EditorScenes[i].bWindowHovered) { - FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(PROJECT_MANAGER.GetCurrent()->ProjectScene); - CAMERA_SYSTEM.SetIsIndividualInputActive(MainCamera, false); - } + if (EDITOR.EditorScenes[i].Scene != nullptr) + { + if (CurrentMainCamera != nullptr) + CAMERA_SYSTEM.SetIsIndividualInputActive(CurrentMainCamera, false); + } - return; - } + continue; + } - if (Button == GLFW_MOUSE_BUTTON_1 && Action == GLFW_PRESS) - { - bool bEditingTerrain = false; - if (SELECTED.GetSelected() != nullptr && SELECTED.GetSelected()->HasComponent()) + if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_PRESS) { - bEditingTerrain = TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE; + CAMERA_SYSTEM.SetIsIndividualInputActive(CurrentMainCamera, true); } - - if (!bEditingTerrain) + else if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_RELEASE) { - SELECTED.DetermineEntityUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY()); - SELECTED.CheckForSelectionisNeeded = true; + CAMERA_SYSTEM.SetIsIndividualInputActive(CurrentMainCamera, false); } - - INSPECTOR_WINDOW.bLeftMousePressed = true; - } - else if (Button == GLFW_MOUSE_BUTTON_1 && Action == GLFW_RELEASE) - { - INSPECTOR_WINDOW.bLeftMousePressed = false; - GIZMO_MANAGER.DeactivateAllGizmo(); - } - if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_PRESS) - { - EDITOR.bIsCameraInputActive = true; - //ENGINE.GetCamera()->SetIsInputActive(true); - if (PROJECT_MANAGER.GetCurrent() != nullptr && PROJECT_MANAGER.GetCurrent()->ProjectScene != nullptr) + if (Button == GLFW_MOUSE_BUTTON_1 && Action == GLFW_PRESS) { - FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(PROJECT_MANAGER.GetCurrent()->ProjectScene); - CAMERA_SYSTEM.SetIsIndividualInputActive(MainCamera, true); + if (EDITOR.EditorScenes[i].bWindowHovered) + { + bool bEditingTerrain = false; + if (SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene) != nullptr && SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene)->HasComponent()) + { + bEditingTerrain = TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE; + } + + if (!bEditingTerrain) + { + FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(EDITOR.EditorScenes[i].Scene->GetObjectID()); + SELECTED.DetermineEntityUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY(), EDITOR.EditorScenes[i].Scene); + CurrentSelectionData->CheckForSelectionisNeeded = true; + } + } + + INSPECTOR_WINDOW.bLeftMousePressed = true; } - } - else if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_RELEASE) - { - EDITOR.bIsCameraInputActive = false; - ENGINE.GetCamera()->SetIsInputActive(false); - if (PROJECT_MANAGER.GetCurrent() != nullptr && PROJECT_MANAGER.GetCurrent()->ProjectScene != nullptr) + else if (Button == GLFW_MOUSE_BUTTON_1 && Action == GLFW_RELEASE) { - FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(PROJECT_MANAGER.GetCurrent()->ProjectScene); - CAMERA_SYSTEM.SetIsIndividualInputActive(MainCamera, false); + INSPECTOR_WINDOW.bLeftMousePressed = false; + GIZMO_MANAGER.DeactivateAllGizmo(EDITOR.EditorScenes[i].Scene); } } } @@ -165,9 +161,9 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) { if (Key == GLFW_KEY_ESCAPE && Action == GLFW_PRESS) { - if (FEEditor::getInstance().IsInGameMode()) + if (EDITOR.IsInGameMode()) { - FEEditor::getInstance().SetGameMode(false); + EDITOR.SetGameMode(false); } else { @@ -177,66 +173,71 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) } } - if (!ImGui::GetIO().WantCaptureKeyboard && Key == GLFW_KEY_DELETE) + for (size_t i = 0; i < EDITOR.EditorScenes.size(); i++) { - if (SELECTED.GetSelected() != nullptr) + if (EDITOR.EditorScenes[i].Scene != EDITOR.GetFocusedScene()) + continue; + + FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(EDITOR.EditorScenes[i].Scene->GetObjectID()); + if (!ImGui::GetIO().WantCaptureKeyboard && Key == GLFW_KEY_DELETE) { - if (SELECTED.InstancedSubObjectIndexSelected != -1 && SELECTED.GetSelected()->HasComponent()) + if (SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene) != nullptr) { - INSTANCED_RENDERING_SYSTEM.DeleteIndividualInstance(SELECTED.GetSelected(), SELECTED.InstancedSubObjectIndexSelected); - } - else - { - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (!ActiveScenes.empty()) + if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1 && SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene)->HasComponent()) + { + INSTANCED_RENDERING_SYSTEM.DeleteIndividualInstance(SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene), CurrentSelectionData->InstancedSubObjectIndexSelected); + } + else { - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - CurrentScene->DeleteEntity(SELECTED.GetSelected()); + if (EDITOR.GetFocusedScene() != nullptr) + { + EDITOR.GetFocusedScene()->DeleteEntity(SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene)); + } } + + SELECTED.Clear(EDITOR.EditorScenes[i].Scene); + PROJECT_MANAGER.GetCurrent()->SetModified(true); } + } - SELECTED.Clear(); - PROJECT_MANAGER.GetCurrent()->SetModified(true); + if (!ImGui::GetIO().WantCaptureKeyboard && Mods == GLFW_MOD_CONTROL && Key == GLFW_KEY_C && Action == GLFW_RELEASE) + { + if (SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene) != nullptr) + EDITOR.SetSceneEntityIDInClipboard(SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene)->GetObjectID()); } - } - if (!ImGui::GetIO().WantCaptureKeyboard && Mods == GLFW_MOD_CONTROL && Key == GLFW_KEY_C && Action == GLFW_RELEASE) - { - if (SELECTED.GetSelected() != nullptr) - EDITOR.SetSceneEntityIDInClipboard(SELECTED.GetSelected()->GetObjectID()); + if (!ImGui::GetIO().WantCaptureKeyboard && (Key == GLFW_KEY_RIGHT_SHIFT || Key == GLFW_KEY_LEFT_SHIFT) && Action == GLFW_RELEASE) + { + int NewState = GIZMO_MANAGER.GizmosState + 1; + if (NewState > 2) + NewState = 0; + GIZMO_MANAGER.UpdateGizmoState(NewState, EDITOR.EditorScenes[i].Scene); + } } if (!ImGui::GetIO().WantCaptureKeyboard && Mods == GLFW_MOD_CONTROL && Key == GLFW_KEY_V && Action == GLFW_RELEASE) { if (!EDITOR.GetSceneEntityIDInClipboard().empty()) { - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (!ActiveScenes.empty()) + if (EDITOR.GetFocusedScene() != nullptr) { - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - - FEEntity* EntityToDuplicate = CurrentScene->GetEntity(EDITOR.GetSceneEntityIDInClipboard()); - FENaiveSceneGraphNode* NodeToDuplicate = CurrentScene->SceneGraph.GetNodeByEntityID(EntityToDuplicate->GetObjectID()); - FENaiveSceneGraphNode* DuplicatedNode = CurrentScene->SceneGraph.DuplicateNode(NodeToDuplicate->GetObjectID(), NodeToDuplicate->GetParent()->GetObjectID()); - if (DuplicatedNode != nullptr) + FEEntity* EntityToDuplicate = EDITOR.GetFocusedScene()->GetEntity(EDITOR.GetSceneEntityIDInClipboard()); + // Enitity could be deleted in the meantime + // or it could be from another scene + if (EntityToDuplicate != nullptr) { - FEEntity* DuplicatedEntity = DuplicatedNode->GetEntity(); - SELECTED.SetSelected(DuplicatedEntity); + FENaiveSceneGraphNode* NodeToDuplicate = EDITOR.GetFocusedScene()->SceneGraph.GetNodeByEntityID(EntityToDuplicate->GetObjectID()); + FENaiveSceneGraphNode* DuplicatedNode = EDITOR.GetFocusedScene()->SceneGraph.DuplicateNode(NodeToDuplicate->GetObjectID(), NodeToDuplicate->GetParent()->GetObjectID()); + if (DuplicatedNode != nullptr) + { + FEEntity* DuplicatedEntity = DuplicatedNode->GetEntity(); + SELECTED.SetSelected(DuplicatedEntity); + } } } } } - if (!ImGui::GetIO().WantCaptureKeyboard && (Key == GLFW_KEY_RIGHT_SHIFT || Key == GLFW_KEY_LEFT_SHIFT) && Action == GLFW_RELEASE) - { - int NewState = GIZMO_MANAGER.GizmosState + 1; - if (NewState > 2) - NewState = 0; - GIZMO_MANAGER.UpdateGizmoState(NewState); - } - if (!ImGui::GetIO().WantCaptureKeyboard && (Key == GLFW_KEY_RIGHT_SHIFT || Key == GLFW_KEY_LEFT_SHIFT) && Action == GLFW_RELEASE) { INSPECTOR_WINDOW.bShiftPressed = false; @@ -252,15 +253,14 @@ void FEEditor::InitializeResources() ENGINE.AddKeyCallback(KeyButtonCallback); ENGINE.AddMouseButtonCallback(MouseButtonCallback); ENGINE.AddMouseMoveCallback(MouseMoveCallback); - ENGINE.AddRenderTargetResizeCallback(RenderTargetResizeCallback); + ENGINE.AddOnViewportResizeCallback(OnViewportResize); ENGINE.AddDropCallback(DropCallback); SELECTED.InitializeResources(); - ENGINE.GetCamera()->SetIsInputActive(bIsCameraInputActive); if (PROJECT_MANAGER.GetCurrent() != nullptr && PROJECT_MANAGER.GetCurrent()->ProjectScene != nullptr) { FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(PROJECT_MANAGER.GetCurrent()->ProjectScene); - CAMERA_SYSTEM.SetIsIndividualInputActive(MainCamera, bIsCameraInputActive); + CAMERA_SYSTEM.SetIsIndividualInputActive(MainCamera, false); } PROJECT_MANAGER.InitializeResources(); PREVIEW_MANAGER.InitializeResources(); @@ -270,42 +270,25 @@ void FEEditor::InitializeResources() // **************************** Gizmos **************************** GIZMO_MANAGER.InitializeResources(); - if (!SCENE_MANAGER.GetActiveScenes().empty()) - { - // hide all resources for gizmos from content browser - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("45191B6F172E3B531978692E"/*"transformationGizmoMesh"*/)); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("637C784B2E5E5C6548190E1B"/*"scaleGizmoMesh"*/)); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("19622421516E5B317E1B5360"/*"rotateGizmoMesh"*/)); - - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity); - - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleZGizmoEntity); - - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateXGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().GameModel); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateZGizmoEntity); - - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(PREVIEW_MANAGER.PreviewEntity); - } + // hide all resources for gizmos from content browser + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("45191B6F172E3B531978692E"/*"transformationGizmoMesh"*/)); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("637C784B2E5E5C6548190E1B"/*"scaleGizmoMesh"*/)); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("19622421516E5B317E1B5360"/*"rotateGizmoMesh"*/)); + + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoGM); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoGM); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoGM); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoGM); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoGM); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoGM); + + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoGM); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoGM); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleZGizmoGM); + + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateXGizmoGM); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateYGizmoGM); + EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateZGizmoGM); SCENE_GRAPH_WINDOW.InitializeResources(); CONTENT_BROWSER_WINDOW.InitializeResources(); @@ -327,37 +310,37 @@ void FEEditor::MouseMoveCallback(double Xpos, double Ypos) DRAG_AND_DROP_MANAGER.MouseMove(); - if (SELECTED.GetSelected() != nullptr) + for (size_t i = 0; i < EDITOR.EditorScenes.size(); i++) { - if (SELECTED.GetSelected() != nullptr && SELECTED.GetSelected()->HasComponent()) + if (EDITOR.EditorScenes[i].Scene != EDITOR.GetFocusedScene()) + continue; + + if (SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene) != nullptr) { - if (TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE) - return; - } + if (SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene) != nullptr && SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene)->HasComponent()) + { + if (TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE) + return; + } - GIZMO_MANAGER.MouseMove(EDITOR.GetLastMouseX(), EDITOR.GetLastMouseY(), EDITOR.GetMouseX(), EDITOR.GetMouseY()); + GIZMO_MANAGER.MouseMove(EDITOR.GetLastMouseX(), EDITOR.GetLastMouseY(), EDITOR.GetMouseX(), EDITOR.GetMouseY(), EDITOR.EditorScenes[i].Scene); + } } } void FEEditor::AfterEngineUpdate() { SELECTED.OnCameraUpdate(); - GIZMO_MANAGER.Render(); + GIZMO_MANAGER.Update(); } void FEEditor::Render() { - // FIX ME! Temporary solution, only supports one scene std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); if (ActiveScenes.empty()) { - CurrentEditorScene = nullptr; - CurrentEditorCameraEntity = nullptr; - } - else - { - CurrentEditorScene = SCENE_MANAGER.GetActiveScenes()[0]; - CurrentEditorCameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(CurrentEditorScene); + EditorScenes.clear(); + SetFocusedScene(nullptr); } DRAG_AND_DROP_MANAGER.Render(); @@ -368,6 +351,7 @@ void FEEditor::Render() return; ImGui::DockSpaceOverViewport(ImGui::GetMainViewport()); + DockspaceID = ImGui::GetMainViewport()->ID; ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); if (ImGui::BeginMainMenuBar()) @@ -504,38 +488,47 @@ void FEEditor::Render() } ImGui::PopStyleVar(); - ImGui::Begin("Scene", nullptr, ImGuiWindowFlags_None | ImGuiWindowFlags_NoScrollbar); - - SceneWindow = ImGui::GetCurrentWindow(); - SceneWindowTarget->StickToCurrentWindow(); - - ENGINE.SetRenderTargetSize((size_t)SceneWindow->ContentRegionRect.GetWidth(), (size_t)SceneWindow->ContentRegionRect.GetHeight()); + for (size_t i = 0; i < EditorScenes.size(); i++) + { + std::string WindowName = EditorScenes[i].Scene->GetName(); + if (EditorScenes[i].bMain) + WindowName = "Main Scene"; - ENGINE.SetRenderTargetXShift((int)SceneWindow->ContentRegionRect.GetTL().x); - ENGINE.SetRenderTargetYShift((int)SceneWindow->ContentRegionRect.GetTL().y); + if (ImGui::Begin(WindowName.c_str(), nullptr, ImGuiWindowFlags_None | ImGuiWindowFlags_NoScrollbar)) + { + EditorScenes[i].SceneWindow = ImGui::GetCurrentWindow(); + if (EditorScenes[i].bMain) + { + SceneWindowTarget->StickToCurrentWindow(); + } - if (ENGINE.GetCamera()->GetCameraType() == 1) - ENGINE.RenderTargetCenterForCamera(reinterpret_cast(ENGINE.GetCamera())); + if (ImGui::IsWindowFocused()) + SetFocusedScene(EditorScenes[i].Scene); - ImGuiStyle& style = ImGui::GetStyle(); - style.WindowBorderSize = 0.0f; - style.WindowPadding = ImVec2(0.0f, 0.0f); + FEEntity* CameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(EditorScenes[i].Scene); + FECameraComponent& CameraComponent = CameraEntity->GetComponent(); - if (RENDERER.FinalScene != nullptr) - { - ImGui::Image((void*)(intptr_t)RENDERER.FinalScene->GetTextureID(), ImVec2(ImGui::GetCurrentWindow()->ContentRegionRect.GetWidth(), ImGui::GetCurrentWindow()->ContentRegionRect.GetHeight()), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); - } - else if (RENDERER.SceneToTextureFB->GetColorAttachment() != nullptr) - { - ImGui::Image((void*)(intptr_t)RENDERER.SceneToTextureFB->GetColorAttachment()->GetTextureID(), ImVec2(ImGui::GetCurrentWindow()->ContentRegionRect.GetWidth(), ImGui::GetCurrentWindow()->ContentRegionRect.GetHeight()), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); - } - // Something went terribly wrong! - else - { + if (CameraComponent.GetViewport() == nullptr) + { + std::string NewViewportID = ENGINE.AddViewport(EditorScenes[i].SceneWindow); + CAMERA_SYSTEM.SetCameraViewport(CameraEntity, NewViewportID); + SELECTED.AddSceneData(EditorScenes[i].Scene->GetObjectID()); + GIZMO_MANAGER.AddSceneData(EditorScenes[i].Scene->GetObjectID()); + } - } + ImGuiStyle& Style = ImGui::GetStyle(); + Style.WindowBorderSize = 0.0f; + Style.WindowPadding = ImVec2(0.0f, 0.0f); - ImGui::End(); + FETexture* CameraResult = RENDERER.GetCameraResult(CAMERA_SYSTEM.GetMainCameraEntity(EditorScenes[i].Scene)); + if (CameraResult != nullptr) + { + ImGui::Image((void*)(intptr_t)CameraResult->GetTextureID(), ImVec2(ImGui::GetCurrentWindow()->ContentRegionRect.GetWidth(), ImGui::GetCurrentWindow()->ContentRegionRect.GetHeight()), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); + } + } + + ImGui::End(); + } SCENE_GRAPH_WINDOW.Render(); CONTENT_BROWSER_WINDOW.Render(); @@ -546,12 +539,18 @@ void FEEditor::Render() GyzmosSettingsWindowObject.Show(); GyzmosSettingsWindowObject.Render(); - const int ObjectIndex = SELECTED.GetIndexOfObjectUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY()); - if (ObjectIndex >= 0) + for (size_t i = 0; i < EditorScenes.size(); i++) { - if (!GIZMO_MANAGER.WasSelected(ObjectIndex)) + if (EditorScenes[i].Scene != EDITOR.GetFocusedScene()) + continue; + + const int ObjectIndex = SELECTED.GetIndexOfObjectUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY(), EditorScenes[i].Scene); + if (ObjectIndex >= 0) { - SELECTED.SetSelectedByIndex(ObjectIndex); + if (!GIZMO_MANAGER.WasSelected(ObjectIndex, EditorScenes[i].Scene)) + { + SELECTED.SetSelectedByIndex(ObjectIndex, EditorScenes[i].Scene); + } } } @@ -584,11 +583,21 @@ void FEEditor::CloseWindowCallBack() } } -void FEEditor::RenderTargetResizeCallback(int NewW, int NewH) +void FEEditor::OnViewportResize(std::string ViewportID) { - if (ENGINE.GetCamera()->GetCameraType() == 1) - ENGINE.RenderTargetCenterForCamera(reinterpret_cast(ENGINE.GetCamera())); - SELECTED.ReInitializeResources(); + if (PROJECT_MANAGER.GetCurrent() == nullptr) + return; + + for (size_t i = 0; i < EDITOR.EditorScenes.size(); i++) + { + FEEntity* CameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.EditorScenes[i].Scene); + FECameraComponent& CameraComponent = CameraEntity->GetComponent(); + + if (CameraComponent.GetViewport()->GetID() == ViewportID) + { + SELECTED.UpdateResources(EDITOR.EditorScenes[i].Scene); + } + } } void FEEditor::DropCallback(const int Count, const char** Paths) @@ -605,12 +614,9 @@ void FEEditor::DropCallback(const int Count, const char** Paths) if (PROJECT_MANAGER.GetCurrent() != nullptr) { - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (!ActiveScenes.empty()) + if (EDITOR.GetFocusedScene() != nullptr) { - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - std::vector LoadedObjects = CurrentScene->ImportAsset(Paths[i]); + std::vector LoadedObjects = EDITOR.GetFocusedScene()->ImportAsset(Paths[i]); for (size_t j = 0; j < LoadedObjects.size(); j++) { if (LoadedObjects[j] != nullptr) @@ -640,18 +646,6 @@ bool FEEditor::IsInGameMode() const void FEEditor::SetGameMode(const bool GameMode) { this->bGameMode = GameMode; - if (this->bGameMode) - { - ENGINE.SetRenderTargetMode(FE_GLFW_MODE); - if (ENGINE.GetCamera()->GetCameraType() == 1) - ENGINE.RenderTargetCenterForCamera(reinterpret_cast(ENGINE.GetCamera())); - } - else - { - ENGINE.SetRenderTargetMode(FE_CUSTOM_MODE); - if (ENGINE.GetCamera()->GetCameraType() == 1) - ENGINE.RenderTargetCenterForCamera(reinterpret_cast(ENGINE.GetCamera())); - } } void FEEditor::DisplayEffectsWindow() const @@ -674,264 +668,6 @@ void FEEditor::DisplayEffectsWindow() const bFirstCall = false; } - if (ImGui::CollapsingHeader("Anti-Aliasing(FXAA)", 0)) - { - static const char* options[5] = { "none", "1x", "2x", "4x", "8x" }; - static std::string SelectedOption = "1x"; - - static bool bFirstLook = true; - if (bFirstLook) - { - const float FXAASpanMax = RENDERER.GetFXAASpanMax(); - if (FXAASpanMax == 0.0f) - { - SelectedOption = options[0]; - } - else if (FXAASpanMax > 0.1f && FXAASpanMax < 1.1f) - { - SelectedOption = options[1]; - } - else if (FXAASpanMax > 1.1f && FXAASpanMax < 2.1f) - { - SelectedOption = options[2]; - } - else if (FXAASpanMax > 2.1f && FXAASpanMax < 4.1f) - { - SelectedOption = options[3]; - } - else if (FXAASpanMax > 4.1f && FXAASpanMax < 8.1f) - { - SelectedOption = options[4]; - } - else - { - SelectedOption = options[5]; - } - - bFirstLook = false; - } - - static bool bDebugSettings = false; - if (ImGui::Checkbox("debug view", &bDebugSettings)) - { - const float FXAASpanMax = RENDERER.GetFXAASpanMax(); - if (FXAASpanMax == 0.0f) - { - SelectedOption = options[0]; - } - else if (FXAASpanMax > 0.1f && FXAASpanMax < 1.1f) - { - SelectedOption = options[1]; - } - else if (FXAASpanMax > 1.1f && FXAASpanMax < 2.1f) - { - SelectedOption = options[2]; - } - else if (FXAASpanMax > 2.1f && FXAASpanMax < 4.1f) - { - SelectedOption = options[3]; - } - else if (FXAASpanMax > 4.1f && FXAASpanMax < 8.1f) - { - SelectedOption = options[4]; - } - else - { - SelectedOption = options[5]; - } - } - - if (!bDebugSettings) - { - ImGui::Text("Anti Aliasing Strength:"); - if (ImGui::BeginCombo("##Anti Aliasing Strength", SelectedOption.c_str(), ImGuiWindowFlags_None)) - { - for (size_t i = 0; i < 5; i++) - { - const bool is_selected = (SelectedOption == options[i]); - if (ImGui::Selectable(options[i], is_selected)) - { - RENDERER.SetFXAASpanMax(float(pow(2.0, (i - 1)))); - if (i == 0) - RENDERER.SetFXAASpanMax(0.0f); - SelectedOption = options[i]; - } - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - ImGui::EndCombo(); - } - } - else - { - ImGui::Text("FXAASpanMax:"); - ImGui::SetNextItemWidth(FieldWidth); - float FXAASpanMax = RENDERER.GetFXAASpanMax(); - ImGui::DragFloat("##FXAASpanMax", &FXAASpanMax, 0.0f, 0.001f, 32.0f); - RENDERER.SetFXAASpanMax(FXAASpanMax); - - ImGui::PushID(GUIID++); - ImGui::SameLine(); - ResetButton->Render(); - if (ResetButton->IsClicked()) - { - RENDERER.SetFXAASpanMax(8.0f); - } - ImGui::PopID(); - - ImGui::Text("FXAAReduceMin:"); - ImGui::SetNextItemWidth(FieldWidth); - float FXAAReduceMin = RENDERER.GetFXAAReduceMin(); - ImGui::DragFloat("##FXAAReduceMin", &FXAAReduceMin, 0.01f, 0.001f, 100.0f); - RENDERER.SetFXAAReduceMin(FXAAReduceMin); - - ImGui::PushID(GUIID++); - ImGui::SameLine(); - ResetButton->Render(); - if (ResetButton->IsClicked()) - { - RENDERER.SetFXAAReduceMin(0.008f); - } - ImGui::PopID(); - - ImGui::Text("FXAAReduceMul:"); - ImGui::SetNextItemWidth(FieldWidth); - float FXAAReduceMul = RENDERER.GetFXAAReduceMul(); - ImGui::DragFloat("##FXAAReduceMul", &FXAAReduceMul, 0.01f, 0.001f, 100.0f); - RENDERER.SetFXAAReduceMul(FXAAReduceMul); - - ImGui::PushID(GUIID++); - ImGui::SameLine(); - ResetButton->Render(); - if (ResetButton->IsClicked()) - { - RENDERER.SetFXAAReduceMul(0.400f); - } - ImGui::PopID(); - } - } - - if (ImGui::CollapsingHeader("Bloom", 0)) - { - ImGui::Text("Threshold:"); - float Threshold = RENDERER.GetBloomThreshold(); - ImGui::SetNextItemWidth(FieldWidth); - ImGui::DragFloat("##Threshold", &Threshold, 0.01f, 0.001f, 30.0f); - RENDERER.SetBloomThreshold(Threshold); - - ImGui::PushID(GUIID++); - ImGui::SameLine(); - ResetButton->Render(); - if (ResetButton->IsClicked()) - { - RENDERER.SetBloomThreshold(1.5f); - } - ImGui::PopID(); - - ImGui::Text("Size:"); - float Size = RENDERER.GetBloomSize(); - ImGui::SetNextItemWidth(FieldWidth); - ImGui::DragFloat("##BloomSize", &Size, 0.01f, 0.001f, 100.0f); - RENDERER.SetBloomSize(Size); - - ImGui::PushID(GUIID++); - ImGui::SameLine(); - ResetButton->Render(); - if (ResetButton->IsClicked()) - { - RENDERER.SetBloomSize(5.0f); - } - ImGui::PopID(); - } - - if (ImGui::CollapsingHeader("Depth of Field", 0)) - { - ImGui::Text("Near distance:"); - ImGui::SetNextItemWidth(FieldWidth); - float DepthThreshold = RENDERER.GetDOFNearDistance(); - ImGui::DragFloat("##depthThreshold", &DepthThreshold, 0.0f, 0.001f, 100.0f); - RENDERER.SetDOFNearDistance(DepthThreshold); - - ImGui::Text("Far distance:"); - ImGui::SetNextItemWidth(FieldWidth); - float DepthThresholdFar = RENDERER.GetDOFFarDistance(); - ImGui::DragFloat("##depthThresholdFar", &DepthThresholdFar, 0.0f, 0.001f, 100.0f); - RENDERER.SetDOFFarDistance(DepthThresholdFar); - - ImGui::Text("Strength:"); - ImGui::SetNextItemWidth(FieldWidth); - float Strength = RENDERER.GetDOFStrength(); - ImGui::DragFloat("##Strength", &Strength, 0.0f, 0.001f, 10.0f); - RENDERER.SetDOFStrength(Strength); - - ImGui::Text("Distance dependent strength:"); - ImGui::SetNextItemWidth(FieldWidth); - float IntMult = RENDERER.GetDOFDistanceDependentStrength(); - ImGui::DragFloat("##Distance dependent strength", &IntMult, 0.0f, 0.001f, 100.0f); - RENDERER.SetDOFDistanceDependentStrength(IntMult); - } - - if (ImGui::CollapsingHeader("Distance fog", 0)) - { - bool bEnabledFog = RENDERER.IsDistanceFogEnabled(); - if (ImGui::Checkbox("Enable fog", &bEnabledFog)) - { - RENDERER.SetDistanceFogEnabled(bEnabledFog); - } - - if (bEnabledFog) - { - ImGui::Text("Density:"); - ImGui::SetNextItemWidth(FieldWidth); - float FogDensity = RENDERER.GetDistanceFogDensity(); - ImGui::DragFloat("##fogDensity", &FogDensity, 0.0001f, 0.0f, 5.0f); - RENDERER.SetDistanceFogDensity(FogDensity); - - ImGui::PushID(GUIID++); - ImGui::SameLine(); - ResetButton->Render(); - if (ResetButton->IsClicked()) - { - RENDERER.SetDistanceFogDensity(0.007f); - } - ImGui::PopID(); - - ImGui::Text("Gradient:"); - ImGui::SetNextItemWidth(FieldWidth); - float FogGradient = RENDERER.GetDistanceFogGradient(); - ImGui::DragFloat("##fogGradient", &FogGradient, 0.001f, 0.0f, 5.0f); - RENDERER.SetDistanceFogGradient(FogGradient); - - ImGui::PushID(GUIID++); - ImGui::SameLine(); - ResetButton->Render(); - if (ResetButton->IsClicked()) - { - RENDERER.SetDistanceFogGradient(2.5f); - } - ImGui::PopID(); - } - } - - if (ImGui::CollapsingHeader("Chromatic Aberration", 0)) - { - ImGui::Text("Shift strength:"); - ImGui::SetNextItemWidth(FieldWidth); - float intensity = RENDERER.GetChromaticAberrationIntensity(); - ImGui::DragFloat("##intensity", &intensity, 0.01f, 0.0f, 30.0f); - RENDERER.SetChromaticAberrationIntensity(intensity); - - ImGui::PushID(GUIID++); - ImGui::SameLine(); - ResetButton->Render(); - if (ResetButton->IsClicked()) - { - RENDERER.SetChromaticAberrationIntensity(1.0f); - } - ImGui::PopID(); - } - if (ImGui::CollapsingHeader("Sky", 0)) { bool bEnabledSky = SKY_DOME_SYSTEM.IsEnabled(); @@ -948,145 +684,12 @@ void FEEditor::DisplayEffectsWindow() const ImGui::PushID(GUIID++); ImGui::SameLine(); - ResetButton->Render(); + ResetButton->Update(); if (ResetButton->IsClicked()) { RENDERER.SetDistanceToSky(50.0f); - }*/ - ImGui::PopID(); - } - - if (ImGui::CollapsingHeader("SSAO", 0)) - { - static const char* options[5] = { "Off", "Low", "Medium", "High", "Custom"}; - static std::string SelectedOption = "Medium"; - - static bool bFirstLook = true; - if (bFirstLook) - { - const int SampleCount = RENDERER.GetSSAOSampleCount(); - - if (!RENDERER.IsSSAOEnabled()) - { - SelectedOption = options[0]; - } - else if (SampleCount == 4) - { - SelectedOption = options[1]; - } - else if (SampleCount == 16 && RENDERER.GetSSAORadiusSmallDetails()) - { - SelectedOption = options[2]; - } - else if (SampleCount == 32 && RENDERER.GetSSAORadiusSmallDetails()) - { - SelectedOption = options[3]; - } - else - { - SelectedOption = options[4]; - } - - //bFirstLook = false; - } - - static bool bDebugSettings = false; - if (ImGui::Checkbox("Debug view", &bDebugSettings)) - { - - } - - if (!bDebugSettings) - { - ImGui::Text("SSAO Quality:"); - ImGui::SetNextItemWidth(150); - if (ImGui::BeginCombo("##SSAO Quality", SelectedOption.c_str(), ImGuiWindowFlags_None)) - { - for (size_t i = 0; i < 5; i++) - { - const bool is_selected = (SelectedOption == options[i]); - if (ImGui::Selectable(options[i], is_selected)) - { - RENDERER.SetSSAOResultBlured(true); - RENDERER.SetSSAOBias(0.013f); - RENDERER.SetSSAORadius(10.0f); - RENDERER.SetSSAORadiusSmallDetails(0.4f); - RENDERER.SetSSAOSmallDetailsWeight(0.2f); - - if (i == 0) - { - RENDERER.SetSSAOEnabled(false); - } - else if (i == 1) - { - RENDERER.SetSSAOEnabled(true); - - RENDERER.SetSSAOSampleCount(4); - RENDERER.SetSSAOSmallDetailsEnabled(false); - } - else if (i == 2) - { - RENDERER.SetSSAOEnabled(true); - - RENDERER.SetSSAOSampleCount(16); - RENDERER.SetSSAOSmallDetailsEnabled(true); - } - else if (i == 3) - { - RENDERER.SetSSAOEnabled(true); - - RENDERER.SetSSAOSampleCount(32); - RENDERER.SetSSAOSmallDetailsEnabled(true); - } - - SelectedOption = options[i]; - } - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - ImGui::EndCombo(); - } - } - else - { - bool TempBool = RENDERER.IsSSAOEnabled(); - ImGui::Checkbox("SSAO active", &TempBool); - RENDERER.SetSSAOEnabled(TempBool); - - TempBool = RENDERER.IsSSAOSmallDetailsEnabled(); - ImGui::Checkbox("SSAO small details", &TempBool); - RENDERER.SetSSAOSmallDetailsEnabled(TempBool); - - TempBool = RENDERER.IsSSAOResultBlured(); - ImGui::Checkbox("SSAO blured", &TempBool); - RENDERER.SetSSAOResultBlured(TempBool); - - int TempInt = RENDERER.GetSSAOSampleCount(); - ImGui::SetNextItemWidth(100); - ImGui::DragInt("SSAO sample count", &TempInt); - RENDERER.SetSSAOSampleCount(TempInt); - - float TempFloat = RENDERER.GetSSAOBias(); - ImGui::SetNextItemWidth(100); - ImGui::DragFloat("SSAO bias", &TempFloat, 0.1f); - RENDERER.SetSSAOBias(TempFloat); - - TempFloat = RENDERER.GetSSAORadius(); - ImGui::SetNextItemWidth(100); - ImGui::DragFloat("SSAO radius", &TempFloat, 0.1f); - RENDERER.SetSSAORadius(TempFloat); - - TempFloat = RENDERER.GetSSAORadiusSmallDetails(); - ImGui::SetNextItemWidth(100); - ImGui::DragFloat("SSAO radius small details", &TempFloat, 0.1f); - RENDERER.SetSSAORadiusSmallDetails(TempFloat); - - TempFloat = RENDERER.GetSSAOSmallDetailsWeight(); - ImGui::SetNextItemWidth(100); - ImGui::DragFloat("SSAO small details weight", &TempFloat, 0.01f); - RENDERER.SetSSAOSmallDetailsWeight(TempFloat); } + ImGui::PopID();*/ } ImGui::PopStyleVar(); @@ -1202,28 +805,54 @@ void FEEditor::SetUpImgui() int TexW, TexH; io.Fonts->GetTexDataAsRGBA32(&TexPixels, &TexW, &TexH); - io.DisplaySize = ImVec2(static_cast(ENGINE.GetWindowWidth()), static_cast(ENGINE.GetWindowHeight())); + io.DisplaySize = ImVec2(static_cast(APPLICATION.GetMainWindow()->GetWidth()), static_cast(APPLICATION.GetMainWindow()->GetHeight())); ImGui::StyleColorsDark(); SetImguiStyle(); } -FEScene* FEEditor::GetCurrentEditorScene() const +void FEEditor::OnProjectClose() { - return CurrentEditorScene; + EditorScenes.clear(); + SetFocusedScene(nullptr); + + PROJECT_MANAGER.CloseCurrentProject(); + CONTENT_BROWSER_WINDOW.Clear(); + SCENE_GRAPH_WINDOW.Clear(); } -FEEntity* FEEditor::GetCurrentEditorCameraEntity() const +void FEEditor::AddEditorScene(FEScene* Scene, bool bMain) { - return CurrentEditorCameraEntity; + FEEditorSceneData EditorSceneData; + EditorSceneData.bMain = bMain; + EditorSceneData.Scene = Scene; + EditorSceneData.CameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(Scene); + EditorScenes.push_back(EditorSceneData); } -void FEEditor::OnProjectClose() +FEScene* FEEditor::GetFocusedScene() const { - CurrentEditorScene = nullptr; - CurrentEditorCameraEntity = nullptr; + return SCENE_MANAGER.GetScene(FocusedEditorSceneID); +} - PROJECT_MANAGER.CloseCurrentProject(); - CONTENT_BROWSER_WINDOW.Clear(); - SCENE_GRAPH_WINDOW.Clear(); +void FEEditor::SetFocusedScene(FEScene* NewSceneInFocus) +{ + if (NewSceneInFocus == nullptr) + { + FocusedEditorSceneID = ""; + return; + } + + BeforeChangeOfFocusedScene(NewSceneInFocus); + + FocusedEditorSceneID = NewSceneInFocus->GetObjectID(); +} + +void FEEditor::BeforeChangeOfFocusedScene(FEScene* NewSceneInFocus) +{ + if (!FocusedEditorSceneID.empty() && NewSceneInFocus != EDITOR.GetFocusedScene()) + { + SELECTED.Clear(EDITOR.GetFocusedScene()); + GIZMO_MANAGER.HideAllGizmo(EDITOR.GetFocusedScene()); + } } \ No newline at end of file diff --git a/FEEditor.h b/FEEditor.h index 0b9f7f6..fdd5633 100644 --- a/FEEditor.h +++ b/FEEditor.h @@ -3,9 +3,22 @@ #include "EditorWindows/InspectorWindow.h" #include -class DragAndDropTarget; +struct FEEditorSceneData +{ + bool bMain = false; + + FEScene* Scene = nullptr; + FEEntity* CameraEntity = nullptr; + + ImGuiWindow* SceneWindow = nullptr; + bool bWindowHovered = false; +}; + class FEEditor { + friend class FEProjectManager; + // FIX ME! It is temporary solution + friend class PrefabEditorWindow; public: SINGLETON_PUBLIC_PART(FEEditor) @@ -27,26 +40,24 @@ class FEEditor std::string GetSceneEntityIDInClipboard(); void SetSceneEntityIDInClipboard(std::string NewValue); - FEScene* GetCurrentEditorScene() const; - FEEntity* GetCurrentEditorCameraEntity() const; + FEScene* GetFocusedScene() const; private: SINGLETON_PRIVATE_PART(FEEditor) // Mouse and input double LastMouseX, LastMouseY; double MouseX, MouseY; - bool bSceneWindowHovered; - bool bIsCameraInputActive = false; - FEScene* CurrentEditorScene = nullptr; - FEEntity* CurrentEditorCameraEntity = nullptr; + std::string FocusedEditorSceneID = ""; + ImGuiID DockspaceID = 0; + + void AddEditorScene(FEScene* Scene, bool bMain = false); + + std::vector EditorScenes; // Clipboard std::string SceneEntityIDInClipboard; - // Scene window - static ImGuiWindow* SceneWindow; - // Drag and drop DragAndDropTarget* SceneWindowTarget = nullptr; @@ -55,7 +66,7 @@ class FEEditor static void MouseButtonCallback(int Button, int Action, int Mods); static void MouseMoveCallback(double Xpos, double Ypos); static void KeyButtonCallback(int Key, int Scancode, int Action, int Mods); - static void RenderTargetResizeCallback(int NewW, int NewH); + static void OnViewportResize(std::string ViewportID); static void DropCallback(int Count, const char** Paths); static void CloseWindowCallBack(); @@ -88,6 +99,9 @@ class FEEditor void SetImguiStyle(); void OnProjectClose(); + + void SetFocusedScene(FEScene* NewSceneInFocus); + void BeforeChangeOfFocusedScene(FEScene* NewSceneInFocus); }; #define EDITOR FEEditor::getInstance() \ No newline at end of file diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index 868f857..a326788 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -1,7 +1,6 @@ #include "FEEditorGizmoManager.h" using namespace FocalEngine; #include "FEEditor.h" -//using namespace GizmoManager; GizmoManager* GizmoManager::Instance = nullptr; GizmoManager::GizmoManager() {} @@ -9,7 +8,7 @@ GizmoManager::~GizmoManager() {} void GizmoManager::InitializeResources() { - SELECTED.SetOnUpdateFunc(OnSelectedObjectUpdate); + SELECTED.SetOnUpdateFunction(OnSelectedObjectUpdate); FEMesh* TransformationGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "45191B6F172E3B531978692E.model").c_str(), "transformationGizmoMesh"); RESOURCE_MANAGER.MakeMeshStandard(TransformationGizmoMesh); @@ -20,8 +19,8 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - FEGameModel* CurrentModel = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + TransformationXGizmoGM = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationXGizmoGM); // TransformationYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYGizmoMaterial"); @@ -30,8 +29,8 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - CurrentModel = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + TransformationYGizmoGM = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationYGizmoGM); // TransformationZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationZGizmoMaterial"); @@ -40,8 +39,8 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - CurrentModel = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + TransformationZGizmoGM = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationZGizmoGM); // Plane gizmos CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXYGizmoMaterial"); @@ -50,8 +49,8 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - CurrentModel = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + TransformationXYGizmoGM = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationXYGizmoGM); CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); @@ -59,8 +58,8 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - CurrentModel = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + TransformationYZGizmoGM = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationYZGizmoGM); CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); @@ -68,8 +67,8 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - CurrentModel = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + TransformationXZGizmoGM = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(TransformationXZGizmoGM); // Scale gizmos. FEMesh* ScaleGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "637C784B2E5E5C6548190E1B.model").c_str(), "scaleGizmoMesh"); @@ -82,8 +81,8 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - CurrentModel = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + ScaleXGizmoGM = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(ScaleXGizmoGM); // ScaleYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleYGizmoMaterial"); @@ -92,8 +91,8 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - CurrentModel = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + ScaleYGizmoGM = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(ScaleYGizmoGM); // ScaleZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleZGizmoMaterial"); @@ -102,8 +101,8 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - CurrentModel = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + ScaleZGizmoGM = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(ScaleZGizmoGM); // RotateAroundAxis gizmos FEMesh* RotateGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "19622421516E5B317E1B5360.model").c_str(), "rotateGizmoMesh"); @@ -116,8 +115,8 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - CurrentModel = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + RotateXGizmoGM = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(RotateXGizmoGM); // RotateYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateYGizmoMaterial"); @@ -126,8 +125,8 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - CurrentModel = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + RotateYGizmoGM = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(RotateYGizmoGM); // RotateZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateZGizmoMaterial"); @@ -136,8 +135,8 @@ void GizmoManager::InitializeResources() CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); - CurrentModel = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(CurrentModel); + RotateZGizmoGM = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM"); + RESOURCE_MANAGER.MakeGameModelStandard(RotateZGizmoGM); TransformationGizmoIcon = RESOURCE_MANAGER.LoadFETexture((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "456A31026A1C3152181A6064.texture").c_str(), "transformationGizmoIcon"); RESOURCE_MANAGER.MakeTextureStandard(TransformationGizmoIcon); @@ -147,44 +146,58 @@ void GizmoManager::InitializeResources() RESOURCE_MANAGER.MakeTextureStandard(RotateGizmoIcon); } -void GizmoManager::HideAllGizmo() +void GizmoManager::HideAllGizmo(FEScene* Scene) { - TransformationXGizmoEntity->GetComponent().SetVisibility(false); - TransformationYGizmoEntity->GetComponent().SetVisibility(false); - TransformationZGizmoEntity->GetComponent().SetVisibility(false); + if (Scene == nullptr) + return; + + FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(Scene->GetObjectID()); + if (GizmoSceneData == nullptr) + return; + + GizmoSceneData->TransformationXGizmoEntity->GetComponent().SetVisibility(false); + GizmoSceneData->TransformationYGizmoEntity->GetComponent().SetVisibility(false); + GizmoSceneData->TransformationZGizmoEntity->GetComponent().SetVisibility(false); - TransformationXYGizmoEntity->GetComponent().SetVisibility(false); - TransformationYZGizmoEntity->GetComponent().SetVisibility(false); - TransformationXZGizmoEntity->GetComponent().SetVisibility(false); + GizmoSceneData->TransformationXYGizmoEntity->GetComponent().SetVisibility(false); + GizmoSceneData->TransformationYZGizmoEntity->GetComponent().SetVisibility(false); + GizmoSceneData->TransformationXZGizmoEntity->GetComponent().SetVisibility(false); - bTransformationXGizmoActive = false; - bTransformationYGizmoActive = false; - bTransformationZGizmoActive = false; + GizmoSceneData->bTransformationXGizmoActive = false; + GizmoSceneData->bTransformationYGizmoActive = false; + GizmoSceneData->bTransformationZGizmoActive = false; - bTransformationXYGizmoActive = false; - bTransformationYZGizmoActive = false; - bTransformationXZGizmoActive = false; + GizmoSceneData->bTransformationXYGizmoActive = false; + GizmoSceneData->bTransformationYZGizmoActive = false; + GizmoSceneData->bTransformationXZGizmoActive = false; - ScaleXGizmoEntity->GetComponent().SetVisibility(false); - ScaleYGizmoEntity->GetComponent().SetVisibility(false); - ScaleZGizmoEntity->GetComponent().SetVisibility(false); + GizmoSceneData->ScaleXGizmoEntity->GetComponent().SetVisibility(false); + GizmoSceneData->ScaleYGizmoEntity->GetComponent().SetVisibility(false); + GizmoSceneData->ScaleZGizmoEntity->GetComponent().SetVisibility(false); - bScaleXGizmoActive = false; - bScaleYGizmoActive = false; - bScaleZGizmoActive = false; + GizmoSceneData->bScaleXGizmoActive = false; + GizmoSceneData->bScaleYGizmoActive = false; + GizmoSceneData->bScaleZGizmoActive = false; - RotateXGizmoEntity->GetComponent().SetVisibility(false); - RotateYGizmoEntity->GetComponent().SetVisibility(false); - RotateZGizmoEntity->GetComponent().SetVisibility(false); + GizmoSceneData->RotateXGizmoEntity->GetComponent().SetVisibility(false); + GizmoSceneData->RotateYGizmoEntity->GetComponent().SetVisibility(false); + GizmoSceneData->RotateZGizmoEntity->GetComponent().SetVisibility(false); - bRotateXGizmoActive = false; - bRotateYGizmoActive = false; - bRotateZGizmoActive = false; + GizmoSceneData->bRotateXGizmoActive = false; + GizmoSceneData->bRotateYGizmoActive = false; + GizmoSceneData->bRotateZGizmoActive = false; } -void GizmoManager::UpdateGizmoState(int NewState) +void GizmoManager::UpdateGizmoState(int NewState, FEScene* Scene) { - if (SELECTED.GetSelected() != nullptr && SELECTED.GetSelected()->HasComponent()) + if (Scene == nullptr) + return; + + FEGizmoSceneData* GizmoSceneData = GetSceneData(Scene->GetObjectID()); + if (GizmoSceneData == nullptr) + return; + + if (SELECTED.GetSelected(Scene) != nullptr && SELECTED.GetSelected(Scene)->HasComponent()) { if (TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE) return; @@ -193,39 +206,39 @@ void GizmoManager::UpdateGizmoState(int NewState) if (NewState < 0 || NewState > 2) NewState = 0; - GizmosState = NewState; - HideAllGizmo(); + GizmoSceneData->GizmosState = NewState; + HideAllGizmo(Scene); - if (SELECTED.GetSelected() == nullptr || SELECTED.GetSelected()->GetType() == FE_CAMERA) + if (SELECTED.GetSelected(Scene) == nullptr || SELECTED.GetSelected(Scene)->GetType() == FE_CAMERA_DEPRECATED) return; switch (NewState) { case TRANSFORM_GIZMOS: { - TransformationXGizmoEntity->GetComponent().SetVisibility(true); - TransformationYGizmoEntity->GetComponent().SetVisibility(true); - TransformationZGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->TransformationXGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->TransformationYGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->TransformationZGizmoEntity->GetComponent().SetVisibility(true); - TransformationXYGizmoEntity->GetComponent().SetVisibility(true); - TransformationYZGizmoEntity->GetComponent().SetVisibility(true); - TransformationXZGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->TransformationXYGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->TransformationYZGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->TransformationXZGizmoEntity->GetComponent().SetVisibility(true); break; } case SCALE_GIZMOS: { - ScaleXGizmoEntity->GetComponent().SetVisibility(true); - ScaleYGizmoEntity->GetComponent().SetVisibility(true); - ScaleZGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->ScaleXGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->ScaleYGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->ScaleZGizmoEntity->GetComponent().SetVisibility(true); break; } case ROTATE_GIZMOS: { - RotateXGizmoEntity->GetComponent().SetVisibility(true); - RotateYGizmoEntity->GetComponent().SetVisibility(true); - RotateZGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->RotateXGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->RotateYGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->RotateZGizmoEntity->GetComponent().SetVisibility(true); break; } @@ -234,214 +247,238 @@ void GizmoManager::UpdateGizmoState(int NewState) } } -void GizmoManager::DeactivateAllGizmo() +void GizmoManager::DeactivateAllGizmo(FEScene* Scene) { - bTransformationXGizmoActive = false; - bTransformationYGizmoActive = false; - bTransformationZGizmoActive = false; - - bTransformationXYGizmoActive = false; - bTransformationYZGizmoActive = false; - bTransformationXZGizmoActive = false; - - bScaleXGizmoActive = false; - bScaleYGizmoActive = false; - bScaleZGizmoActive = false; - - bRotateXGizmoActive = false; - bRotateYGizmoActive = false; - bRotateZGizmoActive = false; -} - -void GizmoManager::Render() -{ - if (EDITOR.GetCurrentEditorScene() == nullptr) + if (Scene == nullptr) return; - // If we cleared the scene, we should not render gizmos. - if (EDITOR.GetCurrentEditorScene()->GetEntityByName("TransformationXGizmoEntity").empty() || EDITOR.GetCurrentEditorScene()->GetEntityByName("TransformationXGizmoEntity")[0] == nullptr) + FEGizmoSceneData* GizmoSceneData = GetSceneData(Scene->GetObjectID()); + if (GizmoSceneData == nullptr) return; - if (SELECTED.GetSelected() == nullptr || SELECTED.GetSelected()->GetType() == FE_CAMERA) - { - HideAllGizmo(); - return; - } - - FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); - FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); - const glm::vec3 ObjectSpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); - glm::vec3 ToObject = ObjectSpaceOriginInWorldSpace - CameraTransformComponent.GetPosition(FE_WORLD_SPACE); - ToObject = glm::normalize(ToObject); - - ParentGizmoEntity->GetComponent().SetPosition((CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + ToObject * 0.15f)); - //ParentGizmoEntity->GetComponent().Update(); - //ParentGizmoEntity->GetComponent().ForceSetWorldMatrix(ParentGizmoEntity->GetComponent().GetLocalMatrix()); - if (GIZMO_MANAGER.GizmosState == TRANSFORM_GIZMOS) - { - // X Gizmos - GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); - if (GIZMO_MANAGER.bTransformationXZGizmoActive || GIZMO_MANAGER.bTransformationXYGizmoActive || GIZMO_MANAGER.bTransformationXGizmoActive) - GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->bTransformationXGizmoActive = false; + GizmoSceneData->bTransformationYGizmoActive = false; + GizmoSceneData->bTransformationZGizmoActive = false; - // Y Gizmos - GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); - if (GIZMO_MANAGER.bTransformationYZGizmoActive || GIZMO_MANAGER.bTransformationXYGizmoActive || GIZMO_MANAGER.bTransformationYGizmoActive) - GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->bTransformationXYGizmoActive = false; + GizmoSceneData->bTransformationYZGizmoActive = false; + GizmoSceneData->bTransformationXZGizmoActive = false; - // Z Gizmos - GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); - if (GIZMO_MANAGER.bTransformationYZGizmoActive || GIZMO_MANAGER.bTransformationXZGizmoActive || GIZMO_MANAGER.bTransformationZGizmoActive) - GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->bScaleXGizmoActive = false; + GizmoSceneData->bScaleYGizmoActive = false; + GizmoSceneData->bScaleZGizmoActive = false; - // XY Gizmos - GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); - if (GIZMO_MANAGER.bTransformationXYGizmoActive) - GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); - - // YZ Gizmos - GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); - if (GIZMO_MANAGER.bTransformationYZGizmoActive) - GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); - - // XZ Gizmos - GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); - if (GIZMO_MANAGER.bTransformationXZGizmoActive) - GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); - } - else if (GIZMO_MANAGER.GizmosState == SCALE_GIZMOS) - { - // X Gizmos - GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); - if (GIZMO_MANAGER.bScaleXGizmoActive) - GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); - - // Y Gizmos - GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); - if (GIZMO_MANAGER.bScaleYGizmoActive) - GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->bRotateXGizmoActive = false; + GizmoSceneData->bRotateYGizmoActive = false; + GizmoSceneData->bRotateZGizmoActive = false; +} - // Z Gizmos - GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); - if (GIZMO_MANAGER.bScaleZGizmoActive) - GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); - } - else if (GIZMO_MANAGER.GizmosState == ROTATE_GIZMOS) +void GizmoManager::Update() +{ + auto PerSceneIterator = PerSceneData.begin(); + while (PerSceneIterator != PerSceneData.end()) { - if (SELECTED.SELECTED.GetSelected() != nullptr) + FEGizmoSceneData* GizmoSceneData = PerSceneIterator->second; + if (GizmoSceneData == nullptr) { - GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().SetVisibility(true); - GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().SetVisibility(true); - GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().SetVisibility(true); + PerSceneIterator++; + continue; } + + FEScene* Scene = SCENE_MANAGER.GetScene(GizmoSceneData->SceneID); - // X Gizmos - GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); - if (GIZMO_MANAGER.bRotateXGizmoActive) + if (SELECTED.GetSelected(Scene) == nullptr || SELECTED.GetSelected(Scene)->GetType() == FE_CAMERA_DEPRECATED) { - GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); - GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().SetVisibility(false); - GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().SetVisibility(false); + HideAllGizmo(Scene); + PerSceneIterator++; + continue; } - // Y Gizmos - GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); - if (GIZMO_MANAGER.bRotateYGizmoActive) + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); + FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(Scene); + const glm::vec3 ObjectSpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); + glm::vec3 ToObject = ObjectSpaceOriginInWorldSpace - CameraTransformComponent.GetPosition(FE_WORLD_SPACE); + ToObject = glm::normalize(ToObject); + + GizmoSceneData->ParentGizmoEntity->GetComponent().SetPosition((CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + ToObject * 0.15f)); + //ParentGizmoEntity->GetComponent().Update(); + //ParentGizmoEntity->GetComponent().ForceSetWorldMatrix(ParentGizmoEntity->GetComponent().GetLocalMatrix()); + if (GizmoSceneData->GizmosState == TRANSFORM_GIZMOS) { - GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); - GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().SetVisibility(false); - GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().SetVisibility(false); + // X Gizmos + GizmoSceneData->TransformationXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); + if (GizmoSceneData->bTransformationXZGizmoActive || GizmoSceneData->bTransformationXYGizmoActive || GizmoSceneData->bTransformationXGizmoActive) + GizmoSceneData->TransformationXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + + // Y Gizmos + GizmoSceneData->TransformationYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); + if (GizmoSceneData->bTransformationYZGizmoActive || GizmoSceneData->bTransformationXYGizmoActive || GizmoSceneData->bTransformationYGizmoActive) + GizmoSceneData->TransformationYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + + // Z Gizmos + GizmoSceneData->TransformationZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); + if (GizmoSceneData->bTransformationYZGizmoActive || GizmoSceneData->bTransformationXZGizmoActive || GizmoSceneData->bTransformationZGizmoActive) + GizmoSceneData->TransformationZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + + // XY Gizmos + GizmoSceneData->TransformationXYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); + if (GizmoSceneData->bTransformationXYGizmoActive) + GizmoSceneData->TransformationXYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + + // YZ Gizmos + GizmoSceneData->TransformationYZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); + if (GizmoSceneData->bTransformationYZGizmoActive) + GizmoSceneData->TransformationYZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + + // XZ Gizmos + GizmoSceneData->TransformationXZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); + if (GizmoSceneData->bTransformationXZGizmoActive) + GizmoSceneData->TransformationXZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); } - - // Z Gizmos - GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); - if (GIZMO_MANAGER.bRotateZGizmoActive) + else if (GizmoSceneData->GizmosState == SCALE_GIZMOS) { - GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); - GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().SetVisibility(false); - GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().SetVisibility(false); + // X Gizmos + GizmoSceneData->ScaleXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); + if (GizmoSceneData->bScaleXGizmoActive) + GizmoSceneData->ScaleXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + + // Y Gizmos + GizmoSceneData->ScaleYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); + if (GizmoSceneData->bScaleYGizmoActive) + GizmoSceneData->ScaleYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + + // Z Gizmos + GizmoSceneData->ScaleZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); + if (GizmoSceneData->bScaleZGizmoActive) + GizmoSceneData->ScaleZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); } + else if (GizmoSceneData->GizmosState == ROTATE_GIZMOS) + { + if (SELECTED.SELECTED.GetSelected(Scene) != nullptr) + { + GizmoSceneData->RotateXGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->RotateYGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->RotateZGizmoEntity->GetComponent().SetVisibility(true); + } + + // X Gizmos + GizmoSceneData->RotateXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); + if (GizmoSceneData->bRotateXGizmoActive) + { + GizmoSceneData->RotateXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->RotateYGizmoEntity->GetComponent().SetVisibility(false); + GizmoSceneData->RotateZGizmoEntity->GetComponent().SetVisibility(false); + } + + // Y Gizmos + GizmoSceneData->RotateYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); + if (GizmoSceneData->bRotateYGizmoActive) + { + GizmoSceneData->RotateYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->RotateXGizmoEntity->GetComponent().SetVisibility(false); + GizmoSceneData->RotateZGizmoEntity->GetComponent().SetVisibility(false); + } + + // Z Gizmos + GizmoSceneData->RotateZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); + if (GizmoSceneData->bRotateZGizmoActive) + { + GizmoSceneData->RotateZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->RotateXGizmoEntity->GetComponent().SetVisibility(false); + GizmoSceneData->RotateYGizmoEntity->GetComponent().SetVisibility(false); + } + } + + PerSceneIterator++; } } -bool GizmoManager::WasSelected(int Index) +bool GizmoManager::WasSelected(int Index, FEScene* Scene) { - DeactivateAllGizmo(); + if (Scene == nullptr) + return false; - if (SELECTED.SceneEntitiesUnderMouse[Index]->GetType() == FE_CAMERA) - return true; + FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(Scene->GetObjectID()); + if (GizmoSceneData == nullptr) + return false; - FEEntity* SelectedEntity = SELECTED.SceneEntitiesUnderMouse[Index]; + DeactivateAllGizmo(Scene); + + FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(Scene->GetObjectID()); + if (CurrentSelectionData == nullptr) + return false; + + FEEntity* SelectedEntity = CurrentSelectionData->SceneEntitiesUnderMouse[Index]; FETransformComponent& CurrentTransform = SelectedEntity->GetComponent(); - if (GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == TransformationXGizmoEntity->GetObjectID()) + if (GizmoSceneData->GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == GizmoSceneData->TransformationXGizmoEntity->GetObjectID()) { - bTransformationXGizmoActive = true; + GizmoSceneData->bTransformationXGizmoActive = true; } - else if (GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == TransformationYGizmoEntity->GetObjectID()) + else if (GizmoSceneData->GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == GizmoSceneData->TransformationYGizmoEntity->GetObjectID()) { - bTransformationYGizmoActive = true; + GizmoSceneData->bTransformationYGizmoActive = true; } - else if (GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == TransformationZGizmoEntity->GetObjectID()) + else if (GizmoSceneData->GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == GizmoSceneData->TransformationZGizmoEntity->GetObjectID()) { - bTransformationZGizmoActive = true; + GizmoSceneData->bTransformationZGizmoActive = true; } - else if (GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == TransformationXYGizmoEntity->GetObjectID()) + else if (GizmoSceneData->GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == GizmoSceneData->TransformationXYGizmoEntity->GetObjectID()) { - bTransformationXYGizmoActive = true; + GizmoSceneData->bTransformationXYGizmoActive = true; } - else if (GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == TransformationYZGizmoEntity->GetObjectID()) + else if (GizmoSceneData->GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == GizmoSceneData->TransformationYZGizmoEntity->GetObjectID()) { - bTransformationYZGizmoActive = true; + GizmoSceneData->bTransformationYZGizmoActive = true; } - else if (GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == TransformationXZGizmoEntity->GetObjectID()) + else if (GizmoSceneData->GizmosState == TRANSFORM_GIZMOS && SelectedEntity->GetObjectID() == GizmoSceneData->TransformationXZGizmoEntity->GetObjectID()) { - bTransformationXZGizmoActive = true; + GizmoSceneData->bTransformationXZGizmoActive = true; } - else if (GizmosState == SCALE_GIZMOS && SelectedEntity->GetObjectID() == ScaleXGizmoEntity->GetObjectID()) + else if (GizmoSceneData->GizmosState == SCALE_GIZMOS && SelectedEntity->GetObjectID() == GizmoSceneData->ScaleXGizmoEntity->GetObjectID()) { if (SelectedEntity != nullptr && CurrentTransform.IsUniformScalingSet()) { - bScaleXGizmoActive = true; - bScaleYGizmoActive = true; - bScaleZGizmoActive = true; + GizmoSceneData->bScaleXGizmoActive = true; + GizmoSceneData->bScaleYGizmoActive = true; + GizmoSceneData->bScaleZGizmoActive = true; } - bScaleXGizmoActive = true; + GizmoSceneData->bScaleXGizmoActive = true; } - else if (GizmosState == SCALE_GIZMOS && SelectedEntity->GetObjectID() == ScaleYGizmoEntity->GetObjectID()) + else if (GizmoSceneData->GizmosState == SCALE_GIZMOS && SelectedEntity->GetObjectID() == GizmoSceneData->ScaleYGizmoEntity->GetObjectID()) { if (SelectedEntity != nullptr && CurrentTransform.IsUniformScalingSet()) { - bScaleXGizmoActive = true; - bScaleYGizmoActive = true; - bScaleZGizmoActive = true; + GizmoSceneData->bScaleXGizmoActive = true; + GizmoSceneData->bScaleYGizmoActive = true; + GizmoSceneData->bScaleZGizmoActive = true; } - bScaleYGizmoActive = true; + GizmoSceneData->bScaleYGizmoActive = true; } - else if (GizmosState == SCALE_GIZMOS && SelectedEntity->GetObjectID() == ScaleZGizmoEntity->GetObjectID()) + else if (GizmoSceneData->GizmosState == SCALE_GIZMOS && SelectedEntity->GetObjectID() == GizmoSceneData->ScaleZGizmoEntity->GetObjectID()) { if (SelectedEntity != nullptr && CurrentTransform.IsUniformScalingSet()) { - bScaleXGizmoActive = true; - bScaleYGizmoActive = true; - bScaleZGizmoActive = true; + GizmoSceneData->bScaleXGizmoActive = true; + GizmoSceneData->bScaleYGizmoActive = true; + GizmoSceneData->bScaleZGizmoActive = true; } - bScaleZGizmoActive = true; + GizmoSceneData->bScaleZGizmoActive = true; } - else if (GizmosState == ROTATE_GIZMOS && SelectedEntity->GetObjectID() == RotateXGizmoEntity->GetObjectID()) + else if (GizmoSceneData->GizmosState == ROTATE_GIZMOS && SelectedEntity->GetObjectID() == GizmoSceneData->RotateXGizmoEntity->GetObjectID()) { - bRotateXGizmoActive = true; + GizmoSceneData->bRotateXGizmoActive = true; } - else if (GizmosState == ROTATE_GIZMOS && SelectedEntity->GetObjectID() == RotateYGizmoEntity->GetObjectID()) + else if (GizmoSceneData->GizmosState == ROTATE_GIZMOS && SelectedEntity->GetObjectID() == GizmoSceneData->RotateYGizmoEntity->GetObjectID()) { - bRotateYGizmoActive = true; + GizmoSceneData->bRotateYGizmoActive = true; } - else if (GizmosState == ROTATE_GIZMOS && SelectedEntity->GetObjectID() == RotateZGizmoEntity->GetObjectID()) + else if (GizmoSceneData->GizmosState == ROTATE_GIZMOS && SelectedEntity->GetObjectID() == GizmoSceneData->RotateZGizmoEntity->GetObjectID()) { - bRotateZGizmoActive = true; + GizmoSceneData->bRotateZGizmoActive = true; } else { @@ -451,22 +488,38 @@ bool GizmoManager::WasSelected(int Index) return true; } -glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal) +glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, FEScene* Scene) { - FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); - FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); + if (Scene == nullptr) + return glm::vec3(); + + FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(Scene->GetObjectID()); + if (GizmoSceneData == nullptr) + return glm::vec3(); + + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); + FEViewport* CurrentViewport = CAMERA_SYSTEM.GetMainCameraViewport(Scene); + glm::ivec2 ViewportPosition = glm::ivec2(CurrentViewport->GetX(), CurrentViewport->GetY()); + glm::ivec2 ViewportSize = glm::ivec2(CurrentViewport->GetWidth(), CurrentViewport->GetHeight()); + + FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(Scene); const glm::vec3 EntitySpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); - const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); + const glm::vec3 LastFrameMouseRay = GEOMETRY.CreateMouseRayToWorld(LastMouseX, LastMouseY, + CameraComponent.GetViewMatrix(), CameraComponent.GetProjectionMatrix(), + ViewportPosition, ViewportSize); + const glm::vec3 MouseRay = GEOMETRY.CreateMouseRayToWorld(MouseX, MouseY, + CameraComponent.GetViewMatrix(), CameraComponent.GetProjectionMatrix(), + ViewportPosition, ViewportSize); - const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); const glm::vec3 CameraPosition = CameraTransformComponent.GetPosition(FE_WORLD_SPACE); const float SignedDistanceToOrigin = glm::dot(PlaneNormal, EntitySpaceOriginInWorldSpace); const float Nominator = SignedDistanceToOrigin - glm::dot(CameraPosition, PlaneNormal); - const float LastDenominator = glm::dot(LastMouseRayVector, PlaneNormal); - const float Denominator = glm::dot(MouseRayVector, PlaneNormal); + const float LastDenominator = glm::dot(LastFrameMouseRay, PlaneNormal); + const float Denominator = glm::dot(MouseRay, PlaneNormal); if (Denominator == 0 || LastDenominator == 0) return glm::vec3(0.0f); @@ -474,28 +527,44 @@ glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal) const float LastIntersectionT = Nominator / LastDenominator; const float IntersectionT = Nominator / Denominator; - const glm::vec3 LastPointOnPlane = CameraPosition + LastIntersectionT * LastMouseRayVector; - const glm::vec3 PointOnPlane = CameraPosition + IntersectionT * MouseRayVector; + const glm::vec3 LastPointOnPlane = CameraPosition + LastIntersectionT * LastFrameMouseRay; + const glm::vec3 PointOnPlane = CameraPosition + IntersectionT * MouseRay; return PointOnPlane - LastPointOnPlane; } -glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, glm::vec3& LastMousePointOnPlane) +glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, glm::vec3& LastMousePointOnPlane, FEScene* Scene) { - FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); - FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); + if (Scene == nullptr) + return glm::vec3(); + + FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(Scene->GetObjectID()); + if (GizmoSceneData == nullptr) + return glm::vec3(); + + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); + FEViewport* CurrentViewport = CAMERA_SYSTEM.GetMainCameraViewport(Scene); + glm::ivec2 ViewportPosition = glm::ivec2(CurrentViewport->GetX(), CurrentViewport->GetY()); + glm::ivec2 ViewportSize = glm::ivec2(CurrentViewport->GetWidth(), CurrentViewport->GetHeight()); + + FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(Scene); const glm::vec3 EntitySpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); - const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); + const glm::vec3 LastFrameMouseRay = GEOMETRY.CreateMouseRayToWorld(LastMouseX, LastMouseY, + CameraComponent.GetViewMatrix(), CameraComponent.GetProjectionMatrix(), + ViewportPosition, ViewportSize); + const glm::vec3 MouseRay = GEOMETRY.CreateMouseRayToWorld(MouseX, MouseY, + CameraComponent.GetViewMatrix(), CameraComponent.GetProjectionMatrix(), + ViewportPosition, ViewportSize); - const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); const glm::vec3 CameraPosition = CameraTransformComponent.GetPosition(FE_WORLD_SPACE); const float SignedDistanceToOrigin = glm::dot(PlaneNormal, EntitySpaceOriginInWorldSpace); const float Nominator = SignedDistanceToOrigin - glm::dot(CameraPosition, PlaneNormal); - const float LastDenominator = glm::dot(LastMouseRayVector, PlaneNormal); - const float Denominator = glm::dot(MouseRayVector, PlaneNormal); + const float LastDenominator = glm::dot(LastFrameMouseRay, PlaneNormal); + const float Denominator = glm::dot(MouseRay, PlaneNormal); if (Denominator == 0 || LastDenominator == 0) return glm::vec3(0.0f); @@ -503,17 +572,36 @@ glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, const float LastIntersectionT = Nominator / LastDenominator; const float IntersectionT = Nominator / Denominator; - const glm::vec3 LastPointOnPlane = CameraPosition + LastIntersectionT * LastMouseRayVector; - const glm::vec3 PointOnPlane = CameraPosition + IntersectionT * MouseRayVector; + const glm::vec3 LastPointOnPlane = CameraPosition + LastIntersectionT * LastFrameMouseRay; + const glm::vec3 PointOnPlane = CameraPosition + IntersectionT * MouseRay; LastMousePointOnPlane = LastPointOnPlane; return PointOnPlane; } -void GizmoManager::MouseMoveTransformationGizmos() +void GizmoManager::MouseMoveTransformationGizmos(FEScene* Scene) { - FETransformComponent& CameraTransformComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); - FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); + if (Scene == nullptr) + return; + + FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(Scene->GetObjectID()); + if (GizmoSceneData == nullptr) + return; + + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); + FEViewport* CurrentViewport = CAMERA_SYSTEM.GetMainCameraViewport(Scene); + glm::ivec2 ViewportPosition = glm::ivec2(CurrentViewport->GetX(), CurrentViewport->GetY()); + glm::ivec2 ViewportSize = glm::ivec2(CurrentViewport->GetWidth(), CurrentViewport->GetHeight()); + + FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(Scene); + + const glm::vec3 LastFrameMouseRay = GEOMETRY.CreateMouseRayToWorld(LastMouseX, LastMouseY, + CameraComponent.GetViewMatrix(), CameraComponent.GetProjectionMatrix(), + ViewportPosition, ViewportSize); + const glm::vec3 MouseRay = GEOMETRY.CreateMouseRayToWorld(MouseX, MouseY, + CameraComponent.GetViewMatrix(), CameraComponent.GetProjectionMatrix(), + ViewportPosition, ViewportSize); float MouseRayParametricIntersection = 0.0f; float GizmoRayParametricIntersection = 0.0f; @@ -523,15 +611,13 @@ void GizmoManager::MouseMoveTransformationGizmos() bool bAppliedSomeChanges = false; - if (GIZMO_MANAGER.bTransformationXGizmoActive) + if (GizmoSceneData->bTransformationXGizmoActive) { - const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); - GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), LastMouseRayVector, + GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), LastFrameMouseRay, glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f), LastFrameMouseRayParametricIntersection, LastFrameGizmoRayParametricIntersection); - const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); - GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRayVector, + GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRay, glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f), MouseRayParametricIntersection, GizmoRayParametricIntersection); @@ -543,15 +629,13 @@ void GizmoManager::MouseMoveTransformationGizmos() } } - if (GIZMO_MANAGER.bTransformationYGizmoActive) + if (GizmoSceneData->bTransformationYGizmoActive) { - const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); - GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), LastMouseRayVector, + GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), LastFrameMouseRay, glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 1.0f, 0.0f), LastFrameMouseRayParametricIntersection, LastFrameGizmoRayParametricIntersection); - const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); - GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRayVector, + GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRay, glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 1.0f, 0.0f), MouseRayParametricIntersection, GizmoRayParametricIntersection); @@ -563,15 +647,13 @@ void GizmoManager::MouseMoveTransformationGizmos() } } - if (GIZMO_MANAGER.bTransformationZGizmoActive) + if (GizmoSceneData->bTransformationZGizmoActive) { - const glm::vec3 LastMouseRayVector = SELECTED.MouseRay(LastMouseX, LastMouseY); - GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), LastMouseRayVector, + GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), LastFrameMouseRay, glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 0.0f, 1.0f), LastFrameMouseRayParametricIntersection, LastFrameGizmoRayParametricIntersection); - const glm::vec3 MouseRayVector = SELECTED.MouseRay(MouseX, MouseY); - GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRayVector, + GEOMETRY.RaysIntersection(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRay, glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), glm::vec3(0.0f, 0.0f, 1.0f), MouseRayParametricIntersection, GizmoRayParametricIntersection); @@ -583,9 +665,9 @@ void GizmoManager::MouseMoveTransformationGizmos() } } - if (GIZMO_MANAGER.bTransformationXYGizmoActive) + if (GizmoSceneData->bTransformationXYGizmoActive) { - const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(0.0f, 0.0f, 1.0f)); + const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(0.0f, 0.0f, 1.0f), Scene); if (!GEOMETRY.IsEpsilonEqual(Difference, glm::vec3(0.0f))) { bAppliedSomeChanges = true; @@ -593,9 +675,9 @@ void GizmoManager::MouseMoveTransformationGizmos() } } - if (GIZMO_MANAGER.bTransformationYZGizmoActive) + if (GizmoSceneData->bTransformationYZGizmoActive) { - const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(1.0f, 0.0f, 0.0f)); + const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(1.0f, 0.0f, 0.0f), Scene); if (!GEOMETRY.IsEpsilonEqual(Difference, glm::vec3(0.0f))) { bAppliedSomeChanges = true; @@ -603,9 +685,9 @@ void GizmoManager::MouseMoveTransformationGizmos() } } - if (GIZMO_MANAGER.bTransformationXZGizmoActive) + if (GizmoSceneData->bTransformationXZGizmoActive) { - const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(0.0f, 1.0f, 0.0f)); + const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(0.0f, 1.0f, 0.0f), Scene); if (!GEOMETRY.IsEpsilonEqual(Difference, glm::vec3(0.0f))) { bAppliedSomeChanges = true; @@ -614,17 +696,24 @@ void GizmoManager::MouseMoveTransformationGizmos() } if (bAppliedSomeChanges) - ApplyChangesToSelectedObject(ObjTransform); + ApplyChangesToSelectedObject(ObjTransform, Scene); } -void GizmoManager::MouseMoveScaleGizmos() +void GizmoManager::MouseMoveScaleGizmos(FEScene* Scene) { - FECameraComponent& CameraComponent = EDITOR.GetCurrentEditorCameraEntity()->GetComponent(); - FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); + if (Scene == nullptr) + return; + + FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(Scene->GetObjectID()); + if (GizmoSceneData == nullptr) + return; + + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); + FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(Scene); - if (GIZMO_MANAGER.bScaleXGizmoActive && GIZMO_MANAGER.bScaleYGizmoActive && GIZMO_MANAGER.bScaleZGizmoActive) + if (GizmoSceneData->bScaleXGizmoActive && GizmoSceneData->bScaleYGizmoActive && GizmoSceneData->bScaleZGizmoActive) { - const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(-CameraComponent.GetForward()); + const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(-CameraComponent.GetForward(), Scene); float Magnitude = Difference.x + Difference.y + Difference.z; glm::vec3 EntityScale = ObjTransform.GetScale(); @@ -638,44 +727,51 @@ void GizmoManager::MouseMoveScaleGizmos() EntityScale += Magnitude; ObjTransform.SetScale(EntityScale); } - else if (GIZMO_MANAGER.bScaleXGizmoActive || GIZMO_MANAGER.bScaleYGizmoActive || GIZMO_MANAGER.bScaleZGizmoActive) + else if (GizmoSceneData->bScaleXGizmoActive || GizmoSceneData->bScaleYGizmoActive || GizmoSceneData->bScaleZGizmoActive) { - if (GIZMO_MANAGER.bScaleXGizmoActive) + if (GizmoSceneData->bScaleXGizmoActive) { - const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(0.0f, 0.0f, 1.0f)); + const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(0.0f, 0.0f, 1.0f), Scene); glm::vec3 EntityScale = ObjTransform.GetScale(); EntityScale.x += Difference.x; ObjTransform.SetScale(EntityScale); } - if (GIZMO_MANAGER.bScaleYGizmoActive) + if (GizmoSceneData->bScaleYGizmoActive) { - const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(0.0f, 0.0f, 1.0f)); + const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(0.0f, 0.0f, 1.0f), Scene); glm::vec3 EntityScale = ObjTransform.GetScale(); EntityScale.y += Difference.y; ObjTransform.SetScale(EntityScale); } - if (GIZMO_MANAGER.bScaleZGizmoActive) + if (GizmoSceneData->bScaleZGizmoActive) { - const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(0.0f, 1.0f, 0.0f)); + const glm::vec3 Difference = GetMousePositionDifferenceOnPlane(glm::vec3(0.0f, 1.0f, 0.0f), Scene); glm::vec3 EntityScale = ObjTransform.GetScale(); EntityScale.z += Difference.z; ObjTransform.SetScale(EntityScale); } } - ApplyChangesToSelectedObject(ObjTransform); + ApplyChangesToSelectedObject(ObjTransform, Scene); } -void GizmoManager::MouseMoveRotateGizmos() +void GizmoManager::MouseMoveRotateGizmos(FEScene* Scene) { - if (!GIZMO_MANAGER.bRotateXGizmoActive && - !GIZMO_MANAGER.bRotateYGizmoActive && - !GIZMO_MANAGER.bRotateZGizmoActive) + if (Scene == nullptr) + return; + + FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(Scene->GetObjectID()); + if (GizmoSceneData == nullptr) + return; + + if (!GizmoSceneData->bRotateXGizmoActive && + !GizmoSceneData->bRotateYGizmoActive && + !GizmoSceneData->bRotateZGizmoActive) return; - FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(); + FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(Scene); const float DifferenceX = static_cast(MouseX - LastMouseX); const float DifferenceY = static_cast(MouseY - LastMouseY); @@ -684,257 +780,313 @@ void GizmoManager::MouseMoveRotateGizmos() glm::vec3 AxisOfRotation = glm::vec3(0.0f, 0.0f, 0.0f); - if (GIZMO_MANAGER.bRotateXGizmoActive) + if (GizmoSceneData->bRotateXGizmoActive) AxisOfRotation = glm::vec3(1.0f, 0.0f, 0.0f); - if (GIZMO_MANAGER.bRotateYGizmoActive) + if (GizmoSceneData->bRotateYGizmoActive) AxisOfRotation = glm::vec3(0.0f, 1.0f, 0.0f); - if (GIZMO_MANAGER.bRotateZGizmoActive) + if (GizmoSceneData->bRotateZGizmoActive) AxisOfRotation = glm::vec3(0.0f, 0.0f, 1.0f); ObjTransform.RotateAroundAxis(AxisOfRotation, Difference, FE_WORLD_SPACE); - ApplyChangesToSelectedObject(ObjTransform); + ApplyChangesToSelectedObject(ObjTransform, Scene); } -void GizmoManager::MouseMove(const double LastMouseX, const double LastMouseY, const double MouseX, const double MouseY) +void GizmoManager::MouseMove(const double LastMouseX, const double LastMouseY, const double MouseX, const double MouseY, FEScene* Scene) { + if (Scene == nullptr) + return; + + FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(Scene->GetObjectID()); + if (GizmoSceneData == nullptr) + return; + this->LastMouseX = LastMouseX; this->LastMouseY = LastMouseY; this->MouseX = MouseX; this->MouseY = MouseY; - if (GizmosState == TRANSFORM_GIZMOS) + if (GizmoSceneData->GizmosState == TRANSFORM_GIZMOS) { - MouseMoveTransformationGizmos(); + MouseMoveTransformationGizmos(Scene); } - else if (GizmosState == SCALE_GIZMOS) + else if (GizmoSceneData->GizmosState == SCALE_GIZMOS) { - MouseMoveScaleGizmos(); + MouseMoveScaleGizmos(Scene); } - else if (GizmosState == ROTATE_GIZMOS) + else if (GizmoSceneData->GizmosState == ROTATE_GIZMOS) { - MouseMoveRotateGizmos(); + MouseMoveRotateGizmos(Scene); } } -void GizmoManager::OnSelectedObjectUpdate() +void GizmoManager::OnSelectedObjectUpdate(FEScene* Scene) { - if (SELECTED.GetSelected() == nullptr) + if (Scene == nullptr) + return; + + FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(Scene->GetObjectID()); + if (GizmoSceneData == nullptr) + return; + + if (SELECTED.GetSelected(Scene) == nullptr) { - GIZMO_MANAGER.HideAllGizmo(); + GIZMO_MANAGER.HideAllGizmo(Scene); } else { - if (SELECTED.GetSelected() != nullptr && SELECTED.GetSelected()->HasComponent()) + if (SELECTED.GetSelected(Scene) != nullptr && SELECTED.GetSelected(Scene)->HasComponent()) { if (TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE) { - GIZMO_MANAGER.HideAllGizmo(); + GIZMO_MANAGER.HideAllGizmo(Scene); return; } } - if (GIZMO_MANAGER.GizmosState == TRANSFORM_GIZMOS) + if (GizmoSceneData->GizmosState == TRANSFORM_GIZMOS) { - GIZMO_MANAGER.TransformationXGizmoEntity->GetComponent().SetVisibility(true); - GIZMO_MANAGER.TransformationYGizmoEntity->GetComponent().SetVisibility(true); - GIZMO_MANAGER.TransformationZGizmoEntity->GetComponent().SetVisibility(true); - GIZMO_MANAGER.TransformationXYGizmoEntity->GetComponent().SetVisibility(true); - GIZMO_MANAGER.TransformationYZGizmoEntity->GetComponent().SetVisibility(true); - GIZMO_MANAGER.TransformationXZGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->TransformationXGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->TransformationYGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->TransformationZGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->TransformationXYGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->TransformationYZGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->TransformationXZGizmoEntity->GetComponent().SetVisibility(true); } - else if (GIZMO_MANAGER.GizmosState == SCALE_GIZMOS) + else if (GizmoSceneData->GizmosState == SCALE_GIZMOS) { - GIZMO_MANAGER.ScaleXGizmoEntity->GetComponent().SetVisibility(true); - GIZMO_MANAGER.ScaleYGizmoEntity->GetComponent().SetVisibility(true); - GIZMO_MANAGER.ScaleZGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->ScaleXGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->ScaleYGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->ScaleZGizmoEntity->GetComponent().SetVisibility(true); } - else if (GIZMO_MANAGER.GizmosState == ROTATE_GIZMOS) + else if (GizmoSceneData->GizmosState == ROTATE_GIZMOS) { - GIZMO_MANAGER.RotateXGizmoEntity->GetComponent().SetVisibility(true); - GIZMO_MANAGER.RotateYGizmoEntity->GetComponent().SetVisibility(true); - GIZMO_MANAGER.RotateZGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->RotateXGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->RotateYGizmoEntity->GetComponent().SetVisibility(true); + GizmoSceneData->RotateZGizmoEntity->GetComponent().SetVisibility(true); } } } -FETransformComponent GizmoManager::GetTransformComponentOfSelectedObject() +FETransformComponent GizmoManager::GetTransformComponentOfSelectedObject(FEScene* Scene) { - if (SELECTED.GetSelected() == nullptr) + if (Scene == nullptr) return FETransformComponent(); - if (SELECTED.InstancedSubObjectIndexSelected != -1 && SELECTED.GetSelected()->HasComponent()) + if (SELECTED.GetSelected(Scene) == nullptr) + return FETransformComponent(); + + FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(Scene->GetObjectID()); + if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1 && SELECTED.GetSelected(Scene)->HasComponent()) { - FEInstancedComponent& InstancedComponent = SELECTED.GetSelected()->GetComponent(); - FETransformComponent& DummyTransform = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(SELECTED.InstancedSubObjectIndexSelected)); + FEInstancedComponent& InstancedComponent = SELECTED.GetSelected(Scene)->GetComponent(); + FETransformComponent& DummyTransform = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(CurrentSelectionData->InstancedSubObjectIndexSelected)); DummyTransform.SetSceneIndependent(true); return DummyTransform; } else { - return SELECTED.GetSelected()->GetComponent(); + return SELECTED.GetSelected(Scene)->GetComponent(); } } -void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent Changes) +void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent Changes, FEScene* Scene) { - if (SELECTED.GetSelected() == nullptr) + if (Scene == nullptr) + return; + + if (SELECTED.GetSelected(Scene) == nullptr) return; - if (SELECTED.InstancedSubObjectIndexSelected != -1) + FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(Scene->GetObjectID()); + if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1) { - INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(SELECTED.GetSelected(), SELECTED.InstancedSubObjectIndexSelected, Changes.GetWorldMatrix()); + INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(SELECTED.GetSelected(Scene), CurrentSelectionData->InstancedSubObjectIndexSelected, Changes.GetWorldMatrix()); } else { - SELECTED.GetSelected()->GetComponent() = Changes; + SELECTED.GetSelected(Scene)->GetComponent() = Changes; } } -void GizmoManager::ReInitializeEntities() +void GizmoManager::ClearAllSceneData() { - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (!ActiveScenes.empty()) - { - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - ParentGizmoEntity = CurrentScene->CreateEntity("ParentGizmoEntity"); - ParentGizmoGraphNode = CurrentScene->SceneGraph.GetNodeByEntityID(ParentGizmoEntity->GetObjectID()); - - // TransformationXGizmo - TransformationXGizmoEntity = CurrentScene->CreateEntity("TransformationXGizmoEntity"); - TransformationXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXGizmoGM")[0]); - TransformationXGizmoEntity->SetName("TransformationXGizmoEntity"); - TransformationXGizmoEntity->GetComponent().SetCastShadows(false); - TransformationXGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - TransformationXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - TransformationXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // TransformationYGizmo - TransformationYGizmoEntity = CurrentScene->CreateEntity("TransformationYGizmoEntity"); - TransformationYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYGizmoGM")[0]); - TransformationYGizmoEntity->SetName("TransformationYGizmoEntity"); - TransformationYGizmoEntity->GetComponent().SetCastShadows(false); - TransformationYGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - TransformationYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - TransformationYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // TransformationZGizmo - TransformationZGizmoEntity = CurrentScene->CreateEntity("TransformationZGizmoEntity"); - TransformationZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationZGizmoGM")[0]); - TransformationZGizmoEntity->SetName("TransformationZGizmoEntity"); - TransformationZGizmoEntity->GetComponent().SetCastShadows(false); - TransformationZGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - TransformationZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - TransformationZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // Plane gizmos - TransformationXYGizmoEntity = CurrentScene->CreateEntity("TransformationXYGizmoEntity"); - TransformationXYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXYGizmoGM")[0]); - TransformationXYGizmoEntity->SetName("TransformationXYGizmoEntity"); - TransformationXYGizmoEntity->GetComponent().SetCastShadows(false); - TransformationXYGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationXYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - TransformationXYGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); - TransformationXYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); - TransformationXYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - TransformationYZGizmoEntity = CurrentScene->CreateEntity("TransformationYZGizmoEntity"); - TransformationYZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYZGizmoGM")[0]); - TransformationYZGizmoEntity->SetName("TransformationYZGizmoEntity"); - TransformationYZGizmoEntity->GetComponent().SetCastShadows(false); - TransformationYZGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationYZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - TransformationYZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); - TransformationYZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); - TransformationYZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - TransformationXZGizmoEntity = CurrentScene->CreateEntity("TransformationXZGizmoEntity"); - TransformationXZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXZGizmoGM")[0]); - TransformationXZGizmoEntity->SetName("TransformationXZGizmoEntity"); - TransformationXZGizmoEntity->GetComponent().SetCastShadows(false); - TransformationXZGizmoEntity->GetComponent().SetReceivingShadows(false); - TransformationXZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - TransformationXZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); - TransformationXZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); - TransformationXZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // ScaleXGizmo - ScaleXGizmoEntity = CurrentScene->CreateEntity("ScaleXGizmoEntity"); - ScaleXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleXGizmoGM")[0]); - ScaleXGizmoEntity->SetName("ScaleXGizmoEntity"); - ScaleXGizmoEntity->GetComponent().SetCastShadows(false); - ScaleXGizmoEntity->GetComponent().SetReceivingShadows(false); - ScaleXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - ScaleXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - ScaleXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(ScaleXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // ScaleYGizmo - ScaleYGizmoEntity = CurrentScene->CreateEntity("ScaleYGizmoEntity"); - ScaleYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleYGizmoGM")[0]); - ScaleYGizmoEntity->SetName("ScaleYGizmoEntity"); - ScaleYGizmoEntity->GetComponent().SetCastShadows(false); - ScaleYGizmoEntity->GetComponent().SetReceivingShadows(false); - ScaleYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - ScaleYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - ScaleYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(ScaleYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // ScaleZGizmo - ScaleZGizmoEntity = CurrentScene->CreateEntity("ScaleZGizmoEntity"); - ScaleZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleZGizmoGM")[0]); - ScaleZGizmoEntity->SetName("ScaleZGizmoEntity"); - ScaleZGizmoEntity->GetComponent().SetCastShadows(false); - ScaleZGizmoEntity->GetComponent().SetReceivingShadows(false); - ScaleZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - ScaleZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); - ScaleZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(ScaleZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // RotateXGizmo - RotateXGizmoEntity = CurrentScene->CreateEntity("RotateXGizmoEntity"); - RotateXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateXGizmoGM")[0]); - RotateXGizmoEntity->SetName("RotateXGizmoEntity"); - RotateXGizmoEntity->GetComponent().SetCastShadows(false); - RotateXGizmoEntity->GetComponent().SetReceivingShadows(false); - RotateXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - RotateXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateXGizmoEntity->GetComponent().SetRotation(RotateXStandardRotation); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(RotateXGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // RotateYGizmo - RotateYGizmoEntity = CurrentScene->CreateEntity("RotateYGizmoEntity"); - RotateYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateYGizmoGM")[0]); - RotateYGizmoEntity->SetName("RotateYGizmoEntity"); - RotateYGizmoEntity->GetComponent().SetCastShadows(false); - RotateYGizmoEntity->GetComponent().SetReceivingShadows(false); - RotateYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - RotateYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateYGizmoEntity->GetComponent().SetRotation(RotateYStandardRotation); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(RotateYGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); - - // RotateZGizmo - RotateZGizmoEntity = CurrentScene->CreateEntity("RotateZGizmoEntity"); - RotateZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateZGizmoGM")[0]); - RotateZGizmoEntity->SetName("RotateZGizmoEntity"); - RotateZGizmoEntity->GetComponent().SetCastShadows(false); - RotateZGizmoEntity->GetComponent().SetReceivingShadows(false); - RotateZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); - RotateZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); - RotateZGizmoEntity->GetComponent().SetRotation(RotateZStandardRotation); - CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(RotateZGizmoEntity->GetObjectID())->GetObjectID(), ParentGizmoGraphNode->GetObjectID(), false); + auto PerSceneIterator = PerSceneData.begin(); + while (PerSceneIterator != PerSceneData.end()) + { + delete PerSceneIterator->second; + PerSceneIterator++; } + + PerSceneData.clear(); +} + +void GizmoManager::ClearSceneData(const std::string& SceneID) +{ + auto FoundSceneData = PerSceneData.find(SceneID); + if (FoundSceneData != PerSceneData.end()) + { + delete FoundSceneData->second; + PerSceneData.erase(FoundSceneData); + } +} + +void GizmoManager::AddSceneData(const std::string& SceneID) +{ + FEScene* CurrentScene = SCENE_MANAGER.GetScene(SceneID); + if (CurrentScene == nullptr) + return; + + PerSceneData[SceneID] = new FEGizmoSceneData(); + PerSceneData[SceneID]->SceneID = SceneID; + + PerSceneData[SceneID]->ParentGizmoEntity = CurrentScene->CreateEntity("ParentGizmoEntity"); + PerSceneData[SceneID]->ParentGizmoGraphNode = CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->ParentGizmoEntity->GetObjectID()); + + // TransformationXGizmo + PerSceneData[SceneID]->TransformationXGizmoEntity = CurrentScene->CreateEntity("TransformationXGizmoEntity"); + PerSceneData[SceneID]->TransformationXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXGizmoGM")[0]); + PerSceneData[SceneID]->TransformationXGizmoEntity->SetName("TransformationXGizmoEntity"); + PerSceneData[SceneID]->TransformationXGizmoEntity->GetComponent().SetCastShadows(false); + PerSceneData[SceneID]->TransformationXGizmoEntity->GetComponent().SetReceivingShadows(false); + PerSceneData[SceneID]->TransformationXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + PerSceneData[SceneID]->TransformationXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + PerSceneData[SceneID]->TransformationXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->TransformationXGizmoEntity->GetObjectID())->GetObjectID(), PerSceneData[SceneID]->ParentGizmoGraphNode->GetObjectID(), false); + + // TransformationYGizmo + PerSceneData[SceneID]->TransformationYGizmoEntity = CurrentScene->CreateEntity("TransformationYGizmoEntity"); + PerSceneData[SceneID]->TransformationYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYGizmoGM")[0]); + PerSceneData[SceneID]->TransformationYGizmoEntity->SetName("TransformationYGizmoEntity"); + PerSceneData[SceneID]->TransformationYGizmoEntity->GetComponent().SetCastShadows(false); + PerSceneData[SceneID]->TransformationYGizmoEntity->GetComponent().SetReceivingShadows(false); + PerSceneData[SceneID]->TransformationYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + PerSceneData[SceneID]->TransformationYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + PerSceneData[SceneID]->TransformationYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->TransformationYGizmoEntity->GetObjectID())->GetObjectID(), PerSceneData[SceneID]->ParentGizmoGraphNode->GetObjectID(), false); + + // TransformationZGizmo + PerSceneData[SceneID]->TransformationZGizmoEntity = CurrentScene->CreateEntity("TransformationZGizmoEntity"); + PerSceneData[SceneID]->TransformationZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationZGizmoGM")[0]); + PerSceneData[SceneID]->TransformationZGizmoEntity->SetName("TransformationZGizmoEntity"); + PerSceneData[SceneID]->TransformationZGizmoEntity->GetComponent().SetCastShadows(false); + PerSceneData[SceneID]->TransformationZGizmoEntity->GetComponent().SetReceivingShadows(false); + PerSceneData[SceneID]->TransformationZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + PerSceneData[SceneID]->TransformationZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + PerSceneData[SceneID]->TransformationZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->TransformationZGizmoEntity->GetObjectID())->GetObjectID(), PerSceneData[SceneID]->ParentGizmoGraphNode->GetObjectID(), false); + + // Plane gizmos + PerSceneData[SceneID]->TransformationXYGizmoEntity = CurrentScene->CreateEntity("TransformationXYGizmoEntity"); + PerSceneData[SceneID]->TransformationXYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXYGizmoGM")[0]); + PerSceneData[SceneID]->TransformationXYGizmoEntity->SetName("TransformationXYGizmoEntity"); + PerSceneData[SceneID]->TransformationXYGizmoEntity->GetComponent().SetCastShadows(false); + PerSceneData[SceneID]->TransformationXYGizmoEntity->GetComponent().SetReceivingShadows(false); + PerSceneData[SceneID]->TransformationXYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + PerSceneData[SceneID]->TransformationXYGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.005f, 0.0f)); + PerSceneData[SceneID]->TransformationXYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale, GizmosScale * 0.02f)); + PerSceneData[SceneID]->TransformationXYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), PerSceneData[SceneID]->ParentGizmoGraphNode->GetObjectID(), false); + + PerSceneData[SceneID]->TransformationYZGizmoEntity = CurrentScene->CreateEntity("TransformationYZGizmoEntity"); + PerSceneData[SceneID]->TransformationYZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYZGizmoGM")[0]); + PerSceneData[SceneID]->TransformationYZGizmoEntity->SetName("TransformationYZGizmoEntity"); + PerSceneData[SceneID]->TransformationYZGizmoEntity->GetComponent().SetCastShadows(false); + PerSceneData[SceneID]->TransformationYZGizmoEntity->GetComponent().SetReceivingShadows(false); + PerSceneData[SceneID]->TransformationYZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + PerSceneData[SceneID]->TransformationYZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.0f, 0.005f, 0.005f)); + PerSceneData[SceneID]->TransformationYZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 0.02f, GizmosScale, GizmosScale)); + PerSceneData[SceneID]->TransformationYZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), PerSceneData[SceneID]->ParentGizmoGraphNode->GetObjectID(), false); + + PerSceneData[SceneID]->TransformationXZGizmoEntity = CurrentScene->CreateEntity("TransformationXZGizmoEntity"); + PerSceneData[SceneID]->TransformationXZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXZGizmoGM")[0]); + PerSceneData[SceneID]->TransformationXZGizmoEntity->SetName("TransformationXZGizmoEntity"); + PerSceneData[SceneID]->TransformationXZGizmoEntity->GetComponent().SetCastShadows(false); + PerSceneData[SceneID]->TransformationXZGizmoEntity->GetComponent().SetReceivingShadows(false); + PerSceneData[SceneID]->TransformationXZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + PerSceneData[SceneID]->TransformationXZGizmoEntity->GetComponent().SetPosition(glm::vec3(0.005f, 0.0f, 0.005f)); + PerSceneData[SceneID]->TransformationXZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale, GizmosScale * 0.02f, GizmosScale)); + PerSceneData[SceneID]->TransformationXZGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, 0.0f)); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->TransformationXZGizmoEntity->GetObjectID())->GetObjectID(), PerSceneData[SceneID]->ParentGizmoGraphNode->GetObjectID(), false); + + // ScaleXGizmo + PerSceneData[SceneID]->ScaleXGizmoEntity = CurrentScene->CreateEntity("ScaleXGizmoEntity"); + PerSceneData[SceneID]->ScaleXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleXGizmoGM")[0]); + PerSceneData[SceneID]->ScaleXGizmoEntity->SetName("ScaleXGizmoEntity"); + PerSceneData[SceneID]->ScaleXGizmoEntity->GetComponent().SetCastShadows(false); + PerSceneData[SceneID]->ScaleXGizmoEntity->GetComponent().SetReceivingShadows(false); + PerSceneData[SceneID]->ScaleXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + PerSceneData[SceneID]->ScaleXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + PerSceneData[SceneID]->ScaleXGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f, 0.0f, -90.0f)); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->ScaleXGizmoEntity->GetObjectID())->GetObjectID(), PerSceneData[SceneID]->ParentGizmoGraphNode->GetObjectID(), false); + + // ScaleYGizmo + PerSceneData[SceneID]->ScaleYGizmoEntity = CurrentScene->CreateEntity("ScaleYGizmoEntity"); + PerSceneData[SceneID]->ScaleYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleYGizmoGM")[0]); + PerSceneData[SceneID]->ScaleYGizmoEntity->SetName("ScaleYGizmoEntity"); + PerSceneData[SceneID]->ScaleYGizmoEntity->GetComponent().SetCastShadows(false); + PerSceneData[SceneID]->ScaleYGizmoEntity->GetComponent().SetReceivingShadows(false); + PerSceneData[SceneID]->ScaleYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + PerSceneData[SceneID]->ScaleYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + PerSceneData[SceneID]->ScaleYGizmoEntity->GetComponent().SetRotation(glm::vec3(0.0f)); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->ScaleYGizmoEntity->GetObjectID())->GetObjectID(), PerSceneData[SceneID]->ParentGizmoGraphNode->GetObjectID(), false); + + // ScaleZGizmo + PerSceneData[SceneID]->ScaleZGizmoEntity = CurrentScene->CreateEntity("ScaleZGizmoEntity"); + PerSceneData[SceneID]->ScaleZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleZGizmoGM")[0]); + PerSceneData[SceneID]->ScaleZGizmoEntity->SetName("ScaleZGizmoEntity"); + PerSceneData[SceneID]->ScaleZGizmoEntity->GetComponent().SetCastShadows(false); + PerSceneData[SceneID]->ScaleZGizmoEntity->GetComponent().SetReceivingShadows(false); + PerSceneData[SceneID]->ScaleZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + PerSceneData[SceneID]->ScaleZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale)); + PerSceneData[SceneID]->ScaleZGizmoEntity->GetComponent().SetRotation(glm::vec3(90.0f, 0.0f, 90.0f)); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->ScaleZGizmoEntity->GetObjectID())->GetObjectID(), PerSceneData[SceneID]->ParentGizmoGraphNode->GetObjectID(), false); + + // RotateXGizmo + PerSceneData[SceneID]->RotateXGizmoEntity = CurrentScene->CreateEntity("RotateXGizmoEntity"); + PerSceneData[SceneID]->RotateXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateXGizmoGM")[0]); + PerSceneData[SceneID]->RotateXGizmoEntity->SetName("RotateXGizmoEntity"); + PerSceneData[SceneID]->RotateXGizmoEntity->GetComponent().SetCastShadows(false); + PerSceneData[SceneID]->RotateXGizmoEntity->GetComponent().SetReceivingShadows(false); + PerSceneData[SceneID]->RotateXGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + PerSceneData[SceneID]->RotateXGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); + PerSceneData[SceneID]->RotateXGizmoEntity->GetComponent().SetRotation(RotateXStandardRotation); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->RotateXGizmoEntity->GetObjectID())->GetObjectID(), PerSceneData[SceneID]->ParentGizmoGraphNode->GetObjectID(), false); + + // RotateYGizmo + PerSceneData[SceneID]->RotateYGizmoEntity = CurrentScene->CreateEntity("RotateYGizmoEntity"); + PerSceneData[SceneID]->RotateYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateYGizmoGM")[0]); + PerSceneData[SceneID]->RotateYGizmoEntity->SetName("RotateYGizmoEntity"); + PerSceneData[SceneID]->RotateYGizmoEntity->GetComponent().SetCastShadows(false); + PerSceneData[SceneID]->RotateYGizmoEntity->GetComponent().SetReceivingShadows(false); + PerSceneData[SceneID]->RotateYGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + PerSceneData[SceneID]->RotateYGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); + PerSceneData[SceneID]->RotateYGizmoEntity->GetComponent().SetRotation(RotateYStandardRotation); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->RotateYGizmoEntity->GetObjectID())->GetObjectID(), PerSceneData[SceneID]->ParentGizmoGraphNode->GetObjectID(), false); + + // RotateZGizmo + PerSceneData[SceneID]->RotateZGizmoEntity = CurrentScene->CreateEntity("RotateZGizmoEntity"); + PerSceneData[SceneID]->RotateZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateZGizmoGM")[0]); + PerSceneData[SceneID]->RotateZGizmoEntity->SetName("RotateZGizmoEntity"); + PerSceneData[SceneID]->RotateZGizmoEntity->GetComponent().SetCastShadows(false); + PerSceneData[SceneID]->RotateZGizmoEntity->GetComponent().SetReceivingShadows(false); + PerSceneData[SceneID]->RotateZGizmoEntity->GetComponent().SetIsPostprocessApplied(false); + PerSceneData[SceneID]->RotateZGizmoEntity->GetComponent().SetScale(glm::vec3(GizmosScale * 2.0f)); + PerSceneData[SceneID]->RotateZGizmoEntity->GetComponent().SetRotation(RotateZStandardRotation); + CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->RotateZGizmoEntity->GetObjectID())->GetObjectID(), PerSceneData[SceneID]->ParentGizmoGraphNode->GetObjectID(), false); +} + +FEGizmoSceneData* GizmoManager::GetSceneData(const std::string& SceneID) +{ + auto FoundScene = PerSceneData.find(SceneID); + if (FoundScene != PerSceneData.end()) + { + return FoundScene->second; + } + + return nullptr; } \ No newline at end of file diff --git a/FEEditorGizmoManager.h b/FEEditorGizmoManager.h index 567e89b..ec3572f 100644 --- a/FEEditorGizmoManager.h +++ b/FEEditorGizmoManager.h @@ -4,21 +4,20 @@ #include "FEEditorSelectedObject.h" using namespace FocalEngine; -class FEEditor; -struct SelectedObject; - const int TRANSFORM_GIZMOS = 0; const int SCALE_GIZMOS = 1; const int ROTATE_GIZMOS = 2; -class GizmoManager +class FEGizmoSceneData { - friend FEEditor; - friend SelectedObject; -public: - SINGLETON_PUBLIC_PART(GizmoManager) - - float GizmosScale = 0.00175f; + friend class FEEditor; + friend class FEEditorSelectedObject; + friend class GizmoManager; + friend class FEEditorInspectorWindow; + friend class GyzmosSettingsWindow; + + std::string SceneID = ""; + int GizmosState = TRANSFORM_GIZMOS; // Parent Gizmo Entity @@ -66,35 +65,74 @@ class GizmoManager FETexture* TransformationGizmoIcon = nullptr; FETexture* ScaleGizmoIcon = nullptr; FETexture* RotateGizmoIcon = nullptr; +}; + +class GizmoManager +{ + friend class FEEditor; + friend class FEProjectManager; + friend class GyzmosSettingsWindow; +public: + SINGLETON_PUBLIC_PART(GizmoManager) + + float GizmosScale = 0.00175f; + int GizmosState = TRANSFORM_GIZMOS; + + glm::vec3 RotateXStandardRotation = glm::vec3(0.0f, 0.0f, -90.0f); + glm::vec3 RotateYStandardRotation = glm::vec3(0.0f); + glm::vec3 RotateZStandardRotation = glm::vec3(90.0f, 0.0f, 90.0f); + + FETexture* TransformationGizmoIcon = nullptr; + FETexture* ScaleGizmoIcon = nullptr; + FETexture* RotateGizmoIcon = nullptr; void InitializeResources(); - void ReInitializeEntities(); - void DeactivateAllGizmo(); - void HideAllGizmo(); - void UpdateGizmoState(int NewState); - void Render(); - bool WasSelected(int Index); + void DeactivateAllGizmo(FEScene* Scene); + void HideAllGizmo(FEScene* Scene); + void UpdateGizmoState(int NewState, FEScene* Scene); + void Update(); + bool WasSelected(int Index, FEScene* Scene); - void MouseMove(double LastMouseX, double LastMouseY, double MouseX, double MouseY); + void MouseMove(double LastMouseX, double LastMouseY, double MouseX, double MouseY, FEScene* Scene); private: SINGLETON_PRIVATE_PART(GizmoManager) double LastMouseX = 0, LastMouseY = 0, MouseX = 0, MouseY = 0; - glm::vec3 GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal); - glm::vec3 GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, glm::vec3& LastMousePointOnPlane); + FEGameModel* TransformationXGizmoGM = nullptr; + FEGameModel* TransformationYGizmoGM = nullptr; + FEGameModel* TransformationZGizmoGM = nullptr; + + FEGameModel* TransformationXYGizmoGM = nullptr; + FEGameModel* TransformationYZGizmoGM = nullptr; + FEGameModel* TransformationXZGizmoGM = nullptr; + + FEGameModel* ScaleXGizmoGM = nullptr; + FEGameModel* ScaleYGizmoGM = nullptr; + FEGameModel* ScaleZGizmoGM = nullptr; + + FEGameModel* RotateXGizmoGM = nullptr; + FEGameModel* RotateYGizmoGM = nullptr; + FEGameModel* RotateZGizmoGM = nullptr; + + glm::vec3 GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, FEScene* Scene); + glm::vec3 GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, glm::vec3& LastMousePointOnPlane, FEScene* Scene); + + void MouseMoveTransformationGizmos(FEScene* Scene); + void MouseMoveScaleGizmos(FEScene* Scene); + void MouseMoveRotateGizmos(FEScene* Scene); - void MouseMoveTransformationGizmos(); - void MouseMoveScaleGizmos(); - void MouseMoveRotateGizmos(); + static void OnSelectedObjectUpdate(FEScene* Scene); - static void OnSelectedObjectUpdate(); + FETransformComponent GetTransformComponentOfSelectedObject(FEScene* Scene); + void ApplyChangesToSelectedObject(FETransformComponent Changes, FEScene* Scene); - FETransformComponent GetTransformComponentOfSelectedObject(); - void MoveSelectedEntityAlongAxis(const glm::vec3& AxisOfMovement, FETransformComponent& ObjectTransform); - void RotateSelectedEntity(const glm::vec3& AxisOfRotation, FETransformComponent& ObjectTransform, const float& RotationAmount); - void ApplyChangesToSelectedObject(FETransformComponent Changes); + std::unordered_map PerSceneData; + void ClearAllSceneData(); + void ClearSceneData(const std::string& SceneID); + void AddSceneData(const std::string& SceneID); + FEGizmoSceneData* GetSceneData(const std::string& SceneID); }; #define GIZMO_MANAGER GizmoManager::getInstance() \ No newline at end of file diff --git a/FEEditorHaloSelectionEffect.cpp b/FEEditorHaloSelectionEffect.cpp index 779cc55..9aef1e6 100644 --- a/FEEditorHaloSelectionEffect.cpp +++ b/FEEditorHaloSelectionEffect.cpp @@ -1,4 +1,5 @@ #include "FEEditorHaloSelectionEffect.h" +#include "FEEditor.h" using namespace FocalEngine; FEEditorHaloSelectionEffect* FEEditorHaloSelectionEffect::Instance = nullptr; @@ -7,8 +8,6 @@ FEEditorHaloSelectionEffect::~FEEditorHaloSelectionEffect() {} void FEEditorHaloSelectionEffect::InitializeResources() { - HaloObjectsFb = RESOURCE_MANAGER.CreateFramebuffer(FE_COLOR_ATTACHMENT, ENGINE.GetRenderTargetWidth(), ENGINE.GetRenderTargetHeight()); - HaloMaterial = RESOURCE_MANAGER.CreateMaterial("haloMaterial"); RESOURCE_MANAGER.MakeMaterialStandard(HaloMaterial); @@ -20,7 +19,6 @@ void FEEditorHaloSelectionEffect::InitializeResources() nullptr, "E4F5165B2E1B05321A182C77"/*"HaloDrawObjectShader"*/); - RESOURCE_MANAGER.MakeShaderStandard(HaloDrawObjectShader); HaloMaterial->Shader = HaloDrawObjectShader; @@ -33,34 +31,6 @@ void FEEditorHaloSelectionEffect::InitializeResources() "16A2A65B2C1B013217219C67"/*"HaloDrawInstancedObjectShader"*/); RESOURCE_MANAGER.MakeShaderStandard(HaloDrawInstancedObjectShader); - PostProcess = ENGINE.CreatePostProcess("selectionHaloEffect", ENGINE.GetRenderTargetWidth() / 4, ENGINE.GetRenderTargetHeight() / 4); - - FEShader* BlurShader = RESOURCE_MANAGER.GetShader("7F3E4F5C130B537F0846274F"/*"FEBloomBlur"*/); - PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_OWN_TEXTURE, BlurShader)); - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(1.0f, 0.0f), "FEBlurDirection")); - // because input texture at first stage is full resolution, we should blur harder to get simular blur on both sides. - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.5f * 4.0f, "BloomSize")); - PostProcess->Stages.back()->InTexture.push_back(HaloObjectsFb->GetColorAttachment()); - PostProcess->Stages.back()->OutTexture = RESOURCE_MANAGER.CreateSameFormatTexture(RENDERER.SceneToTextureFB->GetColorAttachment(), ENGINE.GetRenderTargetWidth() / 4, ENGINE.GetRenderTargetHeight() / 4); - - PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(0.0f, 1.0f), "FEBlurDirection")); - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.5f, "BloomSize")); - PostProcess->Stages.back()->InTexture.push_back(PostProcess->Stages[0]->OutTexture); - PostProcess->Stages.back()->OutTexture = RESOURCE_MANAGER.CreateSameFormatTexture(RENDERER.SceneToTextureFB->GetColorAttachment(), ENGINE.GetRenderTargetWidth() / 4, ENGINE.GetRenderTargetHeight() / 4); - - PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(1.0f, 0.0f), "FEBlurDirection")); - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.0f, "BloomSize")); - PostProcess->Stages.back()->InTexture.push_back(PostProcess->Stages[0]->OutTexture); - PostProcess->Stages.back()->OutTexture = RESOURCE_MANAGER.CreateSameFormatTexture(RENDERER.SceneToTextureFB->GetColorAttachment(), ENGINE.GetRenderTargetWidth() / 4, ENGINE.GetRenderTargetHeight() / 4); - - PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(0.0f, 1.0f), "FEBlurDirection")); - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.0f, "BloomSize")); - PostProcess->Stages.back()->InTexture.push_back(PostProcess->Stages[0]->OutTexture); - PostProcess->Stages.back()->OutTexture = RESOURCE_MANAGER.CreateSameFormatTexture(RENDERER.SceneToTextureFB->GetColorAttachment(), ENGINE.GetRenderTargetWidth() / 4, ENGINE.GetRenderTargetHeight() / 4); - HaloFinalShader = RESOURCE_MANAGER.CreateShader("HaloFinalShader", RESOURCE_MANAGER.LoadGLSL("SubSystems//FocalEngine//CoreExtensions//PostProcessEffects//FE_ScreenQuad_VS.glsl").c_str(), RESOURCE_MANAGER.LoadGLSL("Resources//Materials//FE_HaloSelectionEffect_FS.glsl").c_str(), nullptr, @@ -69,57 +39,151 @@ void FEEditorHaloSelectionEffect::InitializeResources() nullptr, "4AC7365B2C1B07324721A127"/*"HaloFinalShader"*/); - PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_OWN_TEXTURE, HaloFinalShader)); RESOURCE_MANAGER.MakeShaderStandard(HaloFinalShader); - PostProcess->Stages.back()->InTexture.push_back(RENDERER.PostProcessEffects[RENDERER.PostProcessEffects.size() - 1]->Stages.back()->OutTexture); - PostProcess->Stages.back()->InTextureSource.push_back(FE_POST_PROCESS_OWN_TEXTURE); - PostProcess->Stages.back()->InTexture.push_back(PostProcess->Stages[3]->OutTexture); - PostProcess->Stages.back()->InTextureSource.push_back(FE_POST_PROCESS_OWN_TEXTURE); - PostProcess->Stages.back()->InTexture.push_back(PostProcess->Stages[0]->InTexture[0]); - PostProcess->Stages.back()->OutTexture = RESOURCE_MANAGER.CreateSameFormatTexture(RENDERER.SceneToTextureFB->GetColorAttachment(), ENGINE.GetRenderTargetWidth(), ENGINE.GetRenderTargetHeight()); - - RENDERER.AddPostProcess(PostProcess, true); } -void FEEditorHaloSelectionEffect::ReInitializeResources() +void FEEditorHaloSelectionEffect::UpdateResources(FEScene* Scene) { - delete HaloObjectsFb; - HaloObjectsFb = RESOURCE_MANAGER.CreateFramebuffer(FE_COLOR_ATTACHMENT, ENGINE.GetRenderTargetWidth(), ENGINE.GetRenderTargetHeight()); - PostProcess = ENGINE.CreatePostProcess("selectionHaloEffect", ENGINE.GetRenderTargetWidth() / 4, ENGINE.GetRenderTargetHeight() / 4); + if (Scene == nullptr) + return; + + FEHaloSelectionData* CurrentHaloSelectionData = GetSceneData(Scene->GetObjectID()); + if (CurrentHaloSelectionData == nullptr) + return; + + FECameraRenderingData* CameraData = RENDERER.GetCameraRenderingData(CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())); + std::vector& PostProcesses = CameraData->PostProcessEffects; + + delete CurrentHaloSelectionData->HaloObjectsFB; + CurrentHaloSelectionData->HaloObjectsFB = RESOURCE_MANAGER.CreateFramebuffer(FE_COLOR_ATTACHMENT, CameraData->SceneToTextureFB->GetWidth(), CameraData->SceneToTextureFB->GetHeight()); + CurrentHaloSelectionData->PostProcess = ENGINE.CreatePostProcess("selectionHaloEffect", CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4); FEShader* BlurShader = RESOURCE_MANAGER.GetShader("7F3E4F5C130B537F0846274F"/*"FEBloomBlur"*/); - PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_OWN_TEXTURE, BlurShader)); - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(1.0f, 0.0f), "FEBlurDirection")); + CurrentHaloSelectionData->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_OWN_TEXTURE, BlurShader)); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(1.0f, 0.0f), "FEBlurDirection")); // because input texture at first stage is full resolution, we should blur harder to get simular blur on both sides. - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.5f * 4.0f, "BloomSize")); - PostProcess->Stages.back()->InTexture.push_back(HaloObjectsFb->GetColorAttachment()); - PostProcess->ReplaceOutTexture(0, RESOURCE_MANAGER.CreateSameFormatTexture(RENDERER.SceneToTextureFB->GetColorAttachment(), ENGINE.GetRenderTargetWidth() / 4, ENGINE.GetRenderTargetHeight() / 4)); - - PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(0.0f, 1.0f), "FEBlurDirection")); - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.5f, "BloomSize")); - PostProcess->Stages.back()->InTexture.push_back(PostProcess->Stages[0]->OutTexture); - PostProcess->ReplaceOutTexture(1, RESOURCE_MANAGER.CreateSameFormatTexture(RENDERER.SceneToTextureFB->GetColorAttachment(), ENGINE.GetRenderTargetWidth() / 4, ENGINE.GetRenderTargetHeight() / 4)); - - PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(1.0f, 0.0f), "FEBlurDirection")); - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.0f, "BloomSize")); - PostProcess->Stages.back()->InTexture.push_back(PostProcess->Stages[0]->OutTexture); - PostProcess->ReplaceOutTexture(2, RESOURCE_MANAGER.CreateSameFormatTexture(RENDERER.SceneToTextureFB->GetColorAttachment(), ENGINE.GetRenderTargetWidth() / 4, ENGINE.GetRenderTargetHeight() / 4)); - - PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(0.0f, 1.0f), "FEBlurDirection")); - PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.0f, "BloomSize")); - PostProcess->Stages.back()->InTexture.push_back(PostProcess->Stages[0]->OutTexture); - PostProcess->ReplaceOutTexture(3, RESOURCE_MANAGER.CreateSameFormatTexture(RENDERER.SceneToTextureFB->GetColorAttachment(), ENGINE.GetRenderTargetWidth() / 4, ENGINE.GetRenderTargetHeight() / 4)); - - PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_OWN_TEXTURE, HaloFinalShader)); - PostProcess->Stages.back()->InTexture.push_back(RENDERER.PostProcessEffects[RENDERER.PostProcessEffects.size() - 1]->Stages.back()->OutTexture); - PostProcess->Stages.back()->InTextureSource.push_back(FE_POST_PROCESS_OWN_TEXTURE); - PostProcess->Stages.back()->InTexture.push_back(PostProcess->Stages[3]->OutTexture); - PostProcess->Stages.back()->InTextureSource.push_back(FE_POST_PROCESS_OWN_TEXTURE); - PostProcess->Stages.back()->InTexture.push_back(PostProcess->Stages[0]->InTexture[0]); - PostProcess->ReplaceOutTexture(4, RESOURCE_MANAGER.CreateSameFormatTexture(RENDERER.SceneToTextureFB->GetColorAttachment(), ENGINE.GetRenderTargetWidth(), ENGINE.GetRenderTargetHeight())); - - RENDERER.AddPostProcess(PostProcess, true); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.5f * 4.0f, "BloomSize")); + CurrentHaloSelectionData->PostProcess->Stages.back()->InTexture.push_back(CurrentHaloSelectionData->HaloObjectsFB->GetColorAttachment()); + CurrentHaloSelectionData->PostProcess->ReplaceOutTexture(0, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); + + CurrentHaloSelectionData->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(0.0f, 1.0f), "FEBlurDirection")); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.5f, "BloomSize")); + CurrentHaloSelectionData->PostProcess->Stages.back()->InTexture.push_back(CurrentHaloSelectionData->PostProcess->Stages[0]->OutTexture); + CurrentHaloSelectionData->PostProcess->ReplaceOutTexture(1, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); + + CurrentHaloSelectionData->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(1.0f, 0.0f), "FEBlurDirection")); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.0f, "BloomSize")); + CurrentHaloSelectionData->PostProcess->Stages.back()->InTexture.push_back(CurrentHaloSelectionData->PostProcess->Stages[0]->OutTexture); + CurrentHaloSelectionData->PostProcess->ReplaceOutTexture(2, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); + + CurrentHaloSelectionData->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(0.0f, 1.0f), "FEBlurDirection")); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.0f, "BloomSize")); + CurrentHaloSelectionData->PostProcess->Stages.back()->InTexture.push_back(CurrentHaloSelectionData->PostProcess->Stages[0]->OutTexture); + CurrentHaloSelectionData->PostProcess->ReplaceOutTexture(3, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); + + CurrentHaloSelectionData->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_OWN_TEXTURE, HaloFinalShader)); + + CurrentHaloSelectionData->PostProcess->Stages.back()->InTexture.push_back(PostProcesses[PostProcesses.size() - 1]->Stages.back()->OutTexture); + CurrentHaloSelectionData->PostProcess->Stages.back()->InTextureSource.push_back(FE_POST_PROCESS_OWN_TEXTURE); + CurrentHaloSelectionData->PostProcess->Stages.back()->InTexture.push_back(CurrentHaloSelectionData->PostProcess->Stages[3]->OutTexture); + CurrentHaloSelectionData->PostProcess->Stages.back()->InTextureSource.push_back(FE_POST_PROCESS_OWN_TEXTURE); + CurrentHaloSelectionData->PostProcess->Stages.back()->InTexture.push_back(CurrentHaloSelectionData->PostProcess->Stages[0]->InTexture[0]); + CurrentHaloSelectionData->PostProcess->ReplaceOutTexture(4, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth(), CameraData->SceneToTextureFB->GetHeight())); + + RENDERER.AddPostProcess(CameraData, CurrentHaloSelectionData->PostProcess, true); +} + +void FEEditorHaloSelectionEffect::ClearAllSceneData() +{ + auto PerSceneIterator = PerSceneData.begin(); + while (PerSceneIterator != PerSceneData.end()) + { + delete PerSceneIterator->second; + PerSceneIterator++; + } + + PerSceneData.clear(); +} + +void FEEditorHaloSelectionEffect::ClearSceneData(const std::string& SceneID) +{ + auto FoundSceneData = PerSceneData.find(SceneID); + if (FoundSceneData != PerSceneData.end()) + { + delete FoundSceneData->second; + PerSceneData.erase(FoundSceneData); + } +} + +void FEEditorHaloSelectionEffect::AddSceneData(const std::string& SceneID) +{ + FEScene* CurrentScene = SCENE_MANAGER.GetScene(SceneID); + if (CurrentScene == nullptr) + return; + + if (PerSceneData.find(SceneID) != PerSceneData.end()) + return; + + PerSceneData[SceneID] = new FEHaloSelectionData(); + PerSceneData[SceneID]->SceneID = SceneID; + + FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(CurrentScene); + FECameraRenderingData* CameraData = RENDERER.GetCameraRenderingData(MainCamera); + if (CameraData == nullptr) + return; + std::vector& PostProcesses = CameraData->PostProcessEffects; + + PerSceneData[SceneID]->HaloObjectsFB = RESOURCE_MANAGER.CreateFramebuffer(FE_COLOR_ATTACHMENT, CameraData->SceneToTextureFB->GetWidth(), CameraData->SceneToTextureFB->GetHeight()); + PerSceneData[SceneID]->PostProcess = ENGINE.CreatePostProcess("selectionHaloEffect", CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4); + + FEShader* BlurShader = RESOURCE_MANAGER.GetShader("7F3E4F5C130B537F0846274F"/*"FEBloomBlur"*/); + PerSceneData[SceneID]->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_OWN_TEXTURE, BlurShader)); + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(1.0f, 0.0f), "FEBlurDirection")); + // because input texture at first stage is full resolution, we should blur harder to get simular blur on both sides. + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.5f * 4.0f, "BloomSize")); + PerSceneData[SceneID]->PostProcess->Stages.back()->InTexture.push_back(PerSceneData[SceneID]->HaloObjectsFB->GetColorAttachment()); + PerSceneData[SceneID]->PostProcess->ReplaceOutTexture(0, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); + + PerSceneData[SceneID]->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(0.0f, 1.0f), "FEBlurDirection")); + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.5f, "BloomSize")); + PerSceneData[SceneID]->PostProcess->Stages.back()->InTexture.push_back(PerSceneData[SceneID]->PostProcess->Stages[0]->OutTexture); + PerSceneData[SceneID]->PostProcess->ReplaceOutTexture(1, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); + + PerSceneData[SceneID]->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(1.0f, 0.0f), "FEBlurDirection")); + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.0f, "BloomSize")); + PerSceneData[SceneID]->PostProcess->Stages.back()->InTexture.push_back(PerSceneData[SceneID]->PostProcess->Stages[0]->OutTexture); + PerSceneData[SceneID]->PostProcess->ReplaceOutTexture(2, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); + + PerSceneData[SceneID]->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(0.0f, 1.0f), "FEBlurDirection")); + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.0f, "BloomSize")); + PerSceneData[SceneID]->PostProcess->Stages.back()->InTexture.push_back(PerSceneData[SceneID]->PostProcess->Stages[0]->OutTexture); + PerSceneData[SceneID]->PostProcess->ReplaceOutTexture(3, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); + + PerSceneData[SceneID]->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_OWN_TEXTURE, HaloFinalShader)); + + PerSceneData[SceneID]->PostProcess->Stages.back()->InTexture.push_back(PostProcesses[PostProcesses.size() - 1]->Stages.back()->OutTexture); + PerSceneData[SceneID]->PostProcess->Stages.back()->InTextureSource.push_back(FE_POST_PROCESS_OWN_TEXTURE); + PerSceneData[SceneID]->PostProcess->Stages.back()->InTexture.push_back(PerSceneData[SceneID]->PostProcess->Stages[3]->OutTexture); + PerSceneData[SceneID]->PostProcess->Stages.back()->InTextureSource.push_back(FE_POST_PROCESS_OWN_TEXTURE); + PerSceneData[SceneID]->PostProcess->Stages.back()->InTexture.push_back(PerSceneData[SceneID]->PostProcess->Stages[0]->InTexture[0]); + PerSceneData[SceneID]->PostProcess->ReplaceOutTexture(4, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth(), CameraData->SceneToTextureFB->GetHeight())); + + RENDERER.AddPostProcess(CameraData, PerSceneData[SceneID]->PostProcess, true); +} + +FEHaloSelectionData* FEEditorHaloSelectionEffect::GetSceneData(const std::string& SceneID) +{ + auto FoundScene = PerSceneData.find(SceneID); + if (FoundScene != PerSceneData.end()) + { + return FoundScene->second; + } + + return nullptr; } \ No newline at end of file diff --git a/FEEditorHaloSelectionEffect.h b/FEEditorHaloSelectionEffect.h index 2ed5b70..e009693 100644 --- a/FEEditorHaloSelectionEffect.h +++ b/FEEditorHaloSelectionEffect.h @@ -3,27 +3,43 @@ #include "../FEngine.h" using namespace FocalEngine; -class FEEditorSelectedObject; -class FEEditor; +class FEHaloSelectionData +{ + friend class FEEditor; + friend class FEEditorSelectedObject; + friend class FEEditorHaloSelectionEffect; + + std::string SceneID = ""; + FEFramebuffer* HaloObjectsFB = nullptr; + FEPostProcess* PostProcess = nullptr; + + ~FEHaloSelectionData() + { + delete HaloObjectsFB; + } +}; class FEEditorHaloSelectionEffect { - friend FEEditorSelectedObject; - friend FEEditor; + friend class FEEditorSelectedObject; + friend class FEEditor; private: SINGLETON_PUBLIC_PART(FEEditorHaloSelectionEffect) SINGLETON_PRIVATE_PART(FEEditorHaloSelectionEffect) void InitializeResources(); - void ReInitializeResources(); + void UpdateResources(FEScene* Scene); - FEFramebuffer* HaloObjectsFb = nullptr; FEMaterial* HaloMaterial = nullptr; - FEPostProcess* PostProcess = nullptr; - FEShader* HaloDrawInstancedObjectShader = nullptr; FEShader* HaloDrawObjectShader = nullptr; FEShader* HaloFinalShader = nullptr; + + std::unordered_map PerSceneData; + void ClearAllSceneData(); + void ClearSceneData(const std::string& SceneID); + void AddSceneData(const std::string& SceneID); + FEHaloSelectionData* GetSceneData(const std::string& SceneID); }; #define HALO_SELECTION_EFFECT FEEditorHaloSelectionEffect::getInstance() \ No newline at end of file diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index ace4e31..2685488 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -10,12 +10,9 @@ FETransformComponent FEEditorPreviewManager::OriginalTransform = FETransformComp void FEEditorPreviewManager::InitializeResources() { - PreviewScene = SCENE_MANAGER.CreateScene("EditorPreviewScene", "", false); + PreviewScene = SCENE_MANAGER.CreateScene("EditorPreviewScene"); - PreviewFB = RESOURCE_MANAGER.CreateFramebuffer(FE_COLOR_ATTACHMENT | FE_DEPTH_ATTACHMENT, 128, 128); PreviewGameModel = new FEGameModel(nullptr, nullptr, "editorPreviewGameModel"); - PreviewPrefab = new FEPrefab(PreviewGameModel, "editorPreviewPrefab"); - MeshPreviewMaterial = RESOURCE_MANAGER.CreateMaterial("meshPreviewMaterial"); RESOURCE_MANAGER.MakeMaterialStandard(MeshPreviewMaterial); MeshPreviewMaterial->Shader = RESOURCE_MANAGER.CreateShader("FEMeshPreviewShader", RESOURCE_MANAGER.LoadGLSL("Resources//Materials//FE_MeshPreview_VS.glsl").c_str(), @@ -28,56 +25,34 @@ void FEEditorPreviewManager::InitializeResources() RESOURCE_MANAGER.MakeShaderStandard(MeshPreviewMaterial->Shader); - PreviewEntity = PreviewScene->CreateEntity("EditorPreviewEntity"); PreviewEntity->AddComponent(PreviewGameModel); - PreviewEntity->GetComponent().SetVisibility(false); + PreviewEntity->GetComponent().SetVisibility(true); LocalCameraEntity = PreviewScene->CreateEntity("EditorPreview CameraEntity"); LocalCameraEntity->AddComponent(); FECameraComponent& CameraComponent = LocalCameraEntity->GetComponent(); - CameraComponent.SetIsUsingDefaultRenderTargetSize(false); CameraComponent.SetRenderTargetSize(128, 128); + CameraComponent.SetDistanceFogEnabled(false); + CAMERA_SYSTEM.SetMainCamera(LocalCameraEntity); - /*LocalSunEntity = PreviewScene->CreateEntity("EditorPreview LightEntity"); + LocalSunEntity = PreviewScene->CreateEntity("EditorPreview LightEntity"); LocalSunEntity->AddComponent(FE_DIRECTIONAL_LIGHT); FELightComponent& LightComponent = LocalSunEntity->GetComponent(); LocalSunEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); - LightComponent.SetIntensity(10.0f);*/ + LightComponent.SetIntensity(10.0f); + LightComponent.SetCastShadows(false); - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (!ActiveScenes.empty()) - { - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - PreviewEntity = PreviewScene->CreateEntity("EditorPreviewEntity"); - PreviewEntity->AddComponent(PreviewGameModel); - PreviewEntity->GetComponent().SetVisibility(false); - - /*LocalSunEntity = PreviewScene->CreateEntity("EditorPreview LightEntity"); - LocalSunEntity->AddComponent(FE_DIRECTIONAL_LIGHT); - FELightComponent& LightComponent = LocalSunEntity->GetComponent(); - LocalSunEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); - LightComponent.SetIntensity(10.0f);*/ - } + // FIX ME! This scene should not have skydome. Fix bloom shader. + FEEntity* SkyDome = PreviewScene->CreateEntity("SkyDome"); + SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); + SKY_DOME_SYSTEM.AddToEntity(SkyDome); + + SCENE_MANAGER.DeactivateScene(PreviewScene); } void FEEditorPreviewManager::ReInitializeEntities() { - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (!ActiveScenes.empty()) - { - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - PreviewEntity = CurrentScene->CreateEntity("EditorPreviewEntity"); - PreviewEntity->AddComponent(PreviewGameModel); - PreviewEntity->GetComponent().SetVisibility(false); - - /*LocalLightEntity = SCENE.CreateEntity("EditorPreview LightEntity"); - FELightComponent& LightComponent = LocalLightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); - LocalLightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); - LightComponent.SetIntensity(10.0f);*/ - } } void FEEditorPreviewManager::UpdateAll() @@ -105,105 +80,16 @@ void FEEditorPreviewManager::UpdateAll() void FEEditorPreviewManager::BeforePreviewActions() { - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (ActiveScenes.empty()) - return; - - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - - PreviewFB->Bind(); - // We use these values even with the deferred renderer because the final image will not undergo gamma correction. Therefore, values exceeding 1.0f will not function correctly. - OriginalClearColor = ENGINE.GetClearColor(); - ENGINE.SetClearColor(glm::vec4(0.55f, 0.73f, 0.87f, 1.0f)); - - FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); - - OriginalTransform = PreviewEntity->GetComponent(); - // The transform impacts the AABB. Therefore, the necessary values must be set prior to any calculations. PreviewEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, 0.0)); PreviewEntity->GetComponent().SetScale(glm::vec3(1.0, 1.0, 1.0)); PreviewEntity->GetComponent().SetRotation(glm::vec3(15.0, -15.0, 0.0)); - - //CameraComponent.SetAspectRatio(1.0f); - FE_GL_ERROR(glViewport(0, 0, 128, 128)); - - PreviewEntity->GetComponent().SetVisibility(true); - - FEEntity* CurrentLightEntity = nullptr; - std::vector< std::string> LightsIDList = CurrentScene->GetEntityIDListWith(); - for (size_t i = 0; i < LightsIDList.size(); i++) - { - FEEntity* LightEntity = CurrentScene->GetEntity(LightsIDList[i]); - FETransformComponent& TransformComponent = LightEntity->GetComponent(); - FELightComponent& LightComponent = LightEntity->GetComponent(); - - if (LightComponent.GetType() == FE_DIRECTIONAL_LIGHT) - { - CurrentLightEntity = LightEntity; - break; - } - } - FETransformComponent& TransformComponent = CurrentLightEntity->GetComponent(); - FELightComponent& LightComponent = CurrentLightEntity->GetComponent(); - - RegularLightWorldMatrix = TransformComponent.GetWorldMatrix(); - - RegularLightRotation = TransformComponent.GetRotation(); - TransformComponent.SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); - TransformComponent.ForceSetWorldMatrix(TransformComponent.GetLocalMatrix()); - - RegularLightIntensity = LightComponent.GetIntensity(); - LightComponent.SetIntensity(10.0f); - - //LocalSunEntity->GetComponent().SetLightEnabled(true); - - bIsRegularFogEnabled = RENDERER.IsDistanceFogEnabled(); - RENDERER.SetDistanceFogEnabled(false); } void FEEditorPreviewManager::AfterPreviewActions() { - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (ActiveScenes.empty()) - return; - - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - - // We are reversing all of our previously applied transformations. - PreviewEntity->GetComponent() = OriginalTransform; - - PreviewFB->UnBind(); - - ENGINE.SetClearColor(OriginalClearColor); - - PreviewEntity->GetComponent().SetVisibility(false); - //LocalSunEntity->GetComponent().SetLightEnabled(false); - - FEEntity* CurrentLightEntity = nullptr; - std::vector< std::string> LightsIDList = CurrentScene->GetEntityIDListWith(); - for (size_t i = 0; i < LightsIDList.size(); i++) - { - FEEntity* LightEntity = CurrentScene->GetEntity(LightsIDList[i]); - FETransformComponent& TransformComponent = LightEntity->GetComponent(); - FELightComponent& LightComponent = LightEntity->GetComponent(); - - if (LightComponent.GetType() == FE_DIRECTIONAL_LIGHT) - { - CurrentLightEntity = LightEntity; - break; - } - } - FETransformComponent& TransformComponent = CurrentLightEntity->GetComponent(); - FELightComponent& LightComponent = CurrentLightEntity->GetComponent(); - - TransformComponent.SetRotation(RegularLightRotation); - TransformComponent.ForceSetWorldMatrix(RegularLightWorldMatrix); - LightComponent.SetIntensity(RegularLightIntensity); - - RENDERER.SetDistanceFogEnabled(bIsRegularFogEnabled); + PreviewGameModel->Mesh = nullptr; + PreviewGameModel->Material = nullptr; } void FEEditorPreviewManager::CreateMeshPreview(const std::string MeshID) @@ -228,14 +114,10 @@ void FEEditorPreviewManager::CreateMeshPreview(const std::string MeshID) // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. PreviewEntity->GetComponent().SetPosition(-glm::vec3(Max.x - XSize / 2.0f, Max.y - YSize / 2.0f, Max.z - ZSize / 2.0f)); - // FIX ME! Temporary solution LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); - LocalCameraEntity->GetComponent().Update(); - LocalCameraEntity->GetComponent().ForceSetWorldMatrix(LocalCameraEntity->GetComponent().GetLocalMatrix()); CAMERA_SYSTEM.IndividualUpdate(LocalCameraEntity, 0.0); - // Rendering mesh to texture. - RENDERER.RenderGameModelComponent(PreviewEntity, LocalCameraEntity); + RENDERER.Render(PreviewScene); AfterPreviewActions(); @@ -243,8 +125,9 @@ void FEEditorPreviewManager::CreateMeshPreview(const std::string MeshID) if (MeshPreviewTextures.find(MeshID) != MeshPreviewTextures.end()) delete MeshPreviewTextures[MeshID]; - MeshPreviewTextures[MeshID] = PreviewFB->GetColorAttachment(); - PreviewFB->SetColorAttachment(RESOURCE_MANAGER.CreateSameFormatTexture(PreviewFB->GetColorAttachment())); + FETexture* CameraResult = RENDERER.GetCameraResult(LocalCameraEntity); + if (CameraResult != nullptr) + MeshPreviewTextures[MeshID] = RESOURCE_MANAGER.CreateCopyOfTexture(CameraResult); } FETexture* FEEditorPreviewManager::GetMeshPreview(const std::string MeshID) @@ -289,14 +172,10 @@ void FEEditorPreviewManager::CreateMaterialPreview(const std::string MaterialID) PreviewEntity->GetComponent().SetReceivingShadows(false); BeforePreviewActions(); - // FIX ME! Temporary solution - LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, 70.0f)); - LocalCameraEntity->GetComponent().Update(); - LocalCameraEntity->GetComponent().ForceSetWorldMatrix(LocalCameraEntity->GetComponent().GetLocalMatrix()); + LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, 50.0f)); CAMERA_SYSTEM.IndividualUpdate(LocalCameraEntity, 0.0); - // Rendering material to texture - RENDERER.RenderGameModelComponentForward(PreviewEntity, LocalCameraEntity, true); + RENDERER.Render(PreviewScene); AfterPreviewActions(); @@ -304,10 +183,13 @@ void FEEditorPreviewManager::CreateMaterialPreview(const std::string MaterialID) if (MaterialPreviewTextures.find(MaterialID) != MaterialPreviewTextures.end()) delete MaterialPreviewTextures[MaterialID]; - MaterialPreviewTextures[MaterialID] = PreviewFB->GetColorAttachment(); - PreviewFB->SetColorAttachment(RESOURCE_MANAGER.CreateSameFormatTexture(PreviewFB->GetColorAttachment())); + FETexture* CameraResult = RENDERER.GetCameraResult(LocalCameraEntity); + if (CameraResult != nullptr) + { + MaterialPreviewTextures[MaterialID] = RESOURCE_MANAGER.CreateCopyOfTexture(CameraResult); + } - // looking for all gameModels that uses this material to also update them + // Looking for all gameModels that uses this material to also update them. const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); for (size_t i = 0; i < GameModelList.size(); i++) { @@ -316,14 +198,15 @@ void FEEditorPreviewManager::CreateMaterialPreview(const std::string MaterialID) CreateGameModelPreview(CurrentGameModel->GetObjectID()); } + // FIX ME! // looking for all prefabs that uses this material to also update them - const std::vector PrefabList = RESOURCE_MANAGER.GetPrefabList(); + /*const std::vector PrefabList = RESOURCE_MANAGER.GetPrefabList(); for (size_t i = 0; i < PrefabList.size(); i++) { FEPrefab* CurrentPrefab = RESOURCE_MANAGER.GetPrefab(PrefabList[i]); if (CurrentPrefab->UsesMaterial(MaterialID)) CreatePrefabPreview(CurrentPrefab->GetObjectID()); - } + }*/ } FETexture* FEEditorPreviewManager::GetMaterialPreview(const std::string MaterialID) @@ -352,7 +235,6 @@ FETexture* FEEditorPreviewManager::GetMaterialPreview(const std::string Material CreatePrefabPreview(CurrentPrefab->GetObjectID()); } } - } RESOURCE_MANAGER.GetMaterial(MaterialID)->SetDirtyFlag(false); @@ -380,7 +262,6 @@ void FEEditorPreviewManager::CreateGameModelPreview(const std::string GameModelI PreviewEntity->GetComponent().SetReceivingShadows(false); BeforePreviewActions(); - //FEAABB MeshAABB = PreviewEntity->GetAABB(); FEAABB MeshAABB = PreviewEntity->GetComponent().GameModel->Mesh->GetAABB(); MeshAABB.Transform(PreviewEntity->GetComponent().GetWorldMatrix()); const glm::vec3 min = MeshAABB.GetMin(); @@ -392,14 +273,10 @@ void FEEditorPreviewManager::CreateGameModelPreview(const std::string GameModelI // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. PreviewEntity->GetComponent().SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); - // FIX ME! Temporary solution LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); - LocalCameraEntity->GetComponent().Update(); - LocalCameraEntity->GetComponent().ForceSetWorldMatrix(LocalCameraEntity->GetComponent().GetLocalMatrix()); CAMERA_SYSTEM.IndividualUpdate(LocalCameraEntity, 0.0); - // rendering game model to texture - RENDERER.RenderGameModelComponentForward(PreviewEntity, LocalCameraEntity, true); + RENDERER.Render(PreviewScene); AfterPreviewActions(); @@ -407,10 +284,12 @@ void FEEditorPreviewManager::CreateGameModelPreview(const std::string GameModelI if (GameModelPreviewTextures.find(GameModelID) != GameModelPreviewTextures.end()) delete GameModelPreviewTextures[GameModelID]; - GameModelPreviewTextures[GameModelID] = PreviewFB->GetColorAttachment(); - PreviewFB->SetColorAttachment(RESOURCE_MANAGER.CreateSameFormatTexture(PreviewFB->GetColorAttachment())); + FETexture* CameraResult = RENDERER.GetCameraResult(LocalCameraEntity); + if (CameraResult != nullptr) + GameModelPreviewTextures[GameModelID] = RESOURCE_MANAGER.CreateCopyOfTexture(CameraResult); } +// FIX ME! Should not be needed as now there will be scene for new game model. void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel, FETexture** ResultingTexture) { if (GameModel == nullptr) @@ -419,14 +298,13 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel PreviewGameModel->Mesh = GameModel->Mesh; PreviewGameModel->Material = GameModel->Material; PreviewEntity->GetComponent().SetReceivingShadows(false); - if (*ResultingTexture == nullptr) - *ResultingTexture = RESOURCE_MANAGER.CreateSameFormatTexture(PreviewFB->GetColorAttachment()); - FETexture* TempTexture = PreviewFB->GetColorAttachment(); - PreviewFB->SetColorAttachment(*ResultingTexture); + //if (*ResultingTexture == nullptr) + // *ResultingTexture = RESOURCE_MANAGER.CreateSameFormatTexture(PreviewFB->GetColorAttachment()); + //FETexture* TempTexture = PreviewFB->GetColorAttachment(); + //PreviewFB->SetColorAttachment(*ResultingTexture); BeforePreviewActions(); - //FEAABB MeshAABB = PreviewEntity->GetAABB(); FEAABB MeshAABB = PreviewEntity->GetComponent().GameModel->Mesh->GetAABB(); MeshAABB.Transform(PreviewEntity->GetComponent().GetWorldMatrix()); const glm::vec3 min = MeshAABB.GetMin(); @@ -438,18 +316,14 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. PreviewEntity->GetComponent().SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); - // FIX ME! Temporary solution LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); - LocalCameraEntity->GetComponent().Update(); - LocalCameraEntity->GetComponent().ForceSetWorldMatrix(LocalCameraEntity->GetComponent().GetLocalMatrix()); CAMERA_SYSTEM.IndividualUpdate(LocalCameraEntity, 0.0); - // rendering game model to texture - RENDERER.RenderGameModelComponentForward(PreviewEntity, LocalCameraEntity, true); + RENDERER.Render(PreviewScene); AfterPreviewActions(); - PreviewFB->SetColorAttachment(TempTexture); + //PreviewFB->SetColorAttachment(TempTexture); } FETexture* FEEditorPreviewManager::GetGameModelPreview(const std::string GameModelID) @@ -505,14 +379,10 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) if (GameModel == nullptr) return; - //Fix ME! - //PreviewEntity->Prefab = Prefab; PreviewEntity->GetComponent().GameModel = GameModel; PreviewEntity->GetComponent().SetReceivingShadows(false); BeforePreviewActions(); - //PreviewEntity->SetDirtyFlag(true); - //FEAABB MeshAABB = PreviewEntity->GetAABB(); FEAABB MeshAABB = PreviewEntity->GetComponent().GameModel->Mesh->GetAABB(); MeshAABB.Transform(PreviewEntity->GetComponent().GetWorldMatrix()); const glm::vec3 min = MeshAABB.GetMin(); @@ -524,14 +394,10 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. PreviewEntity->GetComponent().SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); - // FIX ME! Temporary solution LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); - LocalCameraEntity->GetComponent().Update(); - LocalCameraEntity->GetComponent().ForceSetWorldMatrix(LocalCameraEntity->GetComponent().GetLocalMatrix()); CAMERA_SYSTEM.IndividualUpdate(LocalCameraEntity, 0.0); - // rendering game model to texture - RENDERER.RenderGameModelComponentForward(PreviewEntity, LocalCameraEntity, true); + RENDERER.Render(PreviewScene); //PreviewEntity->Prefab = PreviewPrefab; PreviewEntity->GetComponent().GameModel = PreviewGameModel; @@ -542,8 +408,8 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) if (PrefabPreviewTextures.find(PrefabID) != PrefabPreviewTextures.end()) delete PrefabPreviewTextures[PrefabID]; - PrefabPreviewTextures[PrefabID] = PreviewFB->GetColorAttachment(); - PreviewFB->SetColorAttachment(RESOURCE_MANAGER.CreateSameFormatTexture(PreviewFB->GetColorAttachment())); + //PrefabPreviewTextures[PrefabID] = PreviewFB->GetColorAttachment(); + //PreviewFB->SetColorAttachment(RESOURCE_MANAGER.CreateSameFormatTexture(PreviewFB->GetColorAttachment())); } void CreatePrefabPreview(FEPrefab* Prefab, FETexture** ResultingTexture) @@ -553,33 +419,33 @@ void CreatePrefabPreview(FEPrefab* Prefab, FETexture** ResultingTexture) FETexture* FEEditorPreviewManager::GetPrefabPreview(const std::string PrefabID) { - FEPrefab* CurrentPrefab = RESOURCE_MANAGER.GetPrefab(PrefabID); - if (CurrentPrefab == nullptr) - { - LOG.Add("FEEditorPreviewManager::GetPrefabPreview could not find prefab with ID: " + PrefabID, "FE_LOG_RENDERING", FE_LOG_ERROR); - return RESOURCE_MANAGER.NoTexture; - } - - // if Prefab's dirty flag is set we need to update preview - if (CurrentPrefab->IsDirty()) - { - CreatePrefabPreview(PrefabID); - CurrentPrefab->SetDirtyFlag(false); - } - - for (int i = 0; i < CurrentPrefab->ComponentsCount(); i++) - { - // if Prefab's material dirty flag is set we need to update preview - if (CurrentPrefab->GetComponent(i)->GameModel->GetMaterial() != nullptr && CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->IsDirty()) - { - CreateMaterialPreview(CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->GetObjectID()); - CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->SetDirtyFlag(false); - } - } - - // if we somehow could not find preview, we will create it. - if (PrefabPreviewTextures.find(PrefabID) == PrefabPreviewTextures.end()) - CreatePrefabPreview(PrefabID); + //FEPrefab* CurrentPrefab = RESOURCE_MANAGER.GetPrefab(PrefabID); + //if (CurrentPrefab == nullptr) + //{ + // LOG.Add("FEEditorPreviewManager::GetPrefabPreview could not find prefab with ID: " + PrefabID, "FE_LOG_RENDERING", FE_LOG_ERROR); + // return RESOURCE_MANAGER.NoTexture; + //} + // + //// if Prefab's dirty flag is set we need to update preview + //if (CurrentPrefab->IsDirty()) + //{ + // CreatePrefabPreview(PrefabID); + // CurrentPrefab->SetDirtyFlag(false); + //} + + //for (int i = 0; i < CurrentPrefab->ComponentsCount(); i++) + //{ + // // if Prefab's material dirty flag is set we need to update preview + // if (CurrentPrefab->GetComponent(i)->GameModel->GetMaterial() != nullptr && CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->IsDirty()) + // { + // CreateMaterialPreview(CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->GetObjectID()); + // CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->SetDirtyFlag(false); + // } + //} + + //// if we somehow could not find preview, we will create it. + //if (PrefabPreviewTextures.find(PrefabID) == PrefabPreviewTextures.end()) + // CreatePrefabPreview(PrefabID); // if still we don't have it if (PrefabPreviewTextures.find(PrefabID) == PrefabPreviewTextures.end()) diff --git a/FEEditorPreviewManager.h b/FEEditorPreviewManager.h index 3aa0fe4..f8f962d 100644 --- a/FEEditorPreviewManager.h +++ b/FEEditorPreviewManager.h @@ -31,21 +31,14 @@ class FEEditorPreviewManager FEScene* PreviewScene = nullptr; - FEFramebuffer* PreviewFB; FEEntity* PreviewEntity; - FEPrefab* PreviewPrefab; FEGameModel* PreviewGameModel; FEMaterial* MeshPreviewMaterial; - // FIX ME! Make it work. - // Local directional entity FEEntity* LocalSunEntity; FEEntity* LocalCameraEntity; // Saved scene settings - glm::vec3 RegularLightRotation = glm::vec3(0.0f, 0.0f, 0.0f); - float RegularLightIntensity = 0.0f; - glm::mat4 RegularLightWorldMatrix = glm::identity(); bool bIsRegularFogEnabled = false; std::unordered_map MeshPreviewTextures; diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index e56d966..b5f4bb0 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -1,5 +1,6 @@ #include "FEEditorSelectedObject.h" #include "FEProject.h" +#include "FEEditor.h" using namespace FocalEngine; FEEditorSelectedObject* FEEditorSelectedObject::Instance = nullptr; @@ -10,10 +11,6 @@ void FEEditorSelectedObject::InitializeResources() { HALO_SELECTION_EFFECT.InitializeResources(); - PixelAccurateSelectionFB = RESOURCE_MANAGER.CreateFramebuffer(FE_COLOR_ATTACHMENT | FE_DEPTH_ATTACHMENT, ENGINE.GetRenderTargetWidth(), ENGINE.GetRenderTargetHeight()); - delete PixelAccurateSelectionFB->GetColorAttachment(); - PixelAccurateSelectionFB->SetColorAttachment(RESOURCE_MANAGER.CreateTexture(GL_RGB, GL_RGB, ENGINE.GetRenderTargetWidth(), ENGINE.GetRenderTargetHeight())); - PixelAccurateSelectionMaterial = RESOURCE_MANAGER.CreateMaterial("pixelAccurateSelectionMaterial"); RESOURCE_MANAGER.MakeMaterialStandard(PixelAccurateSelectionMaterial); @@ -39,53 +36,43 @@ void FEEditorSelectedObject::InitializeResources() const FEShaderParam ColorParam(glm::vec3(0.0f, 0.0f, 0.0f), "baseColor"); PixelAccurateSelectionMaterial->AddParameter(ColorParam); - - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (!ActiveScenes.empty()) - { - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - DummyEntity = CurrentScene->CreateEntity("Editor_Selection_Dummy_Entity"); - } } -void FEEditorSelectedObject::ReInitializeResources() +void FEEditorSelectedObject::UpdateResources(FEScene* Scene) { - HALO_SELECTION_EFFECT.ReInitializeResources(); + HALO_SELECTION_EFFECT.UpdateResources(Scene); - delete PixelAccurateSelectionFB; - PixelAccurateSelectionFB = RESOURCE_MANAGER.CreateFramebuffer(FE_COLOR_ATTACHMENT | FE_DEPTH_ATTACHMENT, ENGINE.GetRenderTargetWidth(), ENGINE.GetRenderTargetHeight()); - delete PixelAccurateSelectionFB->GetColorAttachment(); - PixelAccurateSelectionFB->SetColorAttachment(RESOURCE_MANAGER.CreateTexture(GL_RGB, GL_RGB, ENGINE.GetRenderTargetWidth(), ENGINE.GetRenderTargetHeight())); + if (Scene == nullptr) + return; - // FIX ME! Temporary solution, only supports one scene - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); - if (!ActiveScenes.empty()) - { - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - if (CurrentScene->GetEntityByName("Editor_Selection_Dummy_Entity").empty()) - DummyEntity = CurrentScene->CreateEntity("Editor_Selection_Dummy_Entity"); - } -} + FESelectionData* CurrentSelectionData = GetSceneData(Scene->GetObjectID()); + if (CurrentSelectionData == nullptr) + return; -void FEEditorSelectedObject::SetOnUpdateFunc(void(*Func)()) -{ - OnUpdateFunc = Func; -} + FEEntity* CurrentCamera = CAMERA_SYSTEM.GetMainCameraEntity(Scene); + FECameraComponent& CameraComponent = CurrentCamera->GetComponent(); -FEEntity* FEEditorSelectedObject::GetSelected() const -{ - return Container; + delete CurrentSelectionData->PixelAccurateSelectionFB; + CurrentSelectionData->PixelAccurateSelectionFB = RESOURCE_MANAGER.CreateFramebuffer(FE_COLOR_ATTACHMENT | FE_DEPTH_ATTACHMENT, CameraComponent.GetRenderTargetWidth(), CameraComponent.GetRenderTargetHeight()); + delete CurrentSelectionData->PixelAccurateSelectionFB->GetColorAttachment(); + CurrentSelectionData->PixelAccurateSelectionFB->SetColorAttachment(RESOURCE_MANAGER.CreateTexture(GL_RGB, GL_RGB, CameraComponent.GetRenderTargetWidth(), CameraComponent.GetRenderTargetHeight())); } -bool FEEditorSelectedObject::GetDirtyFlag() const +void FEEditorSelectedObject::SetOnUpdateFunction(std::function Func) { - return bDirtyFlag; + OnUpdateFunction = Func; } -void FEEditorSelectedObject::SetDirtyFlag(const bool NewValue) +FEEntity* FEEditorSelectedObject::GetSelected(FEScene* Scene) { - bDirtyFlag = NewValue; + if (Scene == nullptr) + return nullptr; + + FESelectionData* CurrentSelectionData = GetSceneData(Scene->GetObjectID()); + if (CurrentSelectionData == nullptr) + return nullptr; + + return CurrentSelectionData->Container; } void FEEditorSelectedObject::SetSelected(FEEntity* SelectedObject) @@ -93,72 +80,74 @@ void FEEditorSelectedObject::SetSelected(FEEntity* SelectedObject) if (SelectedObject == nullptr) return; - if (Container != nullptr && Container->HasComponent() && Container != SelectedObject) - TERRAIN_SYSTEM.SetBrushMode(Container, FE_TERRAIN_BRUSH_NONE); - - if (Container != SelectedObject) - bDirtyFlag = true; - - Container = SelectedObject; - if (OnUpdateFunc != nullptr) - OnUpdateFunc(); -} + FEScene* CurrentScene = SelectedObject->GetParentScene(); + if (CurrentScene == nullptr) + return; -void FEEditorSelectedObject::Clear() -{ - if (InstancedSubObjectIndexSelected != -1 && Container->HasComponent()) + FESelectionData* CurrentSelectionData = GetSceneData(CurrentScene->GetObjectID()); + if (CurrentSelectionData == nullptr) { - INSTANCED_RENDERING_SYSTEM.SetIndividualSelectMode(Container, false); + AddSceneData(CurrentScene->GetObjectID()); + CurrentSelectionData = GetSceneData(CurrentScene->GetObjectID()); } - InstancedSubObjectIndexSelected = -1; - Container = nullptr; - bDirtyFlag = true; + if (CurrentSelectionData->Container != nullptr && CurrentSelectionData->Container->HasComponent() && CurrentSelectionData->Container != SelectedObject) + TERRAIN_SYSTEM.SetBrushMode(CurrentSelectionData->Container, FE_TERRAIN_BRUSH_NONE); - if (!SCENE_MANAGER.GetActiveScenes().empty()) - if (OnUpdateFunc != nullptr) - OnUpdateFunc(); + CurrentSelectionData->Container = SelectedObject; + if (OnUpdateFunction != nullptr) + OnUpdateFunction(CurrentScene); } -glm::dvec3 FEEditorSelectedObject::MouseRay(const double MouseX, const double MouseY) const +void FEEditorSelectedObject::Clear(FEScene* Scene) { - FEEntity* MainCameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(PROJECT_MANAGER.GetCurrent()->GetScene()); - FECameraComponent& CameraComponent = MainCameraEntity->GetComponent(); + if (Scene == nullptr) + return; + + FESelectionData* CurrentSelectionData = GetSceneData(Scene->GetObjectID()); + if (CurrentSelectionData == nullptr) + return; - glm::dvec2 NormalizedMouseCoords; - NormalizedMouseCoords.x = (2.0f * MouseX) / ENGINE.GetRenderTargetWidth() - 1; - NormalizedMouseCoords.y = 1.0f - (2.0f * (MouseY)) / ENGINE.GetRenderTargetHeight(); + if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1 && CurrentSelectionData->Container->HasComponent()) + { + INSTANCED_RENDERING_SYSTEM.SetIndividualSelectMode(CurrentSelectionData->Container, false); + } - const glm::dvec4 ClipCoords = glm::dvec4(NormalizedMouseCoords.x, NormalizedMouseCoords.y, -1.0, 1.0); - glm::dvec4 EyeCoords = glm::inverse(CameraComponent.GetProjectionMatrix()) * ClipCoords; - EyeCoords.z = -1.0f; - EyeCoords.w = 0.0f; - glm::dvec3 WorldRay = glm::inverse(CameraComponent.GetViewMatrix()) * EyeCoords; - WorldRay = glm::normalize(WorldRay); + CurrentSelectionData->InstancedSubObjectIndexSelected = -1; + CurrentSelectionData->Container = nullptr; - return WorldRay; + if (!SCENE_MANAGER.GetActiveScenes().empty()) + if (OnUpdateFunction != nullptr) + OnUpdateFunction(Scene); } -void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, const double MouseY) +void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, const double MouseY, FEScene* Scene) { - SELECTED.SceneEntitiesUnderMouse.clear(); - SELECTED.InstancedSubObjectsInfo.clear(); + FESelectionData* CurrentSelectionData = GetSceneData(Scene->GetObjectID()); + if (CurrentSelectionData == nullptr) + return; - // FIX ME! Temporary solution, only supports one scene - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; + CurrentSelectionData->SceneEntitiesUnderMouse.clear(); + CurrentSelectionData->InstancedSubObjectsInfo.clear(); - // FIX ME! Temporary solution - FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(CurrentScene); + FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(Scene); FETransformComponent& CameraTransformComponent = MainCamera->GetComponent(); FECameraComponent& CameraComponent = MainCamera->GetComponent(); - const glm::vec3 MouseRayVector = MouseRay(MouseX, MouseY); - const std::vector EntityList = CurrentScene->GetEntityIDList(); + FEViewport* CurrentViewport = CAMERA_SYSTEM.GetMainCameraViewport(Scene); + glm::ivec2 ViewportPosition = glm::ivec2(CurrentViewport->GetX(), CurrentViewport->GetY()); + glm::ivec2 ViewportSize = glm::ivec2(CurrentViewport->GetWidth(), CurrentViewport->GetHeight()); + + const glm::vec3 MouseRay = GEOMETRY.CreateMouseRayToWorld(MouseX, MouseY, + CameraComponent.GetViewMatrix(), CameraComponent.GetProjectionMatrix(), + ViewportPosition, ViewportSize); + + const std::vector EntityList = Scene->GetEntityIDList(); for (size_t i = 0; i < EntityList.size(); i++) { float Distance = 0; - FEEntity* CurrentEntity = CurrentScene->GetEntity(EntityList[i]); + FEEntity* CurrentEntity = Scene->GetEntity(EntityList[i]); if (CurrentEntity != nullptr) { FEAABB Box; @@ -175,45 +164,65 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons Box = TERRAIN_SYSTEM.GetAABB(CurrentEntity); } - if (Box.RayIntersect(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRayVector, Distance)) + if (Box.RayIntersect(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRay, Distance)) { if (CurrentEntity->HasComponent()) { FEInstancedComponent& InstancedComponent = CurrentEntity->GetComponent(); if (INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(CurrentEntity)) { - InstancedSubObjectsInfo[CurrentEntity] = std::vector(); + CurrentSelectionData->InstancedSubObjectsInfo[CurrentEntity] = std::vector(); for (size_t j = 0; j < InstancedComponent.IndividualInstancedAABB.size(); j++) { - if (InstancedComponent.IndividualInstancedAABB[j].RayIntersect(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRayVector, Distance)) + if (InstancedComponent.IndividualInstancedAABB[j].RayIntersect(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRay, Distance)) { - InstancedSubObjectsInfo[CurrentEntity].push_back(static_cast(j)); + CurrentSelectionData->InstancedSubObjectsInfo[CurrentEntity].push_back(static_cast(j)); } } } } - SELECTED.SceneEntitiesUnderMouse.push_back(CurrentEntity); + CurrentSelectionData->SceneEntitiesUnderMouse.push_back(CurrentEntity); } } } } -int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, const double MouseY) +int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, const double MouseY, FEScene* Scene) { + FESelectionData* CurrentSelectionData = GetSceneData(Scene->GetObjectID()); + if (CurrentSelectionData == nullptr) + return -1; + #ifndef EDITOR_SELECTION_DEBUG_MODE - if (!CheckForSelectionisNeeded) + if (!CurrentSelectionData->CheckForSelectionisNeeded) return -1; #endif - CheckForSelectionisNeeded = false; + CurrentSelectionData->CheckForSelectionisNeeded = false; + + int LocalMouseX = static_cast(MouseX); + int LocalMouseY = static_cast(MouseY); - PixelAccurateSelectionFB->Bind(); + FEViewport* CurrentViewport = CAMERA_SYSTEM.GetMainCameraViewport(Scene); + glm::ivec2 ViewportPosition = glm::ivec2(CurrentViewport->GetX(), CurrentViewport->GetY()); + LocalMouseX -= ViewportPosition.x; + LocalMouseY -= ViewportPosition.y; + + // If the mouse is out of the viewport, return -1 + if (LocalMouseY < 0) + return -1; + + CurrentSelectionData->PixelAccurateSelectionFB->Bind(); glm::vec4 OriginalClearColor = ENGINE.GetClearColor(); + glm::ivec4 OriginalViewport = RENDERER.GetViewport(); + RENDERER.SetViewport(0, 0, CurrentSelectionData->PixelAccurateSelectionFB->GetWidth(), CurrentSelectionData->PixelAccurateSelectionFB->GetHeight()); ENGINE.SetClearColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.0f)); FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); - for (size_t i = 0; i < SELECTED.SceneEntitiesUnderMouse.size(); i++) + FEEntity* CurrentCamera = CAMERA_SYSTEM.GetMainCameraEntity(Scene); + + for (size_t i = 0; i < CurrentSelectionData->SceneEntitiesUnderMouse.size(); i++) { #ifdef EDITOR_SELECTION_DEBUG_MODE int r = (i + 1) * 50 & 255; @@ -224,7 +233,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons int g = ((i + 1) >> 8) & 255; int b = ((i + 1) >> 16) & 255; #endif - FEEntity* PotentiallySelectedEntity = SELECTED.SceneEntitiesUnderMouse[i]; + FEEntity* PotentiallySelectedEntity = CurrentSelectionData->SceneEntitiesUnderMouse[i]; if (PotentiallySelectedEntity->HasComponent()) { FEGameModelComponent& GameModelComponent = PotentiallySelectedEntity->GetComponent(); @@ -241,11 +250,11 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons if (!PotentiallySelectedEntity->HasComponent()) { - RENDERER.RenderGameModelComponent(PotentiallySelectedEntity); + RENDERER.RenderGameModelComponent(PotentiallySelectedEntity, CurrentCamera); } else if (PotentiallySelectedEntity->HasComponent()) { - // Render instanced object only if it is not in individual select mode + // Update instanced object only if it is not in individual select mode if (!INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(PotentiallySelectedEntity)) { PixelAccurateSelectionMaterial->Shader = FEPixelAccurateInstancedSelection; @@ -253,7 +262,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons GameModelComponent.GameModel->SetBillboardMaterial(PixelAccurateSelectionMaterial); FEInstancedComponent& InstancedComponent = PotentiallySelectedEntity->GetComponent(); - RENDERER.RenderGameModelComponentWithInstanced(PotentiallySelectedEntity, nullptr); + RENDERER.RenderGameModelComponentWithInstanced(PotentiallySelectedEntity, CurrentCamera); PixelAccurateSelectionMaterial->Shader = FEPixelAccurateSelection; GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterials); @@ -272,40 +281,37 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); - RENDERER.RenderTerrainComponent(PotentiallySelectedEntity); + RENDERER.RenderTerrainComponent(PotentiallySelectedEntity, CurrentCamera); TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); } } - int LastColorShiftIndex = static_cast(SELECTED.SceneEntitiesUnderMouse.size() - 1); + int LastColorShiftIndex = static_cast(CurrentSelectionData->SceneEntitiesUnderMouse.size() - 1); - // FIX ME! Temporary solution, only supports one scene - FEScene* CurrentScene = SCENE_MANAGER.GetActiveScenes()[0]; - - auto it = InstancedSubObjectsInfo.begin(); - while (it != InstancedSubObjectsInfo.end()) + auto InstancedSubObjectIterator = CurrentSelectionData->InstancedSubObjectsInfo.begin(); + while (InstancedSubObjectIterator != CurrentSelectionData->InstancedSubObjectsInfo.end()) { - for (size_t j = 0; j < it->second.size(); j++) + for (size_t j = 0; j < InstancedSubObjectIterator->second.size(); j++) { LastColorShiftIndex++; int r = (LastColorShiftIndex + 1) & 255; int g = ((LastColorShiftIndex + 1) >> 8) & 255; int b = ((LastColorShiftIndex + 1) >> 16) & 255; - static FEEntity* DummyEntity = CurrentScene->CreateEntity("DummyEntity"); + static FEEntity* DummyEntity = Scene->CreateEntity("DummyEntity"); if (!DummyEntity->HasComponent()) DummyEntity->AddComponent(); FEGameModelComponent& DummyGameModelComponent = DummyEntity->GetComponent(); - FEGameModelComponent& OriginalGameModelComponent = it->first->GetComponent(); + FEGameModelComponent& OriginalGameModelComponent = InstancedSubObjectIterator->first->GetComponent(); DummyGameModelComponent.GameModel = OriginalGameModelComponent.GameModel; DummyGameModelComponent.SetVisibility(true); - FEInstancedComponent& InstancedComponent = it->first->GetComponent(); + FEInstancedComponent& InstancedComponent = InstancedSubObjectIterator->first->GetComponent(); FETransformComponent& DummyTransformComponent = DummyEntity->GetComponent(); - DummyTransformComponent = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(it->second[j])); + DummyTransformComponent = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(InstancedSubObjectIterator->second[j])); FEMaterial* RegularMaterial = OriginalGameModelComponent.GameModel->Material; DummyGameModelComponent.GameModel->Material = PixelAccurateSelectionMaterial; @@ -314,79 +320,82 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - RENDERER.RenderGameModelComponent(DummyEntity); + RENDERER.RenderGameModelComponent(DummyEntity, CurrentCamera); OriginalGameModelComponent.GameModel->Material = RegularMaterial; DummyGameModelComponent.SetVisibility(false); } - it++; + InstancedSubObjectIterator++; } - FE_GL_ERROR(glReadPixels(static_cast(MouseX), GLint(ENGINE.GetRenderTargetHeight() - MouseY), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, ColorUnderMouse)); - PixelAccurateSelectionFB->UnBind(); + FETransformComponent& CameraTransformComponent = CurrentCamera->GetComponent(); + FECameraComponent& CameraComponent = CurrentCamera->GetComponent(); + FE_GL_ERROR(glReadPixels(static_cast(LocalMouseX), GLint(CameraComponent.GetRenderTargetHeight() - LocalMouseY), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, CurrentSelectionData->ColorUnderMouse)); + CurrentSelectionData->PixelAccurateSelectionFB->UnBind(); + RENDERER.SetViewport(OriginalViewport); ENGINE.SetClearColor(OriginalClearColor); #ifndef EDITOR_SELECTION_DEBUG_MODE - if (!SELECTED.SceneEntitiesUnderMouse.empty()) + if (!CurrentSelectionData->SceneEntitiesUnderMouse.empty()) { - ColorIndex = 0; - ColorIndex |= static_cast(ColorUnderMouse[2]); - ColorIndex <<= 8; - ColorIndex |= static_cast(ColorUnderMouse[1]); - ColorIndex <<= 8; - ColorIndex |= static_cast(ColorUnderMouse[0]); + CurrentSelectionData->ColorIndex = 0; + CurrentSelectionData->ColorIndex |= static_cast(CurrentSelectionData->ColorUnderMouse[2]); + CurrentSelectionData->ColorIndex <<= 8; + CurrentSelectionData->ColorIndex |= static_cast(CurrentSelectionData->ColorUnderMouse[1]); + CurrentSelectionData->ColorIndex <<= 8; + CurrentSelectionData->ColorIndex |= static_cast(CurrentSelectionData->ColorUnderMouse[0]); - ColorIndex -= 1; + CurrentSelectionData->ColorIndex -= 1; - if (ColorIndex != -1 && ColorIndex >= static_cast(SELECTED.SceneEntitiesUnderMouse.size())) + if (CurrentSelectionData->ColorIndex != -1 && CurrentSelectionData->ColorIndex >= static_cast(CurrentSelectionData->SceneEntitiesUnderMouse.size())) { - ColorIndex -= static_cast(SELECTED.SceneEntitiesUnderMouse.size()); + CurrentSelectionData->ColorIndex -= static_cast(CurrentSelectionData->SceneEntitiesUnderMouse.size()); const FEEntity* SelectedSubObjectInInstance = nullptr; - auto it = InstancedSubObjectsInfo.begin(); - while (it != InstancedSubObjectsInfo.end()) + auto InstancedSubObjectIterator = CurrentSelectionData->InstancedSubObjectsInfo.begin(); + while (InstancedSubObjectIterator != CurrentSelectionData->InstancedSubObjectsInfo.end()) { - if (ColorIndex < static_cast(it->second.size())) + if (CurrentSelectionData->ColorIndex < static_cast(InstancedSubObjectIterator->second.size())) { - InstancedSubObjectIndexSelected = it->second[ColorIndex]; - SelectedSubObjectInInstance = it->first; + CurrentSelectionData->InstancedSubObjectIndexSelected = InstancedSubObjectIterator->second[CurrentSelectionData->ColorIndex]; + SelectedSubObjectInInstance = InstancedSubObjectIterator->first; break; } - ColorIndex -= static_cast(it->second.size()); - it++; + CurrentSelectionData->ColorIndex -= static_cast(InstancedSubObjectIterator->second.size()); + InstancedSubObjectIterator++; } if (SelectedSubObjectInInstance != nullptr) { - for (size_t i = 0; i < SELECTED.SceneEntitiesUnderMouse.size(); i++) + for (size_t i = 0; i < CurrentSelectionData->SceneEntitiesUnderMouse.size(); i++) { - if (SELECTED.SceneEntitiesUnderMouse[i]->GetObjectID() == SelectedSubObjectInInstance->GetObjectID()) + if (CurrentSelectionData->SceneEntitiesUnderMouse[i]->GetObjectID() == SelectedSubObjectInInstance->GetObjectID()) { return static_cast(i); } } } } - else if (ColorIndex != -1) + else if (CurrentSelectionData->ColorIndex != -1) { - return ColorIndex; + return CurrentSelectionData->ColorIndex; } } - SELECTED.Clear(); + SELECTED.Clear(Scene); return -1; #else - ColorIndex = 0; - ColorIndex |= int(ColorUnderMouse[2]); - ColorIndex <<= 8; - ColorIndex |= int(ColorUnderMouse[1]); - ColorIndex <<= 8; - ColorIndex |= int(ColorUnderMouse[0]); + CurrentSelectionData->ColorIndex = 0; + CurrentSelectionData->ColorIndex |= int(CurrentSelectionData->ColorUnderMouse[2]); + CurrentSelectionData->ColorIndex <<= 8; + CurrentSelectionData->ColorIndex |= int(CurrentSelectionData->ColorUnderMouse[1]); + CurrentSelectionData->ColorIndex <<= 8; + CurrentSelectionData->ColorIndex |= int(CurrentSelectionData->ColorUnderMouse[0]); - ColorIndex /= 50; - ColorIndex -= 1; + CurrentSelectionData->ColorIndex /= 50; + CurrentSelectionData->ColorIndex -= 1; return -1; #endif @@ -394,120 +403,219 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons void FEEditorSelectedObject::OnCameraUpdate() const { - HALO_SELECTION_EFFECT.HaloObjectsFb->Bind(); - HALO_SELECTION_EFFECT.HaloMaterial->ClearAllTexturesInfo(); - HALO_SELECTION_EFFECT.HaloMaterial->SetBaseColor(glm::vec3(1.0f, 0.25f, 0.0f)); - FE_GL_ERROR(glViewport(0, 0, RENDERER.SceneToTextureFB->GetWidth(), RENDERER.SceneToTextureFB->GetHeight())); - glm::vec4 OriginalClearColor = ENGINE.GetClearColor(); - ENGINE.SetClearColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.0f)); - FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT)); - - if (Container == nullptr) + auto SceneIterator = PerSceneData.begin(); + while (SceneIterator != PerSceneData.end()) { - HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); - ENGINE.SetClearColor(OriginalClearColor); - HALO_SELECTION_EFFECT.PostProcess->bActive = true; + FESelectionData* CurrentSelectionData = SceneIterator->second; - return; - } + FEScene* CurrentScene = SCENE_MANAGER.GetScene(SceneIterator->first); + if (CurrentScene == nullptr) + { + SceneIterator++; + continue; + } - if (Container->HasComponent()) - { - FEGameModelComponent& GameModelComponent = Container->GetComponent(); - FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; + FEHaloSelectionData* HaloSelectionData = HALO_SELECTION_EFFECT.GetSceneData(CurrentScene->GetObjectID()); + FEEntity* CurrentCamera = CAMERA_SYSTEM.GetMainCameraEntity(CurrentScene); + if (CurrentCamera == nullptr || HaloSelectionData->PostProcess == nullptr) + { + SceneIterator++; + continue; + } + + HaloSelectionData->HaloObjectsFB->Bind(); + HALO_SELECTION_EFFECT.HaloMaterial->ClearAllTexturesInfo(); + HALO_SELECTION_EFFECT.HaloMaterial->SetBaseColor(glm::vec3(1.0f, 0.25f, 0.0f)); + + FECameraComponent& CameraComponent = CurrentCamera->GetComponent(); + RENDERER.SetViewport(0, 0, CameraComponent.GetRenderTargetWidth(), CameraComponent.GetRenderTargetHeight()); - GameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + glm::vec4 OriginalClearColor = ENGINE.GetClearColor(); + ENGINE.SetClearColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.0f)); + FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT)); - if (!Container->HasComponent()) + if (CurrentSelectionData->Container == nullptr) { - RENDERER.RenderGameModelComponent(Container); + HaloSelectionData->HaloObjectsFB->UnBind(); + ENGINE.SetClearColor(OriginalClearColor); + HaloSelectionData->PostProcess->bActive = true; + + SceneIterator++; + continue; } - else if (Container->HasComponent()) + + if (CurrentSelectionData->Container->HasComponent()) { - if (InstancedSubObjectIndexSelected != -1) + FEGameModelComponent& GameModelComponent = CurrentSelectionData->Container->GetComponent(); + FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; + + GameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + + if (!CurrentSelectionData->Container->HasComponent()) + { + RENDERER.RenderGameModelComponent(CurrentSelectionData->Container, CurrentCamera); + } + else if (CurrentSelectionData->Container->HasComponent()) { - if (!DummyEntity->HasComponent()) - DummyEntity->AddComponent(); + if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1) + { + if (!CurrentSelectionData->DummyEntity->HasComponent()) + CurrentSelectionData->DummyEntity->AddComponent(); - FEGameModelComponent& DummyGameModelComponent = DummyEntity->GetComponent(); - DummyGameModelComponent.GameModel = GameModelComponent.GameModel; - DummyGameModelComponent.SetVisibility(true); + FEGameModelComponent& DummyGameModelComponent = CurrentSelectionData->DummyEntity->GetComponent(); + DummyGameModelComponent.GameModel = GameModelComponent.GameModel; + DummyGameModelComponent.SetVisibility(true); - FEInstancedComponent& InstancedComponent = Container->GetComponent(); - DummyEntity->GetComponent() = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(InstancedSubObjectIndexSelected)); + FEInstancedComponent& InstancedComponent = CurrentSelectionData->Container->GetComponent(); + CurrentSelectionData->DummyEntity->GetComponent() = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(CurrentSelectionData->InstancedSubObjectIndexSelected)); - FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; - DummyGameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; + FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; + DummyGameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; - HALO_SELECTION_EFFECT.HaloMaterial->SetBaseColor(glm::vec3(0.61f, 0.86f, 1.0f)); - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + HALO_SELECTION_EFFECT.HaloMaterial->SetBaseColor(glm::vec3(0.61f, 0.86f, 1.0f)); + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - RENDERER.RenderGameModelComponent(DummyEntity); + RENDERER.RenderGameModelComponent(CurrentSelectionData->DummyEntity, CurrentCamera); - GameModelComponent.GameModel->Material = RegularMaterial; - DummyGameModelComponent.SetVisibility(false); - } - else - { - HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawInstancedObjectShader; - FEMaterial* RegularBillboardMaterial = GameModelComponent.GameModel->GetBillboardMaterial(); - GameModelComponent.GameModel->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); + GameModelComponent.GameModel->Material = RegularMaterial; + DummyGameModelComponent.SetVisibility(false); + } + else + { + HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawInstancedObjectShader; + FEMaterial* RegularBillboardMaterial = GameModelComponent.GameModel->GetBillboardMaterial(); + GameModelComponent.GameModel->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); - RENDERER.RenderGameModelComponentWithInstanced(Container, nullptr); + RENDERER.RenderGameModelComponentWithInstanced(CurrentSelectionData->Container, CurrentCamera); - HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; - GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterial); + HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; + GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterial); + } } + + GameModelComponent.GameModel->Material = RegularMaterial; } + else if (CurrentSelectionData->Container->HasComponent()) + { + FETerrainComponent& TerrainComponent = CurrentSelectionData->Container->GetComponent(); + TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); + TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f, 0.25f, 0.0f)); + const float RegularLODLevel = TerrainComponent.GetLODLevel(); + TerrainComponent.SetLODLevel(0.0f); - GameModelComponent.GameModel->Material = RegularMaterial; - } - else if (Container->HasComponent()) - { - FETerrainComponent& TerrainComponent = Container->GetComponent(); - TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); - TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f, 0.25f, 0.0f)); - const float RegularLODLevel = TerrainComponent.GetLODLevel(); - TerrainComponent.SetLODLevel(0.0f); + RENDERER.RenderTerrainComponent(CurrentSelectionData->Container, CurrentCamera); - RENDERER.RenderTerrainComponent(Container); + TerrainComponent.SetLODLevel(RegularLODLevel); + TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); + TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); + } - TerrainComponent.SetLODLevel(RegularLODLevel); - TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); - TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); - } + HaloSelectionData->HaloObjectsFB->UnBind(); + ENGINE.SetClearColor(OriginalClearColor); + HaloSelectionData->PostProcess->bActive = true; - HALO_SELECTION_EFFECT.HaloObjectsFb->UnBind(); - ENGINE.SetClearColor(OriginalClearColor); - HALO_SELECTION_EFFECT.PostProcess->bActive = true; + SceneIterator++; + } } -int FEEditorSelectedObject::DebugGetLastColorIndex() const +int FEEditorSelectedObject::DebugGetLastColorIndex(FEScene* Scene) { - return ColorIndex; + FESelectionData* CurrentSelectionData = GetSceneData(Scene->GetObjectID()); + if (CurrentSelectionData == nullptr) + return -1; + + return CurrentSelectionData->ColorIndex; } -void FEEditorSelectedObject::SetSelectedByIndex(const size_t Index) +void FEEditorSelectedObject::SetSelectedByIndex(const size_t Index, FEScene* Scene) { - if (Index < 0 || Index >= SceneEntitiesUnderMouse.size()) + FESelectionData* CurrentSelectionData = GetSceneData(Scene->GetObjectID()); + if (CurrentSelectionData == nullptr) + return; + + if (Index < 0 || Index >= CurrentSelectionData->SceneEntitiesUnderMouse.size()) return; - if (Container != nullptr) + if (CurrentSelectionData->Container != nullptr) { - if (Container->HasComponent()) + if (CurrentSelectionData->Container->HasComponent()) { - if (SceneEntitiesUnderMouse[Index]->GetObjectID() != Container->GetObjectID()) + if (CurrentSelectionData->SceneEntitiesUnderMouse[Index]->GetObjectID() != CurrentSelectionData->Container->GetObjectID()) { - INSTANCED_RENDERING_SYSTEM.SetIndividualSelectMode(Container, false); - InstancedSubObjectIndexSelected = -1; + INSTANCED_RENDERING_SYSTEM.SetIndividualSelectMode(CurrentSelectionData->Container, false); + CurrentSelectionData->InstancedSubObjectIndexSelected = -1; } } } - Container = SceneEntitiesUnderMouse[Index]; - if (OnUpdateFunc != nullptr) - OnUpdateFunc(); + CurrentSelectionData->Container = CurrentSelectionData->SceneEntitiesUnderMouse[Index]; + if (OnUpdateFunction != nullptr) + OnUpdateFunction(Scene); +} + +void FEEditorSelectedObject::ClearAllSceneData() +{ + auto PerSceneIterator = PerSceneData.begin(); + while (PerSceneIterator != PerSceneData.end()) + { + delete PerSceneIterator->second; + PerSceneIterator++; + } + + PerSceneData.clear(); +} + +void FEEditorSelectedObject::ClearSceneData(const std::string& SceneID) +{ + auto FoundSceneData = PerSceneData.find(SceneID); + if (FoundSceneData != PerSceneData.end()) + { + delete FoundSceneData->second; + PerSceneData.erase(FoundSceneData); + } +} + +void FEEditorSelectedObject::AddSceneData(const std::string& SceneID) +{ + FEScene* CurrentScene = SCENE_MANAGER.GetScene(SceneID); + if (CurrentScene == nullptr) + return; + + if (PerSceneData.find(SceneID) != PerSceneData.end()) + return; + + PerSceneData[SceneID] = new FESelectionData(); + PerSceneData[SceneID]->SceneID = SceneID; + + FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(CurrentScene); + FETransformComponent& CameraTransformComponent = MainCamera->GetComponent(); + FECameraComponent& CameraComponent = MainCamera->GetComponent(); + + PerSceneData[SceneID]->PixelAccurateSelectionFB = RESOURCE_MANAGER.CreateFramebuffer(FE_COLOR_ATTACHMENT | FE_DEPTH_ATTACHMENT, CameraComponent.GetRenderTargetWidth(), CameraComponent.GetRenderTargetHeight()); + delete PerSceneData[SceneID]->PixelAccurateSelectionFB->GetColorAttachment(); + PerSceneData[SceneID]->PixelAccurateSelectionFB->SetColorAttachment(RESOURCE_MANAGER.CreateTexture(GL_RGB, GL_RGB, CameraComponent.GetRenderTargetWidth(), CameraComponent.GetRenderTargetHeight())); + + if (CurrentScene->GetEntityByName("Editor_Selection_Dummy_Entity").empty()) + PerSceneData[SceneID]->DummyEntity = CurrentScene->CreateEntity("Editor_Selection_Dummy_Entity"); + + HALO_SELECTION_EFFECT.AddSceneData(SceneID); +} + +FESelectionData* FEEditorSelectedObject::GetSceneData(const std::string& SceneID) +{ + auto FoundScene = PerSceneData.find(SceneID); + if (FoundScene != PerSceneData.end()) + { + return FoundScene->second; + } + + return nullptr; +} + +void FEEditorSelectedObject::ClearAll() +{ + SELECTED.ClearAllSceneData(); } \ No newline at end of file diff --git a/FEEditorSelectedObject.h b/FEEditorSelectedObject.h index 9329dcf..111e8e4 100644 --- a/FEEditorSelectedObject.h +++ b/FEEditorSelectedObject.h @@ -5,61 +5,76 @@ using namespace FocalEngine; //#define EDITOR_SELECTION_DEBUG_MODE -class FEEditor; +class FESelectionData +{ + friend class FEEditor; + friend class FEEditorSelectedObject; + friend class GizmoManager; + friend class FEEditorInspectorWindow; + + std::string SceneID = ""; +public: + FEFramebuffer* PixelAccurateSelectionFB = nullptr; + + std::vector SceneEntitiesUnderMouse; + FEEntity* PotentiallySelectedEntity = nullptr; + FEEntity* Container = nullptr; + FEEntity* DummyEntity = nullptr; + + bool CheckForSelectionisNeeded = false; + + std::unordered_map> InstancedSubObjectsInfo; + int InstancedSubObjectIndexSelected = -1; + + unsigned char* ColorUnderMouse = new unsigned char[3]; + int ColorIndex = -1; + + ~FESelectionData() + { + delete PixelAccurateSelectionFB; + delete[] ColorUnderMouse; + } +}; class FEEditorSelectedObject { - friend FEEditor; + friend class FEEditor; + friend class GizmoManager; + friend class FEEditorInspectorWindow; SINGLETON_PRIVATE_PART(FEEditorSelectedObject) public: SINGLETON_PUBLIC_PART(FEEditorSelectedObject) void InitializeResources(); - void ReInitializeResources(); - void SetOnUpdateFunc(void(*Func)()); - - FEEntity* GetSelected() const; + void UpdateResources(FEScene* Scene); + void SetOnUpdateFunction(std::function Func); - bool GetDirtyFlag() const; - void SetDirtyFlag(bool NewValue); + FEEntity* GetSelected(FEScene* Scene); void SetSelected(FEEntity* SelectedObject); - void Clear(); + void Clear(FEScene* Scene); + void ClearAll(); - glm::dvec3 MouseRay(double MouseX, double MouseY) const; - void DetermineEntityUnderMouse(double MouseX, double MouseY); - std::vector SceneEntitiesUnderMouse; - - bool CheckForSelectionisNeeded = false; - int GetIndexOfObjectUnderMouse(double MouseX, double MouseY); + void DetermineEntityUnderMouse(double MouseX, double MouseY, FEScene* Scene); + int GetIndexOfObjectUnderMouse(double MouseX, double MouseY, FEScene* Scene); + void SetSelectedByIndex(size_t Index, FEScene* Scene); void OnCameraUpdate() const; - int DebugGetLastColorIndex() const; - std::unordered_map> InstancedSubObjectsInfo; - int InstancedSubObjectIndexSelected = -1; - void SetSelectedByIndex(size_t Index); - - FEShader* FEPixelAccurateInstancedSelection = nullptr; - FEShader* FEPixelAccurateSelection = nullptr; + FESelectionData* GetSceneData(const std::string& SceneID); private: - FEEntity* Container = nullptr; - FEEntity* DummyEntity = nullptr; + FEShader* FEPixelAccurateInstancedSelection = nullptr; + FEShader* FEPixelAccurateSelection = nullptr; + FEMaterial* PixelAccurateSelectionMaterial = nullptr; - bool bDirtyFlag = false; + std::function OnUpdateFunction = nullptr; - void(*OnUpdateFunc)() = nullptr; -#ifdef EDITOR_SELECTION_DEBUG_MODE -public: -#endif - unsigned char* ColorUnderMouse = new unsigned char[3]; - FEFramebuffer* PixelAccurateSelectionFB; - int ColorIndex = -1; -#ifdef EDITOR_SELECTION_DEBUG_MODE -private: -#endif - FEEntity* PotentiallySelectedEntity = nullptr; - FEMaterial* PixelAccurateSelectionMaterial = nullptr; + int DebugGetLastColorIndex(FEScene* Scene); + + std::unordered_map PerSceneData; + void ClearAllSceneData(); + void ClearSceneData(const std::string& SceneID); + void AddSceneData(const std::string& SceneID); }; #define SELECTED FEEditorSelectedObject::getInstance() \ No newline at end of file diff --git a/FEProject.cpp b/FEProject.cpp index aad2832..eee8414 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -1,4 +1,5 @@ #include "FEProject.h" +#include "FEEditor.h" FEProjectManager* FEProjectManager::Instance = nullptr; FEProjectManager::FEProjectManager() {} @@ -45,7 +46,7 @@ void FEProjectManager::CloseCurrentProject() WindowsManager::getInstance().CloseAllWindows(); WindowsManager::getInstance().CloseAllPopups(); - SELECTED.Clear(); + SELECTED.ClearAll(); PREVIEW_MANAGER.Clear(); SCENE_MANAGER.DeleteScene(PROJECT_MANAGER.GetCurrent()->ProjectScene); for (size_t i = 0; i < List.size(); i++) @@ -67,61 +68,23 @@ void FEProjectManager::OpenProject(const int ProjectIndex) PROJECT_MANAGER.GetCurrent()->ProjectScene = SCENE_MANAGER.CreateScene(); PROJECT_MANAGER.GetCurrent()->LoadScene(); // FIX ME! Temporary. - SCENE_GRAPH_WINDOW.SetScene(PROJECT_MANAGER.GetCurrent()->ProjectScene); + EDITOR.AddEditorScene(PROJECT_MANAGER.GetCurrent()->ProjectScene, true); + EDITOR.FocusedEditorSceneID = PROJECT_MANAGER.GetCurrent()->ProjectScene->GetObjectID(); IndexChosen = -1; - GIZMO_MANAGER.ReInitializeEntities(); - - // FIX ME! Entities should just have special tag, not be in the list. - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoEntity); - - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleZGizmoEntity); - - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateXGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateYGizmoEntity); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateZGizmoEntity); - PREVIEW_MANAGER.ReInitializeEntities(); EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(PREVIEW_MANAGER.PreviewEntity); - // all parts of Gizmos are standard resources except entities, so we need to register them again. - // if it is first start and those entities are already registered these calls just returns false. - /*auto it = EDITOR_INTERNAL_RESOURCES.InternalEditorObjects.begin(); - while (it != EDITOR_INTERNAL_RESOURCES.InternalEditorObjects.end()) - { - if (it->second->GetType() == FE_ENTITY) - ProjectScene->CreateEntity(reinterpret_cast(it->second)); - - it++; - }*/ - // after loading project we should update our previews PREVIEW_MANAGER.UpdateAll(); - SELECTED.Clear(); - - // Cleaning dirty flag of entities. - //const std::vector EntityList = ProjectScene->GetEntityList(); - //for (size_t i = 0; i < EntityList.size(); i++) - //{ - // FEEntity* Entity = ProjectScene->GetEntity(EntityList[i]); - // // But before that update AABB. - // Entity->GetAABB(); - // Entity->Transform.SetDirtyFlag(false); - //} + SELECTED.ClearAll(); } void FEProjectManager::DisplayProjectSelection() { static float LowerPanelHight = 90.0f; - const float MainWindowW = static_cast(ENGINE.GetWindowWidth()); - const float MainWindowH = static_cast(ENGINE.GetWindowHeight()); + const float MainWindowW = static_cast(APPLICATION.GetMainWindow()->GetWidth()); + const float MainWindowH = static_cast(APPLICATION.GetMainWindow()->GetHeight()); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 1.0f); ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f)); @@ -254,7 +217,7 @@ void FEProjectManager::DisplayProjectSelection() ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); if (ImGui::BeginPopupModal("New Project", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::SetWindowPos(ImVec2(ENGINE.GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, ENGINE.GetWindowHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); + ImGui::SetWindowPos(ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, APPLICATION.GetMainWindow()->GetHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); ImGui::Text("Insert name of new project :"); static char ProjectName[512] = ""; @@ -360,9 +323,7 @@ FEProject::~FEProject() delete SceneScreenshot; EDITOR_INTERNAL_RESOURCES.ClearListByType(FE_ENTITY); - //ProjectScene->Clear(); RESOURCE_MANAGER.Clear(); - ENGINE.ResetCamera(); VIRTUAL_FILE_SYSTEM.Clear(); } @@ -793,26 +754,26 @@ void FEProject::SaveScene(bool bFullSave) // Saving Effects settings. Json::Value EffectsData; // *********** Gamma Correction & Exposure *********** - EffectsData["Gamma Correction & Exposure"]["Gamma"] = ENGINE.GetCamera()->GetGamma(); - EffectsData["Gamma Correction & Exposure"]["Exposure"] = ENGINE.GetCamera()->GetExposure(); + //EffectsData["Gamma Correction & Exposure"]["Gamma"] = ENGINE.GetCamera()->GetGamma(); + //EffectsData["Gamma Correction & Exposure"]["Exposure"] = ENGINE.GetCamera()->GetExposure(); // *********** Anti-Aliasing(FXAA) *********** - EffectsData["Anti-Aliasing(FXAA)"]["FXAASpanMax"] = RENDERER.GetFXAASpanMax(); - EffectsData["Anti-Aliasing(FXAA)"]["FXAAReduceMin"] = RENDERER.GetFXAAReduceMin(); - EffectsData["Anti-Aliasing(FXAA)"]["FXAAReduceMul"] = RENDERER.GetFXAAReduceMul(); + //EffectsData["Anti-Aliasing(FXAA)"]["FXAASpanMax"] = RENDERER.GetFXAASpanMax(); + //EffectsData["Anti-Aliasing(FXAA)"]["FXAAReduceMin"] = RENDERER.GetFXAAReduceMin(); + //EffectsData["Anti-Aliasing(FXAA)"]["FXAAReduceMul"] = RENDERER.GetFXAAReduceMul(); // *********** Bloom *********** - EffectsData["Bloom"]["thresholdBrightness"] = RENDERER.GetBloomThreshold(); - EffectsData["Bloom"]["BloomSize"] = RENDERER.GetBloomSize(); + //EffectsData["Bloom"]["thresholdBrightness"] = RENDERER.GetBloomThreshold(); + //EffectsData["Bloom"]["BloomSize"] = RENDERER.GetBloomSize(); // *********** Depth of Field *********** - EffectsData["Depth of Field"]["Near distance"] = RENDERER.GetDOFNearDistance(); + /*EffectsData["Depth of Field"]["Near distance"] = RENDERER.GetDOFNearDistance(); EffectsData["Depth of Field"]["Far distance"] = RENDERER.GetDOFFarDistance(); EffectsData["Depth of Field"]["Strength"] = RENDERER.GetDOFStrength(); - EffectsData["Depth of Field"]["Distance dependent strength"] = RENDERER.GetDOFDistanceDependentStrength(); + EffectsData["Depth of Field"]["Distance dependent strength"] = RENDERER.GetDOFDistanceDependentStrength();*/ // *********** Distance fog *********** - EffectsData["Distance fog"]["isDistanceFogEnabled"] = RENDERER.IsDistanceFogEnabled(); - EffectsData["Distance fog"]["Density"] = RENDERER.GetDistanceFogDensity(); - EffectsData["Distance fog"]["Gradient"] = RENDERER.GetDistanceFogGradient(); + //EffectsData["Distance fog"]["isDistanceFogEnabled"] = RENDERER.IsDistanceFogEnabled(); + //EffectsData["Distance fog"]["Density"] = RENDERER.GetDistanceFogDensity(); + //EffectsData["Distance fog"]["Gradient"] = RENDERER.GetDistanceFogGradient(); // *********** Chromatic Aberration *********** - EffectsData["Chromatic Aberration"]["Shift strength"] = RENDERER.GetChromaticAberrationIntensity(); + //EffectsData["Chromatic Aberration"]["Shift strength"] = RENDERER.GetChromaticAberrationIntensity(); // *********** Sky *********** //EffectsData["Sky"]["Enabled"] = RENDERER.IsSkyEnabled() ? 1.0f : 0.0f; //EffectsData["Sky"]["Sphere size"] = RENDERER.GetDistanceToSky(); @@ -822,7 +783,7 @@ void FEProject::SaveScene(bool bFullSave) // Saving Camera settings. Json::Value CameraData; - CameraData["position"]["X"] = ENGINE.GetCamera()->GetPosition()[0]; + /*CameraData["position"]["X"] = ENGINE.GetCamera()->GetPosition()[0]; CameraData["position"]["Y"] = ENGINE.GetCamera()->GetPosition()[1]; CameraData["position"]["Z"] = ENGINE.GetCamera()->GetPosition()[2]; @@ -836,7 +797,7 @@ void FEProject::SaveScene(bool bFullSave) CameraData["aspectRatio"] = ENGINE.GetCamera()->GetAspectRatio(); - CameraData["movementSpeed"] = ENGINE.GetCamera()->GetMovementSpeed(); + CameraData["movementSpeed"] = ENGINE.GetCamera()->GetMovementSpeed();*/ Root["camera"] = CameraData; @@ -1107,7 +1068,7 @@ void FEProject::LoadScene() if (OldPrefab->ComponentsCount() > 1) { - OldPrefab->Scene = SCENE_MANAGER.CreateScene(false, OldPrefab->GetName()); + OldPrefab->Scene = SCENE_MANAGER.CreateScene(OldPrefab->GetName(), "", false); //OldPrefab->Scene->ImportEntity(Entity); } @@ -1216,12 +1177,21 @@ void FEProject::LoadScene() if (OldPrefab->ComponentsCount() > 1) { - OldPrefab->Scene->ImportEntity(Entity); + FEEntity* ImportedEntity = OldPrefab->Scene->ImportEntity(Entity); + + if (ImportedEntity->HasComponent()) + { + ImportedEntity->RemoveComponent(); + } } } } else { + // FIX ME! Delete + FEPrefab* OldPrefab = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()); + OldPrefab->Scene = SCENE_MANAGER.CreateScene(OldPrefab->GetName(), "", false); + // For compatibility with old projects. if (Root["entities"][EntityList[i]].isMember("gameModel")) { @@ -1254,6 +1224,8 @@ void FEProject::LoadScene() { Entity->GetComponent() = ProjectScene->GetEntity(EntityList[i])->Transform; }*/ + + OldPrefab->Scene->ImportEntity(Entity); } } // For compatibility with old projects. @@ -1336,23 +1308,23 @@ void FEProject::LoadScene() // loading Effects settings // *********** Gamma Correction & Exposure *********** - ENGINE.GetCamera()->SetGamma(Root["effects"]["Gamma Correction & Exposure"]["Gamma"].asFloat()); - ENGINE.GetCamera()->SetExposure(Root["effects"]["Gamma Correction & Exposure"]["Exposure"].asFloat()); + //ENGINE.GetCamera()->SetGamma(Root["effects"]["Gamma Correction & Exposure"]["Gamma"].asFloat()); + //ENGINE.GetCamera()->SetExposure(Root["effects"]["Gamma Correction & Exposure"]["Exposure"].asFloat()); // *********** Anti-Aliasing(FXAA) *********** - RENDERER.SetFXAASpanMax(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAASpanMax"].asFloat()); - RENDERER.SetFXAAReduceMin(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAAReduceMin"].asFloat()); - RENDERER.SetFXAAReduceMul(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAAReduceMul"].asFloat()); + //RENDERER.SetFXAASpanMax(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAASpanMax"].asFloat()); + //RENDERER.SetFXAAReduceMin(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAAReduceMin"].asFloat()); + //RENDERER.SetFXAAReduceMul(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAAReduceMul"].asFloat()); // *********** Bloom *********** //PPEffect = RENDERER.getPostProcessEffect("bloom"); - RENDERER.SetBloomThreshold(Root["effects"]["Bloom"]["thresholdBrightness"].asFloat()); - RENDERER.SetBloomSize(Root["effects"]["Bloom"]["BloomSize"].asFloat()); + //RENDERER.SetBloomThreshold(Root["effects"]["Bloom"]["thresholdBrightness"].asFloat()); + //RENDERER.SetBloomSize(Root["effects"]["Bloom"]["BloomSize"].asFloat()); // *********** Depth of Field *********** - RENDERER.SetDOFNearDistance(Root["effects"]["Depth of Field"]["Near distance"].asFloat()); + /*RENDERER.SetDOFNearDistance(Root["effects"]["Depth of Field"]["Near distance"].asFloat()); RENDERER.SetDOFFarDistance(Root["effects"]["Depth of Field"]["Far distance"].asFloat()); RENDERER.SetDOFStrength(Root["effects"]["Depth of Field"]["Strength"].asFloat()); - RENDERER.SetDOFDistanceDependentStrength(Root["effects"]["Depth of Field"]["Distance dependent strength"].asFloat()); + RENDERER.SetDOFDistanceDependentStrength(Root["effects"]["Depth of Field"]["Distance dependent strength"].asFloat());*/ // *********** Distance fog *********** - if (Root["effects"]["Distance fog"].isMember("isDistanceFogEnabled")) + /*if (Root["effects"]["Distance fog"].isMember("isDistanceFogEnabled")) { RENDERER.SetDistanceFogEnabled(Root["effects"]["Distance fog"]["isDistanceFogEnabled"].asBool()); } @@ -1361,9 +1333,9 @@ void FEProject::LoadScene() RENDERER.SetDistanceFogEnabled(Root["effects"]["Distance fog"]["Density"].asFloat() > -1.0f ? true : false); } RENDERER.SetDistanceFogDensity(Root["effects"]["Distance fog"]["Density"].asFloat()); - RENDERER.SetDistanceFogGradient(Root["effects"]["Distance fog"]["Gradient"].asFloat()); + RENDERER.SetDistanceFogGradient(Root["effects"]["Distance fog"]["Gradient"].asFloat());*/ // *********** Chromatic Aberration *********** - RENDERER.SetChromaticAberrationIntensity(Root["effects"]["Chromatic Aberration"]["Shift strength"].asFloat()); + //RENDERER.SetChromaticAberrationIntensity(Root["effects"]["Chromatic Aberration"]["Shift strength"].asFloat()); // *********** Sky *********** //SKY_DOME_SYSTEM.SetEnabled(Root["effects"]["Sky"]["Enabled"].asFloat() > 0.0f ? true : false); //SKY_DOME_SYSTEM.SetDistanceToSky(Root["effects"]["Sky"]["Sphere size"].asFloat()); @@ -1376,6 +1348,15 @@ void FEProject::LoadScene() FEEntity* Entity = ProjectScene->CreateEntity("Camera Entity"); Entity->AddComponent(); FECameraComponent& CameraComponent = Entity->GetComponent(); + if (Root["effects"]["Distance fog"].isMember("isDistanceFogEnabled")) + { + CameraComponent.SetDistanceFogEnabled(Root["effects"]["Distance fog"]["isDistanceFogEnabled"].asBool()); + } + else + { + CameraComponent.SetDistanceFogEnabled(Root["effects"]["Distance fog"]["Density"].asFloat() > -1.0f ? true : false); + } + // Will work in future. //ReadTransformToJson(Root["camera"]["transformation"], &Entity->GetComponent()); @@ -1385,13 +1366,13 @@ void FEProject::LoadScene() Entity->GetComponent().SetPosition(CameraPosition); - ENGINE.GetCamera()->SetPosition(CameraPosition); + //ENGINE.GetCamera()->SetPosition(CameraPosition); - ENGINE.GetCamera()->SetFov(Root["camera"]["fov"].asFloat()); + //ENGINE.GetCamera()->SetFov(Root["camera"]["fov"].asFloat()); CameraComponent.SetFOV(50.680f); - ENGINE.GetCamera()->SetNearPlane(Root["camera"]["nearPlane"].asFloat()); + //ENGINE.GetCamera()->SetNearPlane(Root["camera"]["nearPlane"].asFloat()); CameraComponent.SetNearPlane(Root["camera"]["nearPlane"].asFloat()); - ENGINE.GetCamera()->SetFarPlane(Root["camera"]["farPlane"].asFloat()); + //ENGINE.GetCamera()->SetFarPlane(Root["camera"]["farPlane"].asFloat()); CameraComponent.SetFarPlane(Root["camera"]["farPlane"].asFloat()); glm::vec3 CameraRotation = glm::vec3(Root["camera"]["yaw"].asFloat(), @@ -1403,17 +1384,17 @@ void FEProject::LoadScene() CameraComponent.CurrentMouseXAngle = -CameraRotation.x; CameraComponent.CurrentMouseYAngle = -CameraRotation.y; - ENGINE.GetCamera()->SetYaw(CameraRotation.x); + /*ENGINE.GetCamera()->SetYaw(CameraRotation.x); ENGINE.GetCamera()->SetPitch(CameraRotation.y); - ENGINE.GetCamera()->SetRoll(CameraRotation.z); + ENGINE.GetCamera()->SetRoll(CameraRotation.z);*/ - ENGINE.GetCamera()->SetAspectRatio(Root["camera"]["aspectRatio"].asFloat()); + //ENGINE.GetCamera()->SetAspectRatio(Root["camera"]["aspectRatio"].asFloat()); CameraComponent.SetAspectRatio(Root["camera"]["aspectRatio"].asFloat()); CAMERA_SYSTEM.SetMainCamera(Entity); - if (ProjectVersion >= 0.02f && Root["camera"].isMember("movementSpeed")) - ENGINE.GetCamera()->SetMovementSpeed(Root["camera"]["movementSpeed"].asFloat()); + //if (ProjectVersion >= 0.02f && Root["camera"].isMember("movementSpeed")) + // ENGINE.GetCamera()->SetMovementSpeed(Root["camera"]["movementSpeed"].asFloat()); // After all scene objects are loaded, we need to update all objects. ProjectScene->Update(); @@ -1517,8 +1498,8 @@ void FEProject::LoadScene() void FEProject::CreateDummyScreenshot() { - const size_t Width = ENGINE.GetRenderTargetWidth(); - const size_t Height = ENGINE.GetRenderTargetHeight(); + const size_t Width = ENGINE.GetDefaultViewport()->GetWidth(); + const size_t Height = ENGINE.GetDefaultViewport()->GetHeight(); unsigned char* Pixels = new unsigned char[4 * Width * Height]; for (size_t j = 0; j < Height; j++) diff --git a/Resources/imgui.ini b/Resources/imgui.ini index 963cba5..d1da1db 100644 --- a/Resources/imgui.ini +++ b/Resources/imgui.ini @@ -1,7 +1,7 @@ [Window][Debug##Default] Pos=2513,531 Size=1344,1062 -Collapsed=0 +Collapsed=1 [Window][Scene Entities] Pos=0,28 @@ -938,6 +938,12 @@ Pos=60,60 Size=241,88 Collapsed=0 +[Window][Main Scene] +Pos=506,28 +Size=2866,1604 +Collapsed=0 +DockId=0x0000000B,0 + [Table][0xD0F0C6E3,2] Column 0 Weight=1.0000 Column 1 Weight=1.0000 @@ -950,7 +956,7 @@ DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,28 Size=3840,2043 Sp DockNode ID=0x00000001 Parent=0x00000009 SizeRef=504,1537 Selected=0xB364B046 DockNode ID=0x00000004 Parent=0x00000009 SizeRef=1418,1537 Split=X Selected=0x18B8C0DE DockNode ID=0x00000007 Parent=0x00000004 SizeRef=2866,1256 Split=Y Selected=0x18B8C0DE - DockNode ID=0x0000000B Parent=0x00000007 SizeRef=2430,663 CentralNode=1 Selected=0xE192E354 + DockNode ID=0x0000000B Parent=0x00000007 SizeRef=2430,663 CentralNode=1 Selected=0x0B02E23B DockNode ID=0x0000000C Parent=0x00000007 SizeRef=2430,661 Selected=0x1DE2844E DockNode ID=0x00000008 Parent=0x00000004 SizeRef=466,1256 Selected=0xE7039252 DockNode ID=0x0000000A Parent=0x00000002 SizeRef=2691,700 Selected=0xA36F5690 diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 2c2b1bf..a3135e8 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 2c2b1bf60a434e9de150cf4c6257ce0dfd2146b2 +Subproject commit a3135e8e701a2da0ab89edddd08ed911ac6b9613 diff --git a/main.cpp b/main.cpp index 863eb1d..a207b58 100644 --- a/main.cpp +++ b/main.cpp @@ -25,13 +25,31 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine ENGINE.Render(); #ifdef EDITOR_SELECTION_DEBUG_MODE - std::string objectsUnderMouse = "SceneEntitiesUnderMouse: " + std::to_string(SELECTED.SceneEntitiesUnderMouse.size()); - ImGui::Text(objectsUnderMouse.c_str()); - - std::string colorIndex = "colorIndex: " + std::to_string(SELECTED.ColorIndex); - ImGui::Text(colorIndex.c_str()); - - ImGui::Image((void*)(intptr_t)SELECTED.PixelAccurateSelectionFB->GetColorAttachment()->GetTextureID(), ImVec2(256 * 4, 256 * 4), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); + if (EDITOR.GetFocusedScene() != nullptr) + { + FESelectionData* SelectedData = SELECTED.GetSceneData(EDITOR.GetFocusedScene()->GetObjectID()); + if (SelectedData != nullptr) + { + std::string ObjectsUnderMouse = "Count of considered entities: " + std::to_string(SelectedData->SceneEntitiesUnderMouse.size()); + ImGui::Text(ObjectsUnderMouse.c_str()); + + std::string ColorIndex = "ColorIndex: " + std::to_string(SelectedData->ColorIndex); + ImGui::Text(ColorIndex.c_str()); + + std::string EntityUnderMouse = "Entity under mouse: "; + if (SelectedData->ColorIndex != -1 && SelectedData->ColorIndex < SelectedData->SceneEntitiesUnderMouse.size()) + { + EntityUnderMouse += SelectedData->SceneEntitiesUnderMouse[SelectedData->ColorIndex]->GetName(); + } + else + { + EntityUnderMouse += "None"; + } + ImGui::Text(EntityUnderMouse.c_str()); + + ImGui::Image((void*)(intptr_t)SelectedData->PixelAccurateSelectionFB->GetColorAttachment()->GetTextureID(), ImVec2(256 * 4, 256 * 4), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); + } + } #endif if (ImGui::Button("Put This Frame To Timeline")) From bffa09e5a88c8cd15795157de5a1247c2d25035a Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Tue, 30 Jul 2024 14:47:16 -0400 Subject: [PATCH 24/46] Each scene window now has a unique ID for ImGui to render it properly; GizmoManager now works with FETransformComponent more efficiently; Fixed the issue with GyzmosSettingsWindow not showing up and the problem with switching gizmo states; All editor functions and classes now use FETransformSystem::DuplicateTransformComponent. --- EditorWindows/ContentBrowserWindow.cpp | 5 ++-- EditorWindows/GyzmosSettingsWindow.cpp | 1 + EditorWindows/PrefabEditorWindow.cpp | 10 +++---- EditorWindows/SceneGraphWindow.cpp | 21 +++++++++++-- EditorWindows/SceneGraphWindow.h | 5 +--- FEEditor.cpp | 13 ++++++-- FEEditor.h | 7 ++--- FEEditorGizmoManager.cpp | 41 +++++++++++++------------- FEEditorGizmoManager.h | 7 +++-- FEEditorSelectedObject.cpp | 19 ++++++++++-- SubSystems/FocalEngine | 2 +- 11 files changed, 85 insertions(+), 46 deletions(-) diff --git a/EditorWindows/ContentBrowserWindow.cpp b/EditorWindows/ContentBrowserWindow.cpp index 2d3ec22..28264ff 100644 --- a/EditorWindows/ContentBrowserWindow.cpp +++ b/EditorWindows/ContentBrowserWindow.cpp @@ -55,8 +55,9 @@ static void CreateNewPrefabCallBack(const std::vector SelectionsResul { for (int i = 1; i < SelectionsResult.size(); i++) { - if (SelectionsResult[i]->GetType() == FE_GAMEMODEL) - NewPrefab->AddComponent(reinterpret_cast(SelectionsResult[i])); + // FIX ME! It should be here + //if (SelectionsResult[i]->GetType() == FE_GAMEMODEL) + // NewPrefab->AddComponent(reinterpret_cast(SelectionsResult[i])); } } diff --git a/EditorWindows/GyzmosSettingsWindow.cpp b/EditorWindows/GyzmosSettingsWindow.cpp index 85b5a74..d9f3c35 100644 --- a/EditorWindows/GyzmosSettingsWindow.cpp +++ b/EditorWindows/GyzmosSettingsWindow.cpp @@ -48,6 +48,7 @@ void GyzmosSettingsWindow::Render() return; FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(CurrentScene->GetObjectID()); + if (GizmoSceneData == nullptr) return; FEImGuiWindow::Render(); diff --git a/EditorWindows/PrefabEditorWindow.cpp b/EditorWindows/PrefabEditorWindow.cpp index 9473df8..a9de6e2 100644 --- a/EditorWindows/PrefabEditorWindow.cpp +++ b/EditorWindows/PrefabEditorWindow.cpp @@ -10,7 +10,8 @@ bool PrefabEditorWindow::AddGameModelTargetCallBack(FEObject* Object, void** Ent return false; FEGameModel* NewGameModel = reinterpret_cast(Object); - ObjToWorkWith->AddComponent(NewGameModel); + // FIX ME! It should be here + //ObjToWorkWith->AddComponent(NewGameModel); return true; } @@ -23,8 +24,9 @@ void PrefabEditorWindow::AddNewGameModelCallBack(const std::vector Se { for (int i = 0; i < SelectionsResult.size(); i++) { - if (SelectionsResult[i]->GetType() == FE_GAMEMODEL) - ObjToWorkWith->AddComponent(reinterpret_cast(SelectionsResult[i])); + // FIX ME! It should be here + //if (SelectionsResult[i]->GetType() == FE_GAMEMODEL) + // ObjToWorkWith->AddComponent(reinterpret_cast(SelectionsResult[i])); } } @@ -49,8 +51,6 @@ void PrefabEditorWindow::Show(FEPrefab* Prefab) { if (Prefab->Scene != nullptr) { - if (CurrentPrefabScene != nullptr) - SCENE_MANAGER.DeleteScene(CurrentPrefabScene); CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->Scene, "Scene: " + Prefab->GetName()); FEEntity* Camera = CurrentPrefabScene->CreateEntity("Prefab scene camera"); diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 35e5636..e27bf36 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -193,7 +193,15 @@ void FEEditorSceneGraphWindow::DrawCorrectIcon(const FEObject* SceneObject) cons DragAndDropTarget* FEEditorSceneGraphWindow::GetSceneNodeDragAndDropTarget(FENaiveSceneGraphNode* NodeToFind) { int64_t UniqueID = 0; - UniqueID = static_cast(std::hash{}(NodeToFind->GetEntity()->GetObjectID().c_str())); + // If node is root. + if (NodeToFind->GetEntity() == nullptr) + { + UniqueID = -1; + } + else + { + UniqueID = static_cast(std::hash{}(NodeToFind->GetEntity()->GetObjectID().c_str())); + } if (SceneNodeDragAndDropTargets.find(UniqueID) == SceneNodeDragAndDropTargets.end()) { @@ -221,7 +229,15 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) } } - UniqueID = static_cast(std::hash{}(SubTreeRoot->GetEntity()->GetObjectID().c_str())); + // If node is root. + if (SubTreeRoot->GetEntity() == nullptr) + { + UniqueID = -1; + } + else + { + UniqueID = static_cast(std::hash{}(SubTreeRoot->GetEntity()->GetObjectID().c_str())); + } bool bOpened = ImGui::TreeNodeEx((void*)UniqueID, NodeFlags, Name.c_str(), 0); GetSceneNodeDragAndDropTarget(SubTreeRoot)->StickToItem(); @@ -231,7 +247,6 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) if (SubTreeRoot->GetParent() != nullptr) { SELECTED.SetSelected(SubTreeRoot->GetEntity()); - //SELECTED.SetDirtyFlag(false); } } diff --git a/EditorWindows/SceneGraphWindow.h b/EditorWindows/SceneGraphWindow.h index 1300ea8..41b20a7 100644 --- a/EditorWindows/SceneGraphWindow.h +++ b/EditorWindows/SceneGraphWindow.h @@ -55,7 +55,7 @@ class FEEditorSceneGraphWindow FENaiveSceneGraphNode* NodeTarget = reinterpret_cast(SceneNodeTarget); FENaiveSceneGraphNode* SceneEntity = reinterpret_cast(Object); - FEScene* CurrentScene = NodeTarget->GetEntity()->GetParentScene(); + FEScene* CurrentScene = SceneEntity->GetEntity()->GetParentScene(); return CurrentScene->SceneGraph.MoveNode(SceneEntity->GetObjectID(), NodeTarget->GetObjectID()); } @@ -70,9 +70,6 @@ class FEEditorSceneGraphWindow public: SINGLETON_PUBLIC_PART(FEEditorSceneGraphWindow) - - /*void SetScene(FEScene* Scene); - FEScene* GetScene();*/ }; #define SCENE_GRAPH_WINDOW FEEditorSceneGraphWindow::getInstance() \ No newline at end of file diff --git a/FEEditor.cpp b/FEEditor.cpp index 2a2e6dd..716bfe8 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -208,7 +208,8 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) if (!ImGui::GetIO().WantCaptureKeyboard && (Key == GLFW_KEY_RIGHT_SHIFT || Key == GLFW_KEY_LEFT_SHIFT) && Action == GLFW_RELEASE) { - int NewState = GIZMO_MANAGER.GizmosState + 1; + FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(EDITOR.EditorScenes[i].Scene->GetObjectID()); + int NewState = GizmoSceneData->GizmosState + 1; if (NewState > 2) NewState = 0; GIZMO_MANAGER.UpdateGizmoState(NewState, EDITOR.EditorScenes[i].Scene); @@ -491,11 +492,20 @@ void FEEditor::Render() for (size_t i = 0; i < EditorScenes.size(); i++) { std::string WindowName = EditorScenes[i].Scene->GetName(); + // Window name must be unique. + WindowName += "##" + EditorScenes[i].Scene->GetObjectID(); if (EditorScenes[i].bMain) WindowName = "Main Scene"; if (ImGui::Begin(WindowName.c_str(), nullptr, ImGuiWindowFlags_None | ImGuiWindowFlags_NoScrollbar)) { + if (EditorScenes[i].bJustAdded) + { + ImGui::SetWindowFocus(); + ImGui::SetWindowSize(ImVec2(256, 256)); + EditorScenes[i].bJustAdded = false; + } + EditorScenes[i].SceneWindow = ImGui::GetCurrentWindow(); if (EditorScenes[i].bMain) { @@ -826,7 +836,6 @@ void FEEditor::AddEditorScene(FEScene* Scene, bool bMain) FEEditorSceneData EditorSceneData; EditorSceneData.bMain = bMain; EditorSceneData.Scene = Scene; - EditorSceneData.CameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(Scene); EditorScenes.push_back(EditorSceneData); } diff --git a/FEEditor.h b/FEEditor.h index fdd5633..fb3be43 100644 --- a/FEEditor.h +++ b/FEEditor.h @@ -5,12 +5,11 @@ struct FEEditorSceneData { - bool bMain = false; - FEScene* Scene = nullptr; - FEEntity* CameraEntity = nullptr; - ImGuiWindow* SceneWindow = nullptr; + + bool bJustAdded = true; + bool bMain = false; bool bWindowHovered = false; }; diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index a326788..f4abfcc 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -286,7 +286,6 @@ void GizmoManager::Update() } FEScene* Scene = SCENE_MANAGER.GetScene(GizmoSceneData->SceneID); - if (SELECTED.GetSelected(Scene) == nullptr || SELECTED.GetSelected(Scene)->GetType() == FE_CAMERA_DEPRECATED) { HideAllGizmo(Scene); @@ -295,14 +294,12 @@ void GizmoManager::Update() } FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); - FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(Scene); + FETransformComponent& ObjTransform = GetTransformComponentOfSelectedObject(Scene); const glm::vec3 ObjectSpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); glm::vec3 ToObject = ObjectSpaceOriginInWorldSpace - CameraTransformComponent.GetPosition(FE_WORLD_SPACE); ToObject = glm::normalize(ToObject); GizmoSceneData->ParentGizmoEntity->GetComponent().SetPosition((CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + ToObject * 0.15f)); - //ParentGizmoEntity->GetComponent().Update(); - //ParentGizmoEntity->GetComponent().ForceSetWorldMatrix(ParentGizmoEntity->GetComponent().GetLocalMatrix()); if (GizmoSceneData->GizmosState == TRANSFORM_GIZMOS) { // X Gizmos @@ -503,7 +500,7 @@ glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, glm::ivec2 ViewportPosition = glm::ivec2(CurrentViewport->GetX(), CurrentViewport->GetY()); glm::ivec2 ViewportSize = glm::ivec2(CurrentViewport->GetWidth(), CurrentViewport->GetHeight()); - FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(Scene); + FETransformComponent& ObjTransform = GetTransformComponentOfSelectedObject(Scene); const glm::vec3 EntitySpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); const glm::vec3 LastFrameMouseRay = GEOMETRY.CreateMouseRayToWorld(LastMouseX, LastMouseY, @@ -548,7 +545,7 @@ glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, glm::ivec2 ViewportPosition = glm::ivec2(CurrentViewport->GetX(), CurrentViewport->GetY()); glm::ivec2 ViewportSize = glm::ivec2(CurrentViewport->GetWidth(), CurrentViewport->GetHeight()); - FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(Scene); + FETransformComponent& ObjTransform = GetTransformComponentOfSelectedObject(Scene); const glm::vec3 EntitySpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); const glm::vec3 LastFrameMouseRay = GEOMETRY.CreateMouseRayToWorld(LastMouseX, LastMouseY, @@ -594,7 +591,7 @@ void GizmoManager::MouseMoveTransformationGizmos(FEScene* Scene) glm::ivec2 ViewportPosition = glm::ivec2(CurrentViewport->GetX(), CurrentViewport->GetY()); glm::ivec2 ViewportSize = glm::ivec2(CurrentViewport->GetWidth(), CurrentViewport->GetHeight()); - FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(Scene); + FETransformComponent& ObjTransform = GetTransformComponentOfSelectedObject(Scene); const glm::vec3 LastFrameMouseRay = GEOMETRY.CreateMouseRayToWorld(LastMouseX, LastMouseY, CameraComponent.GetViewMatrix(), CameraComponent.GetProjectionMatrix(), @@ -709,7 +706,7 @@ void GizmoManager::MouseMoveScaleGizmos(FEScene* Scene) return; FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); - FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(Scene); + FETransformComponent& ObjTransform = GetTransformComponentOfSelectedObject(Scene); if (GizmoSceneData->bScaleXGizmoActive && GizmoSceneData->bScaleYGizmoActive && GizmoSceneData->bScaleZGizmoActive) { @@ -771,7 +768,7 @@ void GizmoManager::MouseMoveRotateGizmos(FEScene* Scene) !GizmoSceneData->bRotateZGizmoActive) return; - FETransformComponent ObjTransform = GetTransformComponentOfSelectedObject(Scene); + FETransformComponent& ObjTransform = GetTransformComponentOfSelectedObject(Scene); const float DifferenceX = static_cast(MouseX - LastMouseX); const float DifferenceY = static_cast(MouseY - LastMouseY); @@ -869,21 +866,29 @@ void GizmoManager::OnSelectedObjectUpdate(FEScene* Scene) } } -FETransformComponent GizmoManager::GetTransformComponentOfSelectedObject(FEScene* Scene) +FETransformComponent& GizmoManager::GetTransformComponentOfSelectedObject(FEScene* Scene) { if (Scene == nullptr) - return FETransformComponent(); + return DummyTransformComponent; if (SELECTED.GetSelected(Scene) == nullptr) - return FETransformComponent(); + return DummyTransformComponent; FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(Scene->GetObjectID()); if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1 && SELECTED.GetSelected(Scene)->HasComponent()) { FEInstancedComponent& InstancedComponent = SELECTED.GetSelected(Scene)->GetComponent(); - FETransformComponent& DummyTransform = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(CurrentSelectionData->InstancedSubObjectIndexSelected)); - DummyTransform.SetSceneIndependent(true); - return DummyTransform; + + glm::dvec3 Position, Scale; + glm::dquat Rotation; + GEOMETRY.DecomposeMatrixToTranslationRotationScale(InstancedComponent.GetTransformedInstancedMatrix(CurrentSelectionData->InstancedSubObjectIndexSelected), Position, Rotation, Scale); + + DummyTransformComponent.SetPosition(Position); + DummyTransformComponent.SetQuaternion(Rotation); + DummyTransformComponent.SetScale(Scale); + + DummyTransformComponent.SetSceneIndependent(true); + return DummyTransformComponent; } else { @@ -891,7 +896,7 @@ FETransformComponent GizmoManager::GetTransformComponentOfSelectedObject(FEScene } } -void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent Changes, FEScene* Scene) +void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent& Changes, FEScene* Scene) { if (Scene == nullptr) return; @@ -904,10 +909,6 @@ void GizmoManager::ApplyChangesToSelectedObject(FETransformComponent Changes, FE { INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(SELECTED.GetSelected(Scene), CurrentSelectionData->InstancedSubObjectIndexSelected, Changes.GetWorldMatrix()); } - else - { - SELECTED.GetSelected(Scene)->GetComponent() = Changes; - } } void GizmoManager::ClearAllSceneData() diff --git a/FEEditorGizmoManager.h b/FEEditorGizmoManager.h index ec3572f..5ab3aae 100644 --- a/FEEditorGizmoManager.h +++ b/FEEditorGizmoManager.h @@ -76,7 +76,6 @@ class GizmoManager SINGLETON_PUBLIC_PART(GizmoManager) float GizmosScale = 0.00175f; - int GizmosState = TRANSFORM_GIZMOS; glm::vec3 RotateXStandardRotation = glm::vec3(0.0f, 0.0f, -90.0f); glm::vec3 RotateYStandardRotation = glm::vec3(0.0f); @@ -125,14 +124,16 @@ class GizmoManager static void OnSelectedObjectUpdate(FEScene* Scene); - FETransformComponent GetTransformComponentOfSelectedObject(FEScene* Scene); - void ApplyChangesToSelectedObject(FETransformComponent Changes, FEScene* Scene); + FETransformComponent& GetTransformComponentOfSelectedObject(FEScene* Scene); + void ApplyChangesToSelectedObject(FETransformComponent& Changes, FEScene* Scene); std::unordered_map PerSceneData; void ClearAllSceneData(); void ClearSceneData(const std::string& SceneID); void AddSceneData(const std::string& SceneID); FEGizmoSceneData* GetSceneData(const std::string& SceneID); + + FETransformComponent DummyTransformComponent; }; #define GIZMO_MANAGER GizmoManager::getInstance() \ No newline at end of file diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index b5f4bb0..eeb71ec 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -311,7 +311,14 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons FEInstancedComponent& InstancedComponent = InstancedSubObjectIterator->first->GetComponent(); FETransformComponent& DummyTransformComponent = DummyEntity->GetComponent(); - DummyTransformComponent = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(InstancedSubObjectIterator->second[j])); + + glm::dvec3 Position, Scale; + glm::dquat Rotation; + GEOMETRY.DecomposeMatrixToTranslationRotationScale(InstancedComponent.GetTransformedInstancedMatrix(InstancedSubObjectIterator->second[j]), Position, Rotation, Scale); + + DummyTransformComponent.SetPosition(Position); + DummyTransformComponent.SetQuaternion(Rotation); + DummyTransformComponent.SetScale(Scale); FEMaterial* RegularMaterial = OriginalGameModelComponent.GameModel->Material; DummyGameModelComponent.GameModel->Material = PixelAccurateSelectionMaterial; @@ -469,7 +476,15 @@ void FEEditorSelectedObject::OnCameraUpdate() const DummyGameModelComponent.SetVisibility(true); FEInstancedComponent& InstancedComponent = CurrentSelectionData->Container->GetComponent(); - CurrentSelectionData->DummyEntity->GetComponent() = FETransformComponent(InstancedComponent.GetTransformedInstancedMatrix(CurrentSelectionData->InstancedSubObjectIndexSelected)); + FETransformComponent& DummyTransformComponent = CurrentSelectionData->DummyEntity->GetComponent(); + + glm::dvec3 Position, Scale; + glm::dquat Rotation; + GEOMETRY.DecomposeMatrixToTranslationRotationScale(InstancedComponent.GetTransformedInstancedMatrix(CurrentSelectionData->InstancedSubObjectIndexSelected), Position, Rotation, Scale); + + DummyTransformComponent.SetPosition(Position); + DummyTransformComponent.SetQuaternion(Rotation); + DummyTransformComponent.SetScale(Scale); FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; DummyGameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index a3135e8..1089ec3 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit a3135e8e701a2da0ab89edddd08ed911ac6b9613 +Subproject commit 1089ec300e623399720302d66c7b06c5919280e1 From 9cc6e39342d85b91365a45fa624428a744d4a8e2 Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Tue, 30 Jul 2024 22:32:53 -0400 Subject: [PATCH 25/46] Engine update. --- SubSystems/FocalEngine | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 1089ec3..1b22955 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 1089ec300e623399720302d66c7b06c5919280e1 +Subproject commit 1b22955b4775cbc5ddda4fae3a80c242f8158ade From c9ac168777936bf2800ccf189943c96eac683f5c Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Thu, 1 Aug 2024 21:39:07 -0400 Subject: [PATCH 26/46] Engine update; Improved organization of EditorScenes; Adjusted SceneWindowTarget to work with multiple scene windows; Fixed memory leak in FEEditorContentBrowserWindow::UpdateDirectoryDragAndDropTargets(). --- EditorWindows/ContentBrowserWindow.cpp | 4 + FEEditor.cpp | 137 +++++++++++++++---------- FEEditor.h | 6 +- SubSystems/FocalEngine | 2 +- 4 files changed, 88 insertions(+), 61 deletions(-) diff --git a/EditorWindows/ContentBrowserWindow.cpp b/EditorWindows/ContentBrowserWindow.cpp index 28264ff..f251b25 100644 --- a/EditorWindows/ContentBrowserWindow.cpp +++ b/EditorWindows/ContentBrowserWindow.cpp @@ -787,6 +787,10 @@ void FEEditorContentBrowserWindow::RenderFilterMenu() void FEEditorContentBrowserWindow::UpdateDirectoryDragAndDropTargets() { + for (size_t i = 0; i < DirectoriesTargets.size(); i++) + { + delete DirectoriesTargets[i]; + } DirectoriesTargets.clear(); DirectoryDragAndDropInfo.clear(); AllResources.clear(); diff --git a/FEEditor.cpp b/FEEditor.cpp index 716bfe8..af59e51 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -10,14 +10,38 @@ bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) if (CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene()) == nullptr) return false; - if (Object->GetType() == FE_PREFAB) + if (UserData == nullptr) + return false; + + FEEditorSceneData* EditorSceneData = reinterpret_cast(*UserData); + if (EditorSceneData->Scene == nullptr) + return false; + + if (Object->GetType() == FE_GAMEMODEL) + { + FEGameModel* GameModel = RESOURCE_MANAGER.GetGameModel(Object->GetObjectID()); + + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + + FEEntity* Entity = EditorSceneData->Scene->CreateEntity(Object->GetName()); + Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); + Entity->AddComponent(GameModel); + + SELECTED.SetSelected(Entity); + PROJECT_MANAGER.GetCurrent()->SetModified(true); + + return true; + + } + else if (Object->GetType() == FE_PREFAB) { FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())->GetComponent(0)->GameModel; FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); - FEEntity* Entity = EDITOR.GetFocusedScene()->CreateEntity(Object->GetName()); + FEEntity* Entity = EditorSceneData->Scene->CreateEntity(Object->GetName()); Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); Entity->AddComponent(GameModel); @@ -96,22 +120,22 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) for (size_t i = 0; i < EDITOR.EditorScenes.size(); i++) { - EDITOR.EditorScenes[i].bWindowHovered = false; + EDITOR.EditorScenes[i]->bWindowHovered = false; - if (EDITOR.EditorScenes[i].SceneWindow == nullptr) + if (EDITOR.EditorScenes[i]->SceneWindow == nullptr) continue; - if (EDITOR.EditorScenes[i].Scene != EDITOR.GetFocusedScene()) + if (EDITOR.EditorScenes[i]->Scene != EDITOR.GetFocusedScene()) continue; if (ImGui::GetCurrentContext()->HoveredWindow != nullptr) - EDITOR.EditorScenes[i].bWindowHovered = ImGui::GetCurrentContext()->HoveredWindow->Name == EDITOR.EditorScenes[i].SceneWindow->Name; + EDITOR.EditorScenes[i]->bWindowHovered = ImGui::GetCurrentContext()->HoveredWindow->Name == EDITOR.EditorScenes[i]->SceneWindow->Name; - FEEntity* CurrentMainCamera = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.EditorScenes[i].Scene); + FEEntity* CurrentMainCamera = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.EditorScenes[i]->Scene); - if (ImGui::GetIO().WantCaptureMouse && !EDITOR.EditorScenes[i].bWindowHovered) + if (ImGui::GetIO().WantCaptureMouse && !EDITOR.EditorScenes[i]->bWindowHovered) { - if (EDITOR.EditorScenes[i].Scene != nullptr) + if (EDITOR.EditorScenes[i]->Scene != nullptr) { if (CurrentMainCamera != nullptr) CAMERA_SYSTEM.SetIsIndividualInputActive(CurrentMainCamera, false); @@ -131,18 +155,18 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) if (Button == GLFW_MOUSE_BUTTON_1 && Action == GLFW_PRESS) { - if (EDITOR.EditorScenes[i].bWindowHovered) + if (EDITOR.EditorScenes[i]->bWindowHovered) { bool bEditingTerrain = false; - if (SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene) != nullptr && SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene)->HasComponent()) + if (SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene) != nullptr && SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene)->HasComponent()) { bEditingTerrain = TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE; } if (!bEditingTerrain) { - FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(EDITOR.EditorScenes[i].Scene->GetObjectID()); - SELECTED.DetermineEntityUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY(), EDITOR.EditorScenes[i].Scene); + FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(EDITOR.EditorScenes[i]->Scene->GetObjectID()); + SELECTED.DetermineEntityUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY(), EDITOR.EditorScenes[i]->Scene); CurrentSelectionData->CheckForSelectionisNeeded = true; } } @@ -152,7 +176,7 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) else if (Button == GLFW_MOUSE_BUTTON_1 && Action == GLFW_RELEASE) { INSPECTOR_WINDOW.bLeftMousePressed = false; - GIZMO_MANAGER.DeactivateAllGizmo(EDITOR.EditorScenes[i].Scene); + GIZMO_MANAGER.DeactivateAllGizmo(EDITOR.EditorScenes[i]->Scene); } } } @@ -175,44 +199,44 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) for (size_t i = 0; i < EDITOR.EditorScenes.size(); i++) { - if (EDITOR.EditorScenes[i].Scene != EDITOR.GetFocusedScene()) + if (EDITOR.EditorScenes[i]->Scene != EDITOR.GetFocusedScene()) continue; - FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(EDITOR.EditorScenes[i].Scene->GetObjectID()); + FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(EDITOR.EditorScenes[i]->Scene->GetObjectID()); if (!ImGui::GetIO().WantCaptureKeyboard && Key == GLFW_KEY_DELETE) { - if (SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene) != nullptr) + if (SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene) != nullptr) { - if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1 && SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene)->HasComponent()) + if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1 && SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene)->HasComponent()) { - INSTANCED_RENDERING_SYSTEM.DeleteIndividualInstance(SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene), CurrentSelectionData->InstancedSubObjectIndexSelected); + INSTANCED_RENDERING_SYSTEM.DeleteIndividualInstance(SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene), CurrentSelectionData->InstancedSubObjectIndexSelected); } else { if (EDITOR.GetFocusedScene() != nullptr) { - EDITOR.GetFocusedScene()->DeleteEntity(SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene)); + EDITOR.GetFocusedScene()->DeleteEntity(SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene)); } } - SELECTED.Clear(EDITOR.EditorScenes[i].Scene); + SELECTED.Clear(EDITOR.EditorScenes[i]->Scene); PROJECT_MANAGER.GetCurrent()->SetModified(true); } } if (!ImGui::GetIO().WantCaptureKeyboard && Mods == GLFW_MOD_CONTROL && Key == GLFW_KEY_C && Action == GLFW_RELEASE) { - if (SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene) != nullptr) - EDITOR.SetSceneEntityIDInClipboard(SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene)->GetObjectID()); + if (SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene) != nullptr) + EDITOR.SetSceneEntityIDInClipboard(SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene)->GetObjectID()); } if (!ImGui::GetIO().WantCaptureKeyboard && (Key == GLFW_KEY_RIGHT_SHIFT || Key == GLFW_KEY_LEFT_SHIFT) && Action == GLFW_RELEASE) { - FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(EDITOR.EditorScenes[i].Scene->GetObjectID()); + FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(EDITOR.EditorScenes[i]->Scene->GetObjectID()); int NewState = GizmoSceneData->GizmosState + 1; if (NewState > 2) NewState = 0; - GIZMO_MANAGER.UpdateGizmoState(NewState, EDITOR.EditorScenes[i].Scene); + GIZMO_MANAGER.UpdateGizmoState(NewState, EDITOR.EditorScenes[i]->Scene); } } @@ -266,7 +290,6 @@ void FEEditor::InitializeResources() PROJECT_MANAGER.InitializeResources(); PREVIEW_MANAGER.InitializeResources(); DRAG_AND_DROP_MANAGER.InitializeResources(); - SceneWindowTarget = DRAG_AND_DROP_MANAGER.AddTarget(FE_PREFAB, SceneWindowDragAndDropCallBack, nullptr, "Drop to add to scene"); // **************************** Gizmos **************************** GIZMO_MANAGER.InitializeResources(); @@ -313,18 +336,18 @@ void FEEditor::MouseMoveCallback(double Xpos, double Ypos) for (size_t i = 0; i < EDITOR.EditorScenes.size(); i++) { - if (EDITOR.EditorScenes[i].Scene != EDITOR.GetFocusedScene()) + if (EDITOR.EditorScenes[i]->Scene != EDITOR.GetFocusedScene()) continue; - if (SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene) != nullptr) + if (SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene) != nullptr) { - if (SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene) != nullptr && SELECTED.GetSelected(EDITOR.EditorScenes[i].Scene)->HasComponent()) + if (SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene) != nullptr && SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene)->HasComponent()) { if (TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE) return; } - GIZMO_MANAGER.MouseMove(EDITOR.GetLastMouseX(), EDITOR.GetLastMouseY(), EDITOR.GetMouseX(), EDITOR.GetMouseY(), EDITOR.EditorScenes[i].Scene); + GIZMO_MANAGER.MouseMove(EDITOR.GetLastMouseX(), EDITOR.GetLastMouseY(), EDITOR.GetMouseX(), EDITOR.GetMouseY(), EDITOR.EditorScenes[i]->Scene); } } } @@ -491,46 +514,48 @@ void FEEditor::Render() for (size_t i = 0; i < EditorScenes.size(); i++) { - std::string WindowName = EditorScenes[i].Scene->GetName(); + std::string WindowName = EditorScenes[i]->Scene->GetName(); // Window name must be unique. - WindowName += "##" + EditorScenes[i].Scene->GetObjectID(); - if (EditorScenes[i].bMain) + WindowName += "##" + EditorScenes[i]->Scene->GetObjectID(); + if (EditorScenes[i]->bMain) WindowName = "Main Scene"; if (ImGui::Begin(WindowName.c_str(), nullptr, ImGuiWindowFlags_None | ImGuiWindowFlags_NoScrollbar)) { - if (EditorScenes[i].bJustAdded) + if (EditorScenes[i]->bJustAdded) { ImGui::SetWindowFocus(); ImGui::SetWindowSize(ImVec2(256, 256)); - EditorScenes[i].bJustAdded = false; + EditorScenes[i]->bJustAdded = false; } - EditorScenes[i].SceneWindow = ImGui::GetCurrentWindow(); - if (EditorScenes[i].bMain) - { - SceneWindowTarget->StickToCurrentWindow(); - } + EditorScenes[i]->SceneWindow = ImGui::GetCurrentWindow(); + if (EditorScenes[i]->SceneWindowTarget != nullptr) + EditorScenes[i]->SceneWindowTarget->StickToCurrentWindow(); if (ImGui::IsWindowFocused()) - SetFocusedScene(EditorScenes[i].Scene); + SetFocusedScene(EditorScenes[i]->Scene); - FEEntity* CameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(EditorScenes[i].Scene); + FEEntity* CameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(EditorScenes[i]->Scene); FECameraComponent& CameraComponent = CameraEntity->GetComponent(); if (CameraComponent.GetViewport() == nullptr) { - std::string NewViewportID = ENGINE.AddViewport(EditorScenes[i].SceneWindow); + std::string NewViewportID = ENGINE.AddViewport(EditorScenes[i]->SceneWindow); CAMERA_SYSTEM.SetCameraViewport(CameraEntity, NewViewportID); - SELECTED.AddSceneData(EditorScenes[i].Scene->GetObjectID()); - GIZMO_MANAGER.AddSceneData(EditorScenes[i].Scene->GetObjectID()); + SELECTED.AddSceneData(EditorScenes[i]->Scene->GetObjectID()); + GIZMO_MANAGER.AddSceneData(EditorScenes[i]->Scene->GetObjectID()); + EditorScenes[i]->SceneWindowTarget = DRAG_AND_DROP_MANAGER.AddTarget(std::vector{ FE_GAMEMODEL, FE_PREFAB }, + SceneWindowDragAndDropCallBack, + reinterpret_cast(&EditorScenes[i]), + std::vector{ "Drop to add to scene", "Drop to add to scene" }); } ImGuiStyle& Style = ImGui::GetStyle(); Style.WindowBorderSize = 0.0f; Style.WindowPadding = ImVec2(0.0f, 0.0f); - FETexture* CameraResult = RENDERER.GetCameraResult(CAMERA_SYSTEM.GetMainCameraEntity(EditorScenes[i].Scene)); + FETexture* CameraResult = RENDERER.GetCameraResult(CAMERA_SYSTEM.GetMainCameraEntity(EditorScenes[i]->Scene)); if (CameraResult != nullptr) { ImGui::Image((void*)(intptr_t)CameraResult->GetTextureID(), ImVec2(ImGui::GetCurrentWindow()->ContentRegionRect.GetWidth(), ImGui::GetCurrentWindow()->ContentRegionRect.GetHeight()), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); @@ -551,15 +576,15 @@ void FEEditor::Render() for (size_t i = 0; i < EditorScenes.size(); i++) { - if (EditorScenes[i].Scene != EDITOR.GetFocusedScene()) + if (EditorScenes[i]->Scene != EDITOR.GetFocusedScene()) continue; - const int ObjectIndex = SELECTED.GetIndexOfObjectUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY(), EditorScenes[i].Scene); + const int ObjectIndex = SELECTED.GetIndexOfObjectUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY(), EditorScenes[i]->Scene); if (ObjectIndex >= 0) { - if (!GIZMO_MANAGER.WasSelected(ObjectIndex, EditorScenes[i].Scene)) + if (!GIZMO_MANAGER.WasSelected(ObjectIndex, EditorScenes[i]->Scene)) { - SELECTED.SetSelectedByIndex(ObjectIndex, EditorScenes[i].Scene); + SELECTED.SetSelectedByIndex(ObjectIndex, EditorScenes[i]->Scene); } } } @@ -600,12 +625,12 @@ void FEEditor::OnViewportResize(std::string ViewportID) for (size_t i = 0; i < EDITOR.EditorScenes.size(); i++) { - FEEntity* CameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.EditorScenes[i].Scene); + FEEntity* CameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.EditorScenes[i]->Scene); FECameraComponent& CameraComponent = CameraEntity->GetComponent(); if (CameraComponent.GetViewport()->GetID() == ViewportID) { - SELECTED.UpdateResources(EDITOR.EditorScenes[i].Scene); + SELECTED.UpdateResources(EDITOR.EditorScenes[i]->Scene); } } } @@ -833,10 +858,10 @@ void FEEditor::OnProjectClose() void FEEditor::AddEditorScene(FEScene* Scene, bool bMain) { - FEEditorSceneData EditorSceneData; - EditorSceneData.bMain = bMain; - EditorSceneData.Scene = Scene; - EditorScenes.push_back(EditorSceneData); + FEEditorSceneData* NewEditorSceneData = new FEEditorSceneData(); + NewEditorSceneData->bMain = bMain; + NewEditorSceneData->Scene = Scene; + EditorScenes.push_back(NewEditorSceneData); } FEScene* FEEditor::GetFocusedScene() const diff --git a/FEEditor.h b/FEEditor.h index fb3be43..35c7c57 100644 --- a/FEEditor.h +++ b/FEEditor.h @@ -7,6 +7,7 @@ struct FEEditorSceneData { FEScene* Scene = nullptr; ImGuiWindow* SceneWindow = nullptr; + DragAndDropTarget* SceneWindowTarget = nullptr; bool bJustAdded = true; bool bMain = false; @@ -52,14 +53,11 @@ class FEEditor void AddEditorScene(FEScene* Scene, bool bMain = false); - std::vector EditorScenes; + std::vector EditorScenes; // Clipboard std::string SceneEntityIDInClipboard; - // Drag and drop - DragAndDropTarget* SceneWindowTarget = nullptr; - // Callbacks static void AfterEngineUpdate(); static void MouseButtonCallback(int Button, int Action, int Mods); diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 1b22955..c668b08 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 1b22955b4775cbc5ddda4fae3a80c242f8158ade +Subproject commit c668b081baa9eb5bc201e0f8f86e9b65199ba978 From 2a69e286afa9049078b1c83b9e0569c4f5f0a21b Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Sat, 3 Aug 2024 21:41:50 -0400 Subject: [PATCH 27/46] Engine update; Introduced FEEditorSceneWindow class as a base class for scene windows in the editor; Deleted old code related to the previous non-node editor for materials; Added a material preview in the material editor; Added FEPrefabSceneEditorWindow as a child class of FEEditorSceneWindow, including additional buttons needed for working with prefabs; Renamed PrefabEditorWindow files to FEPrefabEditorManager; Improved FEImGuiWindow functionality; Deleted FEEditorSceneData and moved all its functionality to FEPrefabSceneEditorWindow; Introduced EDITOR_SCENE_TAG to differentiate between user entities and engine editor-introduced ones. --- CMakeLists.txt | 11 +- EditorWindows/ContentBrowserWindow.cpp | 10 +- EditorWindows/DebugTextureViewWindow.h | 2 +- EditorWindows/EditPopups.cpp | 914 +++--------------- EditorWindows/EditPopups.h | 43 +- .../FEEditorSceneWindow.cpp | 154 +++ .../FEEditorSceneWindow.h | 30 + EditorWindows/InspectorWindow.cpp | 20 +- EditorWindows/PrefabEditorManager.cpp | 160 +++ EditorWindows/PrefabEditorManager.h | 37 + EditorWindows/PrefabEditorWindow.cpp | 224 ----- EditorWindows/PrefabEditorWindow.h | 30 - EditorWindows/SceneGraphWindow.cpp | 20 +- EditorWindows/SceneGraphWindow.h | 1 + FEDearImguiWrapper/FEDearImguiWrapper.cpp | 64 +- FEDearImguiWrapper/FEDearImguiWrapper.h | 11 + FEEditor.cpp | 222 ++--- FEEditor.h | 19 +- FEEditorGizmoManager.cpp | 6 +- FEEditorGizmoManager.h | 1 + FEEditorHaloSelectionEffect.cpp | 3 + FEEditorPreviewManager.cpp | 4 +- FEEditorPreviewManager.h | 4 +- FEEditorSelectedObject.cpp | 13 +- FEEditorSelectedObject.h | 2 + SubSystems/FocalEngine | 2 +- 26 files changed, 741 insertions(+), 1266 deletions(-) create mode 100644 EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp create mode 100644 EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.h create mode 100644 EditorWindows/PrefabEditorManager.cpp create mode 100644 EditorWindows/PrefabEditorManager.h delete mode 100644 EditorWindows/PrefabEditorWindow.cpp delete mode 100644 EditorWindows/PrefabEditorWindow.h diff --git a/CMakeLists.txt b/CMakeLists.txt index cd84fde..21cdb28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,11 @@ file(GLOB FEDearImguiWrapper_SRC "FEDearImguiWrapper/FEDearImguiWrapper.h" ) +file(GLOB EditorWindows_BaseWindowClasses_SRC + "EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.h" + "EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp" +) + file(GLOB EditorWindows_SRC "EditorWindows/DeletePopups.cpp" "EditorWindows/DeletePopups.h" @@ -86,8 +91,8 @@ file(GLOB EditorWindows_SRC "EditorWindows/ShaderEditorWindow.h" "EditorWindows/ResizeTexturePopup.cpp" "EditorWindows/ResizeTexturePopup.h" - "EditorWindows/PrefabEditorWindow.cpp" - "EditorWindows/PrefabEditorWindow.h" + "EditorWindows/PrefabEditorManager.cpp" + "EditorWindows/PrefabEditorManager.h" "EditorWindows/DebugTextureViewWindow.cpp" "EditorWindows/DebugTextureViewWindow.h" "EditorWindows/SceneGraphWindow.cpp" @@ -136,6 +141,7 @@ link_directories(${GLFW_LIB_DIR}) add_executable(FocalEngineEditor WIN32 ${Editor_SRC} ${FEDearImguiWrapper_SRC} + ${EditorWindows_BaseWindowClasses_SRC} ${EditorWindows_SRC} ${Editor_Materials_SRC} ${VisualNodeSystem_CustomNodes_SRC} @@ -152,6 +158,7 @@ source_group("Source Files" FILES ${Application_SRC}) # *************** EDITOR *************** source_group("Source Files/" FILES ${Editor_SRC}) source_group("Source Files/FEDearImguiWrapper" FILES ${FEDearImguiWrapper_SRC}) +source_group("Source Files/EditorWindows/BaseWindowClasses" FILES ${EditorWindows_BaseWindowClasses_SRC}) source_group("Source Files/EditorWindows" FILES ${EditorWindows_SRC}) source_group("Source Files/Materials" FILES ${Editor_Materials_SRC}) source_group("Source Files/NodeSystem/CustomNodes" FILES ${VisualNodeSystem_CustomNodes_SRC}) diff --git a/EditorWindows/ContentBrowserWindow.cpp b/EditorWindows/ContentBrowserWindow.cpp index f251b25..f988386 100644 --- a/EditorWindows/ContentBrowserWindow.cpp +++ b/EditorWindows/ContentBrowserWindow.cpp @@ -253,7 +253,7 @@ void FEEditorContentBrowserWindow::Render() { if (ImGui::MenuItem("Edit")) { - EditMaterialPopup::getInstance().Show(RESOURCE_MANAGER.GetMaterial(FilteredResources[ItemUnderMouse]->GetObjectID())); + EDITOR_MATERIAL_WINDOW.Show(RESOURCE_MANAGER.GetMaterial(FilteredResources[ItemUnderMouse]->GetObjectID())); } } @@ -276,7 +276,7 @@ void FEEditorContentBrowserWindow::Render() { if (ImGui::MenuItem("Edit")) { - PrefabEditorWindow::getInstance().Show(RESOURCE_MANAGER.GetPrefab(FilteredResources[ItemUnderMouse]->GetObjectID())); + PREFAB_EDITOR_MANAGER.PrepareEditWinow(RESOURCE_MANAGER.GetPrefab(FilteredResources[ItemUnderMouse]->GetObjectID())); } } @@ -764,7 +764,7 @@ void FEEditorContentBrowserWindow::RenderFilterMenu() } else if (FilteredResources[ItemUnderMouse]->GetType() == FE_MATERIAL) { - EditMaterialPopup::getInstance().Show(RESOURCE_MANAGER.GetMaterial(FilteredResources[ItemUnderMouse]->GetObjectID())); + EDITOR_MATERIAL_WINDOW.Show(RESOURCE_MANAGER.GetMaterial(FilteredResources[ItemUnderMouse]->GetObjectID())); } else if (FilteredResources[ItemUnderMouse]->GetType() == FE_GAMEMODEL) { @@ -775,9 +775,9 @@ void FEEditorContentBrowserWindow::RenderFilterMenu() } else if (FilteredResources[ItemUnderMouse]->GetType() == FE_PREFAB) { - if (!bShouldOpenContextMenu && !PrefabEditorWindow::getInstance().IsVisible()) + if (!bShouldOpenContextMenu) { - PrefabEditorWindow::getInstance().Show(RESOURCE_MANAGER.GetPrefab(FilteredResources[ItemUnderMouse]->GetObjectID())); + PREFAB_EDITOR_MANAGER.PrepareEditWinow(RESOURCE_MANAGER.GetPrefab(FilteredResources[ItemUnderMouse]->GetObjectID())); } } } diff --git a/EditorWindows/DebugTextureViewWindow.h b/EditorWindows/DebugTextureViewWindow.h index 1365a16..224a496 100644 --- a/EditorWindows/DebugTextureViewWindow.h +++ b/EditorWindows/DebugTextureViewWindow.h @@ -1,6 +1,6 @@ #pragma once -#include "PrefabEditorWindow.h" +#include "PrefabEditorManager.h" class DebugTextureViewWindow : public FEImGuiWindow { diff --git a/EditorWindows/EditPopups.cpp b/EditorWindows/EditPopups.cpp index d722d2a..1c89a2f 100644 --- a/EditorWindows/EditPopups.cpp +++ b/EditorWindows/EditPopups.cpp @@ -716,51 +716,101 @@ bool EditGameModelPopup::IsLastSetupLOD(const size_t LODIndex) return true; } -EditMaterialPopup* EditMaterialPopup::Instance = nullptr; +EditMaterialWindow* EditMaterialWindow::Instance = nullptr; -EditMaterialPopup::EditMaterialPopup() +EditMaterialWindow::EditMaterialWindow() { ObjToWorkWith = nullptr; - Flags = ImGuiWindowFlags_NoResize; + Flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; CancelButton = new ImGuiButton("Cancel"); CancelButton->SetDefaultColor(ImVec4(0.7f, 0.5f, 0.5f, 1.0f)); CancelButton->SetHoveredColor(ImVec4(0.95f, 0.5f, 0.0f, 1.0f)); CancelButton->SetActiveColor(ImVec4(0.1f, 1.0f, 0.1f, 1.0f)); -#ifdef USE_NODES NodeAreaTarget = DRAG_AND_DROP_MANAGER.AddTarget(FE_TEXTURE, DragAndDropnodeAreaTargetCallback, reinterpret_cast(&DragAndDropCallbackInfo), "Drop to add texture"); -#endif // USE_NODES + + PreviewScene = SCENE_MANAGER.CreateScene("MaterialEditor_Scene"); + + PreviewGameModel = new FEGameModel(nullptr, nullptr, "MaterialEditor_Preview_GameModel"); + PreviewGameModel->Mesh = RESOURCE_MANAGER.GetMesh("7F251E3E0D08013E3579315F"/*"sphere"*/); + + PreviewEntity = PreviewScene->CreateEntity("MaterialEditor_Scene_PreviewEntity"); + PreviewEntity->AddComponent(PreviewGameModel); + PreviewEntity->GetComponent().SetVisibility(true); + PreviewEntity->GetComponent().SetScale(glm::vec3(0.1f)); + + PreviewCameraEntity = PreviewScene->CreateEntity("MaterialEditor_Scene_CameraEntity"); + PreviewCameraEntity->AddComponent(); + FECameraComponent& CameraComponent = PreviewCameraEntity->GetComponent(); + CameraComponent.Type = 1; + CameraComponent.DistanceToModel = 10.0; + CameraComponent.SetRenderTargetSize(512, 1020); + CameraComponent.SetDistanceFogEnabled(false); + CAMERA_SYSTEM.SetMainCamera(PreviewCameraEntity); + + PreviewLightEntity = PreviewScene->CreateEntity("MaterialEditor_Scene_LightEntity"); + PreviewLightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); + FELightComponent& LightComponent = PreviewLightEntity->GetComponent(); + PreviewLightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); + LightComponent.SetIntensity(5.0f); + LightComponent.SetCastShadows(false); + + FEEntity* SkyDome = PreviewScene->CreateEntity("SkyDome"); + SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); + SKY_DOME_SYSTEM.AddToEntity(SkyDome); + + SCENE_MANAGER.DeactivateScene(PreviewScene); + ENGINE.AddMouseButtonCallback(MouseButtonCallback); +} + +void EditMaterialWindow::MouseButtonCallback(const int Button, const int Action, int Mods) +{ + EDITOR_MATERIAL_WINDOW.bWindowHovered = false; + if (ImGui::GetCurrentContext()->HoveredWindow == EDITOR_MATERIAL_WINDOW.GetWindow()) + EDITOR_MATERIAL_WINDOW.bWindowHovered = true; + + if (ImGui::GetIO().WantCaptureMouse && (!EDITOR_MATERIAL_WINDOW.bWindowHovered || !EDITOR_MATERIAL_WINDOW.bCameraOutputHovered)) + { + CAMERA_SYSTEM.SetIsIndividualInputActive(EDITOR_MATERIAL_WINDOW.PreviewCameraEntity, false); + } + + if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_PRESS && EDITOR_MATERIAL_WINDOW.bWindowHovered && EDITOR_MATERIAL_WINDOW.bCameraOutputHovered) + { + CAMERA_SYSTEM.SetIsIndividualInputActive(EDITOR_MATERIAL_WINDOW.PreviewCameraEntity, true); + } + else if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_RELEASE) + { + CAMERA_SYSTEM.SetIsIndividualInputActive(EDITOR_MATERIAL_WINDOW.PreviewCameraEntity, false); + } } -EditMaterialPopup::~EditMaterialPopup() +EditMaterialWindow::~EditMaterialWindow() { delete CancelButton; delete IconButton; } -#ifdef USE_NODES -FEMaterial* EditMaterialPopup::ObjToWorkWith = nullptr; -VisNodeSys::NodeArea* EditMaterialPopup::MaterialNodeArea = nullptr; -ImVec2 EditMaterialPopup::NodeGridRelativePosition = ImVec2(5, 30); -ImVec2 EditMaterialPopup::WindowPosition = ImVec2(0, 0); -ImVec2 EditMaterialPopup::MousePositionWhenContextMenuWasOpened = ImVec2(0, 0); -FETexture* EditMaterialPopup::TextureForNewNode = nullptr; -#endif // USE_NODES -void EditMaterialPopup::Show(FEMaterial* Material) +FEMaterial* EditMaterialWindow::ObjToWorkWith = nullptr; +VisNodeSys::NodeArea* EditMaterialWindow::MaterialNodeArea = nullptr; +ImVec2 EditMaterialWindow::NodeGridRelativePosition = ImVec2(5, 30); +ImVec2 EditMaterialWindow::WindowPosition = ImVec2(0, 0); +ImVec2 EditMaterialWindow::MousePositionWhenContextMenuWasOpened = ImVec2(0, 0); +FETexture* EditMaterialWindow::TextureForNewNode = nullptr; + +void EditMaterialWindow::Show(FEMaterial* Material) { if (Material != nullptr) { + PreviewGameModel->SetMaterial(Material); + SCENE_MANAGER.ActivateScene(PreviewScene); + TempContainer = RESOURCE_MANAGER.NoTexture; ObjToWorkWith = Material; std::string TempCaption = "Edit material:"; TempCaption += " " + ObjToWorkWith->GetName(); strcpy_s(Caption, TempCaption.size() + 1, TempCaption.c_str()); -#ifdef USE_NODES - Size = ImVec2(1500.0f, 1000.0f); -#else - size = ImVec2(1500.0f, 700.0f); -#endif // USE_NODES + Size = ImVec2(1512.0f, 1000.0f); Position = ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2 - Size.x / 2, APPLICATION.GetMainWindow()->GetHeight() / 2 - Size.y / 2); FEImGuiWindow::Show(); @@ -770,19 +820,20 @@ void EditMaterialPopup::Show(FEMaterial* Material) IconButton->SetUV1(ImVec2(1.0f, 1.0f)); IconButton->SetFramePadding(8); -#ifdef USE_NODES MaterialNodeArea = NODE_SYSTEM.CreateNodeArea(); MaterialNodeArea->SetMainContextMenuFunc(NodeSystemMainContextMenu); MaterialNodeArea->AddNodeEventCallback(TextureNodeCallback); - FEEditorMaterialNode* NewNode = new FEEditorMaterialNode(Material); + MaterialNodeArea->SetRenderOffset(ImVec2(-340, 250)); + + FEEditorMaterialNode* MaterialNode = new FEEditorMaterialNode(Material); ImVec2 PositionOnCanvas; - PositionOnCanvas.x = NodeGridRelativePosition.x + Size.x - Size.x / 6 - NewNode->GetSize().x / 2.0f; - PositionOnCanvas.y = NodeGridRelativePosition.y + Size.y / 2 - NewNode->GetSize().y / 2.0f; - NewNode->SetPosition(PositionOnCanvas); + PositionOnCanvas.x = NodeGridRelativePosition.x + Size.x - Size.x / 6 - MaterialNode->GetSize().x / 2.0f - 150; + PositionOnCanvas.y = NodeGridRelativePosition.y + Size.y / 2 - MaterialNode->GetSize().y / 2.0f - 300; + MaterialNode->SetPosition(PositionOnCanvas); - MaterialNodeArea->AddNode(NewNode); + MaterialNodeArea->AddNode(MaterialNode); // Add all textures of material as a texture nodes // Place them in shifted grid. @@ -804,80 +855,64 @@ void EditMaterialPopup::Show(FEMaterial* Material) // We should recreate proper connections. if (Material->GetAlbedoMap() == Material->Textures[i]) { - MaterialNodeArea->TryToConnect(NewTextureNode, 5, NewNode, 0); + MaterialNodeArea->TryToConnect(NewTextureNode, 5, MaterialNode, 0); } else if (Material->GetAlbedoMap(1) == Material->Textures[i]) { - MaterialNodeArea->TryToConnect(NewTextureNode, 5, NewNode, 6); + MaterialNodeArea->TryToConnect(NewTextureNode, 5, MaterialNode, 6); } if (Material->GetNormalMap() == Material->Textures[i]) { - MaterialNodeArea->TryToConnect(NewTextureNode, 5, NewNode, 1); + MaterialNodeArea->TryToConnect(NewTextureNode, 5, MaterialNode, 1); } else if (Material->GetNormalMap(1) == Material->Textures[i]) { - MaterialNodeArea->TryToConnect(NewTextureNode, 5, NewNode, 7); + MaterialNodeArea->TryToConnect(NewTextureNode, 5, MaterialNode, 7); } if (Material->GetAOMap() == Material->Textures[i]) { - MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetAOMapChannel(), NewNode, 2); + MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetAOMapChannel(), MaterialNode, 2); } else if (Material->GetAOMap(1) == Material->Textures[i]) { - MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetAOMapChannel(), NewNode, 8); + MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetAOMapChannel(), MaterialNode, 8); } if (Material->GetRoughnessMap() == Material->Textures[i]) { - MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetRoughnessMapChannel(), NewNode, 3); + MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetRoughnessMapChannel(), MaterialNode, 3); } else if (Material->GetRoughnessMap(1) == Material->Textures[i]) { - MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetRoughnessMapChannel(), NewNode, 9); + MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetRoughnessMapChannel(), MaterialNode, 9); } if (Material->GetMetalnessMap() == Material->Textures[i]) { - MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetMetalnessMapChannel(), NewNode, 4); + MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetMetalnessMapChannel(), MaterialNode, 4); } else if (Material->GetMetalnessMap(1) == Material->Textures[i]) { - MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetMetalnessMapChannel(), NewNode, 10); + MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetMetalnessMapChannel(), MaterialNode, 10); } if (Material->GetDisplacementMap() == Material->Textures[i]) { - MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetDisplacementMapChannel(), NewNode, 5); + MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetDisplacementMapChannel(), MaterialNode, 5); } else if (Material->GetDisplacementMap(1) == Material->Textures[i]) { - MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetDisplacementMapChannel(), NewNode, 11); + MaterialNodeArea->TryToConnect(NewTextureNode, ObjToWorkWith->GetDisplacementMapChannel(), MaterialNode, 11); } } -#else - // ************** Drag&Drop ************** - TexturesListTarget = DRAG_AND_DROP_MANAGER.addTarget(FE_TEXTURE, DragAndDropTexturesListCallback, reinterpret_cast(&ObjToWorkWith), "Drop to add texture"); - if (MaterialBindingtargets.size() == 0) - { - MaterialBindingInfo.resize(12); - for (size_t i = 0; i < 12; i++) - { - MaterialBindingInfo[i].Material = reinterpret_cast(&ObjToWorkWith); - MaterialBindingInfo[i].TextureBinding = i; - - MaterialBindingCallbackInfo* test = &MaterialBindingInfo[i]; - MaterialBindingtargets.push_back(DRAG_AND_DROP_MANAGER.addTarget(FE_TEXTURE, DragAndDropMaterialBindingsCallback, reinterpret_cast(&MaterialBindingInfo[i]), "Drop to assign texture")); - } - } - // ************** Drag&Drop END ************** -#endif // USE_NODES } } -void EditMaterialPopup::Render() +void EditMaterialWindow::Render() { + bCameraOutputHovered = false; FEImGuiWindow::Render(); if (!IsVisible()) @@ -889,669 +924,32 @@ void EditMaterialPopup::Render() return; } -#ifdef USE_NODES - MaterialNodeArea->SetPosition(ImVec2(0, 0)); - MaterialNodeArea->SetSize(ImVec2(ImGui::GetWindowWidth(), ImGui::GetWindowHeight() - 50.0f)); - MaterialNodeArea->Update(); - NodeAreaTarget->StickToItem(); - - WindowPosition = ImGui::GetWindowPos(); - - if (ImGui::GetIO().MouseReleased[1]) - MousePositionWhenContextMenuWasOpened = ImGui::GetMousePos(); + RENDERER.Render(PreviewScene); - CancelButton->SetPosition(ImVec2(CancelButton->GetPosition().x, ImGui::GetWindowHeight() - 44.0f)); -#else - // lame callback - if (tempContainer != RESOURCE_MANAGER.noTexture) + FETexture* CameraResult = RENDERER.GetCameraResult(PreviewCameraEntity); + if (CameraResult != nullptr) { - if (textureDestination == -1) - { - ObjToWorkWith->addTexture(tempContainer); - } - else - { - int subMaterial = textureDestination > 5; - if (subMaterial) - textureDestination -= 6; - - switch (textureDestination) - { - case 0: - { - ObjToWorkWith->setAlbedoMap(tempContainer, subMaterial); - break; - } - case 1: - { - ObjToWorkWith->setNormalMap(tempContainer, subMaterial); - break; - } - case 2: - { - ObjToWorkWith->setAOMap(tempContainer, 0, subMaterial); - break; - } - case 3: - { - ObjToWorkWith->setRoughnessMap(tempContainer, 0, subMaterial); - break; - } - case 4: - { - ObjToWorkWith->setMetalnessMap(tempContainer, 0, subMaterial); - break; - } - case 5: - { - ObjToWorkWith->setDisplacementMap(tempContainer, 0, subMaterial); - break; - } - } - } - - tempContainer = RESOURCE_MANAGER.noTexture; - PREVIEW_MANAGER.createMaterialPreview(ObjToWorkWith->getObjectID()); - PROJECT_MANAGER.getCurrent()->bModified = true; - } - - ImGui::Text("Textures (%d out of 16):", textureCount); - ImGui::SameLine(); - ImGui::SetCursorPosX(size.x * 0.26f); - ImGui::Text("Bindings:"); - - ImGui::SameLine(); - ImGui::SetCursorPosX(size.x * 0.26f + size.x * 0.49f); - ImGui::Text("Settings:"); - - // Textures - { - ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(0, 162, 232, 50)); - ImGui::BeginChild("Textures", ImVec2(ImGui::GetContentRegionAvail().x * 0.25f, 600), true, ImGuiWindowFlags_HorizontalScrollbar); - - if (!ImGui::IsPopupOpen("##materialPropertiesContext_menu")) - textureFromListUnderMouse = -1; - - if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(1)) - ImGui::OpenPopup("##materialPropertiesContext_menu"); - - TexturesListTarget->stickToCurrentWindow(); - - if (ImGui::BeginPopup("##materialPropertiesContext_menu")) - { - if (textureFromListUnderMouse == -1) - { - if (ImGui::MenuItem("Add texture...")) - { - textureDestination = -1; - selectTexturePopUp::getInstance().show(&tempContainer); - } - } - else - { - if (ImGui::MenuItem("Remove")) - { - ObjToWorkWith->removeTexture(textureFromListUnderMouse); - PROJECT_MANAGER.getCurrent()->bModified = true; - } - } - - ImGui::EndPopup(); - } - - ImGui::Columns(2, "TextureColumns", false); - textureCount = 0; - for (size_t i = 0; i < ObjToWorkWith->textures.size(); i++) - { - if (ObjToWorkWith->textures[i] == nullptr) - continue; - - textureCount++; - ImGui::PushID(ObjToWorkWith->textures[i]->getName().c_str()); - - ObjToWorkWith->textures[i]->getName() == "noTexture" ? iconButton->setTexture(RESOURCE_MANAGER.noTexture) : iconButton->setTexture(RESOURCE_MANAGER.getTexture(ObjToWorkWith->textures[i]->getObjectID())); - iconButton->render(); - - if (iconButton->isHovered()) - { - textureFromListUnderMouse = i; - } - - if (iconButton->isHovered() && ImGui::IsMouseDragging(0) && !DRAG_AND_DROP_MANAGER.objectIsDraged()) - DRAG_AND_DROP_MANAGER.setObject(ObjToWorkWith->textures[i], ObjToWorkWith->textures[i], ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); - - ImGui::Text(ObjToWorkWith->textures[i]->getName().c_str()); - ImGui::PopID(); - ImGui::NextColumn(); - } - ImGui::Columns(1); - - ImGui::PopStyleColor(); - ImGui::EndChild(); - } - - // material options - { - ImGui::SameLine(); - ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(0, 162, 232, 50)); - ImGui::BeginChild("Bindings", ImVec2(ImGui::GetContentRegionAvail().x * 0.49f, 600), true, ImGuiWindowFlags_HorizontalScrollbar); - - ImGui::Text("First sub material:"); - - // ************* Albedo ************* - ImGui::SetCursorPosX(10); - ImGui::SetCursorPosY(38); - ImGui::Text("Albedo:"); - ObjToWorkWith->getAlbedoMap() == nullptr ? iconButton->setTexture(RESOURCE_MANAGER.noTexture) : iconButton->setTexture(ObjToWorkWith->getAlbedoMap()); - iconButton->render(); - if (iconButton->getWasClicked()) - { - textureDestination = 0; - selectTexturePopUp::getInstance().showWithCustomList(&tempContainer, ObjToWorkWith->textures); - } - - if (MaterialBindingtargets.size() > 0) - MaterialBindingtargets[0]->stickToItem(); - - if (ObjToWorkWith->getAlbedoMap() != nullptr) - { - ImGui::SetNextItemWidth(85); - if (ImGui::BeginCombo("Channel##albedo", "rgba", ImGuiWindowFlags_None)) - { - bool is_selected = true; - ImGui::Selectable("rgba", is_selected); - ImGui::SetItemDefaultFocus(); - ImGui::EndCombo(); - } - } - - // ************* Normal ************* - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f); - ImGui::SetCursorPosY(38); - ImGui::Text("Normal:"); - ObjToWorkWith->getNormalMap() == nullptr ? iconButton->setTexture(RESOURCE_MANAGER.noTexture) : iconButton->setTexture(ObjToWorkWith->getNormalMap()); - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f); - iconButton->render(); - if (iconButton->getWasClicked()) - { - textureDestination = 1; - selectTexturePopUp::getInstance().showWithCustomList(&tempContainer, ObjToWorkWith->textures); - } - - if (MaterialBindingtargets.size() > 0) - MaterialBindingtargets[1]->stickToItem(); - - if (ObjToWorkWith->getNormalMap() != nullptr) - { - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f); - ImGui::SetNextItemWidth(85); - if (ImGui::BeginCombo("Channel##normal", "rgb", ImGuiWindowFlags_None)) - { - bool is_selected = true; - ImGui::Selectable("rgb", is_selected); - ImGui::SetItemDefaultFocus(); - ImGui::EndCombo(); - } - } - - // ************* AO ************* - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f * 2.0f); - ImGui::SetCursorPosY(38); - ImGui::Text("AO:"); - ObjToWorkWith->getAOMap() == nullptr ? iconButton->setTexture(RESOURCE_MANAGER.noTexture) : iconButton->setTexture(ObjToWorkWith->getAOMap()); - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f * 2.0f); - iconButton->render(); - if (iconButton->getWasClicked()) - { - textureDestination = 2; - selectTexturePopUp::getInstance().showWithCustomList(&tempContainer, ObjToWorkWith->textures); - } - - if (MaterialBindingtargets.size() > 0) - MaterialBindingtargets[2]->stickToItem(); - - if (ObjToWorkWith->getAOMap() != nullptr) - { - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f * 2.0f); - ImGui::SetNextItemWidth(85); - if (ImGui::BeginCombo("Channel##ao", channels[ObjToWorkWith->getAOMapChannel()].c_str(), ImGuiWindowFlags_None)) - { - for (size_t i = 0; i < channels.size(); i++) - { - // if texture was compresed with out alpha channel - if (i == 3 && ObjToWorkWith->getAOMap()->getInternalFormat() == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) - continue; - - bool is_selected = (channels[ObjToWorkWith->getAOMapChannel()] == channels[i]); - if (ImGui::Selectable(channels[i].c_str(), is_selected)) - ObjToWorkWith->setAOMap(ObjToWorkWith->getAOMap(), i); - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - ImGui::EndCombo(); - } - } - - // ************* Roughness ************* - ImGui::SetCursorPosX(10); - ImGui::SetCursorPosY(38 + 128 + 80); - ImGui::Text("Roughness:"); - ObjToWorkWith->getRoughnessMap() == nullptr ? iconButton->setTexture(RESOURCE_MANAGER.noTexture) : iconButton->setTexture(ObjToWorkWith->getRoughnessMap()); - ImGui::SetCursorPosX(10); - iconButton->render(); - if (iconButton->getWasClicked()) - { - textureDestination = 3; - selectTexturePopUp::getInstance().showWithCustomList(&tempContainer, ObjToWorkWith->textures); - } - - if (MaterialBindingtargets.size() > 0) - MaterialBindingtargets[3]->stickToItem(); - - if (ObjToWorkWith->getRoughnessMap() != nullptr) - { - ImGui::SetCursorPosX(10); - ImGui::SetNextItemWidth(85); - if (ImGui::BeginCombo("Channel##roughness", channels[ObjToWorkWith->getRoughnessMapChannel()].c_str(), ImGuiWindowFlags_None)) - { - for (size_t i = 0; i < channels.size(); i++) - { - // if texture was compresed with out alpha channel - if (i == 3 && ObjToWorkWith->getRoughnessMap()->getInternalFormat() == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) - continue; - - bool is_selected = (channels[ObjToWorkWith->getRoughnessMapChannel()] == channels[i]); - if (ImGui::Selectable(channels[i].c_str(), is_selected)) - ObjToWorkWith->setRoughnessMap(ObjToWorkWith->getRoughnessMap(), i); - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - ImGui::EndCombo(); - } - } - - // ************* Metalness ************* - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f); - ImGui::SetCursorPosY(38 + 128 + 80); - ImGui::Text("Metalness:"); - ObjToWorkWith->getMetalnessMap() == nullptr ? iconButton->setTexture(RESOURCE_MANAGER.noTexture) : iconButton->setTexture(ObjToWorkWith->getMetalnessMap()); - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f); - iconButton->render(); - if (iconButton->getWasClicked()) - { - textureDestination = 4; - selectTexturePopUp::getInstance().showWithCustomList(&tempContainer, ObjToWorkWith->textures); - } - - if (MaterialBindingtargets.size() > 0) - MaterialBindingtargets[4]->stickToItem(); - - if (ObjToWorkWith->getMetalnessMap() != nullptr) - { - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f); - ImGui::SetNextItemWidth(85); - if (ImGui::BeginCombo("Channel##metalness", channels[ObjToWorkWith->getMetalnessMapChannel()].c_str(), ImGuiWindowFlags_None)) - { - for (size_t i = 0; i < channels.size(); i++) - { - // if texture was compresed with out alpha channel - if (i == 3 && ObjToWorkWith->getMetalnessMap()->getInternalFormat() == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) - continue; - - bool is_selected = (channels[ObjToWorkWith->getMetalnessMapChannel()] == channels[i]); - if (ImGui::Selectable(channels[i].c_str(), is_selected)) - ObjToWorkWith->setMetalnessMap(ObjToWorkWith->getMetalnessMap(), i); - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - ImGui::EndCombo(); - } - } - - // ************* Displacement ************* - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f * 2.0f); - ImGui::SetCursorPosY(38 + 128 + 80); - ImGui::Text("Displacement:"); - ObjToWorkWith->getDisplacementMap() == nullptr ? iconButton->setTexture(RESOURCE_MANAGER.noTexture) : iconButton->setTexture(ObjToWorkWith->getDisplacementMap()); - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f * 2.0f); - iconButton->render(); - if (iconButton->getWasClicked()) + ImGui::SetCursorPosX(-10); + ImGui::SetCursorPosY(-10); + + ImGui::Image((void*)(intptr_t)CameraResult->GetTextureID(), ImVec2(512, 1020), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); + if (ImGui::IsItemHovered()) { - textureDestination = 5; - selectTexturePopUp::getInstance().showWithCustomList(&tempContainer, ObjToWorkWith->textures); + bCameraOutputHovered = true; } - - if (MaterialBindingtargets.size() > 0) - MaterialBindingtargets[5]->stickToItem(); - - if (ObjToWorkWith->getDisplacementMap() != nullptr) - { - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f * 2.0f); - ImGui::SetNextItemWidth(85); - if (ImGui::BeginCombo("Channel##displacement", channels[ObjToWorkWith->getDisplacementMapChannel()].c_str(), ImGuiWindowFlags_None)) - { - for (size_t i = 0; i < channels.size(); i++) - { - // if texture was compresed with out alpha channel - if (i == 3 && ObjToWorkWith->getDisplacementMap()->getInternalFormat() == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) - continue; - - bool is_selected = (channels[ObjToWorkWith->getDisplacementMapChannel()] == channels[i]); - if (ImGui::Selectable(channels[i].c_str(), is_selected)) - ObjToWorkWith->setDisplacementMap(ObjToWorkWith->getDisplacementMap(), i); - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - ImGui::EndCombo(); - } - } - - ImGui::SetCursorPosY(38 + 128 + 80 + 128 + 80); - ImGui::Separator(); - - ImGui::Text("Second sub material:"); - // ************* Albedo ************* - ImGui::SetCursorPosX(10); - ImGui::SetCursorPosY(64 + 128 + 80 + 128 + 80); - ImGui::Text("Albedo:"); - ObjToWorkWith->getAlbedoMap(1) == nullptr ? iconButton->setTexture(RESOURCE_MANAGER.noTexture) : iconButton->setTexture(ObjToWorkWith->getAlbedoMap(1)); - iconButton->render(); - if (iconButton->getWasClicked()) - { - textureDestination = 6; - selectTexturePopUp::getInstance().showWithCustomList(&tempContainer, ObjToWorkWith->textures); - } - - if (MaterialBindingtargets.size() > 0) - MaterialBindingtargets[6]->stickToItem(); - - if (ObjToWorkWith->getAlbedoMap(1) != nullptr) - { - ImGui::SetNextItemWidth(85); - if (ImGui::BeginCombo("Channel##albedoSubmaterial", "rgba", ImGuiWindowFlags_None)) - { - bool is_selected = true; - ImGui::Selectable("rgba", is_selected); - ImGui::SetItemDefaultFocus(); - ImGui::EndCombo(); - } - } - - // ************* Normal ************* - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f); - ImGui::SetCursorPosY(64 + 128 + 80 + 128 + 80); - ImGui::Text("Normal:"); - ObjToWorkWith->getNormalMap(1) == nullptr ? iconButton->setTexture(RESOURCE_MANAGER.noTexture) : iconButton->setTexture(ObjToWorkWith->getNormalMap(1)); - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f); - iconButton->render(); - if (iconButton->getWasClicked()) - { - textureDestination = 7; - selectTexturePopUp::getInstance().showWithCustomList(&tempContainer, ObjToWorkWith->textures); - } - - if (MaterialBindingtargets.size() > 0) - MaterialBindingtargets[7]->stickToItem(); - - if (ObjToWorkWith->getNormalMap(1) != nullptr) - { - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f); - ImGui::SetNextItemWidth(85); - if (ImGui::BeginCombo("Channel##normalSubmaterial", "rgb", ImGuiWindowFlags_None)) - { - bool is_selected = true; - ImGui::Selectable("rgb", is_selected); - ImGui::SetItemDefaultFocus(); - ImGui::EndCombo(); - } - } - - // ************* AO ************* - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f * 2.0f); - ImGui::SetCursorPosY(64 + 128 + 80 + 128 + 80); - ImGui::Text("AO:"); - ObjToWorkWith->getAOMap(1) == nullptr ? iconButton->setTexture(RESOURCE_MANAGER.noTexture) : iconButton->setTexture(ObjToWorkWith->getAOMap(1)); - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f * 2.0f); - iconButton->render(); - if (iconButton->getWasClicked()) - { - textureDestination = 8; - selectTexturePopUp::getInstance().showWithCustomList(&tempContainer, ObjToWorkWith->textures); - } - - if (MaterialBindingtargets.size() > 0) - MaterialBindingtargets[8]->stickToItem(); - - if (ObjToWorkWith->getAOMap(1) != nullptr) - { - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f * 2.0f); - ImGui::SetNextItemWidth(85); - if (ImGui::BeginCombo("Channel##aoSubmaterial", channels[ObjToWorkWith->getAOMapChannel(1)].c_str(), ImGuiWindowFlags_None)) - { - for (size_t i = 0; i < channels.size(); i++) - { - // if texture was compresed with out alpha channel - if (i == 3 && ObjToWorkWith->getAOMap(1)->getInternalFormat() == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) - continue; - - bool is_selected = (channels[ObjToWorkWith->getAOMapChannel(1)] == channels[i]); - if (ImGui::Selectable(channels[i].c_str(), is_selected)) - ObjToWorkWith->setAOMap(ObjToWorkWith->getAOMap(1), i, 1); - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - ImGui::EndCombo(); - } - } - - // ************* Roughness ************* - ImGui::SetCursorPosX(10); - ImGui::SetCursorPosY(64 + 128 + 80 + 128 + 80 + 128 + 80); - ImGui::Text("Roughness:"); - ObjToWorkWith->getRoughnessMap(1) == nullptr ? iconButton->setTexture(RESOURCE_MANAGER.noTexture) : iconButton->setTexture(ObjToWorkWith->getRoughnessMap(1)); - ImGui::SetCursorPosX(10); - iconButton->render(); - if (iconButton->getWasClicked()) - { - textureDestination = 9; - selectTexturePopUp::getInstance().showWithCustomList(&tempContainer, ObjToWorkWith->textures); - } - - if (MaterialBindingtargets.size() > 0) - MaterialBindingtargets[9]->stickToItem(); - - if (ObjToWorkWith->getRoughnessMap(1) != nullptr) - { - ImGui::SetCursorPosX(10); - ImGui::SetNextItemWidth(85); - if (ImGui::BeginCombo("Channel##roughnessSubmaterial", channels[ObjToWorkWith->getRoughnessMapChannel(1)].c_str(), ImGuiWindowFlags_None)) - { - for (size_t i = 0; i < channels.size(); i++) - { - // if texture was compresed with out alpha channel - if (i == 3 && ObjToWorkWith->getRoughnessMap(1)->getInternalFormat() == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) - continue; - - bool is_selected = (channels[ObjToWorkWith->getRoughnessMapChannel(1)] == channels[i]); - if (ImGui::Selectable(channels[i].c_str(), is_selected)) - ObjToWorkWith->setRoughnessMap(ObjToWorkWith->getRoughnessMap(1), i, 1); - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - ImGui::EndCombo(); - } - } - - // ************* Metalness ************* - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f); - ImGui::SetCursorPosY(64 + 128 + 80 + 128 + 80 + 128 + 80); - ImGui::Text("Metalness:"); - ObjToWorkWith->getMetalnessMap(1) == nullptr ? iconButton->setTexture(RESOURCE_MANAGER.noTexture) : iconButton->setTexture(ObjToWorkWith->getMetalnessMap(1)); - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f); - iconButton->render(); - if (iconButton->getWasClicked()) - { - textureDestination = 10; - selectTexturePopUp::getInstance().showWithCustomList(&tempContainer, ObjToWorkWith->textures); - } - - if (MaterialBindingtargets.size() > 0) - MaterialBindingtargets[10]->stickToItem(); - - if (ObjToWorkWith->getMetalnessMap(1) != nullptr) - { - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f); - ImGui::SetNextItemWidth(85); - if (ImGui::BeginCombo("Channel##metalnessSubmaterial", channels[ObjToWorkWith->getMetalnessMapChannel(1)].c_str(), ImGuiWindowFlags_None)) - { - for (size_t i = 0; i < channels.size(); i++) - { - // if texture was compresed with out alpha channel - if (i == 3 && ObjToWorkWith->getMetalnessMap(1)->getInternalFormat() == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) - continue; - - bool is_selected = (channels[ObjToWorkWith->getMetalnessMapChannel(1)] == channels[i]); - if (ImGui::Selectable(channels[i].c_str(), is_selected)) - ObjToWorkWith->setMetalnessMap(ObjToWorkWith->getMetalnessMap(1), i, 1); - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - ImGui::EndCombo(); - } - } - - // ************* Displacement ************* - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f * 2.0f); - ImGui::SetCursorPosY(64 + 128 + 80 + 128 + 80 + 128 + 80); - ImGui::Text("Displacement:"); - ObjToWorkWith->getDisplacementMap(1) == nullptr ? iconButton->setTexture(RESOURCE_MANAGER.noTexture) : iconButton->setTexture(ObjToWorkWith->getDisplacementMap(1)); - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f * 2.0f); - iconButton->render(); - if (iconButton->getWasClicked()) - { - textureDestination = 11; - selectTexturePopUp::getInstance().showWithCustomList(&tempContainer, ObjToWorkWith->textures); - } - - if (MaterialBindingtargets.size() > 0) - MaterialBindingtargets[11]->stickToItem(); - - if (ObjToWorkWith->getDisplacementMap(1) != nullptr) - { - ImGui::SetCursorPosX(10 + ImGui::GetContentRegionAvail().x / 3.0f * 2.0f); - ImGui::SetNextItemWidth(85); - if (ImGui::BeginCombo("Channel##displacementSubmaterial", channels[ObjToWorkWith->getDisplacementMapChannel(1)].c_str(), ImGuiWindowFlags_None)) - { - for (size_t i = 0; i < channels.size(); i++) - { - // if texture was compresed with out alpha channel - if (i == 3 && ObjToWorkWith->getDisplacementMap(1)->getInternalFormat() == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) - continue; - - bool is_selected = (channels[ObjToWorkWith->getDisplacementMapChannel(1)] == channels[i]); - if (ImGui::Selectable(channels[i].c_str(), is_selected)) - ObjToWorkWith->setDisplacementMap(ObjToWorkWith->getDisplacementMap(1), i, 1); - - if (is_selected) - ImGui::SetItemDefaultFocus(); - } - ImGui::EndCombo(); - } - } - - ImGui::PopStyleColor(); - ImGui::EndChild(); } - // Settings - { - static float fieldWidth = 350.0f; - ImGui::SameLine(); - ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(0, 162, 232, 50)); - ImGui::BeginChild("Settings", ImVec2(ImGui::GetContentRegionAvail().x * 0.30f, 600), true, ImGuiWindowFlags_HorizontalScrollbar); - - FEShaderParam* debugFlag = ObjToWorkWith->getParameter("debugFlag"); - if (debugFlag != nullptr) - { - ImGui::Text("Debug flag:"); - ImGui::SetNextItemWidth(fieldWidth); - int iData = *(int*)debugFlag->data; - ImGui::SliderInt("##Debug flag", &iData, 0, 10); - debugFlag->updateData(iData); - } - - // ************* Normal ************* - ImGui::Text("Normal map intensity:"); - ImGui::SetNextItemWidth(fieldWidth); - float normalMapIntensity = ObjToWorkWith->getNormalMapIntensity(); - ImGui::DragFloat("##Normal map intensity", &normalMapIntensity, 0.01f, 0.0f, 1.0f); - ObjToWorkWith->setNormalMapIntensity(normalMapIntensity); - - // ************* AO ************* - if (ObjToWorkWith->getAOMap() == nullptr) - { - ImGui::Text("Ambient occlusion intensity:"); - ImGui::SetNextItemWidth(fieldWidth); - float ambientOcclusionIntensity = ObjToWorkWith->getAmbientOcclusionIntensity(); - ImGui::DragFloat("##Ambient occlusion intensity", &ambientOcclusionIntensity, 0.01f, 0.0f, 10.0f); - ObjToWorkWith->setAmbientOcclusionIntensity(ambientOcclusionIntensity); - } - else - { - ImGui::Text("Ambient occlusion map intensity:"); - ImGui::SetNextItemWidth(fieldWidth); - float AOMapIntensity = ObjToWorkWith->getAmbientOcclusionMapIntensity(); - ImGui::DragFloat("##Ambient occlusion map intensity", &AOMapIntensity, 0.01f, 0.0f, 10.0f); - ObjToWorkWith->setAmbientOcclusionMapIntensity(AOMapIntensity); - } + MaterialNodeArea->SetPosition(ImVec2(512 - 10, 0)); + MaterialNodeArea->SetSize(ImVec2(ImGui::GetWindowWidth() - 500, ImGui::GetWindowHeight())); + MaterialNodeArea->Update(); + NodeAreaTarget->StickToItem(); - // ************* Roughness ************* - if (ObjToWorkWith->getRoughnessMap() == nullptr) - { - ImGui::Text("Roughness:"); - ImGui::SetNextItemWidth(fieldWidth); - float roughness = ObjToWorkWith->getRoughness(); - ImGui::DragFloat("##Roughness", &roughness, 0.01f, 0.0f, 1.0f); - ObjToWorkWith->setRoughness(roughness); - } - else - { - ImGui::Text("Roughness map intensity:"); - ImGui::SetNextItemWidth(fieldWidth); - float roughness = ObjToWorkWith->getRoughnessMapIntensity(); - ImGui::DragFloat("##Roughness map intensity", &roughness, 0.01f, 0.0f, 10.0f); - ObjToWorkWith->setRoughnessMapIntensity(roughness); - } + WindowPosition = ImGui::GetWindowPos(); - // ************* Metalness ************* - if (ObjToWorkWith->getMetalnessMap() == nullptr) - { - ImGui::Text("Metalness:"); - ImGui::SetNextItemWidth(fieldWidth); - float metalness = ObjToWorkWith->getMetalness(); - ImGui::DragFloat("##Metalness", &metalness, 0.01f, 0.0f, 1.0f); - ObjToWorkWith->setMetalness(metalness); - } - else - { - ImGui::Text("Metalness map intensity:"); - ImGui::SetNextItemWidth(fieldWidth); - float metalness = ObjToWorkWith->getMetalnessMapIntensity(); - ImGui::DragFloat("##Metalness map intensity", &metalness, 0.01f, 0.0f, 10.0f); - ObjToWorkWith->setMetalnessMapIntensity(metalness); - } + if (ImGui::GetIO().MouseReleased[1]) + MousePositionWhenContextMenuWasOpened = ImGui::GetMousePos(); - ImGui::PopStyleColor(); - ImGui::EndChild(); - } -#endif // USE_NODES + CancelButton->SetPosition(ImVec2(CancelButton->GetPosition().x, ImGui::GetWindowHeight() - 44.0f)); CancelButton->Render(); if (CancelButton->IsClicked()) @@ -1563,13 +961,19 @@ void EditMaterialPopup::Render() FEImGuiWindow::OnRenderEnd(); } -void EditMaterialPopup::Close() +void EditMaterialWindow::Close() { + Stop(); FEImGuiWindow::Close(); } -#ifdef USE_NODES -bool EditMaterialPopup::DragAndDropnodeAreaTargetCallback(FEObject* Object, void** CallbackInfo) +void EditMaterialWindow::Stop() +{ + SCENE_MANAGER.DeactivateScene(PreviewScene); + PreviewGameModel->SetMaterial(nullptr); +} + +bool EditMaterialWindow::DragAndDropnodeAreaTargetCallback(FEObject* Object, void** CallbackInfo) { if (ObjToWorkWith->IsTextureInList(RESOURCE_MANAGER.GetTexture(Object->GetObjectID()))) return false; @@ -1587,83 +991,8 @@ bool EditMaterialPopup::DragAndDropnodeAreaTargetCallback(FEObject* Object, void MaterialNodeArea->AddNode(NewNode); return true; } -#else -bool editMaterialPopup::dragAndDropCallback(FEObject* object, void** oldTexture) -{ - FETexture* newTexture = RESOURCE_MANAGER.getTexture(object->getObjectID()); - *oldTexture = reinterpret_cast(newTexture); - - return true; -} - -bool editMaterialPopup::dragAndDropTexturesListCallback(FEObject* object, void** material) -{ - reinterpret_cast(*material)->addTexture(RESOURCE_MANAGER.getTexture(object->getObjectID())); - return true; -} - -bool editMaterialPopup::dragAndDropMaterialBindingsCallback(FEObject* object, void** callbackInfoPointer) -{ - materialBindingCallbackInfo* info = reinterpret_cast(callbackInfoPointer); - FEMaterial* material = reinterpret_cast(*info->material); - - - if (!material->isTextureInList(RESOURCE_MANAGER.getTexture(object->getObjectID()))) - material->addTexture(RESOURCE_MANAGER.getTexture(object->getObjectID())); - - int subMaterial = info->textureBinding > 5; - if (subMaterial) - info->textureBinding -= 6; - - switch (info->textureBinding) - { - case 0: - { - material->setAlbedoMap(RESOURCE_MANAGER.getTexture(object->getObjectID()), subMaterial); - break; - } - - case 1: - { - material->setNormalMap(RESOURCE_MANAGER.getTexture(object->getObjectID()), subMaterial); - break; - } - - case 2: - { - material->setAOMap(RESOURCE_MANAGER.getTexture(object->getObjectID()), 0, subMaterial); - break; - } - - case 3: - { - material->setRoughnessMap(RESOURCE_MANAGER.getTexture(object->getObjectID()), 0, subMaterial); - break; - } - - case 4: - { - material->setMetalnessMap(RESOURCE_MANAGER.getTexture(object->getObjectID()), 0, subMaterial); - break; - } - - case 5: - { - material->setDisplacementMap(RESOURCE_MANAGER.getTexture(object->getObjectID()), 0, subMaterial); - break; - } - - default: - break; - } - - return true; -} -#endif // USE_NODES - -#ifdef USE_NODES -void EditMaterialPopup::NodeSystemMainContextMenu() +void EditMaterialWindow::NodeSystemMainContextMenu() { if (ImGui::BeginMenu("Add")) { @@ -1690,7 +1019,7 @@ void EditMaterialPopup::NodeSystemMainContextMenu() } } -void EditMaterialPopup::TextureNodeCallback(VisNodeSys::Node* Node, const VisNodeSys::NODE_EVENT EventWithNode) +void EditMaterialWindow::TextureNodeCallback(VisNodeSys::Node* Node, const VisNodeSys::NODE_EVENT EventWithNode) { if (Node == nullptr) return; @@ -1708,7 +1037,7 @@ void EditMaterialPopup::TextureNodeCallback(VisNodeSys::Node* Node, const VisNod } } -void EditMaterialPopup::TextureNodeCreationCallback(const std::vector SelectionsResult) +void EditMaterialWindow::TextureNodeCreationCallback(const std::vector SelectionsResult) { if (SelectionsResult.size() != 1 && SelectionsResult[0]->GetType() != FE_TEXTURE) return; @@ -1730,5 +1059,4 @@ void EditMaterialPopup::TextureNodeCreationCallback(const std::vector } } } -} -#endif // USE_NODES +} \ No newline at end of file diff --git a/EditorWindows/EditPopups.h b/EditorWindows/EditPopups.h index 03ae62a..11e8521 100644 --- a/EditorWindows/EditPopups.h +++ b/EditorWindows/EditPopups.h @@ -81,11 +81,11 @@ class EditGameModelPopup : public FEImGuiWindow void Close(); }; -#define USE_NODES - -class EditMaterialPopup : public FEImGuiWindow +class EditMaterialWindow : public FEImGuiWindow { - SINGLETON_PRIVATE_PART(EditMaterialPopup) + friend class FEEditor; + + SINGLETON_PRIVATE_PART(EditMaterialWindow) ImGuiButton* CancelButton; ImGuiImageButton* IconButton = nullptr; @@ -96,7 +96,6 @@ class EditMaterialPopup : public FEImGuiWindow FETexture* TempContainer = nullptr; int TextureDestination = -1; -#ifdef USE_NODES static FEMaterial* ObjToWorkWith; // ************** Node area ************** @@ -124,28 +123,26 @@ class EditMaterialPopup : public FEImGuiWindow static bool DragAndDropnodeAreaTargetCallback(FEObject* Object, void** CallbackInfo); // ************** Drag&Drop END ************** -#else - FEMaterial* ObjToWorkWith; - // ************** Drag&Drop ************** - struct MaterialBindingCallbackInfo - { - void** Material; - int TextureBinding; - }; - std::vector MaterialBindingInfo; - std::vector MaterialBindingtargets; - DragAndDropTarget* TexturesListTarget; + // ************** Scene ************** + FEScene* PreviewScene; + FEGameModel* PreviewGameModel; + FEEntity* PreviewEntity; + FEEntity* PreviewCameraEntity; + FEEntity* PreviewLightEntity; - static bool DragAndDropCallback(FEObject* Object, void** OldTexture); - static bool DragAndDropTexturesListCallback(FEObject* Object, void** Material); - static bool DragAndDropMaterialBindingsCallback(FEObject* Object, void** CallbackInfoPointer); - // ************** Drag&Drop END ************** -#endif // USE_NODES + bool bWindowHovered = false; + bool bCameraOutputHovered = false; + static void MouseButtonCallback(const int Button, const int Action, int Mods); + // ************** Scene END ************** + + void Stop(); public: - SINGLETON_PUBLIC_PART(EditMaterialPopup) + SINGLETON_PUBLIC_PART(EditMaterialWindow) void Show(FEMaterial* Material); void Render() override; void Close(); -}; \ No newline at end of file +}; + +#define EDITOR_MATERIAL_WINDOW EditMaterialWindow::getInstance() \ No newline at end of file diff --git a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp new file mode 100644 index 0000000..f8106cf --- /dev/null +++ b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp @@ -0,0 +1,154 @@ +#include "FEEditorSceneWindow.h" +#include "../../FEEditor.h" + +bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) +{ + if (EDITOR.GetFocusedScene() == nullptr) + return false; + + if (CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene()) == nullptr) + return false; + + if (UserData == nullptr) + return false; + + FEEditorSceneWindow* EditorSceneWindow = reinterpret_cast(UserData); + if (EditorSceneWindow->GetScene() == nullptr) + return false; + + if (Object->GetType() == FE_GAMEMODEL) + { + FEGameModel* GameModel = RESOURCE_MANAGER.GetGameModel(Object->GetObjectID()); + + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + + FEEntity* Entity = EditorSceneWindow->GetScene()->CreateEntity(Object->GetName()); + Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); + Entity->AddComponent(GameModel); + + SELECTED.SetSelected(Entity); + PROJECT_MANAGER.GetCurrent()->SetModified(true); + + return true; + + } + else if (Object->GetType() == FE_PREFAB) + { + FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())->GetComponent(0)->GameModel; + + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + + std::vector NewNodes = SCENE_MANAGER.ImportSceneAsNode(RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())->Scene, EditorSceneWindow->GetScene()); + if (!NewNodes.empty()) + { + // Currently we are interested in the first node only + FEEntity* Entity = NewNodes[0]->GetEntity(); + Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); + + SELECTED.SetSelected(Entity); + PROJECT_MANAGER.GetCurrent()->SetModified(true); + + return true; + } + } + + return false; +} + +FEEditorSceneWindow::FEEditorSceneWindow(FEScene* Scene, bool bMain) +{ + if (Scene == nullptr) + return; + + this->Scene = Scene; + this->bMain = bMain; + Flags = ImGuiWindowFlags_None | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; + + std::string WindowName = Scene->GetName(); + // Window name must be unique. + WindowName += "##" + Scene->GetObjectID(); + if (bMain) + WindowName = "Main Scene"; + + SetCaption(WindowName); + SetBorderSize(0.0f); + SetPadding(glm::vec2(0.0f, 0.0f)); +} + +FEEditorSceneWindow::~FEEditorSceneWindow() +{ + +} + +void FEEditorSceneWindow::Show() +{ + +} + +void FEEditorSceneWindow::Render() +{ + if (bJustAdded) + { + ImGui::SetWindowFocus(); + Size = ImVec2(910, 512); + bJustAdded = false; + } + + FEImGuiWindow::Render(); + + if (!IsVisible()) + return; + + if (SceneWindowTarget != nullptr) + SceneWindowTarget->StickToCurrentWindow(); + + if (ImGui::IsWindowFocused()) + EDITOR.SetFocusedScene(Scene); + + FEEntity* CameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(Scene); + if (CameraEntity != nullptr) + { + FECameraComponent& CameraComponent = CameraEntity->GetComponent(); + + if (CameraComponent.GetViewport() == nullptr) + { + std::string NewViewportID = ENGINE.AddViewport(GetWindow()); + CAMERA_SYSTEM.SetCameraViewport(CameraEntity, NewViewportID); + SELECTED.AddSceneData(Scene->GetObjectID()); + GIZMO_MANAGER.AddSceneData(Scene->GetObjectID()); + SceneWindowTarget = DRAG_AND_DROP_MANAGER.AddTarget(std::vector{ FE_GAMEMODEL, FE_PREFAB }, + SceneWindowDragAndDropCallBack, + reinterpret_cast(this), + std::vector{ "Drop to add to scene", "Drop to add to scene" }); + } + + ImGuiStyle& Style = ImGui::GetStyle(); + Style.WindowBorderSize = 0.0f; + Style.WindowPadding = ImVec2(0.0f, 0.0f); + + FETexture* CameraResult = RENDERER.GetCameraResult(CAMERA_SYSTEM.GetMainCameraEntity(Scene)); + if (CameraResult != nullptr) + { + ImGui::Image((void*)(intptr_t)CameraResult->GetTextureID(), ImVec2(GetWindow()->ContentRegionRect.GetWidth(), GetWindow()->ContentRegionRect.GetHeight()), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); + } + } + else + { + ImGui::Text("No camera in scene"); + } + + if (bSelfContained) + OnRenderEnd(); +} + +void FEEditorSceneWindow::OnRenderEnd() +{ + FEImGuiWindow::OnRenderEnd(); +} + +FEScene* FEEditorSceneWindow::GetScene() const +{ + return Scene; +} \ No newline at end of file diff --git a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.h b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.h new file mode 100644 index 0000000..03b7518 --- /dev/null +++ b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.h @@ -0,0 +1,30 @@ +#pragma once + +#include "../../FEDearImguiWrapper/FEDearImguiWrapper.h" +#include "../../FEEditorDragAndDropManager.h" +#include + +class FEEditorSceneWindow : public FEImGuiWindow +{ + friend class FEEditor; + +protected: + FEEditorSceneWindow(FEScene* Scene, bool bMain = false); + ~FEEditorSceneWindow(); + + FEScene* Scene = nullptr; + DragAndDropTarget* SceneWindowTarget = nullptr; + + bool bJustAdded = true; + bool bMain = false; + bool bWindowHovered = false; + + bool bSelfContained = true; + bool bWaitingForRemoval = false; +public: + void Show(); + void Render() override; + void OnRenderEnd() override; + + FEScene* GetScene() const; +}; \ No newline at end of file diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index 111a98a..2ec8aa1 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -454,6 +454,10 @@ void FEEditorInspectorWindow::DisplayCameraProperties(FEEntity* CameraEntity) co ImGui::DragFloat("##FarPlane", &FarPlane, 0.1f, 0.01f, 10000.0f); CameraComponent.SetFarPlane(FarPlane); + glm::vec4 CurrentClearColor = CameraComponent.GetClearColor(); + ImGui::ColorEdit4("Clear color", &CurrentClearColor.x); + CameraComponent.SetClearColor(CurrentClearColor); + float Gamma = CameraComponent.GetGamma(); ImGui::Text("Gamma : "); ImGui::SameLine(); @@ -979,13 +983,15 @@ void FEEditorInspectorWindow::Render() if (ImGui::CollapsingHeader("Tag", ImGuiTreeNodeFlags_DefaultOpen)) { - FETagComponent& Tag = EntitySelected->GetComponent(); + FETagComponent& TagComponent = EntitySelected->GetComponent(); char Buffer[256]; memset(Buffer, 0, 256); - strcpy_s(Buffer, Tag.Tag.c_str()); + strcpy_s(Buffer, TagComponent.GetTag().c_str()); if (ImGui::InputText("##Tag Edit", Buffer, 256)) { - Tag.Tag = std::string(Buffer); + std::string NewTag = Buffer; + if (NewTag != EDITOR_SCENE_TAG) + TagComponent.SetTag(NewTag); } } } @@ -1050,6 +1056,14 @@ void FEEditorInspectorWindow::Render() } } + if (EntitySelected->HasComponent()) + { + if (ImGui::CollapsingHeader("Prefab Instance", ImGuiTreeNodeFlags_DefaultOpen)) + { + + } + } + if (EntitySelected->HasComponent()) { if (ImGui::CollapsingHeader("Instanced", ImGuiTreeNodeFlags_DefaultOpen)) diff --git a/EditorWindows/PrefabEditorManager.cpp b/EditorWindows/PrefabEditorManager.cpp new file mode 100644 index 0000000..c1a267e --- /dev/null +++ b/EditorWindows/PrefabEditorManager.cpp @@ -0,0 +1,160 @@ +#include "PrefabEditorManager.h" +#include "SceneGraphWindow.h" +#include "../FEEditor.h" +FEPrefabEditorManager* FEPrefabEditorManager::Instance = nullptr; + + +FEPrefabSceneEditorWindow::FEPrefabSceneEditorWindow(FEScene* Scene) : FEEditorSceneWindow(Scene, false) +{ + bSelfContained = false; + + ApplyButton = new ImGuiButton("Apply"); + ApplyButton->SetSize(ImVec2(140, 24)); + ApplyButton->SetDefaultColor(ImVec4(0.2f, 0.8f, 0.2f, 1.0f)); + + CloseButton = new ImGuiButton("Close"); + CloseButton->SetSize(ImVec2(140, 24)); + CloseButton->SetDefaultColor(ImVec4(0.8f, 0.2f, 0.2f, 1.0f)); +} + +FEPrefabSceneEditorWindow::~FEPrefabSceneEditorWindow() +{ + delete CloseButton; + SCENE_MANAGER.DeleteScene(Scene); + + if (!PREFAB_EDITOR_MANAGER.bClearing) + { + auto WindowIterator = PREFAB_EDITOR_MANAGER.PrefabWindows.begin(); + while (WindowIterator != PREFAB_EDITOR_MANAGER.PrefabWindows.end()) + { + if (WindowIterator->second == this) + { + PREFAB_EDITOR_MANAGER.PrefabWindows.erase(WindowIterator); + break; + } + + WindowIterator++; + } + } +} + +void FEPrefabSceneEditorWindow::Render() +{ + FEEditorSceneWindow::Render(); + + if (!IsVisible()) + return; + + ApplyButton->SetSize(ImVec2(GetWindow()->ContentRegionRect.GetWidth() / 10.0f, GetWindow()->Rect().GetHeight() / 20.0f)); + ApplyButton->SetPosition(ImVec2(5.0f, GetWindow()->Rect().GetHeight() - ApplyButton->GetSize().y - 5.0f)); + ApplyButton->Render(); + if (ApplyButton->IsClicked()) + { + PREFAB_EDITOR_MANAGER.ApplyModificationsToPrefabScene(this); + //bWaitingForRemoval = true; + //Close(); + } + + CloseButton->SetSize(ApplyButton->GetSize()); + CloseButton->SetPosition(ImVec2(GetWindow()->ContentRegionRect.GetWidth() - CloseButton->GetSize().x - 5.0f, + GetWindow()->Rect().GetHeight() - CloseButton->GetSize().y - 5.0f)); + CloseButton->Render(); + if (CloseButton->IsClicked()) + { + bWaitingForRemoval = true; + Close(); + } + + FEEditorSceneWindow::OnRenderEnd(); +} + +FEPrefabEditorManager::FEPrefabEditorManager() +{ + +} + +FEPrefabEditorManager::~FEPrefabEditorManager() +{ + Clear(); +} + +void FEPrefabEditorManager::Clear() +{ + bClearing = true; + + auto WindowIterator = PrefabWindows.begin(); + while (WindowIterator != PrefabWindows.end()) + { + delete WindowIterator->second; + WindowIterator = PrefabWindows.erase(WindowIterator); + } + + PrefabWindows.clear(); + bClearing = false; +} + +void FEPrefabEditorManager::PrepareEditWinow(FEPrefab* Prefab) +{ + if (Prefab->Scene == nullptr) + return; + + // We don't want to open the same prefab scene twice + if (PrefabWindows.find(Prefab) != PrefabWindows.end()) + return; + + FEScene* CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->Scene, "Scene: " + Prefab->GetName()); + + FEEntity* Camera = CurrentPrefabScene->CreateEntity("Prefab scene camera"); + Camera->GetComponent().SetTag(EDITOR_SCENE_TAG); + Camera->AddComponent(); + FECameraComponent& CameraComponent = Camera->GetComponent(); + CameraComponent.Type = 1; + CameraComponent.DistanceToModel = 10.0; + CameraComponent.SetSSAOEnabled(false); + + CAMERA_SYSTEM.SetMainCamera(Camera); + FETransformComponent& CameraTransform = Camera->GetComponent(); + + FEEntity* SkyDomeEntity = CurrentPrefabScene->CreateEntity("Prefab scene skydome"); + SkyDomeEntity->GetComponent().SetTag(EDITOR_SCENE_TAG); + SkyDomeEntity->GetComponent().SetScale(glm::vec3(100.0f)); + SkyDomeEntity->AddComponent(); + + FEEntity* LightEntity = CurrentPrefabScene->CreateEntity("Prefab scene light"); + LightEntity->GetComponent().SetTag(EDITOR_SCENE_TAG); + LightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); + FELightComponent& LightComponent = LightEntity->GetComponent(); + LightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); + LightComponent.SetIntensity(4.3f); + LightComponent.SetCastShadows(false); + + PrefabWindows[Prefab] = new FEPrefabSceneEditorWindow(CurrentPrefabScene); + EDITOR.AddCustomEditorScene(PrefabWindows[Prefab]); +} + +void FEPrefabEditorManager::ApplyModificationsToPrefabScene(FEPrefabSceneEditorWindow* Window) +{ + FEPrefab* Prefab = nullptr; + + auto WindowIterator = PrefabWindows.begin(); + while (WindowIterator != PrefabWindows.end()) + { + if (WindowIterator->second == Window) + { + Prefab = WindowIterator->first; + break; + } + + WindowIterator++; + } + + if (Prefab == nullptr) + return; + + FEScene* ModifiedScene = Window->GetScene(); + Prefab->Scene->Clear(); + + SCENE_MANAGER.ImportSceneAsNode(ModifiedScene, Prefab->Scene, Prefab->Scene->SceneGraph.GetRoot(), [](FEEntity* EntityToCheck) { + return !(EntityToCheck->GetComponent().GetTag() == EDITOR_SCENE_TAG); + }); +} \ No newline at end of file diff --git a/EditorWindows/PrefabEditorManager.h b/EditorWindows/PrefabEditorManager.h new file mode 100644 index 0000000..7d87403 --- /dev/null +++ b/EditorWindows/PrefabEditorManager.h @@ -0,0 +1,37 @@ +#pragma once + +#include "CombineChannelsToTexturePopUp.h" +#include "EditorBaseWindowClasses/FEEditorSceneWindow.h" + +class FEPrefabSceneEditorWindow : public FEEditorSceneWindow +{ + friend class FEPrefabEditorManager; + + ~FEPrefabSceneEditorWindow(); + + ImGuiButton* CloseButton = nullptr; + ImGuiButton* ApplyButton = nullptr; +public: + FEPrefabSceneEditorWindow(FEScene* Scene); + void Render() override; +}; + +class FEPrefabEditorManager +{ + friend class FEEditor; + friend class FEPrefabSceneEditorWindow; + + SINGLETON_PRIVATE_PART(FEPrefabEditorManager) + + std::unordered_map PrefabWindows; + bool bClearing = false; + + void ApplyModificationsToPrefabScene(FEPrefabSceneEditorWindow* Window); +public: + SINGLETON_PUBLIC_PART(FEPrefabEditorManager) + + void PrepareEditWinow(FEPrefab* Prefab); + void Clear(); +}; + +#define PREFAB_EDITOR_MANAGER FEPrefabEditorManager::getInstance() \ No newline at end of file diff --git a/EditorWindows/PrefabEditorWindow.cpp b/EditorWindows/PrefabEditorWindow.cpp deleted file mode 100644 index a9de6e2..0000000 --- a/EditorWindows/PrefabEditorWindow.cpp +++ /dev/null @@ -1,224 +0,0 @@ -#include "PrefabEditorWindow.h" -#include "SceneGraphWindow.h" -#include "../FEEditor.h" -PrefabEditorWindow* PrefabEditorWindow::Instance = nullptr; -FEPrefab* PrefabEditorWindow::ObjToWorkWith = nullptr; - -bool PrefabEditorWindow::AddGameModelTargetCallBack(FEObject* Object, void** EntityPointer) -{ - if (Object == nullptr) - return false; - - FEGameModel* NewGameModel = reinterpret_cast(Object); - // FIX ME! It should be here - //ObjToWorkWith->AddComponent(NewGameModel); - - return true; -} - -void PrefabEditorWindow::ShowTransformConfiguration(FETransformComponent* Transform, const int Index) -{ -} - -void PrefabEditorWindow::AddNewGameModelCallBack(const std::vector SelectionsResult) -{ - for (int i = 0; i < SelectionsResult.size(); i++) - { - // FIX ME! It should be here - //if (SelectionsResult[i]->GetType() == FE_GAMEMODEL) - // ObjToWorkWith->AddComponent(reinterpret_cast(SelectionsResult[i])); - } -} - -PrefabEditorWindow::PrefabEditorWindow() -{ - const std::string TempCaption = "Edit Prefab"; - strcpy_s(Caption, TempCaption.size() + 1, TempCaption.c_str()); - - CloseButton = new ImGuiButton("Close"); - CloseButton->SetSize(ImVec2(140, 24)); - CloseButton->SetPosition(ImVec2(800.0 / 2.0 - 140.0 / 2.0, 800.0 - 35.0)); - - //addGameModelTarget = DRAG_AND_DROP_MANAGER.addTarget(FE_GAMEMODEL, addGameModelTargetCallBack, nullptr, "Drop to add Game model"); -} - -PrefabEditorWindow::~PrefabEditorWindow() -{ - delete CloseButton; -} - -void PrefabEditorWindow::Show(FEPrefab* Prefab) -{ - if (Prefab->Scene != nullptr) - { - CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->Scene, "Scene: " + Prefab->GetName()); - - FEEntity* Camera = CurrentPrefabScene->CreateEntity("Prefab scene camera"); - CurrentCameraEntity = Camera; - Camera->AddComponent(); - FECameraComponent& CameraComponent = Camera->GetComponent(); - // FIX ME! It should be model camera but it is not working with transform component - CameraComponent.Type = 0; - CameraComponent.DistanceToModel = 10.0; - - CAMERA_SYSTEM.SetMainCamera(Camera); - FETransformComponent& CameraTransform = Camera->GetComponent(); - CameraTransform.SetPosition(glm::vec3(0.0f, 0.0f, 30.0f)); - - FEEntity* SkyDomeEntity = CurrentPrefabScene->CreateEntity("Prefab scene skydome"); - SkyDomeEntity->GetComponent().SetScale(glm::vec3(100.0f)); - SkyDomeEntity->AddComponent(); - - FEEntity* LightEntity = CurrentPrefabScene->CreateEntity("Prefab scene light"); - LightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); - FELightComponent& LightComponent = LightEntity->GetComponent(); - LightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); - LightComponent.SetIntensity(4.3f); - LightComponent.SetCastShadows(false); - - EDITOR.AddEditorScene(CurrentPrefabScene); - - /*Size = ImVec2(800, 800); - Position = ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2 - Size.x / 2, APPLICATION.GetMainWindow()->GetHeight() / 2 - Size.y / 2); - - Flags = ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse; - - ObjToWorkWith = Prefab; - - FEImGuiWindow::Show();*/ - } -} - -void PrefabEditorWindow::Render() -{ - FEImGuiWindow::Render(); - - if (!IsVisible()) - return; - - if (ImGui::BeginTabBar("##prefabSettings", ImGuiTabBarFlags_None)) - { - if (ImGui::BeginTabItem("Game Models")) - { - static bool ContextMenuOpened = false; - - ImGui::BeginChildFrame(ImGui::GetID("GameModels ListBox Child"), ImVec2(ImGui::GetContentRegionAvail().x - 10.0f, 500.0f), ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse); - bool bListBoxHovered = false; - if (ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows)) - { - bListBoxHovered = true; - //addGameModelTarget->setActive(true); - } - - static bool bOpenContextMenu = false; - if (ImGui::IsMouseClicked(1)) - { - if (bListBoxHovered) - { - bOpenContextMenu = true; - } - } - - if (ImGui::BeginListBox("##GameModels ListBox", ImVec2(ImGui::GetContentRegionAvail().x - 10.0f, 500.0f))) - { - ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); - - for (int i = 0; i < ObjToWorkWith->ComponentsCount(); i++) - { - FEGameModel* GameModel = ObjToWorkWith->GetComponent(i)->GameModel; - if (GameModel == nullptr) - break; - - ImVec2 PostionBeforeDraw = ImGui::GetCursorPos(); - - const ImVec2 TextSize = ImGui::CalcTextSize(GameModel->GetName().c_str()); - ImGui::SetCursorPos(PostionBeforeDraw + ImVec2(ImGui::GetContentRegionAvail().x / 2.0f - TextSize.x / 2.0f, 16)); - ImGui::Text(GameModel->GetName().c_str()); - ImGui::SetCursorPos(PostionBeforeDraw); - - ImGui::PushID(i); - if (ImGui::Selectable("##item", SelectedGameModel == i ? true : false, ImGuiSelectableFlags_None, ImVec2(ImGui::GetContentRegionAvail().x - 0, 64))) - { - SelectedGameModel = i; - } - ImGui::PopID(); - - if (ImGui::IsItemHovered()) - HoveredGameModelItem = i; - - ImGui::SetCursorPos(PostionBeforeDraw); - ImColor ImageTint = ImGui::IsItemHovered() ? ImColor(1.0f, 1.0f, 1.0f, 0.5f) : ImColor(1.0f, 1.0f, 1.0f, 1.0f); - FETexture* PreviewTexture = PREVIEW_MANAGER.GetPreview(GameModel->GetObjectID()); - ImGui::Image((void*)static_cast(PreviewTexture->GetTextureID()), ImVec2(64, 64), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), ImageTint); - - - ShowTransformConfiguration(&ObjToWorkWith->GetComponent(i)->Transform, i); - } - - ImGui::PopFont(); - ImGui::EndListBox(); - } - - - ImGui::EndChildFrame(); - ImGui::EndTabItem(); - - if (bOpenContextMenu) - { - bOpenContextMenu = false; - ImGui::OpenPopup("##layers_listBox_context_menu"); - } - - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); - if (ImGui::BeginPopup("##layers_listBox_context_menu")) - { - ContextMenuOpened = true; - - if (ImGui::MenuItem("Add game model...")) - { - SelectFEObjectPopUp::getInstance().Show(FE_GAMEMODEL, AddNewGameModelCallBack); - } - - if (HoveredGameModelItem != -1) - { - FEGameModel* GameModel = ObjToWorkWith->GetComponent(HoveredGameModelItem)->GameModel; - if (GameModel != nullptr) - { - ImGui::Separator(); - const std::string LayerName = GameModel->GetName(); - ImGui::Text((std::string("Actions with ") + LayerName).c_str()); - ImGui::Separator(); - - if (ImGui::MenuItem("Remove")) - { - ObjToWorkWith->RemoveComponent(HoveredGameModelItem); - } - } - } - - ImGui::EndPopup(); - } - ImGui::PopStyleVar(); - - if (!ContextMenuOpened) - HoveredGameModelItem = -1; - - ContextMenuOpened = false; - } - ImGui::EndTabBar(); - } - - CloseButton->Render(); - if (CloseButton->IsClicked()) - { - if (CurrentPrefabScene != nullptr) - { - SCENE_MANAGER.DeleteScene(CurrentPrefabScene); - CurrentPrefabScene = nullptr; - } - - Close(); - } - - FEImGuiWindow::OnRenderEnd(); -} \ No newline at end of file diff --git a/EditorWindows/PrefabEditorWindow.h b/EditorWindows/PrefabEditorWindow.h deleted file mode 100644 index 40262ec..0000000 --- a/EditorWindows/PrefabEditorWindow.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include "CombineChannelsToTexturePopUp.h" - -class PrefabEditorWindow : public FEImGuiWindow -{ - SINGLETON_PRIVATE_PART(PrefabEditorWindow) - - // ************** Drag&Drop ************** - DragAndDropTarget* AddGameModelTarget = nullptr; - static bool AddGameModelTargetCallBack(FEObject* Object, void** EntityPointer); - // ************** Drag&Drop END ************** - - ImGuiButton* CloseButton = nullptr; - - static FEPrefab* ObjToWorkWith; - int HoveredGameModelItem = -1; - int SelectedGameModel = -1; - - void ShowTransformConfiguration(FETransformComponent* Transform, int Index); - static void AddNewGameModelCallBack(std::vector SelectionsResult); - - FEScene* CurrentPrefabScene = nullptr; - FEEntity* CurrentCameraEntity = nullptr; -public: - SINGLETON_PUBLIC_PART(PrefabEditorWindow) - - void Show(FEPrefab* Prefab); - void Render() override; -}; \ No newline at end of file diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index e27bf36..8e139f8 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -215,28 +215,38 @@ DragAndDropTarget* FEEditorSceneGraphWindow::GetSceneNodeDragAndDropTarget(FENai void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) { + if (SubTreeRoot == nullptr) + return; + + FEEntity* CurrentEntity = SubTreeRoot->GetEntity(); + if (CurrentEntity != nullptr) + { + if (CurrentEntity->GetComponent().GetTag() == EDITOR_SCENE_TAG) + return; + } + SceneNodeDragAndDropTargetIndex++; int64_t UniqueID = 0; bool bIsLeaf = SubTreeRoot->GetChildren().size() == 0; ImGuiTreeNodeFlags NodeFlags = bIsLeaf ? ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen : ImGuiTreeNodeFlags_OpenOnArrow; std::string Name = SubTreeRoot->GetParent() == nullptr ? PROJECT_MANAGER.GetCurrent()->GetName() : SubTreeRoot->GetName(); - if (SELECTED.GetSelected(EDITOR.GetFocusedScene()) != nullptr && SubTreeRoot->GetEntity() != nullptr) + if (SELECTED.GetSelected(EDITOR.GetFocusedScene()) != nullptr && CurrentEntity != nullptr) { - if (SELECTED.GetSelected(EDITOR.GetFocusedScene())->GetObjectID() == SubTreeRoot->GetEntity()->GetObjectID()) + if (SELECTED.GetSelected(EDITOR.GetFocusedScene())->GetObjectID() == CurrentEntity->GetObjectID()) { NodeFlags |= ImGuiTreeNodeFlags_Selected; } } // If node is root. - if (SubTreeRoot->GetEntity() == nullptr) + if (CurrentEntity == nullptr) { UniqueID = -1; } else { - UniqueID = static_cast(std::hash{}(SubTreeRoot->GetEntity()->GetObjectID().c_str())); + UniqueID = static_cast(std::hash{}(CurrentEntity->GetObjectID().c_str())); } bool bOpened = ImGui::TreeNodeEx((void*)UniqueID, NodeFlags, Name.c_str(), 0); @@ -246,7 +256,7 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) { if (SubTreeRoot->GetParent() != nullptr) { - SELECTED.SetSelected(SubTreeRoot->GetEntity()); + SELECTED.SetSelected(CurrentEntity); } } diff --git a/EditorWindows/SceneGraphWindow.h b/EditorWindows/SceneGraphWindow.h index 41b20a7..ef2f723 100644 --- a/EditorWindows/SceneGraphWindow.h +++ b/EditorWindows/SceneGraphWindow.h @@ -2,6 +2,7 @@ #include "ProjectWasModifiedPopUp.h" +#define EDITOR_SCENE_TAG "EDITOR_PRIVATE_SCENE_ENTITY" class FEEditorSceneGraphWindow { diff --git a/FEDearImguiWrapper/FEDearImguiWrapper.cpp b/FEDearImguiWrapper/FEDearImguiWrapper.cpp index 0bd0e57..9f90091 100644 --- a/FEDearImguiWrapper/FEDearImguiWrapper.cpp +++ b/FEDearImguiWrapper/FEDearImguiWrapper.cpp @@ -7,7 +7,7 @@ ImGuiModalPopup::ImGuiModalPopup() PopupCaption = ""; bShouldOpen = false; bOpened = false; - WindowsManager::getInstance().RegisterPopup(this); + FE_IMGUI_WINDOW_MANAGER.RegisterPopup(this); } void ImGuiModalPopup::Show() @@ -317,11 +317,12 @@ FEImGuiWindow::FEImGuiWindow() Position = ImVec2(0.0f, 0.0f); Size = ImVec2(100.0f, 100.0f); bVisible = false; - WindowsManager::getInstance().RegisterWindow(this); + FE_IMGUI_WINDOW_MANAGER.RegisterWindow(this); } FEImGuiWindow::~FEImGuiWindow() { + FE_IMGUI_WINDOW_MANAGER.UnRegisterWindow(this); } void FEImGuiWindow::Show() @@ -353,8 +354,13 @@ void FEImGuiWindow::Render() ImGui::SetNextWindowSize(Size); bWasClosedLastFrame = false; - ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 2); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); + + if (GetBorderSize() != 0.0f) + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, GetBorderSize()); + + if (GetPadding().x != 0.0f || GetPadding().y != 0.0f) + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(GetPadding().x, GetPadding().y)); + ImGui::Begin(Caption, nullptr, Flags); Window = ImGui::GetCurrentWindow(); } @@ -366,8 +372,13 @@ void FEImGuiWindow::OnRenderEnd() { if (!Window->Collapsed) Size = ImGui::GetWindowSize(); - ImGui::PopStyleVar(); - ImGui::PopStyleVar(); + + if (GetBorderSize() != 0.0f) + ImGui::PopStyleVar(); + + if (GetPadding().x != 0.0f || GetPadding().y != 0.0f) + ImGui::PopStyleVar(); + ImGui::End(); } } @@ -382,8 +393,13 @@ void FEImGuiWindow::Close() if (bVisible) { bVisible = false; - ImGui::PopStyleVar(); - ImGui::PopStyleVar(); + + if (GetBorderSize() != 0.0f) + ImGui::PopStyleVar(); + + if (GetPadding().x != 0.0f || GetPadding().y != 0.0f) + ImGui::PopStyleVar(); + ImGui::End(); } } @@ -403,6 +419,26 @@ void FEImGuiWindow::SetVisible(bool NewValue) bVisible = NewValue; } +float FEImGuiWindow::GetBorderSize() const +{ + return BorderSize; +} + +void FEImGuiWindow::SetBorderSize(float NewValue) +{ + BorderSize = NewValue; +} + +glm::vec2 FEImGuiWindow::GetPadding() const +{ + return Padding; +} + +void FEImGuiWindow::SetPadding(glm::vec2 NewValue) +{ + Padding = NewValue; +} + WindowsManager::WindowsManager() { } @@ -412,6 +448,18 @@ void WindowsManager::RegisterWindow(FEImGuiWindow* Window) Windows.push_back(Window); } +void WindowsManager::UnRegisterWindow(FEImGuiWindow* Window) +{ + for (size_t i = 0; i < Windows.size(); i++) + { + if (Windows[i] == Window) + { + Windows.erase(Windows.begin() + i); + break; + } + } +} + void WindowsManager::RegisterPopup(ImGuiModalPopup* Popup) { PopUps.push_back(Popup); diff --git a/FEDearImguiWrapper/FEDearImguiWrapper.h b/FEDearImguiWrapper/FEDearImguiWrapper.h index 26525fa..dbcf355 100644 --- a/FEDearImguiWrapper/FEDearImguiWrapper.h +++ b/FEDearImguiWrapper/FEDearImguiWrapper.h @@ -23,6 +23,8 @@ class WindowsManager void CloseAllWindows() const; void RenderAllWindows() const; + + void UnRegisterWindow(FEImGuiWindow* Window); private: SINGLETON_PRIVATE_PART(WindowsManager) @@ -162,6 +164,9 @@ class FEImGuiWindow bool bWasClosedLastFrame = false; FEImGuiWindow(); ImGuiWindow* Window = nullptr; + + float BorderSize = 2.0f; + glm::vec2 Padding = glm::vec2(15.0f, 15.0f); public: virtual ~FEImGuiWindow(); virtual void Show(); @@ -177,6 +182,12 @@ class FEImGuiWindow virtual void SetCaption(std::string NewCaption); ImGuiWindow* GetWindow() const; + + float GetBorderSize() const; + void SetBorderSize(float NewValue); + + glm::vec2 GetPadding() const; + void SetPadding(glm::vec2 NewValue); }; class FEArrowScroller diff --git a/FEEditor.cpp b/FEEditor.cpp index af59e51..a10e501 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -2,58 +2,6 @@ FEEditor* FEEditor::Instance = nullptr; -bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) -{ - if (EDITOR.GetFocusedScene() == nullptr) - return false; - - if (CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene()) == nullptr) - return false; - - if (UserData == nullptr) - return false; - - FEEditorSceneData* EditorSceneData = reinterpret_cast(*UserData); - if (EditorSceneData->Scene == nullptr) - return false; - - if (Object->GetType() == FE_GAMEMODEL) - { - FEGameModel* GameModel = RESOURCE_MANAGER.GetGameModel(Object->GetObjectID()); - - FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); - FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); - - FEEntity* Entity = EditorSceneData->Scene->CreateEntity(Object->GetName()); - Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); - Entity->AddComponent(GameModel); - - SELECTED.SetSelected(Entity); - PROJECT_MANAGER.GetCurrent()->SetModified(true); - - return true; - - } - else if (Object->GetType() == FE_PREFAB) - { - FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())->GetComponent(0)->GameModel; - - FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); - FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); - - FEEntity* Entity = EditorSceneData->Scene->CreateEntity(Object->GetName()); - Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); - Entity->AddComponent(GameModel); - - SELECTED.SetSelected(Entity); - PROJECT_MANAGER.GetCurrent()->SetModified(true); - - return true; - } - - return false; -} - FEEditor::FEEditor() { ImGuiIO& IO = ImGui::GetIO(); @@ -118,24 +66,21 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) if (Button == GLFW_MOUSE_BUTTON_1 && Action == GLFW_RELEASE) DRAG_AND_DROP_MANAGER.DropAction(); - for (size_t i = 0; i < EDITOR.EditorScenes.size(); i++) + for (size_t i = 0; i < EDITOR.EditorSceneWindows.size(); i++) { - EDITOR.EditorScenes[i]->bWindowHovered = false; + EDITOR.EditorSceneWindows[i]->bWindowHovered = false; - if (EDITOR.EditorScenes[i]->SceneWindow == nullptr) + if (EDITOR.EditorSceneWindows[i]->Scene != EDITOR.GetFocusedScene()) continue; - if (EDITOR.EditorScenes[i]->Scene != EDITOR.GetFocusedScene()) - continue; - - if (ImGui::GetCurrentContext()->HoveredWindow != nullptr) - EDITOR.EditorScenes[i]->bWindowHovered = ImGui::GetCurrentContext()->HoveredWindow->Name == EDITOR.EditorScenes[i]->SceneWindow->Name; + if (ImGui::GetCurrentContext()->HoveredWindow != nullptr && EDITOR.EditorSceneWindows[i]->GetWindow() != nullptr) + EDITOR.EditorSceneWindows[i]->bWindowHovered = ImGui::GetCurrentContext()->HoveredWindow->Name == EDITOR.EditorSceneWindows[i]->GetWindow()->Name; - FEEntity* CurrentMainCamera = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.EditorScenes[i]->Scene); + FEEntity* CurrentMainCamera = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.EditorSceneWindows[i]->Scene); - if (ImGui::GetIO().WantCaptureMouse && !EDITOR.EditorScenes[i]->bWindowHovered) + if (ImGui::GetIO().WantCaptureMouse && !EDITOR.EditorSceneWindows[i]->bWindowHovered) { - if (EDITOR.EditorScenes[i]->Scene != nullptr) + if (EDITOR.EditorSceneWindows[i]->Scene != nullptr) { if (CurrentMainCamera != nullptr) CAMERA_SYSTEM.SetIsIndividualInputActive(CurrentMainCamera, false); @@ -155,18 +100,18 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) if (Button == GLFW_MOUSE_BUTTON_1 && Action == GLFW_PRESS) { - if (EDITOR.EditorScenes[i]->bWindowHovered) + if (EDITOR.EditorSceneWindows[i]->bWindowHovered) { bool bEditingTerrain = false; - if (SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene) != nullptr && SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene)->HasComponent()) + if (SELECTED.GetSelected(EDITOR.EditorSceneWindows[i]->Scene) != nullptr && SELECTED.GetSelected(EDITOR.EditorSceneWindows[i]->Scene)->HasComponent()) { bEditingTerrain = TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE; } if (!bEditingTerrain) { - FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(EDITOR.EditorScenes[i]->Scene->GetObjectID()); - SELECTED.DetermineEntityUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY(), EDITOR.EditorScenes[i]->Scene); + FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(EDITOR.EditorSceneWindows[i]->Scene->GetObjectID()); + SELECTED.DetermineEntityUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY(), EDITOR.EditorSceneWindows[i]->Scene); CurrentSelectionData->CheckForSelectionisNeeded = true; } } @@ -176,7 +121,7 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) else if (Button == GLFW_MOUSE_BUTTON_1 && Action == GLFW_RELEASE) { INSPECTOR_WINDOW.bLeftMousePressed = false; - GIZMO_MANAGER.DeactivateAllGizmo(EDITOR.EditorScenes[i]->Scene); + GIZMO_MANAGER.DeactivateAllGizmo(EDITOR.EditorSceneWindows[i]->Scene); } } } @@ -197,46 +142,46 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) } } - for (size_t i = 0; i < EDITOR.EditorScenes.size(); i++) + for (size_t i = 0; i < EDITOR.EditorSceneWindows.size(); i++) { - if (EDITOR.EditorScenes[i]->Scene != EDITOR.GetFocusedScene()) + if (EDITOR.EditorSceneWindows[i]->Scene != EDITOR.GetFocusedScene()) continue; - FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(EDITOR.EditorScenes[i]->Scene->GetObjectID()); + FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(EDITOR.EditorSceneWindows[i]->Scene->GetObjectID()); if (!ImGui::GetIO().WantCaptureKeyboard && Key == GLFW_KEY_DELETE) { - if (SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene) != nullptr) + if (SELECTED.GetSelected(EDITOR.EditorSceneWindows[i]->Scene) != nullptr) { - if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1 && SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene)->HasComponent()) + if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1 && SELECTED.GetSelected(EDITOR.EditorSceneWindows[i]->Scene)->HasComponent()) { - INSTANCED_RENDERING_SYSTEM.DeleteIndividualInstance(SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene), CurrentSelectionData->InstancedSubObjectIndexSelected); + INSTANCED_RENDERING_SYSTEM.DeleteIndividualInstance(SELECTED.GetSelected(EDITOR.EditorSceneWindows[i]->Scene), CurrentSelectionData->InstancedSubObjectIndexSelected); } else { if (EDITOR.GetFocusedScene() != nullptr) { - EDITOR.GetFocusedScene()->DeleteEntity(SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene)); + EDITOR.GetFocusedScene()->DeleteEntity(SELECTED.GetSelected(EDITOR.EditorSceneWindows[i]->Scene)); } } - SELECTED.Clear(EDITOR.EditorScenes[i]->Scene); + SELECTED.Clear(EDITOR.EditorSceneWindows[i]->Scene); PROJECT_MANAGER.GetCurrent()->SetModified(true); } } if (!ImGui::GetIO().WantCaptureKeyboard && Mods == GLFW_MOD_CONTROL && Key == GLFW_KEY_C && Action == GLFW_RELEASE) { - if (SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene) != nullptr) - EDITOR.SetSceneEntityIDInClipboard(SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene)->GetObjectID()); + if (SELECTED.GetSelected(EDITOR.EditorSceneWindows[i]->Scene) != nullptr) + EDITOR.SetSceneEntityIDInClipboard(SELECTED.GetSelected(EDITOR.EditorSceneWindows[i]->Scene)->GetObjectID()); } if (!ImGui::GetIO().WantCaptureKeyboard && (Key == GLFW_KEY_RIGHT_SHIFT || Key == GLFW_KEY_LEFT_SHIFT) && Action == GLFW_RELEASE) { - FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(EDITOR.EditorScenes[i]->Scene->GetObjectID()); + FEGizmoSceneData* GizmoSceneData = GIZMO_MANAGER.GetSceneData(EDITOR.EditorSceneWindows[i]->Scene->GetObjectID()); int NewState = GizmoSceneData->GizmosState + 1; if (NewState > 2) NewState = 0; - GIZMO_MANAGER.UpdateGizmoState(NewState, EDITOR.EditorScenes[i]->Scene); + GIZMO_MANAGER.UpdateGizmoState(NewState, EDITOR.EditorSceneWindows[i]->Scene); } } @@ -334,20 +279,20 @@ void FEEditor::MouseMoveCallback(double Xpos, double Ypos) DRAG_AND_DROP_MANAGER.MouseMove(); - for (size_t i = 0; i < EDITOR.EditorScenes.size(); i++) + for (size_t i = 0; i < EDITOR.EditorSceneWindows.size(); i++) { - if (EDITOR.EditorScenes[i]->Scene != EDITOR.GetFocusedScene()) + if (EDITOR.EditorSceneWindows[i]->Scene != EDITOR.GetFocusedScene()) continue; - if (SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene) != nullptr) + if (SELECTED.GetSelected(EDITOR.EditorSceneWindows[i]->Scene) != nullptr) { - if (SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene) != nullptr && SELECTED.GetSelected(EDITOR.EditorScenes[i]->Scene)->HasComponent()) + if (SELECTED.GetSelected(EDITOR.EditorSceneWindows[i]->Scene) != nullptr && SELECTED.GetSelected(EDITOR.EditorSceneWindows[i]->Scene)->HasComponent()) { if (TERRAIN_SYSTEM.GetBrushMode() != FE_TERRAIN_BRUSH_NONE) return; } - GIZMO_MANAGER.MouseMove(EDITOR.GetLastMouseX(), EDITOR.GetLastMouseY(), EDITOR.GetMouseX(), EDITOR.GetMouseY(), EDITOR.EditorScenes[i]->Scene); + GIZMO_MANAGER.MouseMove(EDITOR.GetLastMouseX(), EDITOR.GetLastMouseY(), EDITOR.GetMouseX(), EDITOR.GetMouseY(), EDITOR.EditorSceneWindows[i]->Scene); } } } @@ -363,7 +308,7 @@ void FEEditor::Render() std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); if (ActiveScenes.empty()) { - EditorScenes.clear(); + EditorSceneWindows.clear(); SetFocusedScene(nullptr); } @@ -512,57 +457,32 @@ void FEEditor::Render() } ImGui::PopStyleVar(); - for (size_t i = 0; i < EditorScenes.size(); i++) + for (size_t i = 0; i < EditorSceneWindows.size(); i++) { - std::string WindowName = EditorScenes[i]->Scene->GetName(); - // Window name must be unique. - WindowName += "##" + EditorScenes[i]->Scene->GetObjectID(); - if (EditorScenes[i]->bMain) - WindowName = "Main Scene"; + // Rendeting would be done by RenderAllSubWindows(). - if (ImGui::Begin(WindowName.c_str(), nullptr, ImGuiWindowFlags_None | ImGuiWindowFlags_NoScrollbar)) + // Check if some window is waiting for removal + if (EditorSceneWindows[i]->bWaitingForRemoval) { - if (EditorScenes[i]->bJustAdded) - { - ImGui::SetWindowFocus(); - ImGui::SetWindowSize(ImVec2(256, 256)); - EditorScenes[i]->bJustAdded = false; - } - - EditorScenes[i]->SceneWindow = ImGui::GetCurrentWindow(); - if (EditorScenes[i]->SceneWindowTarget != nullptr) - EditorScenes[i]->SceneWindowTarget->StickToCurrentWindow(); - - if (ImGui::IsWindowFocused()) - SetFocusedScene(EditorScenes[i]->Scene); - - FEEntity* CameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(EditorScenes[i]->Scene); - FECameraComponent& CameraComponent = CameraEntity->GetComponent(); - - if (CameraComponent.GetViewport() == nullptr) - { - std::string NewViewportID = ENGINE.AddViewport(EditorScenes[i]->SceneWindow); - CAMERA_SYSTEM.SetCameraViewport(CameraEntity, NewViewportID); - SELECTED.AddSceneData(EditorScenes[i]->Scene->GetObjectID()); - GIZMO_MANAGER.AddSceneData(EditorScenes[i]->Scene->GetObjectID()); - EditorScenes[i]->SceneWindowTarget = DRAG_AND_DROP_MANAGER.AddTarget(std::vector{ FE_GAMEMODEL, FE_PREFAB }, - SceneWindowDragAndDropCallBack, - reinterpret_cast(&EditorScenes[i]), - std::vector{ "Drop to add to scene", "Drop to add to scene" }); - } - - ImGuiStyle& Style = ImGui::GetStyle(); - Style.WindowBorderSize = 0.0f; - Style.WindowPadding = ImVec2(0.0f, 0.0f); - - FETexture* CameraResult = RENDERER.GetCameraResult(CAMERA_SYSTEM.GetMainCameraEntity(EditorScenes[i]->Scene)); - if (CameraResult != nullptr) + if (FocusedEditorSceneID == EditorSceneWindows[i]->Scene->GetObjectID()) { - ImGui::Image((void*)(intptr_t)CameraResult->GetTextureID(), ImVec2(ImGui::GetCurrentWindow()->ContentRegionRect.GetWidth(), ImGui::GetCurrentWindow()->ContentRegionRect.GetHeight()), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); + FocusedEditorSceneID = ""; + for (size_t j = 0; j < EditorSceneWindows.size(); j++) + { + if (EditorSceneWindows[j]->bMain && EditorSceneWindows[j] != EditorSceneWindows[i]) + { + FocusedEditorSceneID = EditorSceneWindows[j]->Scene->GetObjectID(); + break; + } + } } + + FEScene* Scene = EditorSceneWindows[i]->Scene; + delete EditorSceneWindows[i]; + EditorSceneWindows.erase(EditorSceneWindows.begin() + i); + i--; + continue; } - - ImGui::End(); } SCENE_GRAPH_WINDOW.Render(); @@ -574,17 +494,17 @@ void FEEditor::Render() GyzmosSettingsWindowObject.Show(); GyzmosSettingsWindowObject.Render(); - for (size_t i = 0; i < EditorScenes.size(); i++) + for (size_t i = 0; i < EditorSceneWindows.size(); i++) { - if (EditorScenes[i]->Scene != EDITOR.GetFocusedScene()) + if (EditorSceneWindows[i]->Scene != EDITOR.GetFocusedScene()) continue; - const int ObjectIndex = SELECTED.GetIndexOfObjectUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY(), EditorScenes[i]->Scene); + const int ObjectIndex = SELECTED.GetIndexOfObjectUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY(), EditorSceneWindows[i]->Scene); if (ObjectIndex >= 0) { - if (!GIZMO_MANAGER.WasSelected(ObjectIndex, EditorScenes[i]->Scene)) + if (!GIZMO_MANAGER.WasSelected(ObjectIndex, EditorSceneWindows[i]->Scene)) { - SELECTED.SetSelectedByIndex(ObjectIndex, EditorScenes[i]->Scene); + SELECTED.SetSelectedByIndex(ObjectIndex, EditorSceneWindows[i]->Scene); } } } @@ -623,14 +543,16 @@ void FEEditor::OnViewportResize(std::string ViewportID) if (PROJECT_MANAGER.GetCurrent() == nullptr) return; - for (size_t i = 0; i < EDITOR.EditorScenes.size(); i++) + for (size_t i = 0; i < EDITOR.EditorSceneWindows.size(); i++) { - FEEntity* CameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.EditorScenes[i]->Scene); - FECameraComponent& CameraComponent = CameraEntity->GetComponent(); + FEEntity* CameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.EditorSceneWindows[i]->Scene); + if (CameraEntity == nullptr) + continue; + FECameraComponent& CameraComponent = CameraEntity->GetComponent(); if (CameraComponent.GetViewport()->GetID() == ViewportID) { - SELECTED.UpdateResources(EDITOR.EditorScenes[i]->Scene); + SELECTED.UpdateResources(EDITOR.EditorSceneWindows[i]->Scene); } } } @@ -848,20 +770,30 @@ void FEEditor::SetUpImgui() void FEEditor::OnProjectClose() { - EditorScenes.clear(); + EDITOR_MATERIAL_WINDOW.Stop(); + EditorSceneWindows.clear(); SetFocusedScene(nullptr); PROJECT_MANAGER.CloseCurrentProject(); CONTENT_BROWSER_WINDOW.Clear(); SCENE_GRAPH_WINDOW.Clear(); + PREFAB_EDITOR_MANAGER.Clear(); } void FEEditor::AddEditorScene(FEScene* Scene, bool bMain) { - FEEditorSceneData* NewEditorSceneData = new FEEditorSceneData(); - NewEditorSceneData->bMain = bMain; - NewEditorSceneData->Scene = Scene; - EditorScenes.push_back(NewEditorSceneData); + FEEditorSceneWindow* NewSceneWindow = new FEEditorSceneWindow(Scene, bMain); + NewSceneWindow->SetVisible(true); + EditorSceneWindows.push_back(NewSceneWindow); +} + +void FEEditor::AddCustomEditorScene(FEEditorSceneWindow* SceneWindow) +{ + if (SceneWindow == nullptr) + return; + + SceneWindow->SetVisible(true); + EditorSceneWindows.push_back(SceneWindow); } FEScene* FEEditor::GetFocusedScene() const diff --git a/FEEditor.h b/FEEditor.h index 35c7c57..f69fbd1 100644 --- a/FEEditor.h +++ b/FEEditor.h @@ -1,24 +1,15 @@ #pragma once #include "EditorWindows/InspectorWindow.h" +#include "EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.h" #include -struct FEEditorSceneData -{ - FEScene* Scene = nullptr; - ImGuiWindow* SceneWindow = nullptr; - DragAndDropTarget* SceneWindowTarget = nullptr; - - bool bJustAdded = true; - bool bMain = false; - bool bWindowHovered = false; -}; - class FEEditor { + friend class FEEditorSceneWindow; friend class FEProjectManager; // FIX ME! It is temporary solution - friend class PrefabEditorWindow; + friend class FEPrefabEditorManager; public: SINGLETON_PUBLIC_PART(FEEditor) @@ -52,8 +43,8 @@ class FEEditor ImGuiID DockspaceID = 0; void AddEditorScene(FEScene* Scene, bool bMain = false); - - std::vector EditorScenes; + void AddCustomEditorScene(FEEditorSceneWindow* SceneWindow); + std::vector EditorSceneWindows; // Clipboard std::string SceneEntityIDInClipboard; diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index f4abfcc..e6a722f 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -286,7 +286,7 @@ void GizmoManager::Update() } FEScene* Scene = SCENE_MANAGER.GetScene(GizmoSceneData->SceneID); - if (SELECTED.GetSelected(Scene) == nullptr || SELECTED.GetSelected(Scene)->GetType() == FE_CAMERA_DEPRECATED) + if (SELECTED.GetSelected(Scene) == nullptr || CAMERA_SYSTEM.GetMainCameraEntity(Scene) == nullptr || SELECTED.GetSelected(Scene)->GetType() == FE_CAMERA_DEPRECATED) { HideAllGizmo(Scene); PerSceneIterator++; @@ -585,6 +585,9 @@ void GizmoManager::MouseMoveTransformationGizmos(FEScene* Scene) if (GizmoSceneData == nullptr) return; + if (CAMERA_SYSTEM.GetMainCameraEntity(Scene) == nullptr) + return; + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); FEViewport* CurrentViewport = CAMERA_SYSTEM.GetMainCameraViewport(Scene); @@ -943,6 +946,7 @@ void GizmoManager::AddSceneData(const std::string& SceneID) PerSceneData[SceneID]->SceneID = SceneID; PerSceneData[SceneID]->ParentGizmoEntity = CurrentScene->CreateEntity("ParentGizmoEntity"); + PerSceneData[SceneID]->ParentGizmoEntity->GetComponent().SetTag(EDITOR_SCENE_TAG); PerSceneData[SceneID]->ParentGizmoGraphNode = CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->ParentGizmoEntity->GetObjectID()); // TransformationXGizmo diff --git a/FEEditorGizmoManager.h b/FEEditorGizmoManager.h index 5ab3aae..0d8165d 100644 --- a/FEEditorGizmoManager.h +++ b/FEEditorGizmoManager.h @@ -72,6 +72,7 @@ class GizmoManager friend class FEEditor; friend class FEProjectManager; friend class GyzmosSettingsWindow; + friend class FEEditorSceneWindow; public: SINGLETON_PUBLIC_PART(GizmoManager) diff --git a/FEEditorHaloSelectionEffect.cpp b/FEEditorHaloSelectionEffect.cpp index 9aef1e6..acfd632 100644 --- a/FEEditorHaloSelectionEffect.cpp +++ b/FEEditorHaloSelectionEffect.cpp @@ -52,6 +52,9 @@ void FEEditorHaloSelectionEffect::UpdateResources(FEScene* Scene) return; FECameraRenderingData* CameraData = RENDERER.GetCameraRenderingData(CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())); + if (CameraData == nullptr) + return; + std::vector& PostProcesses = CameraData->PostProcessEffects; delete CurrentHaloSelectionData->HaloObjectsFB; diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index 2685488..19ab995 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -43,7 +43,7 @@ void FEEditorPreviewManager::InitializeResources() LightComponent.SetIntensity(10.0f); LightComponent.SetCastShadows(false); - // FIX ME! This scene should not have skydome. Fix bloom shader. + // FIX ME! This scene should not have skydome. FEEntity* SkyDome = PreviewScene->CreateEntity("SkyDome"); SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); SKY_DOME_SYSTEM.AddToEntity(SkyDome); @@ -225,7 +225,7 @@ FETexture* FEEditorPreviewManager::GetMaterialPreview(const std::string Material { CreateGameModelPreview(CurrentGameModel->GetObjectID()); - // if some Prefab uses this game model we should also update it's preview + // If some Prefab uses this game model we should also update it's preview. std::vector PrefabList = RESOURCE_MANAGER.GetPrefabList(); for (size_t j = 0; j < PrefabList.size(); j++) { diff --git a/FEEditorPreviewManager.h b/FEEditorPreviewManager.h index f8f962d..4a20603 100644 --- a/FEEditorPreviewManager.h +++ b/FEEditorPreviewManager.h @@ -16,10 +16,10 @@ class FEEditorPreviewManager friend class SelectMaterialPopUp; friend class SelectGameModelPopUp; friend class EditGameModelPopup; - friend class EditMaterialPopup; + friend class EditMaterialWindow; friend class DeleteMaterialPopup; friend class SelectFEObjectPopUp; - friend class PrefabEditorWindow; + friend class FEPrefabEditorManager; private: SINGLETON_PUBLIC_PART(FEEditorPreviewManager) diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index eeb71ec..d182a2e 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -214,10 +214,9 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons return -1; CurrentSelectionData->PixelAccurateSelectionFB->Bind(); - glm::vec4 OriginalClearColor = ENGINE.GetClearColor(); glm::ivec4 OriginalViewport = RENDERER.GetViewport(); RENDERER.SetViewport(0, 0, CurrentSelectionData->PixelAccurateSelectionFB->GetWidth(), CurrentSelectionData->PixelAccurateSelectionFB->GetHeight()); - ENGINE.SetClearColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.0f)); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); FEEntity* CurrentCamera = CAMERA_SYSTEM.GetMainCameraEntity(Scene); @@ -300,6 +299,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons int b = ((LastColorShiftIndex + 1) >> 16) & 255; static FEEntity* DummyEntity = Scene->CreateEntity("DummyEntity"); + DummyEntity->GetComponent().SetTag(EDITOR_SCENE_TAG); if (!DummyEntity->HasComponent()) DummyEntity->AddComponent(); @@ -341,7 +341,6 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons FE_GL_ERROR(glReadPixels(static_cast(LocalMouseX), GLint(CameraComponent.GetRenderTargetHeight() - LocalMouseY), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, CurrentSelectionData->ColorUnderMouse)); CurrentSelectionData->PixelAccurateSelectionFB->UnBind(); RENDERER.SetViewport(OriginalViewport); - ENGINE.SetClearColor(OriginalClearColor); #ifndef EDITOR_SELECTION_DEBUG_MODE if (!CurrentSelectionData->SceneEntitiesUnderMouse.empty()) @@ -437,14 +436,12 @@ void FEEditorSelectedObject::OnCameraUpdate() const FECameraComponent& CameraComponent = CurrentCamera->GetComponent(); RENDERER.SetViewport(0, 0, CameraComponent.GetRenderTargetWidth(), CameraComponent.GetRenderTargetHeight()); - glm::vec4 OriginalClearColor = ENGINE.GetClearColor(); - ENGINE.SetClearColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.0f)); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT)); if (CurrentSelectionData->Container == nullptr) { HaloSelectionData->HaloObjectsFB->UnBind(); - ENGINE.SetClearColor(OriginalClearColor); HaloSelectionData->PostProcess->bActive = true; SceneIterator++; @@ -529,7 +526,6 @@ void FEEditorSelectedObject::OnCameraUpdate() const } HaloSelectionData->HaloObjectsFB->UnBind(); - ENGINE.SetClearColor(OriginalClearColor); HaloSelectionData->PostProcess->bActive = true; SceneIterator++; @@ -614,7 +610,10 @@ void FEEditorSelectedObject::AddSceneData(const std::string& SceneID) PerSceneData[SceneID]->PixelAccurateSelectionFB->SetColorAttachment(RESOURCE_MANAGER.CreateTexture(GL_RGB, GL_RGB, CameraComponent.GetRenderTargetWidth(), CameraComponent.GetRenderTargetHeight())); if (CurrentScene->GetEntityByName("Editor_Selection_Dummy_Entity").empty()) + { PerSceneData[SceneID]->DummyEntity = CurrentScene->CreateEntity("Editor_Selection_Dummy_Entity"); + PerSceneData[SceneID]->DummyEntity->GetComponent().SetTag(EDITOR_SCENE_TAG); + } HALO_SELECTION_EFFECT.AddSceneData(SceneID); } diff --git a/FEEditorSelectedObject.h b/FEEditorSelectedObject.h index 111e8e4..5eac29b 100644 --- a/FEEditorSelectedObject.h +++ b/FEEditorSelectedObject.h @@ -41,6 +41,8 @@ class FEEditorSelectedObject friend class FEEditor; friend class GizmoManager; friend class FEEditorInspectorWindow; + friend class FEEditorSceneWindow; + SINGLETON_PRIVATE_PART(FEEditorSelectedObject) public: SINGLETON_PUBLIC_PART(FEEditorSelectedObject) diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index c668b08..5eba947 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit c668b081baa9eb5bc201e0f8f86e9b65199ba978 +Subproject commit 5eba947bdc79d4bd64227d7b71ed4f54267928e6 From 6184afef76fd71dcaba1ab98de34200464574570 Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Sun, 4 Aug 2024 20:24:23 -0400 Subject: [PATCH 28/46] Engine update; ID information will now appear in a content browser tooltip; Fixed an issue where users could add a prefab to another prefab scene; It is now possible to draw scene AABB; Updated DragAndDropManager and DragAndDropTarget to use std::function for callbacks instead of raw function pointers; Reintroduced prefab thumbnail creation via scene rendering; First draft of proper prefab selection rendering. --- EditorWindows/ContentBrowserWindow.cpp | 3 +- .../FEEditorSceneWindow.cpp | 76 +++++---- .../FEEditorSceneWindow.h | 7 +- EditorWindows/InspectorWindow.cpp | 2 +- EditorWindows/PrefabEditorManager.cpp | 82 +++++++++- EditorWindows/PrefabEditorManager.h | 2 + EditorWindows/SceneGraphWindow.cpp | 111 +++++++------ EditorWindows/SceneGraphWindow.h | 2 - FEEditorDragAndDropManager.cpp | 8 +- FEEditorDragAndDropManager.h | 11 +- FEEditorPreviewManager.cpp | 146 ++++++++++-------- FEEditorPreviewManager.h | 2 + FEEditorSelectedObject.cpp | 140 ++++++++++------- SubSystems/FocalEngine | 2 +- 14 files changed, 379 insertions(+), 215 deletions(-) diff --git a/EditorWindows/ContentBrowserWindow.cpp b/EditorWindows/ContentBrowserWindow.cpp index f988386..43168ab 100644 --- a/EditorWindows/ContentBrowserWindow.cpp +++ b/EditorWindows/ContentBrowserWindow.cpp @@ -661,7 +661,8 @@ void FEEditorContentBrowserWindow::RenderFilterMenu() ImGui::BeginTooltip(); ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); - ImGui::TextUnformatted(("Name: " + FilteredResources[i]->GetName() + + ImGui::TextUnformatted(("ID: " + FilteredResources[i]->GetObjectID() + + "\nName: " + FilteredResources[i]->GetName() + "\nType: " + FEObjectTypeToString(FilteredResources[i]->GetType()) + AdditionalTypeInfo + "\nPath: " + VIRTUAL_FILE_SYSTEM.GetCurrentPath() diff --git a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp index f8106cf..8ee1520 100644 --- a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp +++ b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp @@ -1,7 +1,33 @@ #include "FEEditorSceneWindow.h" #include "../../FEEditor.h" -bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) +FEEditorSceneWindow::FEEditorSceneWindow(FEScene* Scene, bool bMain) +{ + if (Scene == nullptr) + return; + + this->Scene = Scene; + this->bMain = bMain; + Flags = ImGuiWindowFlags_None | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; + + std::string WindowName = Scene->GetName(); + // Window name must be unique. + WindowName += "##" + Scene->GetObjectID(); + if (bMain) + WindowName = "Main Scene"; + + SetCaption(WindowName); + SetBorderSize(0.0f); + SetPadding(glm::vec2(0.0f, 0.0f)); + + AcceptedTypes.push_back(FE_GAMEMODEL); + AcceptedTypes.push_back(FE_PREFAB); + ToolTipTexts.push_back("Drop to add to scene"); + ToolTipTexts.push_back("Drop to add to scene"); + CurrentDragAndDropCallback = DragAndDropCallBack; +} + +bool FEEditorSceneWindow::DragAndDropCallBack(FEObject* Object, void** UserData) { if (EDITOR.GetFocusedScene() == nullptr) return false; @@ -40,43 +66,33 @@ bool SceneWindowDragAndDropCallBack(FEObject* Object, void** UserData) FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); - std::vector NewNodes = SCENE_MANAGER.ImportSceneAsNode(RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())->Scene, EditorSceneWindow->GetScene()); + FEPrefab* Prefab = RESOURCE_MANAGER.GetPrefab(Object->GetObjectID()); + FEScene* PrefabScene = Prefab->Scene; + FENaiveSceneGraphNode* RootNode = PrefabScene->SceneGraph.GetRoot(); + + FEEntity* NewEntity = EditorSceneWindow->GetScene()->CreateEntity(Object->GetName()); + FENaiveSceneGraphNode* NewNode = EditorSceneWindow->GetScene()->SceneGraph.GetNodeByEntityID(NewEntity->GetObjectID()); + + std::vector NewNodes = SCENE_MANAGER.ImportSceneAsNode(PrefabScene, EditorSceneWindow->GetScene(), NewNode); if (!NewNodes.empty()) { - // Currently we are interested in the first node only - FEEntity* Entity = NewNodes[0]->GetEntity(); - Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); - - SELECTED.SetSelected(Entity); + NewEntity->AddComponent(Prefab); + SELECTED.SetSelected(NewEntity); PROJECT_MANAGER.GetCurrent()->SetModified(true); + NewEntity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); return true; } + else + { + EditorSceneWindow->GetScene()->DeleteEntity(NewEntity); + return false; + } } return false; } -FEEditorSceneWindow::FEEditorSceneWindow(FEScene* Scene, bool bMain) -{ - if (Scene == nullptr) - return; - - this->Scene = Scene; - this->bMain = bMain; - Flags = ImGuiWindowFlags_None | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; - - std::string WindowName = Scene->GetName(); - // Window name must be unique. - WindowName += "##" + Scene->GetObjectID(); - if (bMain) - WindowName = "Main Scene"; - - SetCaption(WindowName); - SetBorderSize(0.0f); - SetPadding(glm::vec2(0.0f, 0.0f)); -} - FEEditorSceneWindow::~FEEditorSceneWindow() { @@ -118,10 +134,10 @@ void FEEditorSceneWindow::Render() CAMERA_SYSTEM.SetCameraViewport(CameraEntity, NewViewportID); SELECTED.AddSceneData(Scene->GetObjectID()); GIZMO_MANAGER.AddSceneData(Scene->GetObjectID()); - SceneWindowTarget = DRAG_AND_DROP_MANAGER.AddTarget(std::vector{ FE_GAMEMODEL, FE_PREFAB }, - SceneWindowDragAndDropCallBack, + SceneWindowTarget = DRAG_AND_DROP_MANAGER.AddTarget(AcceptedTypes, + CurrentDragAndDropCallback, reinterpret_cast(this), - std::vector{ "Drop to add to scene", "Drop to add to scene" }); + ToolTipTexts); } ImGuiStyle& Style = ImGui::GetStyle(); diff --git a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.h b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.h index 03b7518..1f54f36 100644 --- a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.h +++ b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.h @@ -7,7 +7,8 @@ class FEEditorSceneWindow : public FEImGuiWindow { friend class FEEditor; - +private: + static bool DragAndDropCallBack(FEObject* Object, void** UserData); protected: FEEditorSceneWindow(FEScene* Scene, bool bMain = false); ~FEEditorSceneWindow(); @@ -21,6 +22,10 @@ class FEEditorSceneWindow : public FEImGuiWindow bool bSelfContained = true; bool bWaitingForRemoval = false; + + std::vector AcceptedTypes; + std::vector ToolTipTexts; + std::function CurrentDragAndDropCallback; public: void Show(); void Render() override; diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index 2ec8aa1..2b7984f 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -1060,7 +1060,7 @@ void FEEditorInspectorWindow::Render() { if (ImGui::CollapsingHeader("Prefab Instance", ImGuiTreeNodeFlags_DefaultOpen)) { - + ImGui::Text("Prefab ID : %s", EntitySelected->GetComponent().GetPrefab()->GetObjectID().c_str()); } } diff --git a/EditorWindows/PrefabEditorManager.cpp b/EditorWindows/PrefabEditorManager.cpp index c1a267e..927bcce 100644 --- a/EditorWindows/PrefabEditorManager.cpp +++ b/EditorWindows/PrefabEditorManager.cpp @@ -3,7 +3,6 @@ #include "../FEEditor.h" FEPrefabEditorManager* FEPrefabEditorManager::Instance = nullptr; - FEPrefabSceneEditorWindow::FEPrefabSceneEditorWindow(FEScene* Scene) : FEEditorSceneWindow(Scene, false) { bSelfContained = false; @@ -15,6 +14,12 @@ FEPrefabSceneEditorWindow::FEPrefabSceneEditorWindow(FEScene* Scene) : FEEditorS CloseButton = new ImGuiButton("Close"); CloseButton->SetSize(ImVec2(140, 24)); CloseButton->SetDefaultColor(ImVec4(0.8f, 0.2f, 0.2f, 1.0f)); + + AcceptedTypes.clear(); + AcceptedTypes.push_back(FE_GAMEMODEL); + ToolTipTexts.clear(); + ToolTipTexts.push_back("Drop to add to scene"); + CurrentDragAndDropCallback = FEPrefabSceneEditorWindow::DragAndDropCallBack; } FEPrefabSceneEditorWindow::~FEPrefabSceneEditorWindow() @@ -68,6 +73,42 @@ void FEPrefabSceneEditorWindow::Render() FEEditorSceneWindow::OnRenderEnd(); } +bool FEPrefabSceneEditorWindow::DragAndDropCallBack(FEObject* Object, void** UserData) +{ + if (EDITOR.GetFocusedScene() == nullptr) + return false; + + if (CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene()) == nullptr) + return false; + + if (UserData == nullptr) + return false; + + FEEditorSceneWindow* EditorSceneWindow = reinterpret_cast(UserData); + if (EditorSceneWindow->GetScene() == nullptr) + return false; + + if (Object->GetType() == FE_GAMEMODEL) + { + FEGameModel* GameModel = RESOURCE_MANAGER.GetGameModel(Object->GetObjectID()); + + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + + FEEntity* Entity = EditorSceneWindow->GetScene()->CreateEntity(Object->GetName()); + Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); + Entity->AddComponent(GameModel); + + SELECTED.SetSelected(Entity); + PROJECT_MANAGER.GetCurrent()->SetModified(true); + + return true; + + } + + return false; +} + FEPrefabEditorManager::FEPrefabEditorManager() { @@ -104,16 +145,36 @@ void FEPrefabEditorManager::PrepareEditWinow(FEPrefab* Prefab) FEScene* CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->Scene, "Scene: " + Prefab->GetName()); + // Because by default camera is looking at 0,0,0 we need to place "empty" entity at 0,0,0. + // To ensure that scene AABB would include some entity at 0,0,0. + FEEntity* EmptyEntity = CurrentPrefabScene->CreateEntity("Empty entity"); + + FEAABB SceneAABB = CurrentPrefabScene->GetSceneAABB([](FEEntity* Entity) -> bool { + if (Entity->GetComponent().GetTag() == EDITOR_SCENE_TAG) + return false; + + if (Entity->HasComponent()) + return false; + + if (Entity->HasComponent()) + return false; + + return true; + }); + + CurrentPrefabScene->DeleteEntity(EmptyEntity); + FEEntity* Camera = CurrentPrefabScene->CreateEntity("Prefab scene camera"); Camera->GetComponent().SetTag(EDITOR_SCENE_TAG); Camera->AddComponent(); FECameraComponent& CameraComponent = Camera->GetComponent(); CameraComponent.Type = 1; - CameraComponent.DistanceToModel = 10.0; + CameraComponent.DistanceToModel = SceneAABB.GetLongestAxisLength() * 2.5; CameraComponent.SetSSAOEnabled(false); - CAMERA_SYSTEM.SetMainCamera(Camera); FETransformComponent& CameraTransform = Camera->GetComponent(); + // To make sure that next scene FEAABB calculation will include correct camera position. + CAMERA_SYSTEM.IndividualUpdate(Camera, 0.0); FEEntity* SkyDomeEntity = CurrentPrefabScene->CreateEntity("Prefab scene skydome"); SkyDomeEntity->GetComponent().SetTag(EDITOR_SCENE_TAG); @@ -126,7 +187,17 @@ void FEPrefabEditorManager::PrepareEditWinow(FEPrefab* Prefab) FELightComponent& LightComponent = LightEntity->GetComponent(); LightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); LightComponent.SetIntensity(4.3f); - LightComponent.SetCastShadows(false); + SceneAABB = CurrentPrefabScene->GetSceneAABB([](FEEntity* Entity) -> bool { + if (Entity->GetComponent().GetTag() == EDITOR_SCENE_TAG && !Entity->HasComponent()) + return false; + + if (Entity->HasComponent()) + return false; + + return true; + }); + LightComponent.SetShadowCoverage(SceneAABB.GetLongestAxisLength() * 2); + LightComponent.SetCastShadows(true); PrefabWindows[Prefab] = new FEPrefabSceneEditorWindow(CurrentPrefabScene); EDITOR.AddCustomEditorScene(PrefabWindows[Prefab]); @@ -157,4 +228,7 @@ void FEPrefabEditorManager::ApplyModificationsToPrefabScene(FEPrefabSceneEditorW SCENE_MANAGER.ImportSceneAsNode(ModifiedScene, Prefab->Scene, Prefab->Scene->SceneGraph.GetRoot(), [](FEEntity* EntityToCheck) { return !(EntityToCheck->GetComponent().GetTag() == EDITOR_SCENE_TAG); }); + + Prefab->SetDirtyFlag(true); + PREVIEW_MANAGER.GetPrefabPreview(Prefab->GetObjectID()); } \ No newline at end of file diff --git a/EditorWindows/PrefabEditorManager.h b/EditorWindows/PrefabEditorManager.h index 7d87403..2a691f9 100644 --- a/EditorWindows/PrefabEditorManager.h +++ b/EditorWindows/PrefabEditorManager.h @@ -11,6 +11,8 @@ class FEPrefabSceneEditorWindow : public FEEditorSceneWindow ImGuiButton* CloseButton = nullptr; ImGuiButton* ApplyButton = nullptr; + + static bool DragAndDropCallBack(FEObject* Object, void** UserData); public: FEPrefabSceneEditorWindow(FEScene* Scene); void Render() override; diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 8e139f8..ed8f2c1 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -557,39 +557,36 @@ void FEEditorSceneGraphWindow::Render() ImGui::EndPopup(); } - //FEBasicCamera* Camera = ENGINE.GetCamera(); - //INSPECTOR_WINDOW.ShowTransformConfiguration("Camera", & Camera->TestTransform); + //// FIX ME! It should not be here. + //static bool bDisplayGrid = true; + //ImGui::Checkbox("Display grid", &bDisplayGrid); - // FIX ME! It should not be here. - static bool bDisplayGrid = true; - ImGui::Checkbox("Display grid", &bDisplayGrid); + //static glm::vec3 color = glm::vec3(0.2f, 0.3f, 0.4f); - static glm::vec3 color = glm::vec3(0.2f, 0.3f, 0.4f); - - const float BasicW = 0.1f; - float width = BasicW * 4.0f; - if (bDisplayGrid) - { - const int GridSize = 200; - for (int i = -GridSize / 2; i < GridSize / 2; i++) - { - color = glm::vec3(0.4f, 0.65f, 0.73f); - width = BasicW * 4.0f; - if (i % 2 != 0 && i != 0) - { - color = color / 4.0f; - width = width / 4.0f; - } - else if (i == 0) - { - color = glm::vec3(0.9f, 0.9f, 0.9f); - width = BasicW * 4.0f; - } - - RENDERER.DrawLine(glm::vec3(i, 0.0f, -GridSize / 2), glm::vec3(i, 0.0f, GridSize / 2), color, width); - RENDERER.DrawLine(glm::vec3(-GridSize / 2, 0.0f, i), glm::vec3(GridSize / 2, 0.0f, i), color, width); - } - } + //const float BasicW = 0.1f; + //float width = BasicW * 4.0f; + //if (bDisplayGrid) + //{ + // const int GridSize = 200; + // for (int i = -GridSize / 2; i < GridSize / 2; i++) + // { + // color = glm::vec3(0.4f, 0.65f, 0.73f); + // width = BasicW * 4.0f; + // if (i % 2 != 0 && i != 0) + // { + // color = color / 4.0f; + // width = width / 4.0f; + // } + // else if (i == 0) + // { + // color = glm::vec3(0.9f, 0.9f, 0.9f); + // width = BasicW * 4.0f; + // } + + // RENDERER.DrawLine(glm::vec3(i, 0.0f, -GridSize / 2), glm::vec3(i, 0.0f, GridSize / 2), color, width); + // RENDERER.DrawLine(glm::vec3(-GridSize / 2, 0.0f, i), glm::vec3(GridSize / 2, 0.0f, i), color, width); + // } + //} static float FavgTime = 0.0f; static std::vector AvgTime; @@ -630,36 +627,52 @@ void FEEditorSceneGraphWindow::Render() ImGui::Checkbox("Display AABB of selected object", &bDisplaySelectedObjAABB); // Draw AABB - if (SELECTED.GetSelected(CurrentScene) != nullptr && - (SELECTED.GetSelected(CurrentScene)->HasComponent() || SELECTED.GetSelected(CurrentScene)->HasComponent()) && + FEEntity* SelectedEntity = SELECTED.GetSelected(CurrentScene); + if (SelectedEntity != nullptr && + (SelectedEntity->HasComponent() || SelectedEntity->HasComponent()) && bDisplaySelectedObjAABB) { - if (SELECTED.GetSelected(CurrentScene)->HasComponent()) - { - FEGameModel* GameModel = SELECTED.GetSelected(CurrentScene)->GetComponent().GameModel; - FEAABB SelectedAABB = GameModel->GetMesh()->GetAABB().Transform(SELECTED.GetSelected(CurrentScene)->GetComponent().GetWorldMatrix()); + FEAABB SelectedAABB; + SelectedAABB = SelectedEntity->GetParentScene()->GetEntityAABB(SelectedEntity); + RENDERER.DrawAABB(SelectedAABB); - RENDERER.DrawAABB(SelectedAABB); + if (SelectedEntity->HasComponent()) + { + static bool bDisplaySubObjAABB = false; + ImGui::Checkbox("Display AABB of instanced entity subobjects", &bDisplaySubObjAABB); - if (SELECTED.GetSelected(CurrentScene)->HasComponent()) + if (bDisplaySubObjAABB) { - static bool bDisplaySubObjAABB = false; - ImGui::Checkbox("Display AABB of instanced entity subobjects", &bDisplaySubObjAABB); + FEInstancedComponent& InstancedComponent = SelectedEntity->GetComponent(); + const int MaxIterations = InstancedComponent.IndividualInstancedAABB.size() * 8 >= FE_MAX_LINES ? FE_MAX_LINES : int(InstancedComponent.IndividualInstancedAABB.size()); - if (bDisplaySubObjAABB) + for (size_t j = 0; j < MaxIterations; j++) { - FEInstancedComponent& InstancedComponent = SELECTED.GetSelected(CurrentScene)->GetComponent(); - const int MaxIterations = InstancedComponent.IndividualInstancedAABB.size() * 8 >= FE_MAX_LINES ? FE_MAX_LINES : int(InstancedComponent.IndividualInstancedAABB.size()); - - for (size_t j = 0; j < MaxIterations; j++) - { - RENDERER.DrawAABB(InstancedComponent.IndividualInstancedAABB[j]); - } + RENDERER.DrawAABB(InstancedComponent.IndividualInstancedAABB[j]); } } } } + static bool bDisplaySceneAABB = false; + ImGui::Checkbox("Display AABB of scene", &bDisplaySceneAABB); + if (bDisplaySceneAABB) + { + FEAABB SceneAABB = CurrentScene->GetSceneAABB([](FEEntity* Entity) -> bool { + if (Entity->GetComponent().GetTag() == EDITOR_SCENE_TAG) + return false; + + if (Entity->HasComponent()) + return false; + + if (Entity->HasComponent()) + return false; + + return true; + }); + RENDERER.DrawAABB(SceneAABB); + } + ImGui::PopStyleVar(); ImGui::End(); } \ No newline at end of file diff --git a/EditorWindows/SceneGraphWindow.h b/EditorWindows/SceneGraphWindow.h index ef2f723..208bb59 100644 --- a/EditorWindows/SceneGraphWindow.h +++ b/EditorWindows/SceneGraphWindow.h @@ -2,8 +2,6 @@ #include "ProjectWasModifiedPopUp.h" -#define EDITOR_SCENE_TAG "EDITOR_PRIVATE_SCENE_ENTITY" - class FEEditorSceneGraphWindow { friend class FEEditor; diff --git a/FEEditorDragAndDropManager.cpp b/FEEditorDragAndDropManager.cpp index 5f86ab3..5dc044e 100644 --- a/FEEditorDragAndDropManager.cpp +++ b/FEEditorDragAndDropManager.cpp @@ -14,13 +14,13 @@ void DragAndDropManager::InitializeResources() RESOURCE_MANAGER.MakeTextureStandard(HandCursorUnavailable); } -DragAndDropTarget* DragAndDropManager::AddTarget(const FE_OBJECT_TYPE AcceptedType, bool (*Callback)(FEObject*, void**), void** UserData, const std::string ToolTipText) +DragAndDropTarget* DragAndDropManager::AddTarget(const FE_OBJECT_TYPE AcceptedType, std::function Callback, void** UserData, const std::string ToolTipText) { Targets.push_back(new DragAndDropTarget(AcceptedType, Callback, UserData, ToolTipText)); return Targets.back(); } -DragAndDropTarget* DragAndDropManager::AddTarget(std::vector& AcceptedTypes, bool (*Callback)(FEObject*, void**), void** UserData, std::vector& ToolTipTexts) +DragAndDropTarget* DragAndDropManager::AddTarget(std::vector& AcceptedTypes, std::function Callback, void** UserData, std::vector& ToolTipTexts) { Targets.push_back(new DragAndDropTarget(AcceptedTypes, Callback, UserData, ToolTipTexts)); return Targets.back(); @@ -188,7 +188,7 @@ DragAndDropTarget::DragAndDropTarget() this->Callback = nullptr; } -DragAndDropTarget::DragAndDropTarget(const FE_OBJECT_TYPE AcceptedType, bool (*Callback)(FEObject*, void**), void** UserData, const std::string ToolTipText) +DragAndDropTarget::DragAndDropTarget(const FE_OBJECT_TYPE AcceptedType, std::function Callback, void** UserData, const std::string ToolTipText) { AcceptedTypes.push_back(AcceptedType); this->Callback = Callback; @@ -196,7 +196,7 @@ DragAndDropTarget::DragAndDropTarget(const FE_OBJECT_TYPE AcceptedType, bool (*C ToolTipTexts.push_back(ToolTipText); } -DragAndDropTarget::DragAndDropTarget(std::vector& AcceptedTypes, bool (*Callback)(FEObject*, void**), void** UserData, std::vector& ToolTipTexts) +DragAndDropTarget::DragAndDropTarget(std::vector& AcceptedTypes, std::function Callback, void** UserData, std::vector& ToolTipTexts) { this->AcceptedTypes = AcceptedTypes; this->Callback = Callback; diff --git a/FEEditorDragAndDropManager.h b/FEEditorDragAndDropManager.h index 56d4571..fb7ecce 100644 --- a/FEEditorDragAndDropManager.h +++ b/FEEditorDragAndDropManager.h @@ -10,13 +10,14 @@ class DragAndDropTarget private: std::vector AcceptedTypes; std::vector ToolTipTexts; - bool (*Callback)(FEObject*, void**); + std::function Callback; + void** UserData = nullptr; bool bActive = false; public: DragAndDropTarget(); - DragAndDropTarget(FE_OBJECT_TYPE AcceptedType, bool (*Callback)(FEObject*, void**), void** UserData = nullptr, std::string ToolTipText = ""); - DragAndDropTarget(std::vector& AcceptedTypes, bool (*Callback)(FEObject*, void**), void** UserData, std::vector& ToolTipTexts); + DragAndDropTarget(FE_OBJECT_TYPE AcceptedType, std::function Callback, void** UserData = nullptr, std::string ToolTipText = ""); + DragAndDropTarget(std::vector& AcceptedTypes, std::function Callback, void** UserData, std::vector& ToolTipTexts); ~DragAndDropTarget(); void SetActive(bool Active); @@ -38,8 +39,8 @@ class DragAndDropManager SINGLETON_PUBLIC_PART(DragAndDropManager) void InitializeResources(); - DragAndDropTarget* AddTarget(FE_OBJECT_TYPE AcceptedType, bool (*Callback)(FEObject*, void**), void** UserData = nullptr, std::string ToolTipText = ""); - DragAndDropTarget* AddTarget(std::vector& AcceptedTypes, bool (*Callback)(FEObject*, void**), void** UserData, std::vector& ToolTipTexts); + DragAndDropTarget* AddTarget(FE_OBJECT_TYPE AcceptedType, std::function Callback, void** UserData = nullptr, std::string ToolTipText = ""); + DragAndDropTarget* AddTarget(std::vector& AcceptedTypes, std::function Callback, void** UserData, std::vector& ToolTipTexts); DragAndDropTarget* AddTarget(DragAndDropTarget* NewTarget); void Render() const; diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index 19ab995..2c23cf3 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -198,15 +198,14 @@ void FEEditorPreviewManager::CreateMaterialPreview(const std::string MaterialID) CreateGameModelPreview(CurrentGameModel->GetObjectID()); } - // FIX ME! - // looking for all prefabs that uses this material to also update them - /*const std::vector PrefabList = RESOURCE_MANAGER.GetPrefabList(); + // Looking for all prefabs that uses this material to also update them. + const std::vector PrefabList = RESOURCE_MANAGER.GetPrefabList(); for (size_t i = 0; i < PrefabList.size(); i++) { FEPrefab* CurrentPrefab = RESOURCE_MANAGER.GetPrefab(PrefabList[i]); if (CurrentPrefab->UsesMaterial(MaterialID)) CreatePrefabPreview(CurrentPrefab->GetObjectID()); - }*/ + } } FETexture* FEEditorPreviewManager::GetMaterialPreview(const std::string MaterialID) @@ -322,8 +321,6 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel RENDERER.Render(PreviewScene); AfterPreviewActions(); - - //PreviewFB->SetColorAttachment(TempTexture); } FETexture* FEEditorPreviewManager::GetGameModelPreview(const std::string GameModelID) @@ -369,47 +366,74 @@ void FEEditorPreviewManager::UpdateAllGameModelPreviews() void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) { FEPrefab* Prefab = RESOURCE_MANAGER.GetPrefab(PrefabID); - if (Prefab == nullptr) - return; - - if (Prefab->ComponentsCount() < 1) - return; - - FEGameModel* GameModel = Prefab->GetComponent(0)->GameModel; - if (GameModel == nullptr) + if (Prefab == nullptr || Prefab->Scene == nullptr) return; - PreviewEntity->GetComponent().GameModel = GameModel; - PreviewEntity->GetComponent().SetReceivingShadows(false); - BeforePreviewActions(); + FEScene* CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->Scene, "Scene: " + Prefab->GetName()); - FEAABB MeshAABB = PreviewEntity->GetComponent().GameModel->Mesh->GetAABB(); - MeshAABB.Transform(PreviewEntity->GetComponent().GetWorldMatrix()); - const glm::vec3 min = MeshAABB.GetMin(); - const glm::vec3 max = MeshAABB.GetMax(); + // Because by default camera is looking at 0,0,0 we need to place "empty" entity at 0,0,0. + // To ensure that scene AABB would include some entity at 0,0,0. + CurrentPrefabScene->CreateEntity("Empty entity"); - const float XSize = sqrt((max.x - min.x) * (max.x - min.x)); - const float YSize = sqrt((max.y - min.y) * (max.y - min.y)); - const float ZSize = sqrt((max.z - min.z) * (max.z - min.z)); + FEAABB SceneAABB = CurrentPrefabScene->GetSceneAABB([](FEEntity* Entity) -> bool { + if (Entity->GetComponent().GetTag() == EDITOR_SCENE_TAG) + return false; - // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. - PreviewEntity->GetComponent().SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); - LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); - CAMERA_SYSTEM.IndividualUpdate(LocalCameraEntity, 0.0); + if (Entity->HasComponent()) + return false; - RENDERER.Render(PreviewScene); + if (Entity->HasComponent()) + return false; - //PreviewEntity->Prefab = PreviewPrefab; - PreviewEntity->GetComponent().GameModel = PreviewGameModel; + return true; + }); - AfterPreviewActions(); + FEEntity* Camera = CurrentPrefabScene->CreateEntity("Prefab scene camera"); + Camera->GetComponent().SetTag(EDITOR_SCENE_TAG); + Camera->AddComponent(); + Camera->GetComponent().SetPosition(glm::vec3(0.0, 0.0, SceneAABB.GetLongestAxisLength() * 2)); + FECameraComponent& CameraComponent = Camera->GetComponent(); + CameraComponent.SetRenderTargetSize(128, 128); + CameraComponent.SetDistanceFogEnabled(false); + CameraComponent.SetSSAOEnabled(false); + CAMERA_SYSTEM.SetMainCamera(Camera); + // To make sure that next scene FEAABB calculation will include correct camera position. + CAMERA_SYSTEM.IndividualUpdate(Camera, 0.0); + + FEEntity* SkyDomeEntity = CurrentPrefabScene->CreateEntity("Prefab scene skydome"); + SkyDomeEntity->GetComponent().SetTag(EDITOR_SCENE_TAG); + SkyDomeEntity->GetComponent().SetScale(glm::vec3(100.0f)); + SkyDomeEntity->AddComponent(); + + FEEntity* LightEntity = CurrentPrefabScene->CreateEntity("Prefab scene light"); + LightEntity->GetComponent().SetTag(EDITOR_SCENE_TAG); + LightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); + FELightComponent& LightComponent = LightEntity->GetComponent(); + LightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); + LightComponent.SetIntensity(4.3f); + SceneAABB = CurrentPrefabScene->GetSceneAABB([](FEEntity* Entity) -> bool { + if (Entity->GetComponent().GetTag() == EDITOR_SCENE_TAG && !Entity->HasComponent()) + return false; + + if (Entity->HasComponent()) + return false; + + return true; + }); + LightComponent.SetShadowCoverage(SceneAABB.GetLongestAxisLength() * 2); + LightComponent.SetCastShadows(true); + + RENDERER.Render(CurrentPrefabScene); // if we are updating preview we should delete old texture. if (PrefabPreviewTextures.find(PrefabID) != PrefabPreviewTextures.end()) delete PrefabPreviewTextures[PrefabID]; - //PrefabPreviewTextures[PrefabID] = PreviewFB->GetColorAttachment(); - //PreviewFB->SetColorAttachment(RESOURCE_MANAGER.CreateSameFormatTexture(PreviewFB->GetColorAttachment())); + FETexture* CameraResult = RENDERER.GetCameraResult(Camera); + if (CameraResult != nullptr) + PrefabPreviewTextures[PrefabID] = RESOURCE_MANAGER.CreateCopyOfTexture(CameraResult); + + SCENE_MANAGER.DeleteScene(CurrentPrefabScene); } void CreatePrefabPreview(FEPrefab* Prefab, FETexture** ResultingTexture) @@ -419,33 +443,33 @@ void CreatePrefabPreview(FEPrefab* Prefab, FETexture** ResultingTexture) FETexture* FEEditorPreviewManager::GetPrefabPreview(const std::string PrefabID) { - //FEPrefab* CurrentPrefab = RESOURCE_MANAGER.GetPrefab(PrefabID); - //if (CurrentPrefab == nullptr) - //{ - // LOG.Add("FEEditorPreviewManager::GetPrefabPreview could not find prefab with ID: " + PrefabID, "FE_LOG_RENDERING", FE_LOG_ERROR); - // return RESOURCE_MANAGER.NoTexture; - //} - // - //// if Prefab's dirty flag is set we need to update preview - //if (CurrentPrefab->IsDirty()) - //{ - // CreatePrefabPreview(PrefabID); - // CurrentPrefab->SetDirtyFlag(false); - //} - - //for (int i = 0; i < CurrentPrefab->ComponentsCount(); i++) - //{ - // // if Prefab's material dirty flag is set we need to update preview - // if (CurrentPrefab->GetComponent(i)->GameModel->GetMaterial() != nullptr && CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->IsDirty()) - // { - // CreateMaterialPreview(CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->GetObjectID()); - // CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->SetDirtyFlag(false); - // } - //} - - //// if we somehow could not find preview, we will create it. - //if (PrefabPreviewTextures.find(PrefabID) == PrefabPreviewTextures.end()) - // CreatePrefabPreview(PrefabID); + FEPrefab* CurrentPrefab = RESOURCE_MANAGER.GetPrefab(PrefabID); + if (CurrentPrefab == nullptr) + { + LOG.Add("FEEditorPreviewManager::GetPrefabPreview could not find prefab with ID: " + PrefabID, "FE_LOG_RENDERING", FE_LOG_ERROR); + return RESOURCE_MANAGER.NoTexture; + } + + // if Prefab's dirty flag is set we need to update preview + if (CurrentPrefab->IsDirty()) + { + CreatePrefabPreview(PrefabID); + CurrentPrefab->SetDirtyFlag(false); + } + + for (int i = 0; i < CurrentPrefab->ComponentsCount(); i++) + { + // if Prefab's material dirty flag is set we need to update preview + if (CurrentPrefab->GetComponent(i)->GameModel->GetMaterial() != nullptr && CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->IsDirty()) + { + CreateMaterialPreview(CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->GetObjectID()); + CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->SetDirtyFlag(false); + } + } + + // if we somehow could not find preview, we will create it. + if (PrefabPreviewTextures.find(PrefabID) == PrefabPreviewTextures.end()) + CreatePrefabPreview(PrefabID); // if still we don't have it if (PrefabPreviewTextures.find(PrefabID) == PrefabPreviewTextures.end()) diff --git a/FEEditorPreviewManager.h b/FEEditorPreviewManager.h index 4a20603..2fdf7bd 100644 --- a/FEEditorPreviewManager.h +++ b/FEEditorPreviewManager.h @@ -3,6 +3,8 @@ #include "../FEngine.h" using namespace FocalEngine; +#define EDITOR_SCENE_TAG "EDITOR_PRIVATE_SCENE_ENTITY" + class FEEditorPreviewManager { friend class FEEditor; diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index d182a2e..1549f4a 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -439,7 +439,9 @@ void FEEditorSelectedObject::OnCameraUpdate() const glClearColor(0.0f, 0.0f, 0.0f, 0.0f); FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT)); - if (CurrentSelectionData->Container == nullptr) + FEEntity* SelectedEntity = CurrentSelectionData->Container; + + if (SelectedEntity == nullptr) { HaloSelectionData->HaloObjectsFB->UnBind(); HaloSelectionData->PostProcess->bActive = true; @@ -448,81 +450,107 @@ void FEEditorSelectedObject::OnCameraUpdate() const continue; } - if (CurrentSelectionData->Container->HasComponent()) + FEEntity* ParentPrefabInstance = PREFAB_INSTANCE_SYSTEM.GetParentPrefabInstanceIfAny(SelectedEntity); + if (ParentPrefabInstance != nullptr && PREFAB_INSTANCE_SYSTEM.IsPrefabInstanceUnmodified(ParentPrefabInstance)) { - FEGameModelComponent& GameModelComponent = CurrentSelectionData->Container->GetComponent(); - FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; + FENaiveSceneGraphNode* ParentPrefabInstanceNode = ParentPrefabInstance->GetParentScene()->SceneGraph.GetNodeByEntityID(ParentPrefabInstance->GetObjectID()); + std::vector PrefabElements = ParentPrefabInstanceNode->GetChildren(); + for (size_t i = 0; i < PrefabElements.size(); i++) + { + FEEntity* PrefabElement = PrefabElements[i]->GetEntity(); + if (PrefabElement->HasComponent()) + { + FEGameModelComponent& GameModelComponent = PrefabElement->GetComponent(); + FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; - GameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + GameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - if (!CurrentSelectionData->Container->HasComponent()) - { - RENDERER.RenderGameModelComponent(CurrentSelectionData->Container, CurrentCamera); + RENDERER.RenderGameModelComponent(PrefabElement, CurrentCamera); + + GameModelComponent.GameModel->Material = RegularMaterial; + } } - else if (CurrentSelectionData->Container->HasComponent()) + } + else + { + if (SelectedEntity->HasComponent()) { - if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1) + FEGameModelComponent& GameModelComponent = SelectedEntity->GetComponent(); + FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; + + GameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + + if (!SelectedEntity->HasComponent()) { - if (!CurrentSelectionData->DummyEntity->HasComponent()) - CurrentSelectionData->DummyEntity->AddComponent(); + RENDERER.RenderGameModelComponent(SelectedEntity, CurrentCamera); + } + else if (SelectedEntity->HasComponent()) + { + if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1) + { + if (!CurrentSelectionData->DummyEntity->HasComponent()) + CurrentSelectionData->DummyEntity->AddComponent(); - FEGameModelComponent& DummyGameModelComponent = CurrentSelectionData->DummyEntity->GetComponent(); - DummyGameModelComponent.GameModel = GameModelComponent.GameModel; - DummyGameModelComponent.SetVisibility(true); + FEGameModelComponent& DummyGameModelComponent = CurrentSelectionData->DummyEntity->GetComponent(); + DummyGameModelComponent.GameModel = GameModelComponent.GameModel; + DummyGameModelComponent.SetVisibility(true); - FEInstancedComponent& InstancedComponent = CurrentSelectionData->Container->GetComponent(); - FETransformComponent& DummyTransformComponent = CurrentSelectionData->DummyEntity->GetComponent(); + FEInstancedComponent& InstancedComponent = SelectedEntity->GetComponent(); + FETransformComponent& DummyTransformComponent = CurrentSelectionData->DummyEntity->GetComponent(); - glm::dvec3 Position, Scale; - glm::dquat Rotation; - GEOMETRY.DecomposeMatrixToTranslationRotationScale(InstancedComponent.GetTransformedInstancedMatrix(CurrentSelectionData->InstancedSubObjectIndexSelected), Position, Rotation, Scale); + glm::dvec3 Position, Scale; + glm::dquat Rotation; + GEOMETRY.DecomposeMatrixToTranslationRotationScale(InstancedComponent.GetTransformedInstancedMatrix(CurrentSelectionData->InstancedSubObjectIndexSelected), Position, Rotation, Scale); - DummyTransformComponent.SetPosition(Position); - DummyTransformComponent.SetQuaternion(Rotation); - DummyTransformComponent.SetScale(Scale); + DummyTransformComponent.SetPosition(Position); + DummyTransformComponent.SetQuaternion(Rotation); + DummyTransformComponent.SetScale(Scale); - FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; - DummyGameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; + FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; + DummyGameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; - HALO_SELECTION_EFFECT.HaloMaterial->SetBaseColor(glm::vec3(0.61f, 0.86f, 1.0f)); - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + HALO_SELECTION_EFFECT.HaloMaterial->SetBaseColor(glm::vec3(0.61f, 0.86f, 1.0f)); + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - RENDERER.RenderGameModelComponent(CurrentSelectionData->DummyEntity, CurrentCamera); + RENDERER.RenderGameModelComponent(CurrentSelectionData->DummyEntity, CurrentCamera); - GameModelComponent.GameModel->Material = RegularMaterial; - DummyGameModelComponent.SetVisibility(false); - } - else - { - HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawInstancedObjectShader; - FEMaterial* RegularBillboardMaterial = GameModelComponent.GameModel->GetBillboardMaterial(); - GameModelComponent.GameModel->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); + GameModelComponent.GameModel->Material = RegularMaterial; + DummyGameModelComponent.SetVisibility(false); + } + else + { + HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawInstancedObjectShader; + FEMaterial* RegularBillboardMaterial = GameModelComponent.GameModel->GetBillboardMaterial(); + GameModelComponent.GameModel->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); - RENDERER.RenderGameModelComponentWithInstanced(CurrentSelectionData->Container, CurrentCamera); + RENDERER.RenderGameModelComponentWithInstanced(SelectedEntity, CurrentCamera); - HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; - GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterial); + HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; + GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterial); + } } - } - GameModelComponent.GameModel->Material = RegularMaterial; - } - else if (CurrentSelectionData->Container->HasComponent()) - { - FETerrainComponent& TerrainComponent = CurrentSelectionData->Container->GetComponent(); - TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); - TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f, 0.25f, 0.0f)); - const float RegularLODLevel = TerrainComponent.GetLODLevel(); - TerrainComponent.SetLODLevel(0.0f); + GameModelComponent.GameModel->Material = RegularMaterial; + } + else if (SelectedEntity->HasComponent()) + { + FETerrainComponent& TerrainComponent = SelectedEntity->GetComponent(); + TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); + TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f, 0.25f, 0.0f)); + const float RegularLODLevel = TerrainComponent.GetLODLevel(); + TerrainComponent.SetLODLevel(0.0f); - RENDERER.RenderTerrainComponent(CurrentSelectionData->Container, CurrentCamera); + RENDERER.RenderTerrainComponent(SelectedEntity, CurrentCamera); - TerrainComponent.SetLODLevel(RegularLODLevel); - TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); - TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); + TerrainComponent.SetLODLevel(RegularLODLevel); + TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); + TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); + } } HaloSelectionData->HaloObjectsFB->UnBind(); diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 5eba947..0db60ae 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 5eba947bdc79d4bd64227d7b71ed4f54267928e6 +Subproject commit 0db60ae0b893528640eb65fa3080b4e5f1838fd8 From d5dbce110f21cf6815e34ef0fb91785d3942d32c Mon Sep 17 00:00:00 2001 From: Azzinoth Date: Sun, 11 Aug 2024 13:57:59 -0400 Subject: [PATCH 29/46] Engine update; Shifted from using RESOURCE_MANAGER.Make____Standard to RESOURCE_MANAGER.SetTag(_____, EDITOR_RESOURCE_TAG); Resource tags will now be displayed in the content browser; EDITOR_SCENE_TAG has been replaced by using resource tags instead of entity tag components; Improved code for HaloEffect rendering and rendering for identifying selected entities; Introduced FEProjectManager::CreateNewProject that will properly create a new scene and save it, instead of just saving the text of a pre-created scene save file; FEProject::SaveScene and FEProject::LoadScene were renamed to SaveProject and LoadProject, respectively; The loading and saving of projects were completely rewritten to fully support the new ECS and multiple scenes. --- EditorWindows/ContentBrowserWindow.cpp | 27 +- EditorWindows/DeletePopups.cpp | 5 +- EditorWindows/EditPopups.cpp | 7 +- .../FEEditorSceneWindow.cpp | 4 +- EditorWindows/InspectorWindow.cpp | 20 +- EditorWindows/PrefabEditorManager.cpp | 20 +- EditorWindows/ProjectWasModifiedPopUp.cpp | 4 +- EditorWindows/SceneGraphWindow.cpp | 24 +- EditorWindows/SelectPopups.cpp | 2 +- EditorWindows/ShaderEditorWindow.cpp | 2 +- FEEditor.cpp | 5 +- FEEditor.h | 1 - FEEditorDragAndDropManager.cpp | 4 +- FEEditorDragAndDropManager.h | 2 + FEEditorGizmoManager.cpp | 152 ++- FEEditorHaloSelectionEffect.cpp | 8 +- FEEditorPreviewManager.cpp | 51 +- FEEditorPreviewManager.h | 2 - FEEditorSelectedObject.cpp | 385 +++--- FEEditorSelectedObject.h | 3 + FEProject.cpp | 1137 ++++------------- FEProject.h | 139 +- SubSystems/FocalEngine | 2 +- 23 files changed, 661 insertions(+), 1345 deletions(-) diff --git a/EditorWindows/ContentBrowserWindow.cpp b/EditorWindows/ContentBrowserWindow.cpp index 43168ab..bb39373 100644 --- a/EditorWindows/ContentBrowserWindow.cpp +++ b/EditorWindows/ContentBrowserWindow.cpp @@ -49,7 +49,8 @@ static void CreateNewPrefabCallBack(const std::vector SelectionsResul { if (!SelectionsResult.empty() && SelectionsResult[0]->GetType() == FE_GAMEMODEL) { - FEPrefab* NewPrefab = RESOURCE_MANAGER.CreatePrefab(reinterpret_cast(SelectionsResult[0])); + // FIX ME! + FEPrefab* NewPrefab = RESOURCE_MANAGER.CreatePrefab(); if (SelectionsResult.size() > 1) { @@ -266,9 +267,10 @@ void FEEditorContentBrowserWindow::Render() if (ImGui::MenuItem("Create Prefab out of this Game Model")) { - FEPrefab* NewPrefab = RESOURCE_MANAGER.CreatePrefab(RESOURCE_MANAGER.GetGameModel(FilteredResources[ItemUnderMouse]->GetObjectID())); + // FIX ME ! + /*FEPrefab* NewPrefab = RESOURCE_MANAGER.CreatePrefab(RESOURCE_MANAGER.GetGameModel(FilteredResources[ItemUnderMouse]->GetObjectID())); PROJECT_MANAGER.GetCurrent()->SetModified(true); - VIRTUAL_FILE_SYSTEM.CreateFile(NewPrefab, VIRTUAL_FILE_SYSTEM.GetCurrentPath()); + VIRTUAL_FILE_SYSTEM.CreateFile(NewPrefab, VIRTUAL_FILE_SYSTEM.GetCurrentPath());*/ } } @@ -401,32 +403,32 @@ void FEEditorContentBrowserWindow::Clear() void FEEditorContentBrowserWindow::InitializeResources() { FolderIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/folderIcon.png", "folderIcon"); - RESOURCE_MANAGER.MakeTextureStandard(FolderIcon); + RESOURCE_MANAGER.SetTag(FolderIcon, EDITOR_RESOURCE_TAG); ShaderIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/shaderIcon.png", "shaderIcon"); - RESOURCE_MANAGER.MakeTextureStandard(ShaderIcon); + RESOURCE_MANAGER.SetTag(ShaderIcon, EDITOR_RESOURCE_TAG); VFSBackIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/VFSBackIcon.png", "VFSBackIcon"); - RESOURCE_MANAGER.MakeTextureStandard(VFSBackIcon); + RESOURCE_MANAGER.SetTag(VFSBackIcon, EDITOR_RESOURCE_TAG); TextureIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/textureContentBrowserIcon.png", "textureContentBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(TextureIcon); + RESOURCE_MANAGER.SetTag(TextureIcon, EDITOR_RESOURCE_TAG); MeshIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/meshContentBrowserIcon.png", "meshContentBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(MeshIcon); + RESOURCE_MANAGER.SetTag(MeshIcon, EDITOR_RESOURCE_TAG); MaterialIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/materialContentBrowserIcon.png", "materialContentBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(MaterialIcon); + RESOURCE_MANAGER.SetTag(MaterialIcon, EDITOR_RESOURCE_TAG); GameModelIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/gameModelContentBrowserIcon.png", "gameModelContentBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(GameModelIcon); + RESOURCE_MANAGER.SetTag(GameModelIcon, EDITOR_RESOURCE_TAG); PrefabIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/prefabContentBrowserIcon.png", "prefabContentBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(PrefabIcon); + RESOURCE_MANAGER.SetTag(PrefabIcon, EDITOR_RESOURCE_TAG); AllIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/allContentBrowserIcon.png", "allIcon"); FilterAllTypesButton = new ImGuiImageButton(AllIcon); - RESOURCE_MANAGER.MakeTextureStandard(AllIcon); + RESOURCE_MANAGER.SetTag(AllIcon, EDITOR_RESOURCE_TAG); FilterAllTypesButton->SetSize(ImVec2(32, 32)); FilterTextureTypeButton = new ImGuiImageButton(TextureIcon); @@ -662,6 +664,7 @@ void FEEditorContentBrowserWindow::RenderFilterMenu() ImGui::BeginTooltip(); ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); ImGui::TextUnformatted(("ID: " + FilteredResources[i]->GetObjectID() + + "\nTag: " + FilteredResources[i]->GetTag() + "\nName: " + FilteredResources[i]->GetName() + "\nType: " + FEObjectTypeToString(FilteredResources[i]->GetType()) + AdditionalTypeInfo + diff --git a/EditorWindows/DeletePopups.cpp b/EditorWindows/DeletePopups.cpp index 8664e8c..d02650b 100644 --- a/EditorWindows/DeletePopups.cpp +++ b/EditorWindows/DeletePopups.cpp @@ -306,7 +306,8 @@ void DeleteGameModelPopup::Render() int DeleteGameModelPopup::TimesGameModelUsed(const FEGameModel* GameModel) { int Result = 0; - const std::vector PrefabList = RESOURCE_MANAGER.GetPrefabList(); + // FIX ME! + /*const std::vector PrefabList = RESOURCE_MANAGER.GetPrefabList(); for (int i = 0; i < PrefabList.size(); i++) { @@ -316,7 +317,7 @@ int DeleteGameModelPopup::TimesGameModelUsed(const FEGameModel* GameModel) if (CurrentPrefab->GetComponent(j)->GameModel == GameModel) Result++; } - } + }*/ return Result; } diff --git a/EditorWindows/EditPopups.cpp b/EditorWindows/EditPopups.cpp index 1c89a2f..3c0bccd 100644 --- a/EditorWindows/EditPopups.cpp +++ b/EditorWindows/EditPopups.cpp @@ -1,4 +1,5 @@ #include "EditPopups.h" +#include "../FEEditor.h" EditGameModelPopup* EditGameModelPopup::Instance = nullptr; FEMesh** EditGameModelPopup::MeshToModify = nullptr; @@ -380,7 +381,8 @@ void EditGameModelPopup::Render() ImGui::Text("Preview of game model:"); ImGui::SetCursorPosX(Size.x / 2 - 128 / 2); ImGui::SetCursorPosY(CurrentY + 50); - ImGui::Image((void*)static_cast(TempPreview->GetTextureID()), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); + // FIX ME! + //ImGui::Image((void*)static_cast(TempPreview->GetTextureID()), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); if (CurrentMode == NO_LOD_MODE) { @@ -730,6 +732,7 @@ EditMaterialWindow::EditMaterialWindow() NodeAreaTarget = DRAG_AND_DROP_MANAGER.AddTarget(FE_TEXTURE, DragAndDropnodeAreaTargetCallback, reinterpret_cast(&DragAndDropCallbackInfo), "Drop to add texture"); PreviewScene = SCENE_MANAGER.CreateScene("MaterialEditor_Scene"); + RESOURCE_MANAGER.SetTag(PreviewScene, EDITOR_RESOURCE_TAG); PreviewGameModel = new FEGameModel(nullptr, nullptr, "MaterialEditor_Preview_GameModel"); PreviewGameModel->Mesh = RESOURCE_MANAGER.GetMesh("7F251E3E0D08013E3579315F"/*"sphere"*/); @@ -757,7 +760,7 @@ EditMaterialWindow::EditMaterialWindow() FEEntity* SkyDome = PreviewScene->CreateEntity("SkyDome"); SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); - SKY_DOME_SYSTEM.AddToEntity(SkyDome); + SkyDome->AddComponent(); SCENE_MANAGER.DeactivateScene(PreviewScene); ENGINE.AddMouseButtonCallback(MouseButtonCallback); diff --git a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp index 8ee1520..b3b87d3 100644 --- a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp +++ b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp @@ -61,13 +61,11 @@ bool FEEditorSceneWindow::DragAndDropCallBack(FEObject* Object, void** UserData) } else if (Object->GetType() == FE_PREFAB) { - FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())->GetComponent(0)->GameModel; - FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); FEPrefab* Prefab = RESOURCE_MANAGER.GetPrefab(Object->GetObjectID()); - FEScene* PrefabScene = Prefab->Scene; + FEScene* PrefabScene = Prefab->GetScene(); FENaiveSceneGraphNode* RootNode = PrefabScene->SceneGraph.GetRoot(); FEEntity* NewEntity = EditorSceneWindow->GetScene()->CreateEntity(Object->GetName()); diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index 2b7984f..33f276b 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -22,22 +22,22 @@ void FEEditorInspectorWindow::InitializeResources() ImportHeightMapButton->SetSize(ImVec2(200, 0)); SculptBrushIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/sculptBrush.png", "sculptBrushIcon"); - RESOURCE_MANAGER.MakeTextureStandard(SculptBrushIcon); + RESOURCE_MANAGER.SetTag(SculptBrushIcon, EDITOR_RESOURCE_TAG); SculptBrushButton = new ImGuiImageButton(SculptBrushIcon); SculptBrushButton->SetSize(ImVec2(24, 24)); LevelBrushIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/levelBrush.png", "levelBrushIcon"); - RESOURCE_MANAGER.MakeTextureStandard(LevelBrushIcon); + RESOURCE_MANAGER.SetTag(LevelBrushIcon, EDITOR_RESOURCE_TAG); LevelBrushButton = new ImGuiImageButton(LevelBrushIcon); LevelBrushButton->SetSize(ImVec2(24, 24)); SmoothBrushIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/smoothBrush.png", "smoothBrushIcon"); - RESOURCE_MANAGER.MakeTextureStandard(SmoothBrushIcon); + RESOURCE_MANAGER.SetTag(SmoothBrushIcon, EDITOR_RESOURCE_TAG); SmoothBrushButton = new ImGuiImageButton(SmoothBrushIcon); SmoothBrushButton->SetSize(ImVec2(24, 24)); DrawBrushIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/paintbrush.png", "drawBrushIcon"); - RESOURCE_MANAGER.MakeTextureStandard(DrawBrushIcon); + RESOURCE_MANAGER.SetTag(DrawBrushIcon, EDITOR_RESOURCE_TAG); LayerBrushButton = new ImGuiImageButton(DrawBrushIcon); LayerBrushButton->SetSize(ImVec2(48, 48)); @@ -45,9 +45,9 @@ void FEEditorInspectorWindow::InitializeResources() // ************** Terrain Settings END ************** MouseCursorIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/mouseCursorIcon.png", "mouseCursorIcon"); - RESOURCE_MANAGER.MakeTextureStandard(MouseCursorIcon); + RESOURCE_MANAGER.SetTag(MouseCursorIcon, EDITOR_RESOURCE_TAG); ArrowToGroundIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/arrowToGroundIcon.png", "arrowToGroundIcon"); - RESOURCE_MANAGER.MakeTextureStandard(ArrowToGroundIcon); + RESOURCE_MANAGER.SetTag(ArrowToGroundIcon, EDITOR_RESOURCE_TAG); } void FEEditorInspectorWindow::Clear() @@ -971,7 +971,6 @@ void FEEditorInspectorWindow::Render() float cursorPosX = ImGui::GetCursorPosX(); ImVec2 PreviosCursorPos = ImGui::GetCursorPos(); - ImGui::SetCursorPos(ImVec2(headerWidth - ButtonSize / 8.0f - 4.0f/*- ButtonSize*/, PreviosCursorPos.y + 4.0f/*(headerHeight - ButtonSize) * 0.5f*/)); if (ImGui::Button("x", ImVec2(ButtonSize, ButtonSize))) { @@ -990,8 +989,7 @@ void FEEditorInspectorWindow::Render() if (ImGui::InputText("##Tag Edit", Buffer, 256)) { std::string NewTag = Buffer; - if (NewTag != EDITOR_SCENE_TAG) - TagComponent.SetTag(NewTag); + TagComponent.SetTag(NewTag); } } } @@ -1019,7 +1017,7 @@ void FEEditorInspectorWindow::Render() GameModelComponent.SetWireframeMode(bActive); ImGui::Text("Game Model : "); - FETexture* PreviewTexture = PREVIEW_MANAGER.GetGameModelPreview(GameModelComponent.GameModel->GetObjectID()); + FETexture* PreviewTexture = PREVIEW_MANAGER.GetGameModelPreview(GameModelComponent.GetGameModel()->GetObjectID()); if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) { @@ -1043,7 +1041,7 @@ void FEEditorInspectorWindow::Render() if (ImGui::MenuItem("Show in folder")) { - CONTENT_BROWSER_WINDOW.OpenItemParentFolder(GameModelComponent.GameModel); + CONTENT_BROWSER_WINDOW.OpenItemParentFolder(GameModelComponent.GetGameModel()); } ImGui::EndPopup(); diff --git a/EditorWindows/PrefabEditorManager.cpp b/EditorWindows/PrefabEditorManager.cpp index 927bcce..6c1803c 100644 --- a/EditorWindows/PrefabEditorManager.cpp +++ b/EditorWindows/PrefabEditorManager.cpp @@ -136,21 +136,21 @@ void FEPrefabEditorManager::Clear() void FEPrefabEditorManager::PrepareEditWinow(FEPrefab* Prefab) { - if (Prefab->Scene == nullptr) + if (Prefab->GetScene() == nullptr) return; // We don't want to open the same prefab scene twice if (PrefabWindows.find(Prefab) != PrefabWindows.end()) return; - FEScene* CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->Scene, "Scene: " + Prefab->GetName()); + FEScene* CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->GetScene(), "Scene: " + Prefab->GetName()); // Because by default camera is looking at 0,0,0 we need to place "empty" entity at 0,0,0. // To ensure that scene AABB would include some entity at 0,0,0. FEEntity* EmptyEntity = CurrentPrefabScene->CreateEntity("Empty entity"); FEAABB SceneAABB = CurrentPrefabScene->GetSceneAABB([](FEEntity* Entity) -> bool { - if (Entity->GetComponent().GetTag() == EDITOR_SCENE_TAG) + if (Entity->GetTag() == EDITOR_RESOURCE_TAG) return false; if (Entity->HasComponent()) @@ -165,7 +165,7 @@ void FEPrefabEditorManager::PrepareEditWinow(FEPrefab* Prefab) CurrentPrefabScene->DeleteEntity(EmptyEntity); FEEntity* Camera = CurrentPrefabScene->CreateEntity("Prefab scene camera"); - Camera->GetComponent().SetTag(EDITOR_SCENE_TAG); + RESOURCE_MANAGER.SetTag(Camera, EDITOR_RESOURCE_TAG); Camera->AddComponent(); FECameraComponent& CameraComponent = Camera->GetComponent(); CameraComponent.Type = 1; @@ -177,18 +177,18 @@ void FEPrefabEditorManager::PrepareEditWinow(FEPrefab* Prefab) CAMERA_SYSTEM.IndividualUpdate(Camera, 0.0); FEEntity* SkyDomeEntity = CurrentPrefabScene->CreateEntity("Prefab scene skydome"); - SkyDomeEntity->GetComponent().SetTag(EDITOR_SCENE_TAG); + RESOURCE_MANAGER.SetTag(SkyDomeEntity, EDITOR_RESOURCE_TAG); SkyDomeEntity->GetComponent().SetScale(glm::vec3(100.0f)); SkyDomeEntity->AddComponent(); FEEntity* LightEntity = CurrentPrefabScene->CreateEntity("Prefab scene light"); - LightEntity->GetComponent().SetTag(EDITOR_SCENE_TAG); + RESOURCE_MANAGER.SetTag(LightEntity, EDITOR_RESOURCE_TAG); LightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); FELightComponent& LightComponent = LightEntity->GetComponent(); LightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); LightComponent.SetIntensity(4.3f); SceneAABB = CurrentPrefabScene->GetSceneAABB([](FEEntity* Entity) -> bool { - if (Entity->GetComponent().GetTag() == EDITOR_SCENE_TAG && !Entity->HasComponent()) + if (Entity->GetTag() == EDITOR_RESOURCE_TAG && !Entity->HasComponent()) return false; if (Entity->HasComponent()) @@ -223,10 +223,10 @@ void FEPrefabEditorManager::ApplyModificationsToPrefabScene(FEPrefabSceneEditorW return; FEScene* ModifiedScene = Window->GetScene(); - Prefab->Scene->Clear(); + Prefab->GetScene()->Clear(); - SCENE_MANAGER.ImportSceneAsNode(ModifiedScene, Prefab->Scene, Prefab->Scene->SceneGraph.GetRoot(), [](FEEntity* EntityToCheck) { - return !(EntityToCheck->GetComponent().GetTag() == EDITOR_SCENE_TAG); + SCENE_MANAGER.ImportSceneAsNode(ModifiedScene, Prefab->GetScene(), Prefab->GetScene()->SceneGraph.GetRoot(), [](FEEntity* EntityToCheck) { + return !(EntityToCheck->GetTag() == EDITOR_RESOURCE_TAG); }); Prefab->SetDirtyFlag(true); diff --git a/EditorWindows/ProjectWasModifiedPopUp.cpp b/EditorWindows/ProjectWasModifiedPopUp.cpp index 575d975..219d9e8 100644 --- a/EditorWindows/ProjectWasModifiedPopUp.cpp +++ b/EditorWindows/ProjectWasModifiedPopUp.cpp @@ -38,8 +38,8 @@ void ProjectWasModifiedPopUp::Render() ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10.0f); if (ImGui::Button("Save", ImVec2(140, 0))) { - PROJECT_MANAGER.GetCurrent()->SaveScene(); - ENGINE.TakeScreenshot((PROJECT_MANAGER.GetCurrent()->GetProjectFolder() + "projectScreenShot.texture").c_str()); + PROJECT_MANAGER.GetCurrent()->SaveProject(); + ENGINE.SaveScreenshot((PROJECT_MANAGER.GetCurrent()->GetProjectFolder() + "projectScreenShot.texture").c_str(), PROJECT_MANAGER.GetCurrent()->GetScene()); ObjToWorkWith = nullptr; ImGuiModalPopup::Close(); ButtonPressed = true; diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index ed8f2c1..e802e23 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -12,22 +12,22 @@ FEEditorSceneGraphWindow::FEEditorSceneGraphWindow() void FEEditorSceneGraphWindow::InitializeResources() { EntityIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/entitySceneBrowserIcon.png", "entitySceneBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(EntityIcon); + RESOURCE_MANAGER.SetTag(EntityIcon, EDITOR_RESOURCE_TAG); InstancedEntityIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/instancedEntitySceneBrowserIcon.png", "instancedEntitySceneBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(InstancedEntityIcon); + RESOURCE_MANAGER.SetTag(InstancedEntityIcon, EDITOR_RESOURCE_TAG); DirectionalLightIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/directionalLightSceneBrowserIcon.png", "directionalLightSceneBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(DirectionalLightIcon); + RESOURCE_MANAGER.SetTag(DirectionalLightIcon, EDITOR_RESOURCE_TAG); SpotLightIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/spotLightSceneBrowserIcon.png", "spotLightSceneBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(SpotLightIcon); + RESOURCE_MANAGER.SetTag(SpotLightIcon, EDITOR_RESOURCE_TAG); PointLightIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/pointLightSceneBrowserIcon.png", "pointLightSceneBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(PointLightIcon); + RESOURCE_MANAGER.SetTag(PointLightIcon, EDITOR_RESOURCE_TAG); TerrainIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/terrainSceneBrowserIcon.png", "terrainSceneBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(TerrainIcon); + RESOURCE_MANAGER.SetTag(TerrainIcon, EDITOR_RESOURCE_TAG); CameraIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/cameraSceneBrowserIcon.png", "cameraSceneBrowserIcon"); - RESOURCE_MANAGER.MakeTextureStandard(CameraIcon); + RESOURCE_MANAGER.SetTag(CameraIcon, EDITOR_RESOURCE_TAG); } void FEEditorSceneGraphWindow::Clear() @@ -82,15 +82,15 @@ static void CreateInstancedEntityCallBack(const std::vector Selection if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) { - FEPrefab* SelectedPrefab = RESOURCE_MANAGER.GetPrefab(SelectionsResult[0]->GetObjectID()); - if (SelectedPrefab == nullptr) + FEGameModel* SelectedGameModel = RESOURCE_MANAGER.GetGameModel(SelectionsResult[0]->GetObjectID()); + if (SelectedGameModel == nullptr) return; FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); FEEntity* Entity = EDITOR.GetFocusedScene()->CreateEntity(); Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); - Entity->AddComponent(SelectedPrefab->GetComponent(0)->GameModel); + Entity->AddComponent(SelectedGameModel); Entity->AddComponent(); SELECTED.SetSelected(Entity); @@ -221,7 +221,7 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) FEEntity* CurrentEntity = SubTreeRoot->GetEntity(); if (CurrentEntity != nullptr) { - if (CurrentEntity->GetComponent().GetTag() == EDITOR_SCENE_TAG) + if (CurrentEntity->GetTag() == EDITOR_RESOURCE_TAG) return; } @@ -659,7 +659,7 @@ void FEEditorSceneGraphWindow::Render() if (bDisplaySceneAABB) { FEAABB SceneAABB = CurrentScene->GetSceneAABB([](FEEntity* Entity) -> bool { - if (Entity->GetComponent().GetTag() == EDITOR_SCENE_TAG) + if (Entity->GetTag() == EDITOR_RESOURCE_TAG) return false; if (Entity->HasComponent()) diff --git a/EditorWindows/SelectPopups.cpp b/EditorWindows/SelectPopups.cpp index e355ec0..b3b1706 100644 --- a/EditorWindows/SelectPopups.cpp +++ b/EditorWindows/SelectPopups.cpp @@ -60,7 +60,7 @@ void SelectFEObjectPopUp::Show(const FE_OBJECT_TYPE Type, void(*CallBack)(std::v { TempList = RESOURCE_MANAGER.GetMeshList(); - const std::vector StandardMeshList = RESOURCE_MANAGER.GetStandardMeshList(); + const std::vector StandardMeshList = RESOURCE_MANAGER.GetEnginePrivateMeshList(); for (size_t i = 0; i < StandardMeshList.size(); i++) { if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(RESOURCE_MANAGER.GetMesh(StandardMeshList[i]))) diff --git a/EditorWindows/ShaderEditorWindow.cpp b/EditorWindows/ShaderEditorWindow.cpp index 8421747..8e13f7c 100644 --- a/EditorWindows/ShaderEditorWindow.cpp +++ b/EditorWindows/ShaderEditorWindow.cpp @@ -457,7 +457,7 @@ void ShaderEditorWindow::ReplaceShader(FEShader* OldShader, FEShader* NewShader) } } - MaterialList = RESOURCE_MANAGER.GetStandardMaterialList(); + MaterialList = RESOURCE_MANAGER.GetEnginePrivateMaterialList(); for (size_t i = 0; i < MaterialList.size(); i++) { FEMaterial* TempMaterial = RESOURCE_MANAGER.GetMaterial(MaterialList[i]); diff --git a/FEEditor.cpp b/FEEditor.cpp index a10e501..81751ab 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -7,6 +7,7 @@ FEEditor::FEEditor() ImGuiIO& IO = ImGui::GetIO(); IO.ConfigWindowsMoveFromTitleBarOnly = true; ENGINE.SetVsyncEnabled(true); + RESOURCE_MANAGER.AddTagThatWillPreventDeletion(EDITOR_RESOURCE_TAG); } FEEditor::~FEEditor() {} @@ -329,8 +330,8 @@ void FEEditor::Render() { if (ImGui::MenuItem("Save project")) { - PROJECT_MANAGER.GetCurrent()->SaveScene(); - ENGINE.TakeScreenshot((PROJECT_MANAGER.GetCurrent()->GetProjectFolder() + "projectScreenShot.texture").c_str()); + PROJECT_MANAGER.GetCurrent()->SaveProject(); + ENGINE.SaveScreenshot((PROJECT_MANAGER.GetCurrent()->GetProjectFolder() + "projectScreenShot.texture").c_str(), PROJECT_MANAGER.GetCurrent()->GetScene()); } if (ImGui::MenuItem("Save project as...")) diff --git a/FEEditor.h b/FEEditor.h index f69fbd1..20cd993 100644 --- a/FEEditor.h +++ b/FEEditor.h @@ -8,7 +8,6 @@ class FEEditor { friend class FEEditorSceneWindow; friend class FEProjectManager; - // FIX ME! It is temporary solution friend class FEPrefabEditorManager; public: SINGLETON_PUBLIC_PART(FEEditor) diff --git a/FEEditorDragAndDropManager.cpp b/FEEditorDragAndDropManager.cpp index 5dc044e..cd88f14 100644 --- a/FEEditorDragAndDropManager.cpp +++ b/FEEditorDragAndDropManager.cpp @@ -8,10 +8,10 @@ DragAndDropManager::~DragAndDropManager() {} void DragAndDropManager::InitializeResources() { HandCursor = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/handCursor.png", "handCursor"); - RESOURCE_MANAGER.MakeTextureStandard(HandCursor); + RESOURCE_MANAGER.SetTag(HandCursor, EDITOR_RESOURCE_TAG); HandCursorUnavailable = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/handCursorUnavailable.png", "handCursorUnavailable"); - RESOURCE_MANAGER.MakeTextureStandard(HandCursorUnavailable); + RESOURCE_MANAGER.SetTag(HandCursorUnavailable, EDITOR_RESOURCE_TAG); } DragAndDropTarget* DragAndDropManager::AddTarget(const FE_OBJECT_TYPE AcceptedType, std::function Callback, void** UserData, const std::string ToolTipText) diff --git a/FEEditorDragAndDropManager.h b/FEEditorDragAndDropManager.h index fb7ecce..91cdd90 100644 --- a/FEEditorDragAndDropManager.h +++ b/FEEditorDragAndDropManager.h @@ -4,6 +4,8 @@ #include using namespace FocalEngine; +#define EDITOR_RESOURCE_TAG "EDITOR_PRIVATE_RESOURCE" + class DragAndDropTarget { friend class DragAndDropManager; diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index e6a722f..141dfe2 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -10,140 +10,140 @@ void GizmoManager::InitializeResources() { SELECTED.SetOnUpdateFunction(OnSelectedObjectUpdate); FEMesh* TransformationGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "45191B6F172E3B531978692E.model").c_str(), "transformationGizmoMesh"); - RESOURCE_MANAGER.MakeMeshStandard(TransformationGizmoMesh); + RESOURCE_MANAGER.SetTag(TransformationGizmoMesh, EDITOR_RESOURCE_TAG); // TransformationXGizmo FEMaterial* CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); - TransformationXGizmoGM = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationXGizmoGM); + TransformationXGizmoGM = RESOURCE_MANAGER.CreateGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM"); + RESOURCE_MANAGER.SetTag(TransformationXGizmoGM, EDITOR_RESOURCE_TAG); // TransformationYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); - TransformationYGizmoGM = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationYGizmoGM); + TransformationYGizmoGM = RESOURCE_MANAGER.CreateGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"); + RESOURCE_MANAGER.SetTag(TransformationYGizmoGM, EDITOR_RESOURCE_TAG); // TransformationZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); - TransformationZGizmoGM = new FEGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationZGizmoGM); + TransformationZGizmoGM = RESOURCE_MANAGER.CreateGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"); + RESOURCE_MANAGER.SetTag(TransformationZGizmoGM, EDITOR_RESOURCE_TAG); // Plane gizmos CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXYGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); - TransformationXYGizmoGM = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationXYGizmoGM); + TransformationXYGizmoGM = RESOURCE_MANAGER.CreateGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"); + RESOURCE_MANAGER.SetTag(TransformationXYGizmoGM, EDITOR_RESOURCE_TAG); CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); - TransformationYZGizmoGM = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationYZGizmoGM); + TransformationYZGizmoGM = RESOURCE_MANAGER.CreateGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"); + RESOURCE_MANAGER.SetTag(TransformationYZGizmoGM, EDITOR_RESOURCE_TAG); CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); - TransformationXZGizmoGM = new FEGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(TransformationXZGizmoGM); + TransformationXZGizmoGM = RESOURCE_MANAGER.CreateGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"); + RESOURCE_MANAGER.SetTag(TransformationXZGizmoGM, EDITOR_RESOURCE_TAG); // Scale gizmos. FEMesh* ScaleGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "637C784B2E5E5C6548190E1B.model").c_str(), "scaleGizmoMesh"); - RESOURCE_MANAGER.MakeMeshStandard(ScaleGizmoMesh); + RESOURCE_MANAGER.SetTag(ScaleGizmoMesh, EDITOR_RESOURCE_TAG); // ScaleXGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleXGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); - ScaleXGizmoGM = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(ScaleXGizmoGM); + ScaleXGizmoGM = RESOURCE_MANAGER.CreateGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM"); + RESOURCE_MANAGER.SetTag(ScaleXGizmoGM, EDITOR_RESOURCE_TAG); // ScaleYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleYGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); - ScaleYGizmoGM = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(ScaleYGizmoGM); + ScaleYGizmoGM = RESOURCE_MANAGER.CreateGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM"); + RESOURCE_MANAGER.SetTag(ScaleYGizmoGM, EDITOR_RESOURCE_TAG); // ScaleZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); - ScaleZGizmoGM = new FEGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(ScaleZGizmoGM); + ScaleZGizmoGM = RESOURCE_MANAGER.CreateGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM"); + RESOURCE_MANAGER.SetTag(ScaleZGizmoGM, EDITOR_RESOURCE_TAG); // RotateAroundAxis gizmos FEMesh* RotateGizmoMesh = RESOURCE_MANAGER.LoadFEMesh((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "19622421516E5B317E1B5360.model").c_str(), "rotateGizmoMesh"); - RESOURCE_MANAGER.MakeMeshStandard(RotateGizmoMesh); + RESOURCE_MANAGER.SetTag(RotateGizmoMesh, EDITOR_RESOURCE_TAG); // RotateXGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateXGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); - RotateXGizmoGM = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(RotateXGizmoGM); + RotateXGizmoGM = RESOURCE_MANAGER.CreateGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM"); + RESOURCE_MANAGER.SetTag(RotateXGizmoGM, EDITOR_RESOURCE_TAG); // RotateYGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateYGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); - RotateYGizmoGM = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(RotateYGizmoGM); + RotateYGizmoGM = RESOURCE_MANAGER.CreateGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM"); + RESOURCE_MANAGER.SetTag(RotateYGizmoGM, EDITOR_RESOURCE_TAG); // RotateZGizmo CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); - RESOURCE_MANAGER.MakeMaterialStandard(CurrentMaterial); + RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); - RotateZGizmoGM = new FEGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM"); - RESOURCE_MANAGER.MakeGameModelStandard(RotateZGizmoGM); + RotateZGizmoGM = RESOURCE_MANAGER.CreateGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM"); + RESOURCE_MANAGER.SetTag(RotateZGizmoGM, EDITOR_RESOURCE_TAG); TransformationGizmoIcon = RESOURCE_MANAGER.LoadFETexture((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "456A31026A1C3152181A6064.texture").c_str(), "transformationGizmoIcon"); - RESOURCE_MANAGER.MakeTextureStandard(TransformationGizmoIcon); + RESOURCE_MANAGER.SetTag(TransformationGizmoIcon, EDITOR_RESOURCE_TAG); ScaleGizmoIcon = RESOURCE_MANAGER.LoadFETexture((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "3F2118296C1E4533506A472E.texture").c_str(), "scaleGizmoIcon"); - RESOURCE_MANAGER.MakeTextureStandard(ScaleGizmoIcon); + RESOURCE_MANAGER.SetTag(ScaleGizmoIcon, EDITOR_RESOURCE_TAG); RotateGizmoIcon = RESOURCE_MANAGER.LoadFETexture((RESOURCE_MANAGER.GetDefaultResourcesFolder() + "7F6057403249580D73311B54.texture").c_str(), "rotateGizmoIcon"); - RESOURCE_MANAGER.MakeTextureStandard(RotateGizmoIcon); + RESOURCE_MANAGER.SetTag(RotateGizmoIcon, EDITOR_RESOURCE_TAG); } void GizmoManager::HideAllGizmo(FEScene* Scene) @@ -278,6 +278,12 @@ void GizmoManager::Update() auto PerSceneIterator = PerSceneData.begin(); while (PerSceneIterator != PerSceneData.end()) { + if (SCENE_MANAGER.GetScene(PerSceneIterator->first) == nullptr) + { + PerSceneIterator = PerSceneData.erase(PerSceneIterator); + continue; + } + FEGizmoSceneData* GizmoSceneData = PerSceneIterator->second; if (GizmoSceneData == nullptr) { @@ -303,51 +309,51 @@ void GizmoManager::Update() if (GizmoSceneData->GizmosState == TRANSFORM_GIZMOS) { // X Gizmos - GizmoSceneData->TransformationXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); + GizmoSceneData->TransformationXGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); if (GizmoSceneData->bTransformationXZGizmoActive || GizmoSceneData->bTransformationXYGizmoActive || GizmoSceneData->bTransformationXGizmoActive) - GizmoSceneData->TransformationXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->TransformationXGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // Y Gizmos - GizmoSceneData->TransformationYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); + GizmoSceneData->TransformationYGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); if (GizmoSceneData->bTransformationYZGizmoActive || GizmoSceneData->bTransformationXYGizmoActive || GizmoSceneData->bTransformationYGizmoActive) - GizmoSceneData->TransformationYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->TransformationYGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // Z Gizmos - GizmoSceneData->TransformationZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); + GizmoSceneData->TransformationZGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); if (GizmoSceneData->bTransformationYZGizmoActive || GizmoSceneData->bTransformationXZGizmoActive || GizmoSceneData->bTransformationZGizmoActive) - GizmoSceneData->TransformationZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->TransformationZGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // XY Gizmos - GizmoSceneData->TransformationXYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); + GizmoSceneData->TransformationXYGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); if (GizmoSceneData->bTransformationXYGizmoActive) - GizmoSceneData->TransformationXYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->TransformationXYGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // YZ Gizmos - GizmoSceneData->TransformationYZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); + GizmoSceneData->TransformationYZGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); if (GizmoSceneData->bTransformationYZGizmoActive) - GizmoSceneData->TransformationYZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->TransformationYZGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // XZ Gizmos - GizmoSceneData->TransformationXZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); + GizmoSceneData->TransformationXZGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); if (GizmoSceneData->bTransformationXZGizmoActive) - GizmoSceneData->TransformationXZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->TransformationXZGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); } else if (GizmoSceneData->GizmosState == SCALE_GIZMOS) { // X Gizmos - GizmoSceneData->ScaleXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); + GizmoSceneData->ScaleXGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); if (GizmoSceneData->bScaleXGizmoActive) - GizmoSceneData->ScaleXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->ScaleXGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // Y Gizmos - GizmoSceneData->ScaleYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); + GizmoSceneData->ScaleYGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); if (GizmoSceneData->bScaleYGizmoActive) - GizmoSceneData->ScaleYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->ScaleYGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); // Z Gizmos - GizmoSceneData->ScaleZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); + GizmoSceneData->ScaleZGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); if (GizmoSceneData->bScaleZGizmoActive) - GizmoSceneData->ScaleZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->ScaleZGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); } else if (GizmoSceneData->GizmosState == ROTATE_GIZMOS) { @@ -359,28 +365,28 @@ void GizmoManager::Update() } // X Gizmos - GizmoSceneData->RotateXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); + GizmoSceneData->RotateXGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); if (GizmoSceneData->bRotateXGizmoActive) { - GizmoSceneData->RotateXGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->RotateXGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); GizmoSceneData->RotateYGizmoEntity->GetComponent().SetVisibility(false); GizmoSceneData->RotateZGizmoEntity->GetComponent().SetVisibility(false); } // Y Gizmos - GizmoSceneData->RotateYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); + GizmoSceneData->RotateYGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); if (GizmoSceneData->bRotateYGizmoActive) { - GizmoSceneData->RotateYGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->RotateYGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); GizmoSceneData->RotateXGizmoEntity->GetComponent().SetVisibility(false); GizmoSceneData->RotateZGizmoEntity->GetComponent().SetVisibility(false); } // Z Gizmos - GizmoSceneData->RotateZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); + GizmoSceneData->RotateZGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); if (GizmoSceneData->bRotateZGizmoActive) { - GizmoSceneData->RotateZGizmoEntity->GetComponent().GameModel->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); + GizmoSceneData->RotateZGizmoEntity->GetComponent().GetGameModel()->Material->SetBaseColor(glm::vec3(1.5f, 1.5f, 0.2f)); GizmoSceneData->RotateXGizmoEntity->GetComponent().SetVisibility(false); GizmoSceneData->RotateYGizmoEntity->GetComponent().SetVisibility(false); } @@ -946,11 +952,12 @@ void GizmoManager::AddSceneData(const std::string& SceneID) PerSceneData[SceneID]->SceneID = SceneID; PerSceneData[SceneID]->ParentGizmoEntity = CurrentScene->CreateEntity("ParentGizmoEntity"); - PerSceneData[SceneID]->ParentGizmoEntity->GetComponent().SetTag(EDITOR_SCENE_TAG); + RESOURCE_MANAGER.SetTag(PerSceneData[SceneID]->ParentGizmoEntity, EDITOR_RESOURCE_TAG); PerSceneData[SceneID]->ParentGizmoGraphNode = CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->ParentGizmoEntity->GetObjectID()); // TransformationXGizmo PerSceneData[SceneID]->TransformationXGizmoEntity = CurrentScene->CreateEntity("TransformationXGizmoEntity"); + RESOURCE_MANAGER.SetTag(PerSceneData[SceneID]->TransformationXGizmoEntity, EDITOR_RESOURCE_TAG); PerSceneData[SceneID]->TransformationXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXGizmoGM")[0]); PerSceneData[SceneID]->TransformationXGizmoEntity->SetName("TransformationXGizmoEntity"); PerSceneData[SceneID]->TransformationXGizmoEntity->GetComponent().SetCastShadows(false); @@ -962,6 +969,7 @@ void GizmoManager::AddSceneData(const std::string& SceneID) // TransformationYGizmo PerSceneData[SceneID]->TransformationYGizmoEntity = CurrentScene->CreateEntity("TransformationYGizmoEntity"); + RESOURCE_MANAGER.SetTag(PerSceneData[SceneID]->TransformationYGizmoEntity, EDITOR_RESOURCE_TAG); PerSceneData[SceneID]->TransformationYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYGizmoGM")[0]); PerSceneData[SceneID]->TransformationYGizmoEntity->SetName("TransformationYGizmoEntity"); PerSceneData[SceneID]->TransformationYGizmoEntity->GetComponent().SetCastShadows(false); @@ -973,6 +981,7 @@ void GizmoManager::AddSceneData(const std::string& SceneID) // TransformationZGizmo PerSceneData[SceneID]->TransformationZGizmoEntity = CurrentScene->CreateEntity("TransformationZGizmoEntity"); + RESOURCE_MANAGER.SetTag(PerSceneData[SceneID]->TransformationZGizmoEntity, EDITOR_RESOURCE_TAG); PerSceneData[SceneID]->TransformationZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationZGizmoGM")[0]); PerSceneData[SceneID]->TransformationZGizmoEntity->SetName("TransformationZGizmoEntity"); PerSceneData[SceneID]->TransformationZGizmoEntity->GetComponent().SetCastShadows(false); @@ -984,6 +993,7 @@ void GizmoManager::AddSceneData(const std::string& SceneID) // Plane gizmos PerSceneData[SceneID]->TransformationXYGizmoEntity = CurrentScene->CreateEntity("TransformationXYGizmoEntity"); + RESOURCE_MANAGER.SetTag(PerSceneData[SceneID]->TransformationXYGizmoEntity, EDITOR_RESOURCE_TAG); PerSceneData[SceneID]->TransformationXYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXYGizmoGM")[0]); PerSceneData[SceneID]->TransformationXYGizmoEntity->SetName("TransformationXYGizmoEntity"); PerSceneData[SceneID]->TransformationXYGizmoEntity->GetComponent().SetCastShadows(false); @@ -996,6 +1006,7 @@ void GizmoManager::AddSceneData(const std::string& SceneID) CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->TransformationXYGizmoEntity->GetObjectID())->GetObjectID(), PerSceneData[SceneID]->ParentGizmoGraphNode->GetObjectID(), false); PerSceneData[SceneID]->TransformationYZGizmoEntity = CurrentScene->CreateEntity("TransformationYZGizmoEntity"); + RESOURCE_MANAGER.SetTag(PerSceneData[SceneID]->TransformationYZGizmoEntity, EDITOR_RESOURCE_TAG); PerSceneData[SceneID]->TransformationYZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationYZGizmoGM")[0]); PerSceneData[SceneID]->TransformationYZGizmoEntity->SetName("TransformationYZGizmoEntity"); PerSceneData[SceneID]->TransformationYZGizmoEntity->GetComponent().SetCastShadows(false); @@ -1008,6 +1019,7 @@ void GizmoManager::AddSceneData(const std::string& SceneID) CurrentScene->SceneGraph.MoveNode(CurrentScene->SceneGraph.GetNodeByEntityID(PerSceneData[SceneID]->TransformationYZGizmoEntity->GetObjectID())->GetObjectID(), PerSceneData[SceneID]->ParentGizmoGraphNode->GetObjectID(), false); PerSceneData[SceneID]->TransformationXZGizmoEntity = CurrentScene->CreateEntity("TransformationXZGizmoEntity"); + RESOURCE_MANAGER.SetTag(PerSceneData[SceneID]->TransformationXZGizmoEntity, EDITOR_RESOURCE_TAG); PerSceneData[SceneID]->TransformationXZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("TransformationXZGizmoGM")[0]); PerSceneData[SceneID]->TransformationXZGizmoEntity->SetName("TransformationXZGizmoEntity"); PerSceneData[SceneID]->TransformationXZGizmoEntity->GetComponent().SetCastShadows(false); @@ -1020,6 +1032,7 @@ void GizmoManager::AddSceneData(const std::string& SceneID) // ScaleXGizmo PerSceneData[SceneID]->ScaleXGizmoEntity = CurrentScene->CreateEntity("ScaleXGizmoEntity"); + RESOURCE_MANAGER.SetTag(PerSceneData[SceneID]->ScaleXGizmoEntity, EDITOR_RESOURCE_TAG); PerSceneData[SceneID]->ScaleXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleXGizmoGM")[0]); PerSceneData[SceneID]->ScaleXGizmoEntity->SetName("ScaleXGizmoEntity"); PerSceneData[SceneID]->ScaleXGizmoEntity->GetComponent().SetCastShadows(false); @@ -1031,6 +1044,7 @@ void GizmoManager::AddSceneData(const std::string& SceneID) // ScaleYGizmo PerSceneData[SceneID]->ScaleYGizmoEntity = CurrentScene->CreateEntity("ScaleYGizmoEntity"); + RESOURCE_MANAGER.SetTag(PerSceneData[SceneID]->ScaleYGizmoEntity, EDITOR_RESOURCE_TAG); PerSceneData[SceneID]->ScaleYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleYGizmoGM")[0]); PerSceneData[SceneID]->ScaleYGizmoEntity->SetName("ScaleYGizmoEntity"); PerSceneData[SceneID]->ScaleYGizmoEntity->GetComponent().SetCastShadows(false); @@ -1042,6 +1056,7 @@ void GizmoManager::AddSceneData(const std::string& SceneID) // ScaleZGizmo PerSceneData[SceneID]->ScaleZGizmoEntity = CurrentScene->CreateEntity("ScaleZGizmoEntity"); + RESOURCE_MANAGER.SetTag(PerSceneData[SceneID]->ScaleZGizmoEntity, EDITOR_RESOURCE_TAG); PerSceneData[SceneID]->ScaleZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("ScaleZGizmoGM")[0]); PerSceneData[SceneID]->ScaleZGizmoEntity->SetName("ScaleZGizmoEntity"); PerSceneData[SceneID]->ScaleZGizmoEntity->GetComponent().SetCastShadows(false); @@ -1053,6 +1068,7 @@ void GizmoManager::AddSceneData(const std::string& SceneID) // RotateXGizmo PerSceneData[SceneID]->RotateXGizmoEntity = CurrentScene->CreateEntity("RotateXGizmoEntity"); + RESOURCE_MANAGER.SetTag(PerSceneData[SceneID]->RotateXGizmoEntity, EDITOR_RESOURCE_TAG); PerSceneData[SceneID]->RotateXGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateXGizmoGM")[0]); PerSceneData[SceneID]->RotateXGizmoEntity->SetName("RotateXGizmoEntity"); PerSceneData[SceneID]->RotateXGizmoEntity->GetComponent().SetCastShadows(false); @@ -1064,6 +1080,7 @@ void GizmoManager::AddSceneData(const std::string& SceneID) // RotateYGizmo PerSceneData[SceneID]->RotateYGizmoEntity = CurrentScene->CreateEntity("RotateYGizmoEntity"); + RESOURCE_MANAGER.SetTag(PerSceneData[SceneID]->RotateYGizmoEntity, EDITOR_RESOURCE_TAG); PerSceneData[SceneID]->RotateYGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateYGizmoGM")[0]); PerSceneData[SceneID]->RotateYGizmoEntity->SetName("RotateYGizmoEntity"); PerSceneData[SceneID]->RotateYGizmoEntity->GetComponent().SetCastShadows(false); @@ -1075,6 +1092,7 @@ void GizmoManager::AddSceneData(const std::string& SceneID) // RotateZGizmo PerSceneData[SceneID]->RotateZGizmoEntity = CurrentScene->CreateEntity("RotateZGizmoEntity"); + RESOURCE_MANAGER.SetTag(PerSceneData[SceneID]->RotateZGizmoEntity, EDITOR_RESOURCE_TAG); PerSceneData[SceneID]->RotateZGizmoEntity->AddComponent(RESOURCE_MANAGER.GetGameModelByName("RotateZGizmoGM")[0]); PerSceneData[SceneID]->RotateZGizmoEntity->SetName("RotateZGizmoEntity"); PerSceneData[SceneID]->RotateZGizmoEntity->GetComponent().SetCastShadows(false); diff --git a/FEEditorHaloSelectionEffect.cpp b/FEEditorHaloSelectionEffect.cpp index acfd632..42b455f 100644 --- a/FEEditorHaloSelectionEffect.cpp +++ b/FEEditorHaloSelectionEffect.cpp @@ -9,7 +9,7 @@ FEEditorHaloSelectionEffect::~FEEditorHaloSelectionEffect() {} void FEEditorHaloSelectionEffect::InitializeResources() { HaloMaterial = RESOURCE_MANAGER.CreateMaterial("haloMaterial"); - RESOURCE_MANAGER.MakeMaterialStandard(HaloMaterial); + RESOURCE_MANAGER.SetTag(HaloMaterial, EDITOR_RESOURCE_TAG); HaloDrawObjectShader = RESOURCE_MANAGER.CreateShader("HaloDrawObjectShader", RESOURCE_MANAGER.LoadGLSL("Resources//Materials//FE_HaloDrawObject_VS.glsl").c_str(), RESOURCE_MANAGER.LoadGLSL("Resources//Materials//FE_HaloDrawObject_FS.glsl").c_str(), @@ -19,7 +19,7 @@ void FEEditorHaloSelectionEffect::InitializeResources() nullptr, "E4F5165B2E1B05321A182C77"/*"HaloDrawObjectShader"*/); - RESOURCE_MANAGER.MakeShaderStandard(HaloDrawObjectShader); + RESOURCE_MANAGER.SetTag(HaloDrawObjectShader, EDITOR_RESOURCE_TAG); HaloMaterial->Shader = HaloDrawObjectShader; HaloDrawInstancedObjectShader = RESOURCE_MANAGER.CreateShader("HaloDrawInstancedObjectShader", RESOURCE_MANAGER.LoadGLSL("Resources//Materials//FE_HaloDrawObject_INSTANCED_VS.glsl").c_str(), @@ -29,7 +29,7 @@ void FEEditorHaloSelectionEffect::InitializeResources() nullptr, nullptr, "16A2A65B2C1B013217219C67"/*"HaloDrawInstancedObjectShader"*/); - RESOURCE_MANAGER.MakeShaderStandard(HaloDrawInstancedObjectShader); + RESOURCE_MANAGER.SetTag(HaloDrawInstancedObjectShader, EDITOR_RESOURCE_TAG); HaloFinalShader = RESOURCE_MANAGER.CreateShader("HaloFinalShader", RESOURCE_MANAGER.LoadGLSL("SubSystems//FocalEngine//CoreExtensions//PostProcessEffects//FE_ScreenQuad_VS.glsl").c_str(), RESOURCE_MANAGER.LoadGLSL("Resources//Materials//FE_HaloSelectionEffect_FS.glsl").c_str(), @@ -39,7 +39,7 @@ void FEEditorHaloSelectionEffect::InitializeResources() nullptr, "4AC7365B2C1B07324721A127"/*"HaloFinalShader"*/); - RESOURCE_MANAGER.MakeShaderStandard(HaloFinalShader); + RESOURCE_MANAGER.SetTag(HaloFinalShader, EDITOR_RESOURCE_TAG); } void FEEditorHaloSelectionEffect::UpdateResources(FEScene* Scene) diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index 2c23cf3..d2bb8a4 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -1,4 +1,5 @@ #include "FEEditorPreviewManager.h" +#include "FEEditor.h" using namespace FocalEngine; FEEditorPreviewManager* FEEditorPreviewManager::Instance = nullptr; @@ -11,10 +12,11 @@ FETransformComponent FEEditorPreviewManager::OriginalTransform = FETransformComp void FEEditorPreviewManager::InitializeResources() { PreviewScene = SCENE_MANAGER.CreateScene("EditorPreviewScene"); + RESOURCE_MANAGER.SetTag(PreviewScene, EDITOR_RESOURCE_TAG); PreviewGameModel = new FEGameModel(nullptr, nullptr, "editorPreviewGameModel"); MeshPreviewMaterial = RESOURCE_MANAGER.CreateMaterial("meshPreviewMaterial"); - RESOURCE_MANAGER.MakeMaterialStandard(MeshPreviewMaterial); + RESOURCE_MANAGER.SetTag(MeshPreviewMaterial, EDITOR_RESOURCE_TAG); MeshPreviewMaterial->Shader = RESOURCE_MANAGER.CreateShader("FEMeshPreviewShader", RESOURCE_MANAGER.LoadGLSL("Resources//Materials//FE_MeshPreview_VS.glsl").c_str(), RESOURCE_MANAGER.LoadGLSL("Resources//Materials//FE_MeshPreview_FS.glsl").c_str(), nullptr, @@ -23,7 +25,7 @@ void FEEditorPreviewManager::InitializeResources() nullptr, "607A53601357077F03770357"/*"FEMeshPreviewShader"*/); - RESOURCE_MANAGER.MakeShaderStandard(MeshPreviewMaterial->Shader); + RESOURCE_MANAGER.SetTag(MeshPreviewMaterial->Shader, EDITOR_RESOURCE_TAG); PreviewEntity = PreviewScene->CreateEntity("EditorPreviewEntity"); PreviewEntity->AddComponent(PreviewGameModel); @@ -43,10 +45,9 @@ void FEEditorPreviewManager::InitializeResources() LightComponent.SetIntensity(10.0f); LightComponent.SetCastShadows(false); - // FIX ME! This scene should not have skydome. FEEntity* SkyDome = PreviewScene->CreateEntity("SkyDome"); SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); - SKY_DOME_SYSTEM.AddToEntity(SkyDome); + SkyDome->AddComponent(); SCENE_MANAGER.DeactivateScene(PreviewScene); } @@ -103,7 +104,7 @@ void FEEditorPreviewManager::CreateMeshPreview(const std::string MeshID) BeforePreviewActions(); - FEAABB MeshAABB = PreviewEntity->GetComponent().GameModel->Mesh->GetAABB(); + FEAABB MeshAABB = PreviewEntity->GetComponent().GetGameModel()->Mesh->GetAABB(); MeshAABB.Transform(PreviewEntity->GetComponent().GetWorldMatrix()); const glm::vec3 Min = MeshAABB.GetMin(); const glm::vec3 Max = MeshAABB.GetMax(); @@ -203,7 +204,7 @@ void FEEditorPreviewManager::CreateMaterialPreview(const std::string MaterialID) for (size_t i = 0; i < PrefabList.size(); i++) { FEPrefab* CurrentPrefab = RESOURCE_MANAGER.GetPrefab(PrefabList[i]); - if (CurrentPrefab->UsesMaterial(MaterialID)) + if (CurrentPrefab->IsUsingMaterial(MaterialID)) CreatePrefabPreview(CurrentPrefab->GetObjectID()); } } @@ -230,7 +231,7 @@ FETexture* FEEditorPreviewManager::GetMaterialPreview(const std::string Material { FEPrefab* CurrentPrefab = RESOURCE_MANAGER.GetPrefab(PrefabList[j]); - if (CurrentPrefab->UsesGameModel(CurrentGameModel->GetObjectID())) + if (CurrentPrefab->IsUsingGameModel(CurrentGameModel->GetObjectID())) CreatePrefabPreview(CurrentPrefab->GetObjectID()); } } @@ -261,7 +262,7 @@ void FEEditorPreviewManager::CreateGameModelPreview(const std::string GameModelI PreviewEntity->GetComponent().SetReceivingShadows(false); BeforePreviewActions(); - FEAABB MeshAABB = PreviewEntity->GetComponent().GameModel->Mesh->GetAABB(); + FEAABB MeshAABB = PreviewEntity->GetComponent().GetGameModel()->Mesh->GetAABB(); MeshAABB.Transform(PreviewEntity->GetComponent().GetWorldMatrix()); const glm::vec3 min = MeshAABB.GetMin(); const glm::vec3 max = MeshAABB.GetMax(); @@ -304,7 +305,7 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel BeforePreviewActions(); - FEAABB MeshAABB = PreviewEntity->GetComponent().GameModel->Mesh->GetAABB(); + FEAABB MeshAABB = PreviewEntity->GetComponent().GetGameModel()->Mesh->GetAABB(); MeshAABB.Transform(PreviewEntity->GetComponent().GetWorldMatrix()); const glm::vec3 min = MeshAABB.GetMin(); const glm::vec3 max = MeshAABB.GetMax(); @@ -366,17 +367,17 @@ void FEEditorPreviewManager::UpdateAllGameModelPreviews() void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) { FEPrefab* Prefab = RESOURCE_MANAGER.GetPrefab(PrefabID); - if (Prefab == nullptr || Prefab->Scene == nullptr) + if (Prefab == nullptr || Prefab->GetScene() == nullptr) return; - FEScene* CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->Scene, "Scene: " + Prefab->GetName()); + FEScene* CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->GetScene(), "Scene: " + Prefab->GetName()); // Because by default camera is looking at 0,0,0 we need to place "empty" entity at 0,0,0. // To ensure that scene AABB would include some entity at 0,0,0. CurrentPrefabScene->CreateEntity("Empty entity"); FEAABB SceneAABB = CurrentPrefabScene->GetSceneAABB([](FEEntity* Entity) -> bool { - if (Entity->GetComponent().GetTag() == EDITOR_SCENE_TAG) + if (Entity->GetTag() == EDITOR_RESOURCE_TAG) return false; if (Entity->HasComponent()) @@ -389,7 +390,7 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) }); FEEntity* Camera = CurrentPrefabScene->CreateEntity("Prefab scene camera"); - Camera->GetComponent().SetTag(EDITOR_SCENE_TAG); + RESOURCE_MANAGER.SetTag(Camera, EDITOR_RESOURCE_TAG); Camera->AddComponent(); Camera->GetComponent().SetPosition(glm::vec3(0.0, 0.0, SceneAABB.GetLongestAxisLength() * 2)); FECameraComponent& CameraComponent = Camera->GetComponent(); @@ -401,18 +402,18 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) CAMERA_SYSTEM.IndividualUpdate(Camera, 0.0); FEEntity* SkyDomeEntity = CurrentPrefabScene->CreateEntity("Prefab scene skydome"); - SkyDomeEntity->GetComponent().SetTag(EDITOR_SCENE_TAG); + RESOURCE_MANAGER.SetTag(SkyDomeEntity, EDITOR_RESOURCE_TAG); SkyDomeEntity->GetComponent().SetScale(glm::vec3(100.0f)); SkyDomeEntity->AddComponent(); FEEntity* LightEntity = CurrentPrefabScene->CreateEntity("Prefab scene light"); - LightEntity->GetComponent().SetTag(EDITOR_SCENE_TAG); + RESOURCE_MANAGER.SetTag(LightEntity, EDITOR_RESOURCE_TAG); LightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); FELightComponent& LightComponent = LightEntity->GetComponent(); LightEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); LightComponent.SetIntensity(4.3f); SceneAABB = CurrentPrefabScene->GetSceneAABB([](FEEntity* Entity) -> bool { - if (Entity->GetComponent().GetTag() == EDITOR_SCENE_TAG && !Entity->HasComponent()) + if (Entity->GetTag() == EDITOR_RESOURCE_TAG && !Entity->HasComponent()) return false; if (Entity->HasComponent()) @@ -425,7 +426,7 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) RENDERER.Render(CurrentPrefabScene); - // if we are updating preview we should delete old texture. + // If we are updating preview we should delete old texture. if (PrefabPreviewTextures.find(PrefabID) != PrefabPreviewTextures.end()) delete PrefabPreviewTextures[PrefabID]; @@ -450,28 +451,18 @@ FETexture* FEEditorPreviewManager::GetPrefabPreview(const std::string PrefabID) return RESOURCE_MANAGER.NoTexture; } - // if Prefab's dirty flag is set we need to update preview + // If Prefab's dirty flag is set we need to update preview. if (CurrentPrefab->IsDirty()) { CreatePrefabPreview(PrefabID); CurrentPrefab->SetDirtyFlag(false); } - for (int i = 0; i < CurrentPrefab->ComponentsCount(); i++) - { - // if Prefab's material dirty flag is set we need to update preview - if (CurrentPrefab->GetComponent(i)->GameModel->GetMaterial() != nullptr && CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->IsDirty()) - { - CreateMaterialPreview(CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->GetObjectID()); - CurrentPrefab->GetComponent(i)->GameModel->GetMaterial()->SetDirtyFlag(false); - } - } - - // if we somehow could not find preview, we will create it. + // If we somehow could not find preview, we will create it. if (PrefabPreviewTextures.find(PrefabID) == PrefabPreviewTextures.end()) CreatePrefabPreview(PrefabID); - // if still we don't have it + // If still we don't have it if (PrefabPreviewTextures.find(PrefabID) == PrefabPreviewTextures.end()) return RESOURCE_MANAGER.NoTexture; diff --git a/FEEditorPreviewManager.h b/FEEditorPreviewManager.h index 2fdf7bd..4a20603 100644 --- a/FEEditorPreviewManager.h +++ b/FEEditorPreviewManager.h @@ -3,8 +3,6 @@ #include "../FEngine.h" using namespace FocalEngine; -#define EDITOR_SCENE_TAG "EDITOR_PRIVATE_SCENE_ENTITY" - class FEEditorPreviewManager { friend class FEEditor; diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index 1549f4a..549e606 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -12,7 +12,7 @@ void FEEditorSelectedObject::InitializeResources() HALO_SELECTION_EFFECT.InitializeResources(); PixelAccurateSelectionMaterial = RESOURCE_MANAGER.CreateMaterial("pixelAccurateSelectionMaterial"); - RESOURCE_MANAGER.MakeMaterialStandard(PixelAccurateSelectionMaterial); + RESOURCE_MANAGER.SetTag(PixelAccurateSelectionMaterial, EDITOR_RESOURCE_TAG); FEPixelAccurateSelection = RESOURCE_MANAGER.CreateShader("FEPixelAccurateSelection", RESOURCE_MANAGER.LoadGLSL("Resources//Materials//FE_PixelAccurateSelection_VS.glsl").c_str(), RESOURCE_MANAGER.LoadGLSL("Resources//Materials//FE_PixelAccurateSelection_FS.glsl").c_str(), @@ -21,7 +21,7 @@ void FEEditorSelectedObject::InitializeResources() nullptr, nullptr, "4279660C7D3D27360358354E"/*"FEPixelAccurateSelection"*/); - RESOURCE_MANAGER.MakeShaderStandard(FEPixelAccurateSelection); + RESOURCE_MANAGER.SetTag(FEPixelAccurateSelection, EDITOR_RESOURCE_TAG); PixelAccurateSelectionMaterial->Shader = FEPixelAccurateSelection; FEPixelAccurateInstancedSelection = RESOURCE_MANAGER.CreateShader("FEPixelAccurateInstancedSelection", RESOURCE_MANAGER.LoadGLSL("Resources//Materials//FE_PixelAccurateSelection_INSTANCED_VS.glsl").c_str(), @@ -32,7 +32,7 @@ void FEEditorSelectedObject::InitializeResources() nullptr, "0E213D3542135C15471F0D6B"/*"FEPixelAccurateInstancedSelection"*/); - RESOURCE_MANAGER.MakeShaderStandard(FEPixelAccurateInstancedSelection); + RESOURCE_MANAGER.SetTag(FEPixelAccurateInstancedSelection, EDITOR_RESOURCE_TAG); const FEShaderParam ColorParam(glm::vec3(0.0f, 0.0f, 0.0f), "baseColor"); PixelAccurateSelectionMaterial->AddParameter(ColorParam); @@ -150,20 +150,7 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons FEEntity* CurrentEntity = Scene->GetEntity(EntityList[i]); if (CurrentEntity != nullptr) { - FEAABB Box; - if (CurrentEntity->HasComponent() && !CurrentEntity->HasComponent()) - { - Box = CurrentEntity->GetComponent().GameModel->GetMesh()->GetAABB().Transform(CurrentEntity->GetComponent().GetWorldMatrix()); - } - else if (CurrentEntity->HasComponent() && CurrentEntity->HasComponent()) - { - Box = INSTANCED_RENDERING_SYSTEM.GetAABB(CurrentEntity); - } - else if (CurrentEntity->HasComponent()) - { - Box = TERRAIN_SYSTEM.GetAABB(CurrentEntity); - } - + FEAABB Box = Scene->GetEntityAABB(CurrentEntity); if (Box.RayIntersect(CameraTransformComponent.GetPosition(FE_WORLD_SPACE), MouseRay, Distance)) { if (CurrentEntity->HasComponent()) @@ -188,6 +175,98 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons } } +void FEEditorSelectedObject::RenderEntitySelectionColorID(FEEntity* Entity, glm::vec3 ColorID, FEEntity* CameraEntity, FESelectionData* CurrentSelectionData) +{ + if (Entity == nullptr || CameraEntity == nullptr) + return; + + if (Entity->HasComponent()) + { + FEGameModelComponent& GameModelComponent = Entity->GetComponent(); + if (!GameModelComponent.IsVisible()) + return; + + FEMaterial* RegularMaterial = GameModelComponent.GetGameModel()->Material; + GameModelComponent.GetGameModel()->Material = PixelAccurateSelectionMaterial; + PixelAccurateSelectionMaterial->SetBaseColor(ColorID); + PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); + PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + + if (!Entity->HasComponent()) + { + RENDERER.RenderGameModelComponent(Entity, CameraEntity); + } + else if (Entity->HasComponent()) + { + // Update instanced object only if it is not in individual select mode + if (!INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(Entity)) + { + PixelAccurateSelectionMaterial->Shader = FEPixelAccurateInstancedSelection; + FEMaterial* RegularBillboardMaterials = GameModelComponent.GetGameModel()->GetBillboardMaterial(); + GameModelComponent.GetGameModel()->SetBillboardMaterial(PixelAccurateSelectionMaterial); + + FEInstancedComponent& InstancedComponent = Entity->GetComponent(); + RENDERER.RenderGameModelComponentWithInstanced(Entity, CameraEntity); + + PixelAccurateSelectionMaterial->Shader = FEPixelAccurateSelection; + GameModelComponent.GetGameModel()->SetBillboardMaterial(RegularBillboardMaterials); + } + } + + GameModelComponent.GetGameModel()->Material = RegularMaterial; + PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr); + PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr, 1); + } + else if (Entity->HasComponent()) + { + FETerrainComponent& TerrainComponent = Entity->GetComponent(); + if (!TerrainComponent.IsVisible()) + return; + + TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); + TerrainComponent.Shader->UpdateParameterData("baseColor", ColorID); + RENDERER.RenderTerrainComponent(Entity, CameraEntity); + TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); + TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); + } + else if (Entity->HasComponent() && Entity->HasComponent()) + { + PixelAccurateSelectionMaterial->Shader = FEPixelAccurateInstancedSelection; + + FEInstancedComponent& InstancedComponent = Entity->GetComponent(); + for (size_t i = 0; i < InstancedComponent.InstancedElementsData.size(); i++) + { + FEEntity* EntityWithGameModel = INSTANCED_RENDERING_SYSTEM.GetEntityWithGameModelComponent(InstancedComponent.InstancedElementsData[i]->EntityIDWithGameModelComponent); + if (EntityWithGameModel == nullptr) + continue; + + FEGameModelComponent& GameModelComponent = EntityWithGameModel->GetComponent(); + if (!GameModelComponent.IsVisible()) + continue; + + FEMaterial* RegularMaterial = GameModelComponent.GetGameModel()->Material; + GameModelComponent.GetGameModel()->Material = PixelAccurateSelectionMaterial; + PixelAccurateSelectionMaterial->SetBaseColor(ColorID); + PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); + PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + + FEMaterial* RegularBillboardMaterials = GameModelComponent.GetGameModel()->GetBillboardMaterial(); + GameModelComponent.GetGameModel()->SetBillboardMaterial(PixelAccurateSelectionMaterial); + + RENDERER.RenderGameModelComponentWithInstanced(Entity, nullptr, false, false, i); + + GameModelComponent.GetGameModel()->SetBillboardMaterial(RegularBillboardMaterials); + GameModelComponent.GetGameModel()->Material = RegularMaterial; + PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr); + PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr, 1); + } + + PixelAccurateSelectionMaterial->Shader = FEPixelAccurateSelection; + } +} + int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, const double MouseY, FEScene* Scene) { FESelectionData* CurrentSelectionData = GetSceneData(Scene->GetObjectID()); @@ -232,58 +311,10 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons int g = ((i + 1) >> 8) & 255; int b = ((i + 1) >> 16) & 255; #endif - FEEntity* PotentiallySelectedEntity = CurrentSelectionData->SceneEntitiesUnderMouse[i]; - if (PotentiallySelectedEntity->HasComponent()) - { - FEGameModelComponent& GameModelComponent = PotentiallySelectedEntity->GetComponent(); - if (!GameModelComponent.IsVisible()) - continue; - - // FIX ME! Prefab not supported - FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; - GameModelComponent.GameModel->Material = PixelAccurateSelectionMaterial; - PixelAccurateSelectionMaterial->SetBaseColor(glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); - PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); - PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - - if (!PotentiallySelectedEntity->HasComponent()) - { - RENDERER.RenderGameModelComponent(PotentiallySelectedEntity, CurrentCamera); - } - else if (PotentiallySelectedEntity->HasComponent()) - { - // Update instanced object only if it is not in individual select mode - if (!INSTANCED_RENDERING_SYSTEM.IsIndividualSelectMode(PotentiallySelectedEntity)) - { - PixelAccurateSelectionMaterial->Shader = FEPixelAccurateInstancedSelection; - FEMaterial* RegularBillboardMaterials = GameModelComponent.GameModel->GetBillboardMaterial(); - GameModelComponent.GameModel->SetBillboardMaterial(PixelAccurateSelectionMaterial); - - FEInstancedComponent& InstancedComponent = PotentiallySelectedEntity->GetComponent(); - RENDERER.RenderGameModelComponentWithInstanced(PotentiallySelectedEntity, CurrentCamera); - - PixelAccurateSelectionMaterial->Shader = FEPixelAccurateSelection; - GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterials); - } - } - - GameModelComponent.GameModel->Material = RegularMaterial; - PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr); - PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr, 1); - } - else if (PotentiallySelectedEntity->HasComponent()) - { - FETerrainComponent& TerrainComponent = PotentiallySelectedEntity->GetComponent(); - if (!TerrainComponent.IsVisible()) - continue; - TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); - TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); - RENDERER.RenderTerrainComponent(PotentiallySelectedEntity, CurrentCamera); - TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); - TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); - } + RenderEntitySelectionColorID(CurrentSelectionData->SceneEntitiesUnderMouse[i], + glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f), + CurrentCamera, CurrentSelectionData); } int LastColorShiftIndex = static_cast(CurrentSelectionData->SceneEntitiesUnderMouse.size() - 1); @@ -299,14 +330,14 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons int b = ((LastColorShiftIndex + 1) >> 16) & 255; static FEEntity* DummyEntity = Scene->CreateEntity("DummyEntity"); - DummyEntity->GetComponent().SetTag(EDITOR_SCENE_TAG); + RESOURCE_MANAGER.SetTag(DummyEntity, EDITOR_RESOURCE_TAG); if (!DummyEntity->HasComponent()) DummyEntity->AddComponent(); FEGameModelComponent& DummyGameModelComponent = DummyEntity->GetComponent(); FEGameModelComponent& OriginalGameModelComponent = InstancedSubObjectIterator->first->GetComponent(); - DummyGameModelComponent.GameModel = OriginalGameModelComponent.GameModel; + DummyGameModelComponent.SetGameModel(OriginalGameModelComponent.GetGameModel()); DummyGameModelComponent.SetVisibility(true); FEInstancedComponent& InstancedComponent = InstancedSubObjectIterator->first->GetComponent(); @@ -320,16 +351,8 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons DummyTransformComponent.SetQuaternion(Rotation); DummyTransformComponent.SetScale(Scale); - FEMaterial* RegularMaterial = OriginalGameModelComponent.GameModel->Material; - DummyGameModelComponent.GameModel->Material = PixelAccurateSelectionMaterial; - PixelAccurateSelectionMaterial->SetBaseColor(glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f)); - PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); - PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - PixelAccurateSelectionMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - - RENDERER.RenderGameModelComponent(DummyEntity, CurrentCamera); + RenderEntitySelectionColorID(DummyEntity, glm::vec3(static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f), CurrentCamera, CurrentSelectionData); - OriginalGameModelComponent.GameModel->Material = RegularMaterial; DummyGameModelComponent.SetVisibility(false); } InstancedSubObjectIterator++; @@ -407,6 +430,88 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons #endif } +void FEEditorSelectedObject::RenderEntityHaloEffectInternal(FEEntity* Entity, glm::vec3 Color, FEEntity* CameraEntity, FESelectionData* CurrentSelectionData) +{ + if (Entity == nullptr) + return; + + HALO_SELECTION_EFFECT.HaloMaterial->SetBaseColor(Color); + + if (Entity->HasComponent()) + { + FEGameModelComponent& GameModelComponent = Entity->GetComponent(); + FEMaterial* RegularMaterial = GameModelComponent.GetGameModel()->Material; + + GameModelComponent.GetGameModel()->Material = HALO_SELECTION_EFFECT.HaloMaterial; + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + + if (!Entity->HasComponent()) + { + RENDERER.RenderGameModelComponent(Entity, CameraEntity); + } + else if (Entity->HasComponent()) + { + HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawInstancedObjectShader; + + FEMaterial* RegularBillboardMaterial = GameModelComponent.GetGameModel()->GetBillboardMaterial(); + GameModelComponent.GetGameModel()->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); + + RENDERER.RenderGameModelComponentWithInstanced(Entity, CameraEntity); + + GameModelComponent.GetGameModel()->SetBillboardMaterial(RegularBillboardMaterial); + + HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; + } + + GameModelComponent.GetGameModel()->Material = RegularMaterial; + } + else if (Entity->HasComponent()) + { + FETerrainComponent& TerrainComponent = Entity->GetComponent(); + TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); + TerrainComponent.Shader->UpdateParameterData("baseColor", Color); + const float RegularLODLevel = TerrainComponent.GetLODLevel(); + TerrainComponent.SetLODLevel(0.0f); + + RENDERER.RenderTerrainComponent(Entity, CameraEntity); + + TerrainComponent.SetLODLevel(RegularLODLevel); + TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); + TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); + } + else if (Entity->HasComponent() && Entity->HasComponent()) + { + HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawInstancedObjectShader; + + FEInstancedComponent& InstancedComponent = Entity->GetComponent(); + for (size_t i = 0; i < InstancedComponent.InstancedElementsData.size(); i++) + { + FEEntity* EntityWithGameModel = INSTANCED_RENDERING_SYSTEM.GetEntityWithGameModelComponent(InstancedComponent.InstancedElementsData[i]->EntityIDWithGameModelComponent); + if (EntityWithGameModel == nullptr) + continue; + + FEGameModelComponent& GameModelComponent = EntityWithGameModel->GetComponent(); + + FEMaterial* RegularMaterial = GameModelComponent.GetGameModel()->Material; + + GameModelComponent.GetGameModel()->Material = HALO_SELECTION_EFFECT.HaloMaterial; + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); + HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + + FEMaterial* RegularBillboardMaterial = GameModelComponent.GetGameModel()->GetBillboardMaterial(); + GameModelComponent.GetGameModel()->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); + + RENDERER.RenderGameModelComponentWithInstanced(Entity, nullptr, false, false, i); + + GameModelComponent.GetGameModel()->Material = RegularMaterial; + GameModelComponent.GetGameModel()->SetBillboardMaterial(RegularBillboardMaterial); + } + + HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; + } +} + void FEEditorSelectedObject::OnCameraUpdate() const { auto SceneIterator = PerSceneData.begin(); @@ -431,7 +536,6 @@ void FEEditorSelectedObject::OnCameraUpdate() const HaloSelectionData->HaloObjectsFB->Bind(); HALO_SELECTION_EFFECT.HaloMaterial->ClearAllTexturesInfo(); - HALO_SELECTION_EFFECT.HaloMaterial->SetBaseColor(glm::vec3(1.0f, 0.25f, 0.0f)); FECameraComponent& CameraComponent = CurrentCamera->GetComponent(); RENDERER.SetViewport(0, 0, CameraComponent.GetRenderTargetWidth(), CameraComponent.GetRenderTargetHeight()); @@ -450,106 +554,43 @@ void FEEditorSelectedObject::OnCameraUpdate() const continue; } - FEEntity* ParentPrefabInstance = PREFAB_INSTANCE_SYSTEM.GetParentPrefabInstanceIfAny(SelectedEntity); - if (ParentPrefabInstance != nullptr && PREFAB_INSTANCE_SYSTEM.IsPrefabInstanceUnmodified(ParentPrefabInstance)) + // If selected entity is instanced and in individual select mode. + if (SelectedEntity->HasComponent() && CurrentSelectionData->InstancedSubObjectIndexSelected != -1) { - FENaiveSceneGraphNode* ParentPrefabInstanceNode = ParentPrefabInstance->GetParentScene()->SceneGraph.GetNodeByEntityID(ParentPrefabInstance->GetObjectID()); - std::vector PrefabElements = ParentPrefabInstanceNode->GetChildren(); - for (size_t i = 0; i < PrefabElements.size(); i++) - { - FEEntity* PrefabElement = PrefabElements[i]->GetEntity(); - if (PrefabElement->HasComponent()) - { - FEGameModelComponent& GameModelComponent = PrefabElement->GetComponent(); - FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; - - GameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - - RENDERER.RenderGameModelComponent(PrefabElement, CurrentCamera); - - GameModelComponent.GameModel->Material = RegularMaterial; - } - } - } - else - { - if (SelectedEntity->HasComponent()) - { - FEGameModelComponent& GameModelComponent = SelectedEntity->GetComponent(); - FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; - - GameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); - - if (!SelectedEntity->HasComponent()) - { - RENDERER.RenderGameModelComponent(SelectedEntity, CurrentCamera); - } - else if (SelectedEntity->HasComponent()) - { - if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1) - { - if (!CurrentSelectionData->DummyEntity->HasComponent()) - CurrentSelectionData->DummyEntity->AddComponent(); - - FEGameModelComponent& DummyGameModelComponent = CurrentSelectionData->DummyEntity->GetComponent(); - DummyGameModelComponent.GameModel = GameModelComponent.GameModel; - DummyGameModelComponent.SetVisibility(true); - - FEInstancedComponent& InstancedComponent = SelectedEntity->GetComponent(); - FETransformComponent& DummyTransformComponent = CurrentSelectionData->DummyEntity->GetComponent(); - - glm::dvec3 Position, Scale; - glm::dquat Rotation; - GEOMETRY.DecomposeMatrixToTranslationRotationScale(InstancedComponent.GetTransformedInstancedMatrix(CurrentSelectionData->InstancedSubObjectIndexSelected), Position, Rotation, Scale); - - DummyTransformComponent.SetPosition(Position); - DummyTransformComponent.SetQuaternion(Rotation); - DummyTransformComponent.SetScale(Scale); + FEGameModelComponent& GameModelComponent = SelectedEntity->GetComponent(); + + if (!CurrentSelectionData->DummyEntity->HasComponent()) + CurrentSelectionData->DummyEntity->AddComponent(); - FEMaterial* RegularMaterial = GameModelComponent.GameModel->Material; - DummyGameModelComponent.GameModel->Material = HALO_SELECTION_EFFECT.HaloMaterial; + FEGameModelComponent& DummyGameModelComponent = CurrentSelectionData->DummyEntity->GetComponent(); + DummyGameModelComponent.SetGameModel(GameModelComponent.GetGameModel()); + DummyGameModelComponent.SetVisibility(true); - HALO_SELECTION_EFFECT.HaloMaterial->SetBaseColor(glm::vec3(0.61f, 0.86f, 1.0f)); - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap()); - HALO_SELECTION_EFFECT.HaloMaterial->SetAlbedoMap(RegularMaterial->GetAlbedoMap(1), 1); + FEInstancedComponent& InstancedComponent = SelectedEntity->GetComponent(); + FETransformComponent& DummyTransformComponent = CurrentSelectionData->DummyEntity->GetComponent(); - RENDERER.RenderGameModelComponent(CurrentSelectionData->DummyEntity, CurrentCamera); + glm::dvec3 Position, Scale; + glm::dquat Rotation; + GEOMETRY.DecomposeMatrixToTranslationRotationScale(InstancedComponent.GetTransformedInstancedMatrix(CurrentSelectionData->InstancedSubObjectIndexSelected), Position, Rotation, Scale); - GameModelComponent.GameModel->Material = RegularMaterial; - DummyGameModelComponent.SetVisibility(false); - } - else - { - HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawInstancedObjectShader; - FEMaterial* RegularBillboardMaterial = GameModelComponent.GameModel->GetBillboardMaterial(); - GameModelComponent.GameModel->SetBillboardMaterial(HALO_SELECTION_EFFECT.HaloMaterial); + DummyTransformComponent.SetPosition(Position); + DummyTransformComponent.SetQuaternion(Rotation); + DummyTransformComponent.SetScale(Scale); - RENDERER.RenderGameModelComponentWithInstanced(SelectedEntity, CurrentCamera); + SELECTED.RenderEntityHaloEffectInternal(CurrentSelectionData->DummyEntity, glm::vec3(0.61f, 0.86f, 1.0f), CurrentCamera, CurrentSelectionData); - HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; - GameModelComponent.GameModel->SetBillboardMaterial(RegularBillboardMaterial); - } - } + DummyGameModelComponent.SetVisibility(false); + } + else + { + SELECTED.RenderEntityHaloEffectInternal(SelectedEntity, glm::vec3(1.0f, 0.25f, 0.0f), CurrentCamera, CurrentSelectionData); + FENaiveSceneGraphNode* SelectedEntityNode = CurrentScene->SceneGraph.GetNodeByEntityID(SelectedEntity->GetObjectID()); + std::vector AllChildren = SelectedEntityNode->GetRecursiveChildren(); - GameModelComponent.GameModel->Material = RegularMaterial; - } - else if (SelectedEntity->HasComponent()) + for (size_t i = 0; i < AllChildren.size(); i++) { - FETerrainComponent& TerrainComponent = SelectedEntity->GetComponent(); - TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); - TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f, 0.25f, 0.0f)); - const float RegularLODLevel = TerrainComponent.GetLODLevel(); - TerrainComponent.SetLODLevel(0.0f); - - RENDERER.RenderTerrainComponent(SelectedEntity, CurrentCamera); - - TerrainComponent.SetLODLevel(RegularLODLevel); - TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); - TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); + FEEntity* CurrentEntity = AllChildren[i]->GetEntity(); + SELECTED.RenderEntityHaloEffectInternal(CurrentEntity, glm::vec3(0.61f, 0.86f, 1.0f), CurrentCamera, CurrentSelectionData); } } @@ -640,7 +681,7 @@ void FEEditorSelectedObject::AddSceneData(const std::string& SceneID) if (CurrentScene->GetEntityByName("Editor_Selection_Dummy_Entity").empty()) { PerSceneData[SceneID]->DummyEntity = CurrentScene->CreateEntity("Editor_Selection_Dummy_Entity"); - PerSceneData[SceneID]->DummyEntity->GetComponent().SetTag(EDITOR_SCENE_TAG); + RESOURCE_MANAGER.SetTag(PerSceneData[SceneID]->DummyEntity, EDITOR_RESOURCE_TAG); } HALO_SELECTION_EFFECT.AddSceneData(SceneID); diff --git a/FEEditorSelectedObject.h b/FEEditorSelectedObject.h index 5eac29b..2faf931 100644 --- a/FEEditorSelectedObject.h +++ b/FEEditorSelectedObject.h @@ -77,6 +77,9 @@ class FEEditorSelectedObject void ClearAllSceneData(); void ClearSceneData(const std::string& SceneID); void AddSceneData(const std::string& SceneID); + + void RenderEntitySelectionColorID(FEEntity* Entity, glm::vec3 ColorID, FEEntity* CameraEntity, FESelectionData* CurrentSelectionData); + void RenderEntityHaloEffectInternal(FEEntity* Entity, glm::vec3 Color, FEEntity* CameraEntity, FESelectionData* CurrentSelectionData); }; #define SELECTED FEEditorSelectedObject::getInstance() \ No newline at end of file diff --git a/FEProject.cpp b/FEProject.cpp index eee8414..f6b3077 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -60,14 +60,10 @@ void FEProjectManager::CloseCurrentProject() VIRTUAL_FILE_SYSTEM.SetCurrentPath("/"); } -// FIX ME! Temporary. -#include "EditorWindows/SceneGraphWindow.h" void FEProjectManager::OpenProject(const int ProjectIndex) { PROJECT_MANAGER.SetCurrent(List[ProjectIndex]); - PROJECT_MANAGER.GetCurrent()->ProjectScene = SCENE_MANAGER.CreateScene(); - PROJECT_MANAGER.GetCurrent()->LoadScene(); - // FIX ME! Temporary. + PROJECT_MANAGER.GetCurrent()->LoadProject(); EDITOR.AddEditorScene(PROJECT_MANAGER.GetCurrent()->ProjectScene, true); EDITOR.FocusedEditorSceneID = PROJECT_MANAGER.GetCurrent()->ProjectScene->GetObjectID(); IndexChosen = -1; @@ -242,14 +238,8 @@ void FEProjectManager::DisplayProjectSelection() FILE_SYSTEM.CreateDirectory((std::string(PROJECTS_FOLDER) + std::string("/") + ProjectName + "/").c_str()); List.push_back(new FEProject(ProjectName, std::string(PROJECTS_FOLDER) + std::string("/") + ProjectName + "/")); List.back()->CreateDummyScreenshot(); - //ProjectScene->addLight(FE_DIRECTIONAL_LIGHT, "sun"); - std::fstream File; - File.open((std::string(PROJECTS_FOLDER) + std::string("/") + ProjectName + "/" + "ProjectScene->txt").c_str(), std::ios::out); - File.write(BASIC_SCENE, strlen(BASIC_SCENE)); - File.close(); - //openProject(indexChosen); - //current->saveScene(); + CreateNewProject(ProjectName, std::string(PROJECTS_FOLDER) + std::string("/") + ProjectName + "/"); ImGui::CloseCurrentPopup(); strcpy_s(ProjectName, ""); @@ -273,6 +263,73 @@ void FEProjectManager::DisplayProjectSelection() ImGui::PopStyleVar(); } +void FEProjectManager::CreateNewProject(std::string ProjectName, std::string ProjectPath) +{ + if (ProjectName.empty() || ProjectPath.empty()) + { + LOG.Add("FEProjectManager::CreateNewProject: Project name or path is empty!", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + + if (ContainProject(ProjectPath)) + { + LOG.Add("FEProjectManager::CreateNewProject: Project already exists!", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + + Json::Value Root; + std::ofstream ProjectFile; + Root["version"] = PROJECTS_FILE_VER; + + FEScene* NewScene = SCENE_MANAGER.CreateScene(ProjectName, "", false); + + FEEntity* CameraEntity = NewScene->CreateEntity("Camera"); + CameraEntity->AddComponent(); + FECameraComponent& CameraComponent = CameraEntity->GetComponent(); + CameraComponent.SetRenderTargetSize(128, 128); + CameraComponent.SetDistanceFogEnabled(false); + CAMERA_SYSTEM.SetMainCamera(CameraEntity); + FETransformComponent& CameraTransform = CameraEntity->GetComponent(); + CameraTransform.SetPosition(glm::vec3(-4.2269f, 15.7178f, 19.6429f)); + + FEEntity* SunEntity = NewScene->CreateEntity("Sun"); + SunEntity->AddComponent(FE_DIRECTIONAL_LIGHT); + FELightComponent& LightComponent = SunEntity->GetComponent(); + SunEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); + LightComponent.SetIntensity(4.0f); + LightComponent.SetCastShadows(true); + + FEEntity* SkyDome = NewScene->CreateEntity("SkyDome"); + SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); + SkyDome->AddComponent(); + + Json::Value SceneData; + Json::Value SceneDataNode; + SceneDataNode["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(NewScene); + Json::Value SceneHierarchy = NewScene->SceneGraph.ToJson([](FEEntity* Entity) -> bool { + if (Entity->GetTag() == EDITOR_RESOURCE_TAG) + return false; + + return true; + }); + SceneDataNode["Scene hierarchy"] = SceneHierarchy; + + SceneData[NewScene->GetObjectID()] = SceneDataNode; + Root["Scenes"] = SceneData; + Root["Main scene"] = NewScene->GetObjectID(); + + // Saving into file. + Json::StreamWriterBuilder Builder; + const std::string JsonFile = Json::writeString(Builder, Root); + + ProjectFile.open(ProjectPath + "scene.txt"); + ProjectFile << JsonFile; + ProjectFile.close(); + + SCENE_MANAGER.DeactivateScene(NewScene); + SCENE_MANAGER.DeleteScene(NewScene); +} + bool FEProjectManager::ContainProject(const std::string Path) { if (!FILE_SYSTEM.CheckDirectory(Path.c_str())) @@ -342,57 +399,13 @@ std::string FEProject::GetProjectFolder() return ProjectFolder; } -void FEProject::WriteTransformToJson(Json::Value& Root, const FETransformComponent* Transform) -{ - Root["position"]["X"] = Transform->GetPosition()[0]; - Root["position"]["Y"] = Transform->GetPosition()[1]; - Root["position"]["Z"] = Transform->GetPosition()[2]; - Root["rotation"]["X"] = Transform->GetRotation()[0]; - Root["rotation"]["Y"] = Transform->GetRotation()[1]; - Root["rotation"]["Z"] = Transform->GetRotation()[2]; - Root["scale"]["uniformScaling"] = Transform->IsUniformScalingSet(); - Root["scale"]["X"] = Transform->GetScale()[0]; - Root["scale"]["Y"] = Transform->GetScale()[1]; - Root["scale"]["Z"] = Transform->GetScale()[2]; -} - -void FEProject::SaveScene(bool bFullSave) +void FEProject::SaveProject(bool bFullSave) { Json::Value Root; - std::ofstream SceneFile; + std::ofstream ProjectFile; Root["version"] = PROJECTS_FILE_VER; - - // Saving scene hierarchy. - Json::Value SceneHierarchy = ProjectScene->SceneGraph.ToJson(); - - std::vector KeysToDelete; - Json::Value& SceneNodes = SceneHierarchy["Nodes"]; - - // FIX ME! Temporary. - std::vector ListOfOmitedObjects = { "gizmo", "Gizmo", "EditorPreviewEntity" }; - // Parsing scene hierarchy to delete all internal editor objects. - for (auto it = SceneNodes.begin(); it != SceneNodes.end(); it++) - { - auto test = it.key().asString(); - auto Name = SceneNodes[it.key().asString()]["Name"].asString(); - - for (size_t j = 0; j < ListOfOmitedObjects.size(); j++) - { - if (Name.find(ListOfOmitedObjects[j]) != std::string::npos) - { - KeysToDelete.push_back(it.key().asString()); - break; - } - } - } - - for (size_t i = 0; i < KeysToDelete.size(); i++) - { - SceneNodes.removeMember(KeysToDelete[i]); - } - Root["sceneHierarchy"] = SceneHierarchy; - + if (!bFullSave) { // Saving all unsaved objects. @@ -425,16 +438,19 @@ void FEProject::SaveScene(bool bFullSave) for (size_t i = 0; i < MeshList.size(); i++) { FEMesh* Mesh = RESOURCE_MANAGER.GetMesh(MeshList[i]); - MeshData[Mesh->GetObjectID()]["ID"] = Mesh->GetObjectID(); - MeshData[Mesh->GetObjectID()]["name"] = Mesh->GetName(); - MeshData[Mesh->GetObjectID()]["fileName"] = Mesh->GetObjectID() + ".model"; + if (Mesh->GetTag() == ENGINE_RESOURCE_TAG || + Mesh->GetTag() == EDITOR_RESOURCE_TAG) + continue; + + MeshData[Mesh->GetObjectID()]["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(Mesh); + MeshData[Mesh->GetObjectID()]["FileName"] = Mesh->GetObjectID() + ".model"; if (bFullSave) RESOURCE_MANAGER.SaveFEMesh(Mesh, (GetProjectFolder() + Mesh->GetObjectID() + std::string(".model")).c_str()); Mesh->SetDirtyFlag(false); } - Root["meshes"] = MeshData; + Root["Meshes"] = MeshData; // Saving Textures. std::vector TexturesList = RESOURCE_MANAGER.GetTextureList(); @@ -442,20 +458,19 @@ void FEProject::SaveScene(bool bFullSave) for (size_t i = 0; i < TexturesList.size(); i++) { FETexture* Texture = RESOURCE_MANAGER.GetTexture(TexturesList[i]); - if (!ShouldIncludeInSceneFile(Texture)) + if (Texture->GetTag() == ENGINE_RESOURCE_TAG || + Texture->GetTag() == EDITOR_RESOURCE_TAG) continue; - TexturesData[Texture->GetObjectID()]["ID"] = Texture->GetObjectID(); - TexturesData[Texture->GetObjectID()]["name"] = Texture->GetName(); - TexturesData[Texture->GetObjectID()]["fileName"] = Texture->GetObjectID() + ".texture"; - TexturesData[Texture->GetObjectID()]["type"] = Texture->GetInternalFormat(); + TexturesData[Texture->GetObjectID()]["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(Texture); + TexturesData[Texture->GetObjectID()]["FileName"] = Texture->GetObjectID() + ".texture"; if (bFullSave) RESOURCE_MANAGER.SaveFETexture(Texture, (GetProjectFolder() + Texture->GetObjectID() + std::string(".texture")).c_str()); Texture->SetDirtyFlag(false); } - Root["textures"] = TexturesData; + Root["Textures"] = TexturesData; // Saving Materials. std::vector MaterialList = RESOURCE_MANAGER.GetMaterialList(); @@ -463,34 +478,36 @@ void FEProject::SaveScene(bool bFullSave) for (size_t i = 0; i < MaterialList.size(); i++) { FEMaterial* Material = RESOURCE_MANAGER.GetMaterial(MaterialList[i]); + if (Material->GetTag() == ENGINE_RESOURCE_TAG || + Material->GetTag() == EDITOR_RESOURCE_TAG) + continue; for (size_t j = 0; j < FE_MAX_TEXTURES_PER_MATERIAL; j++) { if (Material->Textures[j] != nullptr) - MaterialData[Material->GetObjectID()]["textures"][std::to_string(j).c_str()] = Material->Textures[j]->GetObjectID(); + MaterialData[Material->GetObjectID()]["Textures"][std::to_string(j).c_str()] = Material->Textures[j]->GetObjectID(); if (Material->TextureBindings[j] != -1) - MaterialData[Material->GetObjectID()]["textureBindings"][std::to_string(j).c_str()] = Material->TextureBindings[j]; + MaterialData[Material->GetObjectID()]["Texture bindings"][std::to_string(j).c_str()] = Material->TextureBindings[j]; if (Material->TextureChannels[j] != -1) - MaterialData[Material->GetObjectID()]["textureChannels"][std::to_string(j).c_str()] = Material->TextureChannels[j]; + MaterialData[Material->GetObjectID()]["Texture channels"][std::to_string(j).c_str()] = Material->TextureChannels[j]; } - MaterialData[Material->GetObjectID()]["ID"] = Material->GetObjectID(); - MaterialData[Material->GetObjectID()]["name"] = Material->GetName(); - MaterialData[Material->GetObjectID()]["metalness"] = Material->GetMetalness(); - MaterialData[Material->GetObjectID()]["roughness"] = Material->GetRoughness(); - MaterialData[Material->GetObjectID()]["normalMapIntensity"] = Material->GetNormalMapIntensity(); - MaterialData[Material->GetObjectID()]["ambientOcclusionIntensity"] = Material->GetAmbientOcclusionIntensity(); - MaterialData[Material->GetObjectID()]["ambientOcclusionMapIntensity"] = Material->GetAmbientOcclusionMapIntensity(); - MaterialData[Material->GetObjectID()]["roughnessMapIntensity"] = Material->GetRoughnessMapIntensity(); - MaterialData[Material->GetObjectID()]["metalnessMapIntensity"] = Material->GetMetalnessMapIntensity(); - MaterialData[Material->GetObjectID()]["tiling"] = Material->GetTiling(); - MaterialData[Material->GetObjectID()]["compackPacking"] = Material->IsCompackPacking(); + MaterialData[Material->GetObjectID()]["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(Material); + MaterialData[Material->GetObjectID()]["Metalness"] = Material->GetMetalness(); + MaterialData[Material->GetObjectID()]["Roughness"] = Material->GetRoughness(); + MaterialData[Material->GetObjectID()]["NormalMap intensity"] = Material->GetNormalMapIntensity(); + MaterialData[Material->GetObjectID()]["AmbientOcclusion intensity"] = Material->GetAmbientOcclusionIntensity(); + MaterialData[Material->GetObjectID()]["AmbientOcclusionMap intensity"] = Material->GetAmbientOcclusionMapIntensity(); + MaterialData[Material->GetObjectID()]["RoughnessMap intensity"] = Material->GetRoughnessMapIntensity(); + MaterialData[Material->GetObjectID()]["MetalnessMap intensity"] = Material->GetMetalnessMapIntensity(); + MaterialData[Material->GetObjectID()]["Tiling"] = Material->GetTiling(); + MaterialData[Material->GetObjectID()]["Compack packing"] = Material->IsCompackPacking(); Material->SetDirtyFlag(false); } - Root["materials"] = MaterialData; + Root["Materials"] = MaterialData; // Saving GameModels. std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); @@ -498,31 +515,34 @@ void FEProject::SaveScene(bool bFullSave) for (size_t i = 0; i < GameModelList.size(); i++) { FEGameModel* GameModel = RESOURCE_MANAGER.GetGameModel(GameModelList[i]); - GameModelData[GameModel->GetObjectID()]["ID"] = GameModel->GetObjectID(); - GameModelData[GameModel->GetObjectID()]["name"] = GameModel->GetName(); - GameModelData[GameModel->GetObjectID()]["mesh"] = GameModel->Mesh->GetObjectID(); - GameModelData[GameModel->GetObjectID()]["material"] = GameModel->Material->GetObjectID(); - GameModelData[GameModel->GetObjectID()]["scaleFactor"] = GameModel->GetScaleFactor(); + if (GameModel->GetTag() == ENGINE_RESOURCE_TAG || + GameModel->GetTag() == EDITOR_RESOURCE_TAG) + continue; + + GameModelData[GameModel->GetObjectID()]["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(GameModel); + GameModelData[GameModel->GetObjectID()]["Mesh"] = GameModel->Mesh->GetObjectID(); + GameModelData[GameModel->GetObjectID()]["Material"] = GameModel->Material->GetObjectID(); + GameModelData[GameModel->GetObjectID()]["ScaleFactor"] = GameModel->GetScaleFactor(); - GameModelData[GameModel->GetObjectID()]["LODs"]["haveLODlevels"] = GameModel->IsUsingLOD(); + GameModelData[GameModel->GetObjectID()]["LODs"]["HaveLODlevels"] = GameModel->IsUsingLOD(); if (GameModel->IsUsingLOD()) { - GameModelData[GameModel->GetObjectID()]["LODs"]["cullDistance"] = GameModel->GetCullDistance(); - GameModelData[GameModel->GetObjectID()]["LODs"]["billboardZeroRotaion"] = GameModel->GetBillboardZeroRotaion(); + GameModelData[GameModel->GetObjectID()]["LODs"]["CullDistance"] = GameModel->GetCullDistance(); + GameModelData[GameModel->GetObjectID()]["LODs"]["Billboard zero rotaion"] = GameModel->GetBillboardZeroRotaion(); GameModelData[GameModel->GetObjectID()]["LODs"]["LODCount"] = GameModel->GetLODCount(); for (size_t j = 0; j < GameModel->GetLODCount(); j++) { - GameModelData[GameModel->GetObjectID()]["LODs"][std::to_string(j)]["mesh"] = GameModel->GetLODMesh(j)->GetObjectID(); - GameModelData[GameModel->GetObjectID()]["LODs"][std::to_string(j)]["maxDrawDistance"] = GameModel->GetLODMaxDrawDistance(j); - GameModelData[GameModel->GetObjectID()]["LODs"][std::to_string(j)]["isBillboard"] = GameModel->IsLODBillboard(j); + GameModelData[GameModel->GetObjectID()]["LODs"][std::to_string(j)]["Mesh"] = GameModel->GetLODMesh(j)->GetObjectID(); + GameModelData[GameModel->GetObjectID()]["LODs"][std::to_string(j)]["Max draw distance"] = GameModel->GetLODMaxDrawDistance(j); + GameModelData[GameModel->GetObjectID()]["LODs"][std::to_string(j)]["IsBillboard"] = GameModel->IsLODBillboard(j); if (GameModel->IsLODBillboard(j)) - GameModelData[GameModel->GetObjectID()]["LODs"][std::to_string(j)]["billboardMaterial"] = GameModel->GetBillboardMaterial()->GetObjectID(); + GameModelData[GameModel->GetObjectID()]["LODs"][std::to_string(j)]["Billboard material"] = GameModel->GetBillboardMaterial()->GetObjectID(); } } GameModel->SetDirtyFlag(false); } - Root["gameModels"] = GameModelData; + Root["GameModels"] = GameModelData; // Saving Prefabs. std::vector PrefabList = RESOURCE_MANAGER.GetPrefabList(); @@ -530,314 +550,62 @@ void FEProject::SaveScene(bool bFullSave) for (size_t i = 0; i < PrefabList.size(); i++) { FEPrefab* Prefab = RESOURCE_MANAGER.GetPrefab(PrefabList[i]); - PrefabData[Prefab->GetObjectID()]["ID"] = Prefab->GetObjectID(); - PrefabData[Prefab->GetObjectID()]["name"] = Prefab->GetName(); + if (Prefab->GetTag() == ENGINE_RESOURCE_TAG || + Prefab->GetTag() == EDITOR_RESOURCE_TAG) + continue; - Json::Value ComponentsData; - for (int j = 0; j < Prefab->ComponentsCount(); j++) - { - ComponentsData[j]["gameModel"]["ID"] = Prefab->GetComponent(j)->GameModel->GetObjectID(); - WriteTransformToJson(ComponentsData[j]["transformation"], &Prefab->GetComponent(j)->Transform); - } + PrefabData[Prefab->GetObjectID()]["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(Prefab); - PrefabData[Prefab->GetObjectID()]["components"] = ComponentsData; + Json::Value PrefabSceneData; + PrefabSceneData["ID"] = Prefab->GetScene()->GetObjectID(); + Json::Value SceneHierarchy = Prefab->GetScene()->SceneGraph.ToJson(); + PrefabSceneData["Scene hierarchy"] = SceneHierarchy; + PrefabData[Prefab->GetObjectID()]["Scene"] = PrefabSceneData; } - Root["prefabs"] = PrefabData; - - // Saving Entities. - //std::vector EntityList = ProjectScene->GetEntityList(); - //Json::Value EntityData; - //for (size_t i = 0; i < EntityList.size(); i++) - //{ - // FEEntity* Entity = ProjectScene->GetEntity(EntityList[i]); - // if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(Entity)) - // continue; - - // // Temporary solution, becuase of the lack of proper ECS system - // bool bOmit = false; - // for (size_t j = 0; j < ListOfOmitedObjects.size(); j++) - // { - // if (Entity->GetName().find(ListOfOmitedObjects[j]) != std::string::npos) - // { - // bOmit = true; - // break; - // } - // } - // if (bOmit) - // continue; - - // EntityData[Entity->GetObjectID()]["ID"] = Entity->GetObjectID(); - // EntityData[Entity->GetObjectID()]["type"] = FEObjectTypeToString(Entity->GetType()); - // EntityData[Entity->GetObjectID()]["name"] = Entity->GetName(); - // EntityData[Entity->GetObjectID()]["visible"] = Entity->IsVisible(); - // // Temporary solution, because of the lack of proper ECS system - // if (Entity->Prefab != nullptr) - // { - // EntityData[Entity->GetObjectID()]["prefab"] = Entity->Prefab->GetObjectID(); - // } - // else - // { - // EntityData[Entity->GetObjectID()]["prefab"] = "none"; - // } - // //WriteTransformToJson(EntityData[Entity->GetObjectID()]["transformation"], &Entity->Transform); - - // //if (Entity->GetType() == FE_ENTITY_INSTANCED_DEPRECATED) - // //{ - // // FEEntityInstanced* InstancedEntity = reinterpret_cast(Entity); - // // EntityData[Entity->GetObjectID()]["modificationsToSpawn"] = InstancedEntity->GetSpawnModificationCount() == 0 ? false : true; - // // if (InstancedEntity->GetSpawnModificationCount()) - // // { - // // std::ofstream InfoFile; - // // Json::Value EntityFileRoot; - // // InfoFile.open(ProjectFolder + Entity->GetObjectID() + ".txt"); - - // // Json::Value ModificationsData; - // // auto ModificationList = InstancedEntity->GetSpawnModifications(); - // // for (int j = 0; j < ModificationList.size(); j++) - // // { - // // ModificationsData[j]["type"] = static_cast(ModificationList[j].Type); - // // ModificationsData[j]["index"] = ModificationList[j].Index; - // // if (ModificationList[j].Type != FE_CHANGE_DELETED) - // // { - // // for (int k = 0; k < 4; k++) - // // { - // // for (int p = 0; p < 4; p++) - // // { - // // ModificationsData[j]["modification"][k][p] = ModificationList[j].Modification[k][p]; - // // } - // // } - // // } - // // } - // // EntityFileRoot["modifications"] = ModificationsData; - - // // InfoFile << EntityFileRoot; - // // InfoFile.close(); - // // } - - // // EntityData[Entity->GetObjectID()]["spawnInfo"]["seed"] = InstancedEntity->SpawnInfo.Seed; - // // EntityData[Entity->GetObjectID()]["spawnInfo"]["objectCount"] = InstancedEntity->SpawnInfo.ObjectCount; - // // EntityData[Entity->GetObjectID()]["spawnInfo"]["radius"] = InstancedEntity->SpawnInfo.Radius; - // // EntityData[Entity->GetObjectID()]["spawnInfo"]["minScale"] = InstancedEntity->SpawnInfo.GetMinScale(); - // // EntityData[Entity->GetObjectID()]["spawnInfo"]["maxScale"] = InstancedEntity->SpawnInfo.GetMaxScale(); - // // EntityData[Entity->GetObjectID()]["spawnInfo"]["rotationDeviation.x"] = InstancedEntity->SpawnInfo.RotationDeviation.x; - // // EntityData[Entity->GetObjectID()]["spawnInfo"]["rotationDeviation.y"] = InstancedEntity->SpawnInfo.RotationDeviation.y; - // // EntityData[Entity->GetObjectID()]["spawnInfo"]["rotationDeviation.z"] = InstancedEntity->SpawnInfo.RotationDeviation.z; - // // if (InstancedEntity->GetSnappedToTerrain() == nullptr) - // // { - // // EntityData[Entity->GetObjectID()]["snappedToTerrain"] = "none"; - // // } - // // else - // // { - // // // FIX ME! - // // //EntityData[Entity->GetObjectID()]["snappedToTerrain"] = InstancedEntity->GetSnappedToTerrain()->GetObjectID(); - // // EntityData[Entity->GetObjectID()]["terrainLayer"] = InstancedEntity->GetTerrainLayer(); - // // EntityData[Entity->GetObjectID()]["minimalLayerIntensity"] = InstancedEntity->GetMinimalLayerIntensity(); - // // } - // //} - - // Entity->SetDirtyFlag(false); - //} - //Root["entities"] = EntityData; - - // Saving Terrains. - std::vector TerrainList = ProjectScene->GetEntityIDListWith(); - Json::Value TerrainData; - for (size_t i = 0; i < TerrainList.size(); i++) - { - FEEntity* Terrain = ProjectScene->GetEntity(TerrainList[i]); - FETerrainComponent& TerrainComponent = Terrain->GetComponent(); + Root["Prefabs"] = PrefabData; - TerrainData[Terrain->GetObjectID()]["ID"] = Terrain->GetObjectID(); - TerrainData[Terrain->GetObjectID()]["name"] = Terrain->GetName(); - - TerrainData[Terrain->GetObjectID()]["heightMap"]["ID"] = TerrainComponent.HeightMap->GetObjectID(); - TerrainData[Terrain->GetObjectID()]["heightMap"]["name"] = TerrainComponent.HeightMap->GetName(); - TerrainData[Terrain->GetObjectID()]["heightMap"]["fileName"] = TerrainComponent.HeightMap->GetObjectID() + ".texture"; - RESOURCE_MANAGER.SaveFETexture(TerrainComponent.HeightMap, (GetProjectFolder() + TerrainComponent.HeightMap->GetObjectID() + std::string(".texture")).c_str()); - - TerrainData[Terrain->GetObjectID()]["hightScale"] = TerrainComponent.GetHightScale(); - TerrainData[Terrain->GetObjectID()]["displacementScale"] = TerrainComponent.GetDisplacementScale(); - TerrainData[Terrain->GetObjectID()]["tileMult"]["X"] = TerrainComponent.GetTileMult().x; - TerrainData[Terrain->GetObjectID()]["tileMult"]["Y"] = TerrainComponent.GetTileMult().y; - TerrainData[Terrain->GetObjectID()]["LODlevel"] = TerrainComponent.GetLODLevel(); - TerrainData[Terrain->GetObjectID()]["chunkPerSide"] = TerrainComponent.GetChunkPerSide(); - - // FIX ME! - WriteTransformToJson(TerrainData[Terrain->GetObjectID()]["transformation"], &Terrain->GetComponent()); - //WriteTransformToJson(TerrainData[Terrain->GetObjectID()]["transformation"], &Terrain->Transform); - - // Saving terrains Layers. - for (int j = 0; j < TerrainComponent.LayerMaps.size(); j++) - { - if (TerrainComponent.LayerMaps[j] != nullptr) - { - TerrainData[Terrain->GetObjectID()]["layerMaps"][j]["ID"] = TerrainComponent.LayerMaps[j]->GetObjectID(); - TerrainData[Terrain->GetObjectID()]["layerMaps"][j]["name"] = TerrainComponent.LayerMaps[j]->GetName(); - TerrainData[Terrain->GetObjectID()]["layerMaps"][j]["fileName"] = TerrainComponent.LayerMaps[j]->GetObjectID() + ".texture"; - RESOURCE_MANAGER.SaveFETexture(TerrainComponent.LayerMaps[j], (GetProjectFolder() + TerrainComponent.LayerMaps[j]->GetObjectID() + std::string(".texture")).c_str()); - } - } - - for (int j = 0; j < FE_TERRAIN_MAX_LAYERS; j++) - { - FETerrainLayer* CurrentLayer = TerrainComponent.GetLayerInSlot(j); - if (CurrentLayer == nullptr) - { - TerrainData[Terrain->GetObjectID()]["layers"][j]["acive"] = false; - break; - } + // Saving scenes. + std::vector SceneList = SCENE_MANAGER.GetAllScenes(); + Json::Value SceneData; + for (size_t i = 0; i < SceneList.size(); i++) + { + if (SceneList[i]->GetTag() == ENGINE_RESOURCE_TAG || + SceneList[i]->GetTag() == EDITOR_RESOURCE_TAG) + continue; + + Json::Value SceneDataNode; + SceneDataNode["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(SceneList[i]); + Json::Value SceneHierarchy = SceneList[i]->SceneGraph.ToJson([](FEEntity* Entity) -> bool { + if (Entity->GetTag() == EDITOR_RESOURCE_TAG) + return false; - TerrainData[Terrain->GetObjectID()]["layers"][j]["acive"] = true; - TerrainData[Terrain->GetObjectID()]["layers"][j]["name"] = CurrentLayer->GetMaterial()->GetName(); - TerrainData[Terrain->GetObjectID()]["layers"][j]["materialID"] = CurrentLayer->GetMaterial()->GetObjectID(); - } + return true; + }); + SceneDataNode["Scene hierarchy"] = SceneHierarchy; - Terrain->SetDirtyFlag(false); + SceneData[SceneList[i]->GetObjectID()] = SceneDataNode; } - Root["terrains"] = TerrainData; - - //// Saving Lights. - //std::vector LightList = ProjectScene->GetLightsList(); - //Json::Value LightData; - //for (size_t i = 0; i < LightList.size(); i++) - //{ - // FELight* Light = ProjectScene->GetLight(LightList[i]); - - // // general light information - // LightData[Light->GetObjectID()]["ID"] = Light->GetObjectID(); - // LightData[Light->GetObjectID()]["type"] = Light->GetType(); - // LightData[Light->GetObjectID()]["name"] = Light->GetName(); - // LightData[Light->GetObjectID()]["intensity"] = Light->GetIntensity(); - // WriteTransformToJson(LightData[Light->GetObjectID()]["transformation"], &Light->Transform); - // LightData[Light->GetObjectID()]["castShadows"] = Light->IsCastShadows(); - // LightData[Light->GetObjectID()]["enabled"] = Light->IsLightEnabled(); - // LightData[Light->GetObjectID()]["color"]["R"] = Light->GetColor()[0]; - // LightData[Light->GetObjectID()]["color"]["G"] = Light->GetColor()[1]; - // LightData[Light->GetObjectID()]["color"]["B"] = Light->GetColor()[2]; - // LightData[Light->GetObjectID()]["staticShadowBias"] = Light->IsStaticShadowBias(); - // LightData[Light->GetObjectID()]["shadowBias"] = Light->GetShadowBias(); - // LightData[Light->GetObjectID()]["shadowBiasVariableIntensity"] = Light->GetShadowBiasVariableIntensity(); - // LightData[Light->GetObjectID()]["shadowBlurFactor"] = Light->GetShadowBlurFactor(); - - // // Type specific information. - // if (Light->GetType() == FE_DIRECTIONAL_LIGHT) - // { - // FEDirectionalLight* DirectionalLight = reinterpret_cast(Light); - - // LightData[DirectionalLight->GetObjectID()]["direction"]["X"] = DirectionalLight->GetDirection()[0]; - // LightData[DirectionalLight->GetObjectID()]["direction"]["Y"] = DirectionalLight->GetDirection()[1]; - // LightData[DirectionalLight->GetObjectID()]["direction"]["Z"] = DirectionalLight->GetDirection()[2]; - // LightData[DirectionalLight->GetObjectID()]["CSM"]["activeCascades"] = DirectionalLight->GetActiveCascades(); - // LightData[DirectionalLight->GetObjectID()]["CSM"]["shadowCoverage"] = DirectionalLight->GetShadowCoverage(); - // LightData[DirectionalLight->GetObjectID()]["CSM"]["CSMZDepth"] = DirectionalLight->GetCSMZDepth(); - // LightData[DirectionalLight->GetObjectID()]["CSM"]["CSMXYDepth"] = DirectionalLight->GetCSMXYDepth(); - // } - // else if (Light->GetType() == FE_SPOT_LIGHT) - // { - // FESpotLight* SpotLight = reinterpret_cast(Light); - - // LightData[SpotLight->GetObjectID()]["spotAngle"] = SpotLight->GetSpotAngle(); - // LightData[SpotLight->GetObjectID()]["spotAngleOuter"] = SpotLight->GetSpotAngleOuter(); - // LightData[SpotLight->GetObjectID()]["direction"]["X"] = SpotLight->GetDirection()[0]; - // LightData[SpotLight->GetObjectID()]["direction"]["Y"] = SpotLight->GetDirection()[1]; - // LightData[SpotLight->GetObjectID()]["direction"]["Z"] = SpotLight->GetDirection()[2]; - // } - // else if (Light->GetType() == FE_POINT_LIGHT) - // { - // FEPointLight* PointLight = reinterpret_cast(Light); - - // LightData[PointLight->GetObjectID()]["range"] = PointLight->GetRange(); - // } - //} - //Root["lights"] = LightData; - - // Saving Effects settings. - Json::Value EffectsData; - // *********** Gamma Correction & Exposure *********** - //EffectsData["Gamma Correction & Exposure"]["Gamma"] = ENGINE.GetCamera()->GetGamma(); - //EffectsData["Gamma Correction & Exposure"]["Exposure"] = ENGINE.GetCamera()->GetExposure(); - // *********** Anti-Aliasing(FXAA) *********** - //EffectsData["Anti-Aliasing(FXAA)"]["FXAASpanMax"] = RENDERER.GetFXAASpanMax(); - //EffectsData["Anti-Aliasing(FXAA)"]["FXAAReduceMin"] = RENDERER.GetFXAAReduceMin(); - //EffectsData["Anti-Aliasing(FXAA)"]["FXAAReduceMul"] = RENDERER.GetFXAAReduceMul(); - // *********** Bloom *********** - //EffectsData["Bloom"]["thresholdBrightness"] = RENDERER.GetBloomThreshold(); - //EffectsData["Bloom"]["BloomSize"] = RENDERER.GetBloomSize(); - // *********** Depth of Field *********** - /*EffectsData["Depth of Field"]["Near distance"] = RENDERER.GetDOFNearDistance(); - EffectsData["Depth of Field"]["Far distance"] = RENDERER.GetDOFFarDistance(); - EffectsData["Depth of Field"]["Strength"] = RENDERER.GetDOFStrength(); - EffectsData["Depth of Field"]["Distance dependent strength"] = RENDERER.GetDOFDistanceDependentStrength();*/ - // *********** Distance fog *********** - //EffectsData["Distance fog"]["isDistanceFogEnabled"] = RENDERER.IsDistanceFogEnabled(); - //EffectsData["Distance fog"]["Density"] = RENDERER.GetDistanceFogDensity(); - //EffectsData["Distance fog"]["Gradient"] = RENDERER.GetDistanceFogGradient(); - // *********** Chromatic Aberration *********** - //EffectsData["Chromatic Aberration"]["Shift strength"] = RENDERER.GetChromaticAberrationIntensity(); - // *********** Sky *********** - //EffectsData["Sky"]["Enabled"] = RENDERER.IsSkyEnabled() ? 1.0f : 0.0f; - //EffectsData["Sky"]["Sphere size"] = RENDERER.GetDistanceToSky(); - - Root["effects"] = EffectsData; - - // Saving Camera settings. - Json::Value CameraData; - - /*CameraData["position"]["X"] = ENGINE.GetCamera()->GetPosition()[0]; - CameraData["position"]["Y"] = ENGINE.GetCamera()->GetPosition()[1]; - CameraData["position"]["Z"] = ENGINE.GetCamera()->GetPosition()[2]; - - CameraData["fov"] = ENGINE.GetCamera()->GetFov(); - CameraData["nearPlane"] = ENGINE.GetCamera()->GetNearPlane(); - CameraData["farPlane"] = ENGINE.GetCamera()->GetFarPlane(); - - CameraData["yaw"] = ENGINE.GetCamera()->GetYaw(); - CameraData["pitch"] = ENGINE.GetCamera()->GetPitch(); - CameraData["roll"] = ENGINE.GetCamera()->GetRoll(); - - CameraData["aspectRatio"] = ENGINE.GetCamera()->GetAspectRatio(); - - CameraData["movementSpeed"] = ENGINE.GetCamera()->GetMovementSpeed();*/ - - Root["camera"] = CameraData; + Root["Scenes"] = SceneData; + Root["Main scene"] = ProjectScene->GetObjectID(); // Saving into file. Json::StreamWriterBuilder Builder; const std::string JsonFile = Json::writeString(Builder, Root); - SceneFile.open(ProjectFolder + "ProjectScene->txt"); - SceneFile << JsonFile; - SceneFile.close(); + ProjectFile.open(ProjectFolder + "scene.txt"); + ProjectFile << JsonFile; + ProjectFile.close(); for (size_t i = 0; i < FilesToDelete.size(); i++) { FILE_SYSTEM.DeleteFile(FilesToDelete[i].c_str()); } - // VFS VIRTUAL_FILE_SYSTEM.SaveState(ProjectFolder + "VFS.txt"); - bModified = false; } -void FEProject::ReadTransformToJson(Json::Value& Root, FETransformComponent* Transform) -{ - Transform->SetPosition(glm::vec3(Root["position"]["X"].asFloat(), - Root["position"]["Y"].asFloat(), - Root["position"]["Z"].asFloat())); - - Transform->SetRotation(glm::vec3(Root["rotation"]["X"].asFloat(), - Root["rotation"]["Y"].asFloat(), - Root["rotation"]["Z"].asFloat())); - - Transform->SetUniformScaling(Root["scale"]["uniformScaling"].asBool()); - - Transform->SetScale(glm::vec3(Root["scale"]["X"].asFloat(), - Root["scale"]["Y"].asFloat(), - Root["scale"]["Z"].asFloat())); -} - -void FEProject::LoadScene() +void FEProject::LoadProject() { std::ifstream SceneFile; SceneFile.open(ProjectFolder + "Scene.txt"); @@ -864,52 +632,52 @@ void FEProject::LoadScene() LOG.Add("Can't find version in scene file of project from " + ProjectFolder, "FE_LOG_LOADING", FE_LOG_WARNING); return; } - else if (ProjectVersion == 0.01f) - { - // Do nothing. - } } - // Loading Meshes - std::vector MeshList = Root["meshes"].getMemberNames(); + // Loading meshes. + std::vector MeshList = Root["Meshes"].getMemberNames(); for (size_t i = 0; i < MeshList.size(); i++) { - RESOURCE_MANAGER.LoadFEMesh((ProjectFolder + Root["meshes"][MeshList[i]]["fileName"].asCString()).c_str(), Root["meshes"][MeshList[i]]["name"].asCString()); + FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Meshes"][MeshList[i]]["FEObjectData"]); + RESOURCE_MANAGER.LoadFEMesh((ProjectFolder + Root["Meshes"][MeshList[i]]["FileName"].asCString()).c_str(), LoadedObjectData.Name); } - // loading Textures - std::vector TexturesList = Root["textures"].getMemberNames(); + // Loading textures. + std::vector TexturesList = Root["Textures"].getMemberNames(); for (size_t i = 0; i < TexturesList.size(); i++) { - // read type of texture if it is not standard then skip it. - if (Root["textures"][TexturesList[i]]["type"] == 33322) + FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Textures"][TexturesList[i]]["FEObjectData"]); + // Terrain textures should be loaded right away, not async. + if (LoadedObjectData.Tag == TERRAIN_SYSTEM_RESOURCE_TAG) { - continue; + RESOURCE_MANAGER.LoadFETexture((ProjectFolder + Root["Textures"][TexturesList[i]]["FileName"].asCString()).c_str()); + } + else + { + RESOURCE_MANAGER.LoadFETextureAsync((ProjectFolder + Root["Textures"][TexturesList[i]]["FileName"].asCString()).c_str(), LoadedObjectData.Name, nullptr, LoadedObjectData.ID); } - - RESOURCE_MANAGER.LoadFETextureAsync((ProjectFolder + Root["textures"][TexturesList[i]]["fileName"].asCString()).c_str(), Root["textures"][TexturesList[i]]["name"].asString(), nullptr, Root["textures"][TexturesList[i]]["ID"].asString()); } - // loading Materials - std::vector MaterialsList = Root["materials"].getMemberNames(); + // Loading materials. + std::vector MaterialsList = Root["Materials"].getMemberNames(); for (size_t i = 0; i < MaterialsList.size(); i++) { - FEMaterial* NewMaterial = RESOURCE_MANAGER.CreateMaterial(Root["materials"][MaterialsList[i]]["name"].asString(), Root["materials"][MaterialsList[i]]["ID"].asString()); - - //newMat->shader = RESOURCE_MANAGER.getShader("FEPhongShader"); - //newMat->shader = RESOURCE_MANAGER.getShader("FESolidColorShader"); + FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Materials"][MaterialsList[i]]["FEObjectData"]); + + FEMaterial* NewMaterial = RESOURCE_MANAGER.CreateMaterial(LoadedObjectData.Name, LoadedObjectData.ID); + RESOURCE_MANAGER.SetTag(NewMaterial, LoadedObjectData.Tag); NewMaterial->Shader = RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/); - std::vector MembersList = Root["materials"][MaterialsList[i]].getMemberNames(); + std::vector MembersList = Root["Materials"][MaterialsList[i]].getMemberNames(); for (size_t j = 0; j < MembersList.size(); j++) { - if (MembersList[j] == "textures") + if (MembersList[j] == "Textures") { for (size_t k = 0; k < FE_MAX_TEXTURES_PER_MATERIAL; k++) { - if (Root["materials"][MaterialsList[i]]["textures"].isMember(std::to_string(k).c_str())) + if (Root["Materials"][MaterialsList[i]]["Textures"].isMember(std::to_string(k).c_str())) { - std::string TextureID = Root["materials"][MaterialsList[i]]["textures"][std::to_string(k).c_str()].asCString(); + std::string TextureID = Root["Materials"][MaterialsList[i]]["Textures"][std::to_string(k).c_str()].asCString(); NewMaterial->Textures[k] = RESOURCE_MANAGER.GetTexture(TextureID); if (NewMaterial->Textures[k] == nullptr) NewMaterial->Textures[k] = RESOURCE_MANAGER.NoTexture; @@ -917,492 +685,135 @@ void FEProject::LoadScene() } } - if (MembersList[j] == "textureBindings") + if (MembersList[j] == "Texture bindings") { for (size_t k = 0; k < FE_MAX_TEXTURES_PER_MATERIAL; k++) { - if (Root["materials"][MaterialsList[i]]["textureBindings"].isMember(std::to_string(k).c_str())) + if (Root["Materials"][MaterialsList[i]]["Texture bindings"].isMember(std::to_string(k).c_str())) { - int Binding = Root["materials"][MaterialsList[i]]["textureBindings"][std::to_string(k).c_str()].asInt(); + int Binding = Root["Materials"][MaterialsList[i]]["Texture bindings"][std::to_string(k).c_str()].asInt(); NewMaterial->TextureBindings[k] = Binding; } } } - if (MembersList[j] == "textureChannels") + if (MembersList[j] == "Texture channels") { for (size_t k = 0; k < FE_MAX_TEXTURES_PER_MATERIAL; k++) { - if (Root["materials"][MaterialsList[i]]["textureChannels"].isMember(std::to_string(k).c_str())) + if (Root["Materials"][MaterialsList[i]]["Texture channels"].isMember(std::to_string(k).c_str())) { - int binding = Root["materials"][MaterialsList[i]]["textureChannels"][std::to_string(k).c_str()].asInt(); + int binding = Root["Materials"][MaterialsList[i]]["Texture channels"][std::to_string(k).c_str()].asInt(); NewMaterial->TextureChannels[k] = binding; } } } } - NewMaterial->SetMetalness(Root["materials"][MaterialsList[i]]["metalness"].asFloat()); - NewMaterial->SetRoughness(Root["materials"][MaterialsList[i]]["roughness"].asFloat()); - NewMaterial->SetNormalMapIntensity(Root["materials"][MaterialsList[i]]["normalMapIntensity"].asFloat()); - NewMaterial->SetAmbientOcclusionIntensity(Root["materials"][MaterialsList[i]]["ambientOcclusionIntensity"].asFloat()); - NewMaterial->SetAmbientOcclusionMapIntensity(Root["materials"][MaterialsList[i]]["ambientOcclusionMapIntensity"].asFloat()); - NewMaterial->SetRoughnessMapIntensity(Root["materials"][MaterialsList[i]]["roughnessMapIntensity"].asFloat()); - NewMaterial->SetMetalnessMapIntensity(Root["materials"][MaterialsList[i]]["metalnessMapIntensity"].asFloat()); + NewMaterial->SetMetalness(Root["Materials"][MaterialsList[i]]["Metalness"].asFloat()); + NewMaterial->SetRoughness(Root["Materials"][MaterialsList[i]]["Roughness"].asFloat()); + NewMaterial->SetNormalMapIntensity(Root["Materials"][MaterialsList[i]]["NormalMap intensity"].asFloat()); + NewMaterial->SetAmbientOcclusionIntensity(Root["Materials"][MaterialsList[i]]["AmbientOcclusion intensity"].asFloat()); + NewMaterial->SetAmbientOcclusionMapIntensity(Root["Materials"][MaterialsList[i]]["AmbientOcclusionMap intensity"].asFloat()); + NewMaterial->SetRoughnessMapIntensity(Root["Materials"][MaterialsList[i]]["RoughnessMap intensity"].asFloat()); + NewMaterial->SetMetalnessMapIntensity(Root["Materials"][MaterialsList[i]]["MetalnessMap intensity"].asFloat()); - if (ProjectVersion >= 0.02f) - { - if (Root["materials"][MaterialsList[i]].isMember("tiling")) - NewMaterial->SetTiling(Root["materials"][MaterialsList[i]]["tiling"].asFloat()); - NewMaterial->SetCompackPacking(Root["materials"][MaterialsList[i]]["compackPacking"].asBool()); - } + if (Root["Materials"][MaterialsList[i]].isMember("Tiling")) + NewMaterial->SetTiling(Root["Materials"][MaterialsList[i]]["Tiling"].asFloat()); + NewMaterial->SetCompackPacking(Root["Materials"][MaterialsList[i]]["Compack packing"].asBool()); } - // loading gameModels - std::vector GameModelList = Root["gameModels"].getMemberNames(); + // Loading game models. + std::vector GameModelList = Root["GameModels"].getMemberNames(); for (size_t i = 0; i < GameModelList.size(); i++) { - FEGameModel* NewGameModel = RESOURCE_MANAGER.CreateGameModel(RESOURCE_MANAGER.GetMesh(Root["gameModels"][GameModelList[i]]["mesh"].asCString()), - RESOURCE_MANAGER.GetMaterial(Root["gameModels"][GameModelList[i]]["material"].asCString()), - Root["gameModels"][GameModelList[i]]["name"].asString(), Root["gameModels"][GameModelList[i]]["ID"].asString()); + FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["GameModels"][GameModelList[i]]["FEObjectData"]); + + FEGameModel* NewGameModel = RESOURCE_MANAGER.CreateGameModel(RESOURCE_MANAGER.GetMesh(Root["GameModels"][GameModelList[i]]["Mesh"].asCString()), + RESOURCE_MANAGER.GetMaterial(Root["GameModels"][GameModelList[i]]["Material"].asCString()), + LoadedObjectData.Name, LoadedObjectData.ID); + RESOURCE_MANAGER.SetTag(NewGameModel, LoadedObjectData.Tag); - NewGameModel->SetScaleFactor(Root["gameModels"][GameModelList[i]]["scaleFactor"].asFloat()); + NewGameModel->SetScaleFactor(Root["GameModels"][GameModelList[i]]["ScaleFactor"].asFloat()); - bool bHaveLODLevels = Root["gameModels"][GameModelList[i]]["LODs"]["haveLODlevels"].asBool(); + bool bHaveLODLevels = Root["GameModels"][GameModelList[i]]["LODs"]["HaveLODlevels"].asBool(); NewGameModel->SetUsingLOD(bHaveLODLevels); if (bHaveLODLevels) { - NewGameModel->SetCullDistance(Root["gameModels"][GameModelList[i]]["LODs"]["cullDistance"].asFloat()); - NewGameModel->SetBillboardZeroRotaion(Root["gameModels"][GameModelList[i]]["LODs"]["billboardZeroRotaion"].asFloat()); + NewGameModel->SetCullDistance(Root["GameModels"][GameModelList[i]]["LODs"]["CullDistance"].asFloat()); + NewGameModel->SetBillboardZeroRotaion(Root["GameModels"][GameModelList[i]]["LODs"]["Billboard zero rotaion"].asFloat()); - size_t LODCount = Root["gameModels"][GameModelList[i]]["LODs"]["LODCount"].asInt(); + size_t LODCount = Root["GameModels"][GameModelList[i]]["LODs"]["LODCount"].asInt(); for (size_t j = 0; j < LODCount; j++) { - NewGameModel->SetLODMesh(j, RESOURCE_MANAGER.GetMesh(Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["mesh"].asString())); - NewGameModel->SetLODMaxDrawDistance(j, Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["maxDrawDistance"].asFloat()); + NewGameModel->SetLODMesh(j, RESOURCE_MANAGER.GetMesh(Root["GameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["Mesh"].asString())); + NewGameModel->SetLODMaxDrawDistance(j, Root["GameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["Max draw distance"].asFloat()); - bool bLODBillboard = Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["isBillboard"].asBool(); + bool bLODBillboard = Root["GameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["IsBillboard"].asBool(); NewGameModel->SetIsLODBillboard(j, bLODBillboard); if (bLODBillboard) - NewGameModel->SetBillboardMaterial(RESOURCE_MANAGER.GetMaterial(Root["gameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["billboardMaterial"].asString())); + NewGameModel->SetBillboardMaterial(RESOURCE_MANAGER.GetMaterial(Root["GameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["Billboard material"].asString())); } } } - // loading prefabs - std::vector PrefabList = Root["prefabs"].getMemberNames(); + // Loading prefabs. + std::unordered_map PrefabToSceneMap; + std::vector PrefabList = Root["Prefabs"].getMemberNames(); for (size_t i = 0; i < PrefabList.size(); i++) { - FEPrefab* NewPrefab = RESOURCE_MANAGER.CreatePrefab(nullptr, Root["prefabs"][PrefabList[i]]["name"].asString(), Root["prefabs"][PrefabList[i]]["ID"].asString()); - - if (Root["prefabs"][PrefabList[i]].isMember("components")) - { - Json::Value Components = Root["prefabs"][PrefabList[i]]["components"]; - for (int j = 0; j < static_cast(Components.size()); j++) - { - FETransformComponent ComponentTransform; - ReadTransformToJson(Components[j]["transformation"], &ComponentTransform); + FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Prefabs"][PrefabList[i]]["FEObjectData"]); + + FEPrefab* NewPrefab = RESOURCE_MANAGER.CreatePrefab(LoadedObjectData.Name, LoadedObjectData.ID); + RESOURCE_MANAGER.SetTag(NewPrefab, LoadedObjectData.Tag); - NewPrefab->AddComponent(RESOURCE_MANAGER.GetGameModel(Components[j]["gameModel"]["ID"].asCString()), ComponentTransform); - } - } + // At this point we are just reading scene ID. + std::string SceneID = Root["Prefabs"][PrefabList[i]]["Scene"]["ID"].asCString(); + // So we need to store them in map and load them later. + PrefabToSceneMap[SceneID] = NewPrefab; } - // Loading Terrains. - std::vector TerrainList = Root["terrains"].getMemberNames(); - for (size_t i = 0; i < TerrainList.size(); i++) + // Loading all prefab scenes. + std::vector SceneList = Root["Scenes"].getMemberNames(); + for (size_t i = 0; i < SceneList.size(); i++) { - FEEntity* Entity = ProjectScene->CreateEntity(Root["terrains"][TerrainList[i]]["name"].asString(), Root["terrains"][TerrainList[i]]["ID"].asString()); - FETransformComponent& TransformComponent = Entity->GetComponent(); - Entity->AddComponent(); - FETerrainComponent& TerrainComponent = Entity->GetComponent(); - TERRAIN_SYSTEM.LoadHeightMap((ProjectFolder + Root["terrains"][TerrainList[i]]["heightMap"]["fileName"].asCString()).c_str(), Entity); - - TerrainComponent.SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); - TerrainComponent.SetDisplacementScale(Root["terrains"][TerrainList[i]]["displacementScale"].asFloat()); - glm::vec2 TileMult; - TileMult.x = Root["terrains"][TerrainList[i]]["tileMult"]["X"].asFloat(); - TileMult.y = Root["terrains"][TerrainList[i]]["tileMult"]["Y"].asFloat(); - TerrainComponent.SetTileMult(TileMult); - TerrainComponent.SetLODLevel(Root["terrains"][TerrainList[i]]["LODlevel"].asFloat()); - TerrainComponent.SetChunkPerSide(Root["terrains"][TerrainList[i]]["chunkPerSide"].asFloat()); - TerrainComponent.SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); - TerrainComponent.SetHightScale(Root["terrains"][TerrainList[i]]["hightScale"].asFloat()); - ReadTransformToJson(Root["terrains"][TerrainList[i]]["transformation"], &TransformComponent); - - if (ProjectVersion >= 0.02f) - { - for (int j = 0; j < FE_TERRAIN_MAX_LAYERS / FE_TERRAIN_LAYER_PER_TEXTURE; j++) - { - if (Root["terrains"][TerrainList[i]].isMember("layerMaps")) - { - FETexture* LoadedTexture = RESOURCE_MANAGER.LoadFETexture((ProjectFolder + Root["terrains"][TerrainList[i]]["layerMaps"][j]["fileName"].asCString()).c_str(), Root["terrains"][TerrainList[i]]["layerMaps"][j]["name"].asString()); - TerrainComponent.LayerMaps[j] = LoadedTexture; - } - } - - for (int j = 0; j < FE_TERRAIN_MAX_LAYERS; j++) - { - if (Root["terrains"][TerrainList[i]]["layers"][j]["acive"].asBool()) - { - TERRAIN_SYSTEM.ActivateVacantLayerSlot(Entity, RESOURCE_MANAGER.GetMaterial(Root["terrains"][TerrainList[i]]["layers"][j]["materialID"].asCString())); - TerrainComponent.GetLayerInSlot(j)->SetName(Root["terrains"][TerrainList[i]]["layers"][j]["name"].asCString()); - } - } - } - } - - // Loading entities. - std::vector EntityList = Root["entities"].getMemberNames(); - for (size_t i = 0; i < EntityList.size(); i++) - { - FEEntity* Entity = ProjectScene->CreateEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); - - if (Root["entities"][EntityList[i]].isMember("type")) - { - if (Root["entities"][EntityList[i]]["type"] == "FE_ENTITY_INSTANCED") - { - // FIX ME! Converting Prefab to GameModels. - FEEntity* EntityWithFirstPrefab = Entity; - FEPrefab* OldPrefab = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()); - - if (OldPrefab->ComponentsCount() > 1) - { - OldPrefab->Scene = SCENE_MANAGER.CreateScene(OldPrefab->GetName(), "", false); - //OldPrefab->Scene->ImportEntity(Entity); - } - - for (size_t c = 0; c < OldPrefab->ComponentsCount(); c++) - { - if (c > 0) - { - Entity = ProjectScene->CreateEntity(Root["entities"][EntityList[i]]["name"].asString() + "_Prefabs_" + std::to_string(c)); - //OldPrefab->Scene->ImportEntity(Entity); - } - FEPrefabComponent* CurrentComponent = OldPrefab->GetComponent(static_cast(c)); - FEGameModel* GameModel = CurrentComponent->GameModel; - - Entity->AddComponent(GameModel); - FEGameModelComponent& GameModelComponent = Entity->GetComponent(); - Entity->AddComponent(); - FEInstancedComponent& InstancedComponent = Entity->GetComponent(); - - if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) - GameModelComponent.SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); - - ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &Entity->GetComponent()); - // FIX ME! - Entity->GetComponent().Combine(CurrentComponent->Transform); - - FESpawnInfo SpawnInfo; - SpawnInfo.Seed = Root["entities"][EntityList[i]]["spawnInfo"]["seed"].asInt(); - SpawnInfo.ObjectCount = Root["entities"][EntityList[i]]["spawnInfo"]["objectCount"].asInt(); - SpawnInfo.Radius = Root["entities"][EntityList[i]]["spawnInfo"]["radius"].asFloat(); - SpawnInfo.SetMinScale(Root["entities"][EntityList[i]]["spawnInfo"]["minScale"].asFloat()); - SpawnInfo.SetMaxScale(Root["entities"][EntityList[i]]["spawnInfo"]["maxScale"].asFloat()); - SpawnInfo.RotationDeviation.x = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.x"].asFloat(); - SpawnInfo.RotationDeviation.y = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.y"].asFloat(); - SpawnInfo.RotationDeviation.z = Root["entities"][EntityList[i]]["spawnInfo"]["rotationDeviation.z"].asFloat(); - - if (Root["entities"][EntityList[i]]["snappedToTerrain"].asString() != "none") - { - FEEntity* TerrainEntity = ProjectScene->GetEntity(Root["entities"][EntityList[i]]["snappedToTerrain"].asString()); - TERRAIN_SYSTEM.SnapInstancedEntity(TerrainEntity, Entity); - - if (Root["entities"][EntityList[i]].isMember("terrainLayer")) - { - if (Root["entities"][EntityList[i]]["terrainLayer"].asInt() != -1) - { - TERRAIN_SYSTEM.ConnectInstancedEntityToLayer(TerrainEntity, Entity, Root["entities"][EntityList[i]]["terrainLayer"].asInt()); - } - - InstancedComponent.SetMinimalLayerIntensityToSpawn(Root["entities"][EntityList[i]]["minimalLayerIntensity"].asFloat()); - } - } - - // FIX ME! That should be done after all entities are loaded. - // And scene was updated. - INSTANCED_RENDERING_SYSTEM.PopulateInstance(Entity, SpawnInfo); - - if (Root["entities"][EntityList[i]]["modificationsToSpawn"].asBool()) - { - std::ifstream InfoFile; - InfoFile.open(ProjectFolder + EntityWithFirstPrefab->GetObjectID() + ".txt"); - - std::string InfoFileData((std::istreambuf_iterator(InfoFile)), std::istreambuf_iterator()); - - Json::Value EntityFileRoot; - JSONCPP_STRING Err; - Json::CharReaderBuilder Builder; - - const std::unique_ptr Reader(Builder.newCharReader()); - if (!Reader->parse(InfoFileData.c_str(), InfoFileData.c_str() + InfoFileData.size(), &EntityFileRoot, &Err)) - return; - - size_t Count = EntityFileRoot["modifications"].size(); - for (int j = 0; j < Count; j++) - { - if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_DELETED) - { - INSTANCED_RENDERING_SYSTEM.DeleteIndividualInstance(Entity, EntityFileRoot["modifications"][j]["index"].asInt()); - } - else if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_MODIFIED) - { - glm::mat4 ModifedMatrix; - for (int k = 0; k < 4; k++) - { - for (int p = 0; p < 4; p++) - { - ModifedMatrix[k][p] = EntityFileRoot["modifications"][j]["modification"][k][p].asFloat(); - } - } - - INSTANCED_RENDERING_SYSTEM.ModifyIndividualInstance(Entity, EntityFileRoot["modifications"][j]["index"].asInt(), ModifedMatrix); - } - else if (EntityFileRoot["modifications"][j]["type"].asInt() == FE_CHANGE_ADDED) - { - glm::mat4 ModifedMatrix; - for (int k = 0; k < 4; k++) - { - for (int p = 0; p < 4; p++) - { - ModifedMatrix[k][p] = EntityFileRoot["modifications"][j]["modification"][k][p].asFloat(); - } - } - - INSTANCED_RENDERING_SYSTEM.AddIndividualInstance(Entity, ModifedMatrix); - } - } - } - - if (OldPrefab->ComponentsCount() > 1) - { - FEEntity* ImportedEntity = OldPrefab->Scene->ImportEntity(Entity); - - if (ImportedEntity->HasComponent()) - { - ImportedEntity->RemoveComponent(); - } - } - } - } - else - { - // FIX ME! Delete - FEPrefab* OldPrefab = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()); - OldPrefab->Scene = SCENE_MANAGER.CreateScene(OldPrefab->GetName(), "", false); - - // For compatibility with old projects. - if (Root["entities"][EntityList[i]].isMember("gameModel")) - { - //FEPrefab* TempPrefab = RESOURCE_MANAGER.CreatePrefab(RESOURCE_MANAGER.GetGameModel(Root["entities"][EntityList[i]]["gameModel"].asCString())); - //ProjectScene->CreateEntity(TempPrefab, Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); - - FEGameModel* GameModel = RESOURCE_MANAGER.GetGameModel(Root["entities"][EntityList[i]]["gameModel"].asCString()); - Entity->AddComponent(GameModel); - } - else - { - /*ProjectScene->CreateEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), - Root["entities"][EntityList[i]]["name"].asString(), - Root["entities"][EntityList[i]]["ID"].asString());*/ - - FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString())->GetComponent(0)->GameModel; - Entity->AddComponent(GameModel); - } - - if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) - { - //ProjectScene->GetEntity(EntityList[i])->SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); - Entity->GetComponent().SetVisibility(Root["entities"][EntityList[i]]["visible"].asBool()); - } - - ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &Entity->GetComponent()); - /*ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &ProjectScene->GetEntity(EntityList[i])->Transform); - FEEntity* Entity = ProjectScene->GetNewStyleEntityByOldStyleID(EntityList[i]); - if (Entity != nullptr) - { - Entity->GetComponent() = ProjectScene->GetEntity(EntityList[i])->Transform; - }*/ - - OldPrefab->Scene->ImportEntity(Entity); - } - } - // For compatibility with old projects. - else - { - //FEEntity* Entity = ProjectScene->CreateEntity(Root["entities"][EntityList[i]]["name"].asString(), Root["entities"][EntityList[i]]["ID"].asString()); - FEGameModel* GameModel = RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString())->GetComponent(0)->GameModel; - Entity->AddComponent(GameModel); - ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &Entity->GetComponent()); - - /*ProjectScene->CreateEntity(RESOURCE_MANAGER.GetPrefab(Root["entities"][EntityList[i]]["prefab"].asCString()), - EntityList[i], - Root["entities"][EntityList[i]]["ID"].asString()); - ReadTransformToJson(Root["entities"][EntityList[i]]["transformation"], &ProjectScene->GetEntity(EntityList[i])->Transform);*/ - } - } + FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Scenes"][SceneList[i]]["FEObjectData"]); + bool bPrefabScene = PrefabToSceneMap.find(LoadedObjectData.ID) != PrefabToSceneMap.end(); + if (!bPrefabScene) + continue; - if (abs(ProjectVersion - 0.025f) <= FLT_EPSILON) - { - // Loading scene hierarchy. - ProjectScene->SceneGraph.FromJson(Root["sceneHierarchy"]); - } + FEScene* NewScene = SCENE_MANAGER.CreateScene(LoadedObjectData.Name, LoadedObjectData.ID, false); + RESOURCE_MANAGER.SetTag(NewScene, LoadedObjectData.Tag); - // Loading Lights. - std::vector LightList = Root["lights"].getMemberNames(); - for (size_t i = 0; i < LightList.size(); i++) - { - FEEntity* Entity = ProjectScene->CreateEntity("Light Entity"); - auto OldType = static_cast(Root["lights"][LightList[i]]["type"].asInt()); - FE_LIGHT_TYPE NewType = FE_DIRECTIONAL_LIGHT; - if (OldType == FE_POINT_LIGHT_DEPRECATED) - { - NewType = FE_POINT_LIGHT; - } - else if (OldType == FE_SPOT_LIGHT_DEPRECATED) - { - NewType = FE_SPOT_LIGHT; - } - Entity->AddComponent(NewType); - FELightComponent& LightComponent = Entity->GetComponent(); - - LightComponent.SetIntensity(Root["lights"][LightList[i]]["intensity"].asFloat()); - ReadTransformToJson(Root["lights"][LightList[i]]["transformation"], &Entity->GetComponent()); - LightComponent.SetCastShadows(Root["lights"][LightList[i]]["castShadows"].asBool()); - LightComponent.SetLightEnabled(Root["lights"][LightList[i]]["enabled"].asBool()); - LightComponent.SetColor(glm::vec3(Root["lights"][LightList[i]]["color"]["R"].asFloat(), - Root["lights"][LightList[i]]["color"]["G"].asFloat(), - Root["lights"][LightList[i]]["color"]["B"].asFloat())); - LightComponent.SetIsStaticShadowBias(Root["lights"][LightList[i]]["staticShadowBias"].asBool()); - LightComponent.SetShadowBias(Root["lights"][LightList[i]]["shadowBias"].asFloat()); - LightComponent.SetShadowBiasVariableIntensity(Root["lights"][LightList[i]]["shadowBiasVariableIntensity"].asFloat()); - if (ProjectVersion >= 0.02f && Root["lights"][LightList[i]].isMember("shadowBlurFactor")) - LightComponent.SetShadowBlurFactor(Root["lights"][LightList[i]]["shadowBlurFactor"].asFloat()); - - if (LightComponent.GetType() == FE_POINT_LIGHT) - { - LightComponent.SetRange(Root["lights"][LightList[i]]["range"].asFloat()); - } - else if (LightComponent.GetType() == FE_SPOT_LIGHT) - { - LightComponent.SetSpotAngle(Root["lights"][LightList[i]]["spotAngle"].asFloat()); - LightComponent.SetSpotAngleOuter(Root["lights"][LightList[i]]["spotAngleOuter"].asFloat()); - - LightComponent.SetSpotAngle(Root["lights"][LightList[i]]["spotAngle"].asFloat()); - LightComponent.SetSpotAngleOuter(Root["lights"][LightList[i]]["spotAngleOuter"].asFloat()); - } - else if (LightComponent.GetType() == FE_DIRECTIONAL_LIGHT) - { - LightComponent.SetActiveCascades(Root["lights"][LightList[i]]["CSM"]["activeCascades"].asInt()); - LightComponent.SetShadowCoverage(Root["lights"][LightList[i]]["CSM"]["shadowCoverage"].asFloat()); - LightComponent.SetCSMZDepth(Root["lights"][LightList[i]]["CSM"]["CSMZDepth"].asFloat()); - LightComponent.SetCSMXYDepth(Root["lights"][LightList[i]]["CSM"]["CSMXYDepth"].asFloat()); - - LightComponent.SetActiveCascades(Root["lights"][LightList[i]]["CSM"]["activeCascades"].asInt()); - LightComponent.SetShadowCoverage(Root["lights"][LightList[i]]["CSM"]["shadowCoverage"].asFloat()); - LightComponent.SetCSMZDepth(Root["lights"][LightList[i]]["CSM"]["CSMZDepth"].asFloat()); - LightComponent.SetCSMXYDepth(Root["lights"][LightList[i]]["CSM"]["CSMXYDepth"].asFloat()); - } + NewScene->SceneGraph.FromJson(Root["Scenes"][SceneList[i]]["Scene hierarchy"]); } - // loading Effects settings - // *********** Gamma Correction & Exposure *********** - //ENGINE.GetCamera()->SetGamma(Root["effects"]["Gamma Correction & Exposure"]["Gamma"].asFloat()); - //ENGINE.GetCamera()->SetExposure(Root["effects"]["Gamma Correction & Exposure"]["Exposure"].asFloat()); - // *********** Anti-Aliasing(FXAA) *********** - //RENDERER.SetFXAASpanMax(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAASpanMax"].asFloat()); - //RENDERER.SetFXAAReduceMin(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAAReduceMin"].asFloat()); - //RENDERER.SetFXAAReduceMul(Root["effects"]["Anti-Aliasing(FXAA)"]["FXAAReduceMul"].asFloat()); - // *********** Bloom *********** - //PPEffect = RENDERER.getPostProcessEffect("bloom"); - //RENDERER.SetBloomThreshold(Root["effects"]["Bloom"]["thresholdBrightness"].asFloat()); - //RENDERER.SetBloomSize(Root["effects"]["Bloom"]["BloomSize"].asFloat()); - // *********** Depth of Field *********** - /*RENDERER.SetDOFNearDistance(Root["effects"]["Depth of Field"]["Near distance"].asFloat()); - RENDERER.SetDOFFarDistance(Root["effects"]["Depth of Field"]["Far distance"].asFloat()); - RENDERER.SetDOFStrength(Root["effects"]["Depth of Field"]["Strength"].asFloat()); - RENDERER.SetDOFDistanceDependentStrength(Root["effects"]["Depth of Field"]["Distance dependent strength"].asFloat());*/ - // *********** Distance fog *********** - /*if (Root["effects"]["Distance fog"].isMember("isDistanceFogEnabled")) + // Now we can connect prefabs with scenes. + for (auto& Pair : PrefabToSceneMap) { - RENDERER.SetDistanceFogEnabled(Root["effects"]["Distance fog"]["isDistanceFogEnabled"].asBool()); + Pair.second->SetScene(SCENE_MANAGER.GetScene(Pair.first)); } - else + + // Only after all prefabs are connected with scenes we can load other scenes. + std::string MainSceneID = Root["Main scene"].asString(); + for (size_t i = 0; i < SceneList.size(); i++) { - RENDERER.SetDistanceFogEnabled(Root["effects"]["Distance fog"]["Density"].asFloat() > -1.0f ? true : false); - } - RENDERER.SetDistanceFogDensity(Root["effects"]["Distance fog"]["Density"].asFloat()); - RENDERER.SetDistanceFogGradient(Root["effects"]["Distance fog"]["Gradient"].asFloat());*/ - // *********** Chromatic Aberration *********** - //RENDERER.SetChromaticAberrationIntensity(Root["effects"]["Chromatic Aberration"]["Shift strength"].asFloat()); - // *********** Sky *********** - //SKY_DOME_SYSTEM.SetEnabled(Root["effects"]["Sky"]["Enabled"].asFloat() > 0.0f ? true : false); - //SKY_DOME_SYSTEM.SetDistanceToSky(Root["effects"]["Sky"]["Sphere size"].asFloat()); - //Fix Me! - FEEntity* SkyDome = ProjectScene->CreateEntity("SkyDome"); - SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); - SKY_DOME_SYSTEM.AddToEntity(SkyDome); + FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Scenes"][SceneList[i]]["FEObjectData"]); + bool bPrefabScene = PrefabToSceneMap.find(LoadedObjectData.ID) != PrefabToSceneMap.end(); + if (bPrefabScene) + continue; - // Loading Camera. - FEEntity* Entity = ProjectScene->CreateEntity("Camera Entity"); - Entity->AddComponent(); - FECameraComponent& CameraComponent = Entity->GetComponent(); - if (Root["effects"]["Distance fog"].isMember("isDistanceFogEnabled")) - { - CameraComponent.SetDistanceFogEnabled(Root["effects"]["Distance fog"]["isDistanceFogEnabled"].asBool()); + bool bShouldBeActive = LoadedObjectData.ID == MainSceneID; + FEScene* NewScene = SCENE_MANAGER.CreateScene(LoadedObjectData.Name, LoadedObjectData.ID, bShouldBeActive); + RESOURCE_MANAGER.SetTag(NewScene, LoadedObjectData.Tag); + + NewScene->SceneGraph.FromJson(Root["Scenes"][SceneList[i]]["Scene hierarchy"]); } - else - { - CameraComponent.SetDistanceFogEnabled(Root["effects"]["Distance fog"]["Density"].asFloat() > -1.0f ? true : false); - } - - // Will work in future. - //ReadTransformToJson(Root["camera"]["transformation"], &Entity->GetComponent()); - - glm::vec3 CameraPosition = glm::vec3(Root["camera"]["position"]["X"].asFloat(), - Root["camera"]["position"]["Y"].asFloat(), - Root["camera"]["position"]["Z"].asFloat()); - - Entity->GetComponent().SetPosition(CameraPosition); - - //ENGINE.GetCamera()->SetPosition(CameraPosition); - - //ENGINE.GetCamera()->SetFov(Root["camera"]["fov"].asFloat()); - CameraComponent.SetFOV(50.680f); - //ENGINE.GetCamera()->SetNearPlane(Root["camera"]["nearPlane"].asFloat()); - CameraComponent.SetNearPlane(Root["camera"]["nearPlane"].asFloat()); - //ENGINE.GetCamera()->SetFarPlane(Root["camera"]["farPlane"].asFloat()); - CameraComponent.SetFarPlane(Root["camera"]["farPlane"].asFloat()); - - glm::vec3 CameraRotation = glm::vec3(Root["camera"]["yaw"].asFloat(), - Root["camera"]["pitch"].asFloat(), - Root["camera"]["roll"].asFloat()); - - Entity->GetComponent().SetRotation(glm::vec3(-CameraRotation.y, -CameraRotation.x, CameraRotation.z)); - // FIX ME! This is temporary solution. - CameraComponent.CurrentMouseXAngle = -CameraRotation.x; - CameraComponent.CurrentMouseYAngle = -CameraRotation.y; - - /*ENGINE.GetCamera()->SetYaw(CameraRotation.x); - ENGINE.GetCamera()->SetPitch(CameraRotation.y); - ENGINE.GetCamera()->SetRoll(CameraRotation.z);*/ - - //ENGINE.GetCamera()->SetAspectRatio(Root["camera"]["aspectRatio"].asFloat()); - CameraComponent.SetAspectRatio(Root["camera"]["aspectRatio"].asFloat()); - - CAMERA_SYSTEM.SetMainCamera(Entity); - //if (ProjectVersion >= 0.02f && Root["camera"].isMember("movementSpeed")) - // ENGINE.GetCamera()->SetMovementSpeed(Root["camera"]["movementSpeed"].asFloat()); - - // After all scene objects are loaded, we need to update all objects. - ProjectScene->Update(); - - // FIX ME! Only after that all systems should be updated and triggered. + ProjectScene = SCENE_MANAGER.GetScene(MainSceneID); // VFS - if (FILE_SYSTEM.CheckFile((ProjectFolder + "VFS.txt").c_str())) + if (FILE_SYSTEM.CheckFile((ProjectFolder + "VFS.txt").c_str())) // _error { VIRTUAL_FILE_SYSTEM.LoadState(ProjectFolder + "VFS.txt"); @@ -1422,7 +833,7 @@ void FEProject::LoadScene() VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(ShaderList[i]), "/Shaders"); } - std::vector StandardShaderList = RESOURCE_MANAGER.GetStandardShadersList(); + std::vector StandardShaderList = RESOURCE_MANAGER.GetEnginePrivateShadersList(); for (size_t i = 0; i < StandardShaderList.size(); i++) { if (OBJECT_MANAGER.GetFEObject(StandardShaderList[i]) == nullptr) @@ -1445,7 +856,7 @@ void FEProject::LoadScene() VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(ShaderList[i]), "/Shaders"); } - std::vector StandardShaderList = RESOURCE_MANAGER.GetStandardShadersList(); + std::vector StandardShaderList = RESOURCE_MANAGER.GetEnginePrivateShadersList(); for (size_t i = 0; i < StandardShaderList.size(); i++) { if (OBJECT_MANAGER.GetFEObject(StandardShaderList[i]) == nullptr) @@ -1453,45 +864,21 @@ void FEProject::LoadScene() VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(StandardShaderList[i]), "/Shaders"); } - std::vector MeshListForVirtualFileSystem = RESOURCE_MANAGER.GetMeshList(); - for (size_t i = 0; i < MeshListForVirtualFileSystem.size(); i++) - { - VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(MeshListForVirtualFileSystem[i]), "/"); - } - + std::vector OtherResourceList = RESOURCE_MANAGER.GetMeshList(); std::vector TextureList = RESOURCE_MANAGER.GetTextureList(); - for (size_t i = 0; i < TextureList.size(); i++) - { - bool bShouldAdd = true; - FETexture* TextureToAdd = RESOURCE_MANAGER.GetTexture(TextureList[i]); - //if (textureToAdd->getInternalFormat() == GL_R16) - //{ - // // Potentially it could be texture hight map. - // std::vector terrainList = ProjectScene->getTerrainList(); - // for (size_t j = 0; j < terrainList.size(); j++) - // { - // if (ProjectScene->getTerrain(terrainList[j])->heightMap == textureToAdd) - // { - // shouldAdd = false; - // break; - // } - // } - //} - - if (bShouldAdd) - VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(TextureList[i]), "/"); - } - + OtherResourceList.insert(OtherResourceList.end(), TextureList.begin(), TextureList.end()); std::vector MaterialList = RESOURCE_MANAGER.GetMaterialList(); - for (size_t i = 0; i < MaterialList.size(); i++) - { - VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(MaterialList[i]), "/"); - } + OtherResourceList.insert(OtherResourceList.end(), MaterialList.begin(), MaterialList.end()); + std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); + OtherResourceList.insert(OtherResourceList.end(), GameModelList.begin(), GameModelList.end()); - std::vector GameModelListForVirtualFileSystem = RESOURCE_MANAGER.GetGameModelList(); - for (size_t i = 0; i < GameModelListForVirtualFileSystem.size(); i++) + for (size_t i = 0; i < OtherResourceList.size(); i++) { - VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(GameModelListForVirtualFileSystem[i]), "/"); + if (OBJECT_MANAGER.GetFEObject(OtherResourceList[i])->GetTag() == ENGINE_RESOURCE_TAG || + OBJECT_MANAGER.GetFEObject(OtherResourceList[i])->GetTag() == EDITOR_RESOURCE_TAG) + continue; + + VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(OtherResourceList[i]), "/"); } } } @@ -1576,8 +963,8 @@ void FEProject::SaveSceneTo(const std::string NewPath) return; SetProjectFolder(NewPath); - ENGINE.TakeScreenshot((GetProjectFolder() + "projectScreenShot.texture").c_str()); - SaveScene(true); + ENGINE.SaveScreenshot((GetProjectFolder() + "projectScreenShot.texture").c_str(), GetScene()); + SaveProject(true); } FEScene* FEProject::GetScene() diff --git a/FEProject.h b/FEProject.h index 243711c..bbd939a 100644 --- a/FEProject.h +++ b/FEProject.h @@ -20,9 +20,9 @@ class FEProject void SetName(std::string NewValue); std::string GetProjectFolder(); - void SaveScene(bool bFullSave = false); + void SaveProject(bool bFullSave = false); void SaveSceneTo(std::string NewPath); - void LoadScene(); + void LoadProject(); FETexture* SceneScreenshot; void CreateDummyScreenshot(); @@ -42,16 +42,13 @@ class FEProject bool bModified = false; std::vector UnSavedObjects; - void WriteTransformToJson(Json::Value& Root, const FETransformComponent* Transform); - void ReadTransformToJson(Json::Value& Root, FETransformComponent* Transform); - std::vector FilesToDelete; bool ShouldIncludeInSceneFile(const FETexture* Texture); void SetProjectFolder(std::string NewValue); }; -#define PROJECTS_FILE_VER 0.025f +#define PROJECTS_FILE_VER 0.04f class FEProjectManager { @@ -59,6 +56,8 @@ class FEProjectManager int IndexChosen = -1; FEProject* Current = nullptr; std::string CustomProjectFolder = "../FocalEngineProjects-master"; + + void CreateNewProject(std::string ProjectName, std::string ProjectPath); public: SINGLETON_PUBLIC_PART(FEProjectManager) SINGLETON_PRIVATE_PART(FEProjectManager) @@ -81,130 +80,4 @@ class FEProjectManager }; #define PROJECTS_FOLDER PROJECT_MANAGER.CustomProjectFolder.c_str() -#define PROJECT_MANAGER FEProjectManager::getInstance() - -static const char* const BASIC_SCENE = R"( - { - "camera" : - { - "aspectRatio" : 2.1216442584991455, - "farPlane" : 5000.0, - "fov" : 70.0, - "movementSpeed" : 10.0, - "nearPlane" : 0.10000000149011612, - "pitch" : 0.0, - "position" : - { - "X" : 0.0, - "Y" : 0.0, - "Z" : 0.0 - }, - "roll" : 0.0, - "yaw" : 0.0 - }, - "effects" : - { - "Anti-Aliasing_FXAA_" : - { - "FXAAReduceMin" : 0.0078125, - "FXAAReduceMul" : 0.40000000596046448, - "FXAASpanMax" : 8.0 - }, - "Bloom" : - { - "BloomSize" : 5.0, - "thresholdBrightness" : 1.0 - }, - "Chromatic Aberration" : - { - "Shift strength" : 1.0 - }, - "Depth of Field" : - { - "Distance dependent strength" : 100.0, - "Far distance" : 9000.0, - "Near distance" : 0.0, - "Strength" : 2.0 - }, - "Distance fog" : - { - "Density" : 0.0070000002160668373, - "Gradient" : 2.5 - }, - "Gamma Correction & Exposure" : - { - "Exposure" : 1.0, - "Gamma" : 2.2000000476837158 - }, - "Sky" : - { - "Enabled" : 0.0, - "Sphere size" : 50.0 - } - }, - "entities" : null, - "gameModels" : null, - "lights" : - { - "732E010E566C183C7968160F" : - { - "CSM" : - { - "CSMXYDepth" : 1.0, - "CSMZDepth" : 3.0, - "activeCascades" : 4, - "shadowCoverage" : 50.0 - }, - "ID" : "732E010E566C183C7968160F", - "castShadows" : true, - "color" : - { - "B" : 1.0, - "G" : 1.0, - "R" : 1.0 - }, - "direction" : - { - "X" : 0.0, - "Y" : 0.0, - "Z" : -1.0 - }, - "enabled" : true, - "intensity" : 1.0, - "name" : "sun", - "shadowBias" : 0.0010000000474974513, - "shadowBiasVariableIntensity" : 1.0, - "shadowBlurFactor" : 1.0, - "staticShadowBias" : false, - "transformation" : - { - "position" : - { - "X" : 0.0, - "Y" : 0.0, - "Z" : 0.0 - }, - "rotation" : - { - "X" : 0.0, - "Y" : 0.0, - "Z" : 0.0 - }, - "scale" : - { - "X" : 1.0, - "Y" : 1.0, - "Z" : 1.0, - "uniformScaling" : true - } - }, - "type" : 9 - } - }, - "materials" : null, - "meshes" : null, - "terrains" : null, - "textures" : null, - "version" : 0.019999999552965164 -} -)"; \ No newline at end of file +#define PROJECT_MANAGER FEProjectManager::getInstance() \ No newline at end of file diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 0db60ae..af91f1a 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 0db60ae0b893528640eb65fa3080b4e5f1838fd8 +Subproject commit af91f1a44afe34ac882bc485f0824962685ea15d From bba951eacd0d128b7ddecebf44515df1009045ff Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Wed, 14 Aug 2024 20:31:36 -0400 Subject: [PATCH 30/46] Engine update; Fixed an issue where engine and editor internal resources were showing up in the pop-up for choosing textures, meshes, and materials; Deleted the FEEditorInternalResources class as it is no longer needed; Implemented a component delete interface in the inspector window; Deleted deprecated FEObject types; Reverted to static linking. --- CMakeLists.txt | 6 +- EditorWindows/EditPopups.cpp | 1 + EditorWindows/InspectorWindow.cpp | 204 ++++++++++++++++++++++++++--- EditorWindows/InspectorWindow.h | 5 + EditorWindows/SceneGraphWindow.cpp | 20 +-- EditorWindows/SelectPopups.cpp | 40 ++++-- EditorWindows/SelectPopups.h | 2 + FEEditor.cpp | 22 ---- FEEditorGizmoManager.cpp | 4 +- FEEditorInternalResources.cpp | 46 ------- FEEditorInternalResources.h | 19 --- FEEditorPreviewManager.cpp | 15 ++- FEEditorPreviewManager.h | 1 - FEEditorSelectedObject.cpp | 26 ++++ FEProject.cpp | 4 - FEProject.h | 1 - SubSystems/FocalEngine | 2 +- 17 files changed, 272 insertions(+), 146 deletions(-) delete mode 100644 FEEditorInternalResources.cpp delete mode 100644 FEEditorInternalResources.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 21cdb28..1c94654 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,8 +12,8 @@ project(FocalEngineEditor) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS_DEBUG "/MP /ZI /W3 /Od /MDd /JMC /sdl /FC /D IMGUI_IMPL_OPENGL_LOADER_GLEW /D WIN32 /D _WINDOWS /D _DEBUG /D FE_DEBUG_ENABLED") -set(CMAKE_CXX_FLAGS_RELEASE "/MP /W3 /O2 /Oi /MD /Gy /sdl /FC /GL /OPT:REF /OPT:ICF /D IMGUI_IMPL_OPENGL_LOADER_GLEW /D NDEBUG /D WIN32 /D _WINDOWS") +set(CMAKE_CXX_FLAGS_DEBUG "/MP /ZI /W3 /Od /MTd /JMC /sdl /FC /D IMGUI_IMPL_OPENGL_LOADER_GLEW /D WIN32 /D _WINDOWS /D _DEBUG /D FE_DEBUG_ENABLED") +set(CMAKE_CXX_FLAGS_RELEASE "/MP /W3 /O2 /Oi /MT /Gy /sdl /FC /GL /OPT:REF /OPT:ICF /D IMGUI_IMPL_OPENGL_LOADER_GLEW /D NDEBUG /D WIN32 /D _WINDOWS") # Turn on the ability to create folders to organize projects (.vcproj) # It creates "CMakePredefinedTargets" folder by default and adds CMake @@ -50,8 +50,6 @@ file(GLOB Editor_SRC "FEEditorGizmoManager.h" "FEEditorHaloSelectionEffect.cpp" "FEEditorHaloSelectionEffect.h" - "FEEditorInternalResources.cpp" - "FEEditorInternalResources.h" "FEEditorPreviewManager.cpp" "FEEditorPreviewManager.h" "FEEditorSelectedObject.cpp" diff --git a/EditorWindows/EditPopups.cpp b/EditorWindows/EditPopups.cpp index 3c0bccd..b0c531a 100644 --- a/EditorWindows/EditPopups.cpp +++ b/EditorWindows/EditPopups.cpp @@ -741,6 +741,7 @@ EditMaterialWindow::EditMaterialWindow() PreviewEntity->AddComponent(PreviewGameModel); PreviewEntity->GetComponent().SetVisibility(true); PreviewEntity->GetComponent().SetScale(glm::vec3(0.1f)); + RESOURCE_MANAGER.SetTag(PreviewEntity, EDITOR_RESOURCE_TAG); PreviewCameraEntity = PreviewScene->CreateEntity("MaterialEditor_Scene_CameraEntity"); PreviewCameraEntity->AddComponent(); diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index 33f276b..cb2e045 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -10,6 +10,32 @@ FEEditorInspectorWindow::FEEditorInspectorWindow() std::vector RegisteredComponentList = COMPONENTS_TOOL.GetComponentInfoList(); AddComponentHandlers[typeid(FELightComponent)] = &FEEditorInspectorWindow::AddLightComponent; AddComponentHandlers[typeid(FECameraComponent)] = &FEEditorInspectorWindow::AddCameraComponent; + AddComponentHandlers[typeid(FEVirtualUIComponent)] = &FEEditorInspectorWindow::AddVirtualUIComponent; + + RemoveComponentHandlers[typeid(FECameraComponent)] = [](FEEntity* ParentEntity) -> void { + ParentEntity->RemoveComponent(); + }; + RemoveComponentHandlers[typeid(FELightComponent)] = [](FEEntity* ParentEntity) -> void { + ParentEntity->RemoveComponent(); + }; + RemoveComponentHandlers[typeid(FEGameModelComponent)] = [](FEEntity* ParentEntity) -> void { + ParentEntity->RemoveComponent(); + }; + RemoveComponentHandlers[typeid(FEInstancedComponent)] = [](FEEntity* ParentEntity) -> void { + ParentEntity->RemoveComponent(); + }; + RemoveComponentHandlers[typeid(FETerrainComponent)] = [](FEEntity* ParentEntity) -> void { + ParentEntity->RemoveComponent(); + }; + RemoveComponentHandlers[typeid(FESkyDomeComponent)] = [](FEEntity* ParentEntity) -> void { + ParentEntity->RemoveComponent(); + }; + RemoveComponentHandlers[typeid(FEPrefabInstanceComponent)] = [](FEEntity* ParentEntity) -> void { + ParentEntity->RemoveComponent(); + }; + RemoveComponentHandlers[typeid(FEVirtualUIComponent)] = [](FEEntity* ParentEntity) -> void { + ParentEntity->RemoveComponent(); + }; } void FEEditorInspectorWindow::InitializeResources() @@ -900,7 +926,7 @@ std::vector FEEditorInspectorWindow::GetAvailableComponentsToAdd(FE auto RegisteredComponentList = COMPONENTS_TOOL.GetComponentInfoList(); for (size_t i = 0; i < RegisteredComponentList.size(); i++) { - if (RegisteredComponentList[i].IsCompatible(Entity)) + if (RegisteredComponentList[i].CanBeAddedToEntity(Entity)) Result.push_back(RegisteredComponentList[i].Name); } @@ -934,6 +960,47 @@ bool FEEditorInspectorWindow::AddComponent(FEEntity* Entity, std::string Compone return false; } +bool FEEditorInspectorWindow::RenderComponentDeleteButton(FEEntity* Entity, FEComponentTypeInfo* ComponentInfo) const +{ + if (!ComponentInfo->CanBeRemovedFromEntity(Entity)) + return false; + + float HeaderHeight = ImGui::GetFrameHeight(); + float HeaderWidth = ImGui::GetContentRegionAvail().x; + + float ButtonSize = 24; + ImVec2 PreviosCursorPos = ImGui::GetCursorPos(); + + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.9f, 0.5f, 0.5f, 1.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.95f, 0.90f, 0.0f, 1.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 1.0f, 0.1f, 1.0f)); + ImGui::SetCursorPos(ImVec2(HeaderWidth - ButtonSize / 8.0f - 2.0f, PreviosCursorPos.y + 2.0f)); + if (ImGui::Button(std::string("x##" + ComponentInfo->Name).c_str(), ImVec2(ButtonSize, ButtonSize))) + { + size_t ComponentHashCode = ComponentInfo->Type->hash_code(); + + auto ComponentIterator = RemoveComponentHandlers.begin(); + while (ComponentIterator != RemoveComponentHandlers.end()) + { + if (ComponentIterator->first.hash_code() == ComponentHashCode) + { + ComponentIterator->second(Entity); + + ImGui::PopStyleColor(3); + ImGui::SetCursorPos(PreviosCursorPos); + return true; + } + + ComponentIterator++; + } + } + + ImGui::PopStyleColor(3); + ImGui::SetCursorPos(PreviosCursorPos); + + return false; +} + void FEEditorInspectorWindow::Render() { if (!bVisible) @@ -964,22 +1031,13 @@ void FEEditorInspectorWindow::Render() if (EntitySelected->HasComponent()) { - float headerHeight = ImGui::GetFrameHeight(); - float headerWidth = ImGui::GetContentRegionAvail().x; - - float ButtonSize = ImGui::GetFrameHeight() * 0.7f; - float cursorPosX = ImGui::GetCursorPosX(); - ImVec2 PreviosCursorPos = ImGui::GetCursorPos(); - - ImGui::SetCursorPos(ImVec2(headerWidth - ButtonSize / 8.0f - 4.0f/*- ButtonSize*/, PreviosCursorPos.y + 4.0f/*(headerHeight - ButtonSize) * 0.5f*/)); - if (ImGui::Button("x", ImVec2(ButtonSize, ButtonSize))) + if (RenderComponentDeleteButton(EntitySelected, COMPONENTS_TOOL.GetComponentInfo())) { - int y = 0; - y++; + ImGui::PopStyleVar(); + ImGui::End(); + return; } - ImGui::SetCursorPos(PreviosCursorPos); - if (ImGui::CollapsingHeader("Tag", ImGuiTreeNodeFlags_DefaultOpen)) { FETagComponent& TagComponent = EntitySelected->GetComponent(); @@ -996,7 +1054,14 @@ void FEEditorInspectorWindow::Render() if (EntitySelected->HasComponent()) { - if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen /*| ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_FramePadding*/)) + if (RenderComponentDeleteButton(EntitySelected, COMPONENTS_TOOL.GetComponentInfo())) + { + ImGui::PopStyleVar(); + ImGui::End(); + return; + } + + if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) { FETransformComponent& Transform = EntitySelected->GetComponent(); ShowTransformConfiguration(EntitySelected->GetName(), &Transform); @@ -1005,7 +1070,14 @@ void FEEditorInspectorWindow::Render() if (EntitySelected->HasComponent()) { - if (ImGui::CollapsingHeader("Game Model", ImGuiTreeNodeFlags_DefaultOpen /*| ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_FramePadding*/)) + if (RenderComponentDeleteButton(EntitySelected, COMPONENTS_TOOL.GetComponentInfo())) + { + ImGui::PopStyleVar(); + ImGui::End(); + return; + } + + if (ImGui::CollapsingHeader("Game Model", ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.95f, 0.90f, 0.0f)); @@ -1056,6 +1128,13 @@ void FEEditorInspectorWindow::Render() if (EntitySelected->HasComponent()) { + if (RenderComponentDeleteButton(EntitySelected, COMPONENTS_TOOL.GetComponentInfo())) + { + ImGui::PopStyleVar(); + ImGui::End(); + return; + } + if (ImGui::CollapsingHeader("Prefab Instance", ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::Text("Prefab ID : %s", EntitySelected->GetComponent().GetPrefab()->GetObjectID().c_str()); @@ -1064,6 +1143,13 @@ void FEEditorInspectorWindow::Render() if (EntitySelected->HasComponent()) { + if (RenderComponentDeleteButton(EntitySelected, COMPONENTS_TOOL.GetComponentInfo())) + { + ImGui::PopStyleVar(); + ImGui::End(); + return; + } + if (ImGui::CollapsingHeader("Instanced", ImGuiTreeNodeFlags_DefaultOpen)) { FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(CurrentScene->GetObjectID()); @@ -1332,6 +1418,13 @@ void FEEditorInspectorWindow::Render() if (EntitySelected->HasComponent()) { + if (RenderComponentDeleteButton(EntitySelected, COMPONENTS_TOOL.GetComponentInfo())) + { + ImGui::PopStyleVar(); + ImGui::End(); + return; + } + if (ImGui::CollapsingHeader("Terrain", ImGuiTreeNodeFlags_DefaultOpen)) { FETerrainComponent& TerrainComponent = EntitySelected->GetComponent(); @@ -1365,6 +1458,13 @@ void FEEditorInspectorWindow::Render() if (EntitySelected->HasComponent()) { + if (RenderComponentDeleteButton(EntitySelected, COMPONENTS_TOOL.GetComponentInfo())) + { + ImGui::PopStyleVar(); + ImGui::End(); + return; + } + if (ImGui::CollapsingHeader("Light", ImGuiTreeNodeFlags_DefaultOpen)) { DisplayLightProperties(SELECTED.GetSelected(CurrentScene)); @@ -1373,12 +1473,34 @@ void FEEditorInspectorWindow::Render() if (EntitySelected->HasComponent()) { + if (RenderComponentDeleteButton(EntitySelected, COMPONENTS_TOOL.GetComponentInfo())) + { + ImGui::PopStyleVar(); + ImGui::End(); + return; + } + if (ImGui::CollapsingHeader("Camera", ImGuiTreeNodeFlags_DefaultOpen)) { DisplayCameraProperties(SELECTED.GetSelected(CurrentScene)); } } + if (EntitySelected->HasComponent()) + { + if (RenderComponentDeleteButton(EntitySelected, COMPONENTS_TOOL.GetComponentInfo())) + { + ImGui::PopStyleVar(); + ImGui::End(); + return; + } + + if (ImGui::CollapsingHeader("Virtual UI", ImGuiTreeNodeFlags_DefaultOpen)) + { + DisplayVirtualUIProperties(SELECTED.GetSelected(CurrentScene)); + } + } + std::vector AvailableComponentTypes = GetAvailableComponentsToAdd(EntitySelected); ImGui::SetNextItemWidth(220.0f); @@ -1871,4 +1993,54 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) } ImGui::EndTabBar(); } +} + +void FEEditorInspectorWindow::AddVirtualUIComponent(FEEntity* Entity) +{ + Entity->AddComponent(); +} + +void FEEditorInspectorWindow::DisplayVirtualUIProperties(FEEntity* VirtualUIEntity) const +{ + FEVirtualUIComponent& VirtualUIComponent = VirtualUIEntity->GetComponent(); + + // TO-DO: Give user ability to change window. + FEWindow* CurrentWindow = VirtualUIComponent.GetWindowToListen(); + + // TO-DO: Give user ability to change canvas mesh. + FEMesh* CurrentCanvasMesh = VirtualUIComponent.GetCanvasMesh(); + + // Internal resolution. + ImGui::Text("Internal Resolution:"); + glm::vec2 InternalResolution = VirtualUIComponent.GetCanvasResolution(); + ImGui::DragFloat2("##InternalResolution", &InternalResolution[0], 1.0f, 1.0f, 4096.0f); + VirtualUIComponent.SetCanvasResolution(InternalResolution); + + bool bActive = VirtualUIComponent.IsInputActive(); + ImGui::Checkbox("Input Active", &bActive); + VirtualUIComponent.SetInputActive(bActive); + + bool bMouseButtonPassThrough = VirtualUIComponent.IsMouseButtonPassThroughActive(); + ImGui::Checkbox("Mouse Button Pass Through", &bMouseButtonPassThrough); + VirtualUIComponent.SetMouseButtonPassThrough(bMouseButtonPassThrough); + + bool bMouseMovePassThrough = VirtualUIComponent.IsMouseMovePassThroughActive(); + ImGui::Checkbox("Mouse Move Pass Through", &bMouseMovePassThrough); + VirtualUIComponent.SetMouseMovePassThrough(bMouseMovePassThrough); + + bool bMouseScrollPassThrough = VirtualUIComponent.IsScrollPassThroughActive(); + ImGui::Checkbox("Mouse Scroll Pass Through", &bMouseScrollPassThrough); + VirtualUIComponent.SetScrollPassThrough(bMouseScrollPassThrough); + + bool bCharPassThrough = VirtualUIComponent.IsCharPassThroughActive(); + ImGui::Checkbox("Char Pass Through", &bCharPassThrough); + VirtualUIComponent.SetCharPassThrough(bCharPassThrough); + + bool bKeyboardPassThrough = VirtualUIComponent.IsKeyPassThroughActive(); + ImGui::Checkbox("Key Pass Through", &bKeyboardPassThrough); + VirtualUIComponent.SetKeyPassThrough(bKeyboardPassThrough); + + bool bDropPassThrough = VirtualUIComponent.IsDropPassThroughActive(); + ImGui::Checkbox("Drop Pass Through", &bDropPassThrough); + VirtualUIComponent.SetDropPassThrough(bDropPassThrough); } \ No newline at end of file diff --git a/EditorWindows/InspectorWindow.h b/EditorWindows/InspectorWindow.h index a970956..9426cf2 100644 --- a/EditorWindows/InspectorWindow.h +++ b/EditorWindows/InspectorWindow.h @@ -14,6 +14,7 @@ class FEEditorInspectorWindow void DisplayLightProperties(FEEntity* LightEntity) const; void DisplayCameraProperties(FEEntity* CameraEntity) const; + void DisplayVirtualUIProperties(FEEntity* VirtualUIEntity) const; // Terrain settings static FEEntity* TerrainToWorkWith; @@ -63,9 +64,13 @@ class FEEditorInspectorWindow bool AddComponent(FEEntity* Entity, std::string ComponentName); std::unordered_map> AddComponentHandlers; + std::unordered_map> RemoveComponentHandlers; + + bool RenderComponentDeleteButton(FEEntity* Entity, FEComponentTypeInfo* ComponentInfo) const; static void AddLightComponent(FEEntity* Entity); static void AddCameraComponent(FEEntity* Entity); + static void AddVirtualUIComponent(FEEntity* Entity); public: SINGLETON_PUBLIC_PART(FEEditorInspectorWindow) }; diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index e802e23..6d19fec 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -43,36 +43,38 @@ void FEEditorSceneGraphWindow::SetCorrectItemColor(FEObject* SceneObject) const { ImGui::PushStyleColor(ImGuiCol_Text, LightItemColor); } - else if (SceneObject->GetType() == FE_CAMERA_DEPRECATED) + // FIX ME ! + /*else if (SceneObject->GetType() == FE_CAMERA_DEPRECATED) { ImGui::PushStyleColor(ImGuiCol_Text, CameraItemColor); } else if (SceneObject->GetType() == FE_TERRAIN_DEPRECATED) { ImGui::PushStyleColor(ImGuiCol_Text, TerrainItemColor); - } + }*/ else if (SceneObject->GetType() == FE_ENTITY) { ImGui::PushStyleColor(ImGuiCol_Text, EntityItemColor); } - else if (SceneObject->GetType() == FE_ENTITY_INSTANCED_DEPRECATED) + /*else if (SceneObject->GetType() == FE_ENTITY_INSTANCED_DEPRECATED) { ImGui::PushStyleColor(ImGuiCol_Text, InstancedEntityItemColor); - } + }*/ } void FEEditorSceneGraphWindow::PopCorrectItemColor(FEObject* SceneObject) { - if (SceneObject->GetType() == FE_DIRECTIONAL_LIGHT || + // FIX ME ! + /*if (SceneObject->GetType() == FE_DIRECTIONAL_LIGHT || SceneObject->GetType() == FE_SPOT_LIGHT || SceneObject->GetType() == FE_POINT_LIGHT || SceneObject->GetType() == FE_CAMERA_DEPRECATED || SceneObject->GetType() == FE_TERRAIN_DEPRECATED || SceneObject->GetType() == FE_ENTITY || SceneObject->GetType() == FE_ENTITY_INSTANCED_DEPRECATED) - { + {*/ ImGui::PopStyleColor(); - } + //} } static void CreateInstancedEntityCallBack(const std::vector SelectionsResult) @@ -158,7 +160,7 @@ void FEEditorSceneGraphWindow::DrawCorrectIcon(const FEObject* SceneObject) cons } }*/ - if (SceneObject->GetType() == FE_DIRECTIONAL_LIGHT) + /*if (SceneObject->GetType() == FE_DIRECTIONAL_LIGHT) { ImGui::Image((void*)(intptr_t)DirectionalLightIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); @@ -184,7 +186,7 @@ void FEEditorSceneGraphWindow::DrawCorrectIcon(const FEObject* SceneObject) cons if (SceneObject->GetType() == FE_CAMERA_DEPRECATED) { ImGui::Image((void*)(intptr_t)CameraIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); - } + }*/ ImGui::SameLine(); return; diff --git a/EditorWindows/SelectPopups.cpp b/EditorWindows/SelectPopups.cpp index b3b1706..5a01760 100644 --- a/EditorWindows/SelectPopups.cpp +++ b/EditorWindows/SelectPopups.cpp @@ -30,6 +30,24 @@ SelectFEObjectPopUp::~SelectFEObjectPopUp() delete IconButton; } +void SelectFEObjectPopUp::FilterOutTags(std::vector& FEObjectIDList, std::vector ListOfTagsToFilterOut) +{ + for (int i = 0; i < FEObjectIDList.size(); i++) + { + FEObject* CurrentObject = OBJECT_MANAGER.GetFEObject(FEObjectIDList[i]); + + for (size_t j = 0; j < ListOfTagsToFilterOut.size(); j++) + { + if (CurrentObject->GetTag() == ListOfTagsToFilterOut[j]) + { + FEObjectIDList.erase(FEObjectIDList.begin() + i); + i--; + break; + } + } + } +} + void SelectFEObjectPopUp::Show(const FE_OBJECT_TYPE Type, void(*CallBack)(std::vector), FEObject* HighlightedObject, const std::vector CustomList) { CurrenType = Type; @@ -51,32 +69,18 @@ void SelectFEObjectPopUp::Show(const FE_OBJECT_TYPE Type, void(*CallBack)(std::v case FE_TEXTURE: { TempList = RESOURCE_MANAGER.GetTextureList(); - TempList.insert(TempList.begin(), RESOURCE_MANAGER.NoTexture->GetObjectID()); - break; } case FE_MESH: { TempList = RESOURCE_MANAGER.GetMeshList(); - - const std::vector StandardMeshList = RESOURCE_MANAGER.GetEnginePrivateMeshList(); - for (size_t i = 0; i < StandardMeshList.size(); i++) - { - if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(RESOURCE_MANAGER.GetMesh(StandardMeshList[i]))) - continue; - - TempList.push_back(StandardMeshList[i]); - } - break; } case FE_MATERIAL: { TempList = RESOURCE_MANAGER.GetMaterialList(); - TempList.insert(TempList.begin(), "18251A5E0F08013Z3939317U"/*"SolidColorMaterial"*/); - break; } @@ -92,6 +96,14 @@ void SelectFEObjectPopUp::Show(const FE_OBJECT_TYPE Type, void(*CallBack)(std::v break; } } + + FilterOutTags(TempList, std::vector{ ENGINE_RESOURCE_TAG, EDITOR_RESOURCE_TAG}); + + if (CurrenType == FE_TEXTURE) + TempList.insert(TempList.begin(), RESOURCE_MANAGER.NoTexture->GetObjectID()); + + if (CurrenType == FE_MATERIAL) + TempList.insert(TempList.begin(), "18251A5E0F08013Z3939317U"/*"SolidColorMaterial"*/); for (size_t i = 0; i < TempList.size(); i++) ItemsList.push_back(OBJECT_MANAGER.GetFEObject(TempList[i])); diff --git a/EditorWindows/SelectPopups.h b/EditorWindows/SelectPopups.h index b8c4ccf..0abab99 100644 --- a/EditorWindows/SelectPopups.h +++ b/EditorWindows/SelectPopups.h @@ -28,6 +28,8 @@ class SelectFEObjectPopUp : public ImGuiModalPopup static bool bOneObjectSelectonMode; bool IsSelected(const FEObject* Object) const; void AddToSelected(FEObject* Object); + + void FilterOutTags(std::vector& FEObjectIDList, std::vector ListOfTagsToFilterOut); public: SINGLETON_PUBLIC_PART(SelectFEObjectPopUp) diff --git a/FEEditor.cpp b/FEEditor.cpp index 81751ab..1cb3cb0 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -237,29 +237,7 @@ void FEEditor::InitializeResources() PREVIEW_MANAGER.InitializeResources(); DRAG_AND_DROP_MANAGER.InitializeResources(); - // **************************** Gizmos **************************** GIZMO_MANAGER.InitializeResources(); - - // hide all resources for gizmos from content browser - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("45191B6F172E3B531978692E"/*"transformationGizmoMesh"*/)); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("637C784B2E5E5C6548190E1B"/*"scaleGizmoMesh"*/)); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(RESOURCE_MANAGER.GetMesh("19622421516E5B317E1B5360"/*"rotateGizmoMesh"*/)); - - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXGizmoGM); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYGizmoGM); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationZGizmoGM); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXYGizmoGM); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationYZGizmoGM); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.TransformationXZGizmoGM); - - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleXGizmoGM); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleYGizmoGM); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.ScaleZGizmoGM); - - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateXGizmoGM); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateYGizmoGM); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(GIZMO_MANAGER.RotateZGizmoGM); - SCENE_GRAPH_WINDOW.InitializeResources(); CONTENT_BROWSER_WINDOW.InitializeResources(); INSPECTOR_WINDOW.InitializeResources(); diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index 141dfe2..4a04478 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -209,7 +209,7 @@ void GizmoManager::UpdateGizmoState(int NewState, FEScene* Scene) GizmoSceneData->GizmosState = NewState; HideAllGizmo(Scene); - if (SELECTED.GetSelected(Scene) == nullptr || SELECTED.GetSelected(Scene)->GetType() == FE_CAMERA_DEPRECATED) + if (SELECTED.GetSelected(Scene) == nullptr) return; switch (NewState) @@ -292,7 +292,7 @@ void GizmoManager::Update() } FEScene* Scene = SCENE_MANAGER.GetScene(GizmoSceneData->SceneID); - if (SELECTED.GetSelected(Scene) == nullptr || CAMERA_SYSTEM.GetMainCameraEntity(Scene) == nullptr || SELECTED.GetSelected(Scene)->GetType() == FE_CAMERA_DEPRECATED) + if (SELECTED.GetSelected(Scene) == nullptr || CAMERA_SYSTEM.GetMainCameraEntity(Scene) == nullptr) { HideAllGizmo(Scene); PerSceneIterator++; diff --git a/FEEditorInternalResources.cpp b/FEEditorInternalResources.cpp deleted file mode 100644 index a85876b..0000000 --- a/FEEditorInternalResources.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "FEEditorInternalResources.h" -using namespace FocalEngine; - -FEEditorInternalResources* FEEditorInternalResources::Instance = nullptr; -FEEditorInternalResources::FEEditorInternalResources() {} -FEEditorInternalResources::~FEEditorInternalResources() {} - -void FEEditorInternalResources::AddResourceToInternalEditorList(FEObject* Object) -{ - if (Object == nullptr) - { - LOG.Add("object is nullptr in function FEEditorInternalResources::addResourceToInternalEditorList.", "FE_LOG_GENERAL", FE_LOG_ERROR); - return; - } - - InternalEditorObjects[Object->GetObjectID()] = Object; -} - -bool FEEditorInternalResources::IsInInternalEditorList(const FEObject* Object) -{ - if (Object == nullptr) - { - LOG.Add("object is nullptr in function FEEditorInternalResources::isInInternalEditorList.", "FE_LOG_GENERAL", FE_LOG_ERROR); - return false; - } - - return !(InternalEditorObjects.find(Object->GetObjectID()) == InternalEditorObjects.end()); -} - -void FEEditorInternalResources::ClearListByType(const FE_OBJECT_TYPE Type) -{ - auto it = InternalEditorObjects.begin(); - while (it != InternalEditorObjects.end()) - { - if (it->second->GetType() == Type) - { - auto temp = it->second; - it++; - InternalEditorObjects.erase(temp->GetObjectID()); - } - else - { - it++; - } - } -} diff --git a/FEEditorInternalResources.h b/FEEditorInternalResources.h deleted file mode 100644 index 287b8ae..0000000 --- a/FEEditorInternalResources.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "FEDearImguiWrapper/FEDearImguiWrapper.h" - -class FEEditorInternalResources -{ -public: - SINGLETON_PUBLIC_PART(FEEditorInternalResources) - SINGLETON_PRIVATE_PART(FEEditorInternalResources) - - std::unordered_map InternalEditorObjects; - - void AddResourceToInternalEditorList(FEObject* Object); - bool IsInInternalEditorList(const FEObject* Object); - - void ClearListByType(FE_OBJECT_TYPE Type); -}; - -#define EDITOR_INTERNAL_RESOURCES FEEditorInternalResources::getInstance() \ No newline at end of file diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index d2bb8a4..ddf44b0 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -30,6 +30,7 @@ void FEEditorPreviewManager::InitializeResources() PreviewEntity = PreviewScene->CreateEntity("EditorPreviewEntity"); PreviewEntity->AddComponent(PreviewGameModel); PreviewEntity->GetComponent().SetVisibility(true); + RESOURCE_MANAGER.SetTag(PreviewEntity, EDITOR_RESOURCE_TAG); LocalCameraEntity = PreviewScene->CreateEntity("EditorPreview CameraEntity"); LocalCameraEntity->AddComponent(); @@ -52,10 +53,6 @@ void FEEditorPreviewManager::InitializeResources() SCENE_MANAGER.DeactivateScene(PreviewScene); } -void FEEditorPreviewManager::ReInitializeEntities() -{ -} - void FEEditorPreviewManager::UpdateAll() { Clear(); @@ -69,13 +66,17 @@ void FEEditorPreviewManager::UpdateAll() const std::vector MaterialList = RESOURCE_MANAGER.GetMaterialList(); for (size_t i = 0; i < MaterialList.size(); i++) { - CreateMaterialPreview(MaterialList[i]); + FEObject* CurrentMaterial = OBJECT_MANAGER.GetFEObject(MaterialList[i]); + if (CurrentMaterial->GetTag() != EDITOR_RESOURCE_TAG) + CreateMaterialPreview(MaterialList[i]); } const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); for (size_t i = 0; i < GameModelList.size(); i++) { - CreateGameModelPreview(GameModelList[i]); + FEObject* CurrentGameModel = OBJECT_MANAGER.GetFEObject(GameModelList[i]); + if (CurrentGameModel->GetTag() != EDITOR_RESOURCE_TAG) + CreateGameModelPreview(GameModelList[i]); } } @@ -254,7 +255,7 @@ FETexture* FEEditorPreviewManager::GetMaterialPreview(const std::string Material void FEEditorPreviewManager::CreateGameModelPreview(const std::string GameModelID) { const FEGameModel* GameModel = RESOURCE_MANAGER.GetGameModel(GameModelID); - if (GameModel == nullptr) + if (GameModel == nullptr || GameModel->Mesh == nullptr || GameModel->Material == nullptr) return; PreviewGameModel->Mesh = GameModel->Mesh; diff --git a/FEEditorPreviewManager.h b/FEEditorPreviewManager.h index 4a20603..bc84c5b 100644 --- a/FEEditorPreviewManager.h +++ b/FEEditorPreviewManager.h @@ -26,7 +26,6 @@ class FEEditorPreviewManager SINGLETON_PRIVATE_PART(FEEditorPreviewManager) void InitializeResources(); - void ReInitializeEntities(); void UpdateAll(); FEScene* PreviewScene = nullptr; diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index 549e606..15b9b18 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -265,6 +265,22 @@ void FEEditorSelectedObject::RenderEntitySelectionColorID(FEEntity* Entity, glm: PixelAccurateSelectionMaterial->Shader = FEPixelAccurateSelection; } + else if (Entity->HasComponent()) + { + FEVirtualUIComponent& VirtualUIComponent = Entity->GetComponent(); + if (!VirtualUIComponent.IsVisible() || VirtualUIComponent.IsInputActive()) + return; + + PixelAccurateSelectionMaterial->SetBaseColor(ColorID); + PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); + + VIRTUAL_UI_SYSTEM.RenderVirtualUIComponent(Entity, PixelAccurateSelectionMaterial); + + PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr); + PixelAccurateSelectionMaterial->SetAlbedoMap(nullptr, 1); + } + + PixelAccurateSelectionMaterial->ClearAllTexturesInfo(); } int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, const double MouseY, FEScene* Scene) @@ -510,6 +526,16 @@ void FEEditorSelectedObject::RenderEntityHaloEffectInternal(FEEntity* Entity, gl HALO_SELECTION_EFFECT.HaloMaterial->Shader = HALO_SELECTION_EFFECT.HaloDrawObjectShader; } + else if (Entity->HasComponent()) + { + FEVirtualUIComponent& VirtualUIComponent = Entity->GetComponent(); + if (!VirtualUIComponent.IsVisible() || VirtualUIComponent.IsInputActive()) + return; + + VIRTUAL_UI_SYSTEM.RenderVirtualUIComponent(Entity, HALO_SELECTION_EFFECT.HaloMaterial); + } + + HALO_SELECTION_EFFECT.HaloMaterial->ClearAllTexturesInfo(); } void FEEditorSelectedObject::OnCameraUpdate() const diff --git a/FEProject.cpp b/FEProject.cpp index f6b3077..0c4baca 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -68,9 +68,6 @@ void FEProjectManager::OpenProject(const int ProjectIndex) EDITOR.FocusedEditorSceneID = PROJECT_MANAGER.GetCurrent()->ProjectScene->GetObjectID(); IndexChosen = -1; - PREVIEW_MANAGER.ReInitializeEntities(); - EDITOR_INTERNAL_RESOURCES.AddResourceToInternalEditorList(PREVIEW_MANAGER.PreviewEntity); - // after loading project we should update our previews PREVIEW_MANAGER.UpdateAll(); SELECTED.ClearAll(); @@ -379,7 +376,6 @@ FEProject::~FEProject() if (SceneScreenshot != RESOURCE_MANAGER.NoTexture) delete SceneScreenshot; - EDITOR_INTERNAL_RESOURCES.ClearListByType(FE_ENTITY); RESOURCE_MANAGER.Clear(); VIRTUAL_FILE_SYSTEM.Clear(); } diff --git a/FEProject.h b/FEProject.h index bbd939a..13de173 100644 --- a/FEProject.h +++ b/FEProject.h @@ -5,7 +5,6 @@ #include "FEDearImguiWrapper/FEDearImguiWrapper.h" #include "FEEditorGizmoManager.h" #include "FEEditorPreviewManager.h" -#include "FEEditorInternalResources.h" #include "FEEditorVirtualFileSystem.h" class FEProject diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index af91f1a..8d64959 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit af91f1a44afe34ac882bc485f0824962685ea15d +Subproject commit 8d6495906e184bdfb603907e141784607df16e01 From f630dc9c8d245c4088752cfef7bf9d3447e59369 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Fri, 16 Aug 2024 20:22:01 -0400 Subject: [PATCH 31/46] Engine update; Users can now add more components using the inspector window; Fixed the creation of new prefabs. --- .../CombineChannelsToTexturePopUp.cpp | 2 +- EditorWindows/ContentBrowserWindow.cpp | 17 ++-- EditorWindows/EditPopups.cpp | 16 ++-- EditorWindows/InspectorWindow.cpp | 53 ++++++++++-- EditorWindows/InspectorWindow.h | 5 ++ EditorWindows/PrefabEditorManager.cpp | 5 +- EditorWindows/SceneGraphWindow.cpp | 86 +------------------ EditorWindows/SelectPopups.h | 4 +- FEEditor.cpp | 2 +- FEProject.cpp | 23 ----- FEProject.h | 1 - SubSystems/FocalEngine | 2 +- 12 files changed, 83 insertions(+), 133 deletions(-) diff --git a/EditorWindows/CombineChannelsToTexturePopUp.cpp b/EditorWindows/CombineChannelsToTexturePopUp.cpp index d2f8ec4..7ca5c19 100644 --- a/EditorWindows/CombineChannelsToTexturePopUp.cpp +++ b/EditorWindows/CombineChannelsToTexturePopUp.cpp @@ -123,7 +123,7 @@ void CombineChannelsToTexturePopUp::NodeSystemMainContextMenu() if (ImGui::MenuItem("Texture node")) { TextureForNewNode = RESOURCE_MANAGER.NoTexture; - SelectFEObjectPopUp::getInstance().Show(FE_TEXTURE, TextureNodeCreationCallback); + SELECT_FEOBJECT_POPUP.Show(FE_TEXTURE, TextureNodeCreationCallback); } if (ImGui::MenuItem("Float node")) diff --git a/EditorWindows/ContentBrowserWindow.cpp b/EditorWindows/ContentBrowserWindow.cpp index bb39373..8b13520 100644 --- a/EditorWindows/ContentBrowserWindow.cpp +++ b/EditorWindows/ContentBrowserWindow.cpp @@ -57,8 +57,13 @@ static void CreateNewPrefabCallBack(const std::vector SelectionsResul for (int i = 1; i < SelectionsResult.size(); i++) { // FIX ME! It should be here - //if (SelectionsResult[i]->GetType() == FE_GAMEMODEL) - // NewPrefab->AddComponent(reinterpret_cast(SelectionsResult[i])); + if (SelectionsResult[i]->GetType() == FE_GAMEMODEL) + { + //FEGameModel* CurrentGameModel = reinterpret_cast(SelectionsResult[i]); + //NewPrefab->GetScene()->CreateEntity(); + + //NewPrefab->AddComponent(reinterpret_cast(SelectionsResult[i])); + } } } @@ -66,7 +71,7 @@ static void CreateNewPrefabCallBack(const std::vector SelectionsResul VIRTUAL_FILE_SYSTEM.CreateFile(NewPrefab, VIRTUAL_FILE_SYSTEM.GetCurrentPath()); } - SelectFEObjectPopUp::getInstance().SetOneObjectSelectonMode(true); + SELECT_FEOBJECT_POPUP.SetOneObjectSelectonMode(true); } void FEEditorContentBrowserWindow::MouseButtonCallback(int Button, int Action, int Mods) @@ -220,8 +225,8 @@ void FEEditorContentBrowserWindow::Render() if (ImGui::MenuItem("Create new prefab")) { - SelectFEObjectPopUp::getInstance().SetOneObjectSelectonMode(false); - SelectFEObjectPopUp::getInstance().Show(FE_GAMEMODEL, CreateNewPrefabCallBack); + SELECT_FEOBJECT_POPUP.SetOneObjectSelectonMode(false); + SELECT_FEOBJECT_POPUP.Show(FE_GAMEMODEL, CreateNewPrefabCallBack); } ImGui::EndMenu(); @@ -356,7 +361,7 @@ void FEEditorContentBrowserWindow::Render() if (ImGui::MenuItem("Choose transparency mask")) { TempTexture = reinterpret_cast(FilteredResources[ItemUnderMouse]); - SelectFEObjectPopUp::getInstance().Show(FE_TEXTURE, AddTransparencyToTextureCallBack); + SELECT_FEOBJECT_POPUP.Show(FE_TEXTURE, AddTransparencyToTextureCallBack); } ImGui::EndMenu(); diff --git a/EditorWindows/EditPopups.cpp b/EditorWindows/EditPopups.cpp index b0c531a..6825fe4 100644 --- a/EditorWindows/EditPopups.cpp +++ b/EditorWindows/EditPopups.cpp @@ -401,7 +401,7 @@ void EditGameModelPopup::Render() UpdatedLODMeshs[0] = TempModel->GetLODMesh(0); MeshToModify = &UpdatedLODMeshs[0]; - SelectFEObjectPopUp::getInstance().Show(FE_MESH, ChangeMeshCallBack, UpdatedLODMeshs[0]); + SELECT_FEOBJECT_POPUP.Show(FE_MESH, ChangeMeshCallBack, UpdatedLODMeshs[0]); } TextSize = ImGui::CalcTextSize("Material component:"); @@ -418,7 +418,7 @@ void EditGameModelPopup::Render() UpdatedMaterial = TempModel->GetMaterial(); MaterialToModify = &UpdatedMaterial; - SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialCallBack, UpdatedMaterial); + SELECT_FEOBJECT_POPUP.Show(FE_MATERIAL, ChangeMaterialCallBack, UpdatedMaterial); } } else if (CurrentMode == HAS_LOD_MODE) @@ -443,7 +443,7 @@ void EditGameModelPopup::Render() UpdatedLODMeshs[i] = TempModel->GetLODMesh(i); MeshToModify = &UpdatedLODMeshs[i]; - SelectFEObjectPopUp::getInstance().Show(FE_MESH, ChangeMeshCallBack, UpdatedLODMeshs[i]); + SELECT_FEOBJECT_POPUP.Show(FE_MESH, ChangeMeshCallBack, UpdatedLODMeshs[i]); } AddBillboard->SetPosition(ImVec2(CurrentXPosition - AddBillboard->GetSize().x / 2, CurrentY + 210.0f + 128.0f / 2.0f + 10.0f / 2.0f)); @@ -501,7 +501,7 @@ void EditGameModelPopup::Render() UpdatedLODMeshs[i] = TempModel->GetLODMesh(i); MeshToModify = &UpdatedLODMeshs[i]; - SelectFEObjectPopUp::getInstance().Show(FE_MESH, ChangeMeshCallBack, UpdatedLODMeshs[i]); + SELECT_FEOBJECT_POPUP.Show(FE_MESH, ChangeMeshCallBack, UpdatedLODMeshs[i]); } } @@ -525,7 +525,7 @@ void EditGameModelPopup::Render() if (ChangeMaterialButton->IsClicked()) { MaterialToModify = &UpdatedMaterial; - SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialCallBack, UpdatedMaterial); + SELECT_FEOBJECT_POPUP.Show(FE_MATERIAL, ChangeMaterialCallBack, UpdatedMaterial); } TextSize = ImGui::CalcTextSize("Billboard Material component:"); @@ -556,7 +556,7 @@ void EditGameModelPopup::Render() } BillboardMaterialToModify = &UpdatedBillboardMaterial; - SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeBillboardMaterialCallBack, UpdatedBillboardMaterial, FinalMaterialList); + SELECT_FEOBJECT_POPUP.Show(FE_MATERIAL, ChangeBillboardMaterialCallBack, UpdatedBillboardMaterial, FinalMaterialList); } } else @@ -574,7 +574,7 @@ void EditGameModelPopup::Render() if (ChangeMaterialButton->IsClicked()) { MaterialToModify = &UpdatedMaterial; - SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialCallBack, UpdatedMaterial); + SELECT_FEOBJECT_POPUP.Show(FE_MATERIAL, ChangeMaterialCallBack, UpdatedMaterial); } } @@ -1004,7 +1004,7 @@ void EditMaterialWindow::NodeSystemMainContextMenu() { TextureForNewNode = RESOURCE_MANAGER.NoTexture; - SelectFEObjectPopUp::getInstance().Show(FE_TEXTURE, TextureNodeCreationCallback); + SELECT_FEOBJECT_POPUP.Show(FE_TEXTURE, TextureNodeCreationCallback); } if (ImGui::MenuItem("Float node")) diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index cb2e045..3b0e41a 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -10,6 +10,9 @@ FEEditorInspectorWindow::FEEditorInspectorWindow() std::vector RegisteredComponentList = COMPONENTS_TOOL.GetComponentInfoList(); AddComponentHandlers[typeid(FELightComponent)] = &FEEditorInspectorWindow::AddLightComponent; AddComponentHandlers[typeid(FECameraComponent)] = &FEEditorInspectorWindow::AddCameraComponent; + AddComponentHandlers[typeid(FEGameModelComponent)] = &FEEditorInspectorWindow::AddGameModelComponent; + AddComponentHandlers[typeid(FEInstancedComponent)] = &FEEditorInspectorWindow::AddInstancedComponent; + AddComponentHandlers[typeid(FETerrainComponent)] = &FEEditorInspectorWindow::AddTerrainComponent; AddComponentHandlers[typeid(FEVirtualUIComponent)] = &FEEditorInspectorWindow::AddVirtualUIComponent; RemoveComponentHandlers[typeid(FECameraComponent)] = [](FEEntity* ParentEntity) -> void { @@ -1094,7 +1097,7 @@ void FEEditorInspectorWindow::Render() if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) { //EntityToModify = EntitySelected; - //SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); + //SELECT_FEOBJECT_POPUP.Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); } //EntityChangePrefabTarget->StickToItem(); @@ -1634,7 +1637,7 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) if (!FilePath.empty()) { FilePath += ".png"; - RESOURCE_MANAGER.ExportFETextureToPNG(TerrainComponent.HeightMap, FilePath.c_str()); + RESOURCE_MANAGER.ExportFETextureToPNG(TerrainComponent.GetHeightMap(), FilePath.c_str()); } } @@ -1648,7 +1651,7 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) if (!FilePath.empty()) { TERRAIN_SYSTEM.LoadHeightMap(FilePath.c_str(), TerrainEntity); - FETexture* LoadedTexture = TerrainComponent.HeightMap;// RESOURCE_MANAGER.LoadPNGHeightmap(FilePath.c_str(), Terrain); + FETexture* LoadedTexture = TerrainComponent.GetHeightMap(); if (LoadedTexture == RESOURCE_MANAGER.NoTexture) { LOG.Add(std::string("can't load height map: ") + FilePath, "FE_LOG_LOADING", FE_LOG_ERROR); @@ -1892,7 +1895,7 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) else { TerrainToWorkWith = TerrainEntity; - SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, CreateNewTerrainLayerWithMaterialCallBack, nullptr, FinalMaterialList); + SELECT_FEOBJECT_POPUP.Show(FE_MATERIAL, CreateNewTerrainLayerWithMaterialCallBack, nullptr, FinalMaterialList); } } @@ -1954,7 +1957,7 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) { TerrainToWorkWith = TerrainEntity; TempLayerIndex = HoveredTerrainLayerItem; - SelectFEObjectPopUp::getInstance().Show(FE_MATERIAL, ChangeMaterialInTerrainLayerCallBack, TerrainComponent.GetLayerInSlot(HoveredTerrainLayerItem)->GetMaterial(), FinalMaterialList); + SELECT_FEOBJECT_POPUP.Show(FE_MATERIAL, ChangeMaterialInTerrainLayerCallBack, TerrainComponent.GetLayerInSlot(HoveredTerrainLayerItem)->GetMaterial(), FinalMaterialList); } } @@ -2043,4 +2046,44 @@ void FEEditorInspectorWindow::DisplayVirtualUIProperties(FEEntity* VirtualUIEnti bool bDropPassThrough = VirtualUIComponent.IsDropPassThroughActive(); ImGui::Checkbox("Drop Pass Through", &bDropPassThrough); VirtualUIComponent.SetDropPassThrough(bDropPassThrough); +} + +void FEEditorInspectorWindow::AddGameModelComponent(FEEntity* Entity) +{ + INSPECTOR_WINDOW.EntityToWorkWith = Entity; + SELECT_FEOBJECT_POPUP.Show(FE_GAMEMODEL, AddNewGameModelComponentCallBack); +} + +void FEEditorInspectorWindow::AddNewGameModelComponentCallBack(const std::vector SelectionsResult) +{ + if (!SelectionsResult.empty() && SelectionsResult[0]->GetType() == FE_GAMEMODEL) + { + FEGameModel* SelectedGameModel = RESOURCE_MANAGER.GetGameModel(SelectionsResult[0]->GetObjectID()); + if (SelectedGameModel == nullptr) + { + LOG.Add("Can't add game model component. Game model is not loaded.", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + + if (INSPECTOR_WINDOW.EntityToWorkWith == nullptr) + { + LOG.Add("Can't add game model component. No entity selected.", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + + INSPECTOR_WINDOW.EntityToWorkWith->AddComponent(SelectedGameModel); + + PROJECT_MANAGER.GetCurrent()->SetModified(true); + } +} + +void FEEditorInspectorWindow::AddTerrainComponent(FEEntity* Entity) +{ + Entity->AddComponent(); + TERRAIN_SYSTEM.SetHeightMap(RESOURCE_MANAGER.CreateBlankHightMapTexture(1024, 1024), Entity); +} + +void FEEditorInspectorWindow::AddInstancedComponent(FEEntity* Entity) +{ + Entity->AddComponent(); } \ No newline at end of file diff --git a/EditorWindows/InspectorWindow.h b/EditorWindows/InspectorWindow.h index 9426cf2..0398432 100644 --- a/EditorWindows/InspectorWindow.h +++ b/EditorWindows/InspectorWindow.h @@ -68,8 +68,13 @@ class FEEditorInspectorWindow bool RenderComponentDeleteButton(FEEntity* Entity, FEComponentTypeInfo* ComponentInfo) const; + FEEntity* EntityToWorkWith = nullptr; static void AddLightComponent(FEEntity* Entity); static void AddCameraComponent(FEEntity* Entity); + static void AddGameModelComponent(FEEntity* Entity); + static void AddNewGameModelComponentCallBack(const std::vector SelectionsResult); + static void AddTerrainComponent(FEEntity* Entity); + static void AddInstancedComponent(FEEntity* Entity); static void AddVirtualUIComponent(FEEntity* Entity); public: SINGLETON_PUBLIC_PART(FEEditorInspectorWindow) diff --git a/EditorWindows/PrefabEditorManager.cpp b/EditorWindows/PrefabEditorManager.cpp index 6c1803c..c9e73c8 100644 --- a/EditorWindows/PrefabEditorManager.cpp +++ b/EditorWindows/PrefabEditorManager.cpp @@ -96,7 +96,6 @@ bool FEPrefabSceneEditorWindow::DragAndDropCallBack(FEObject* Object, void** Use FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); FEEntity* Entity = EditorSceneWindow->GetScene()->CreateEntity(Object->GetName()); - Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); Entity->AddComponent(GameModel); SELECTED.SetSelected(Entity); @@ -169,7 +168,9 @@ void FEPrefabEditorManager::PrepareEditWinow(FEPrefab* Prefab) Camera->AddComponent(); FECameraComponent& CameraComponent = Camera->GetComponent(); CameraComponent.Type = 1; - CameraComponent.DistanceToModel = SceneAABB.GetLongestAxisLength() * 2.5; + // We want to make sure that distance to model is at least 1.0 + double CalculatedDistance = SceneAABB.GetLongestAxisLength() * 2.5; + CameraComponent.DistanceToModel = CalculatedDistance > 1.0 ? SceneAABB.GetLongestAxisLength() * 2.5 : 1.0; CameraComponent.SetSSAOEnabled(false); CAMERA_SYSTEM.SetMainCamera(Camera); FETransformComponent& CameraTransform = Camera->GetComponent(); diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 6d19fec..1f8195f 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -359,11 +359,11 @@ void FEEditorSceneGraphWindow::Render() // SceneObjectsList.push_back(EntityList[i]); //} - const std::vector TerrainList = CurrentScene->GetEntityIDListWith(); + /*const std::vector TerrainList = CurrentScene->GetEntityIDListWith(); for (size_t i = 0; i < TerrainList.size(); i++) { SceneObjectsList.push_back(TerrainList[i]); - } + }*/ //SceneObjectsList.push_back(ENGINE.GetCamera()->GetObjectID()); @@ -448,48 +448,6 @@ void FEEditorSceneGraphWindow::Render() CurrentScene->CreateEntity("Unnamed entity"); } - // FIX ME! - //if (ImGui::MenuItem("Entity")) - //{ - // SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, CreateEntityCallBack); - //} - - //if (ImGui::MenuItem("Instanced entity")) - //{ - // SelectFEObjectPopUp::getInstance().Show(FE_PREFAB, CreateInstancedEntityCallBack); - //} - - //if (ImGui::MenuItem("Terrain")) - //{ - // FEEntity* Entity = SCENE.CreateEntity("Unnamed terrain"); - // FETransformComponent& TransformComponent = Entity->GetComponent(); - // Entity->AddComponent(); - // FETerrainComponent& TerrainComponent = Entity->GetComponent(); - // TerrainComponent.HeightMap = RESOURCE_MANAGER.CreateBlankHightMapTexture(); - - // PROJECT_MANAGER.GetCurrent()->SetModified(true); - //} - - //if (ImGui::BeginMenu("Light")) - //{ - // /*if (ImGui::MenuItem("Directional")) - // { - // SCENE.AddLight(FE_DIRECTIONAL_LIGHT, ""); - // } - - // if (ImGui::MenuItem("Spot")) - // { - // SCENE.AddLight(FE_SPOT_LIGHT, ""); - // } - - // if (ImGui::MenuItem("Point")) - // { - // SCENE.AddLight(FE_POINT_LIGHT, ""); - // }*/ - - // ImGui::EndMenu(); - //} - ImGui::EndMenu(); } } @@ -513,47 +471,7 @@ void FEEditorSceneGraphWindow::Render() CurrentScene->DeleteEntity(Entity); } - - // FIX ME! - /*if (SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - const FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); - if (SELECTED.GetEntity() == Entity) - SELECTED.Clear(); - - SCENE.DeleteEntity(Entity->GetObjectID()); - } - else if (SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - const FELight* Light = SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]); - if (SELECTED.GetLight() == Light) - SELECTED.Clear(); - - SCENE.DeleteLight(Light->GetObjectID()); - }*/ } - - /*if (ImGui::MenuItem("*DEBUG* Test model camera on this")) - { - FEModelViewCamera* NewCamera = new FEModelViewCamera("New ModelViewCamera"); - NewCamera->SetAspectRatio(static_cast(ENGINE.GetRenderTargetWidth()) / static_cast(ENGINE.GetRenderTargetHeight())); - - glm::vec3 Position = glm::vec3(0.0f); - if (SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - const FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); - Position = Entity->Transform.GetPosition(); - } - else if (SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) - { - const FELight* Light = SCENE.GetLight(FilteredSceneObjectsList[SceneObjectHoveredIndex]); - Position = Light->Transform.GetPosition(); - } - - NewCamera->SetTrackingObjectPosition(Position); - NewCamera->SetOnUpdate(OnCameraUpdate); - ENGINE.SetCamera(NewCamera); - }*/ } ImGui::EndPopup(); diff --git a/EditorWindows/SelectPopups.h b/EditorWindows/SelectPopups.h index 0abab99..74772ba 100644 --- a/EditorWindows/SelectPopups.h +++ b/EditorWindows/SelectPopups.h @@ -39,4 +39,6 @@ class SelectFEObjectPopUp : public ImGuiModalPopup bool IsOneObjectSelectonMode(); void SetOneObjectSelectonMode(bool NewValue); -}; \ No newline at end of file +}; + +#define SELECT_FEOBJECT_POPUP SelectFEObjectPopUp::getInstance() \ No newline at end of file diff --git a/FEEditor.cpp b/FEEditor.cpp index 1cb3cb0..fb0f4be 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -634,7 +634,7 @@ void FEEditor::DisplayEffectsWindow() const void FEEditor::RenderAllSubWindows() { - SelectFEObjectPopUp::getInstance().Render(); + SELECT_FEOBJECT_POPUP.Render(); DeleteTexturePopup::getInstance().Render(); DeleteMeshPopup::getInstance().Render(); diff --git a/FEProject.cpp b/FEProject.cpp index 0c4baca..049d947 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -922,29 +922,6 @@ void FEProject::AddUnSavedObject(FEObject* Object) UnSavedObjects.push_back(Object); } -bool FEProject::ShouldIncludeInSceneFile(const FETexture* Texture) -{ - // Terrain should manage it's textures in a different way. - const std::vector TerrainList = ProjectScene->GetEntityIDListWith(); - Json::Value TerrainData; - for (size_t i = 0; i < TerrainList.size(); i++) - { - FEEntity* Terrain = ProjectScene->GetEntity(TerrainList[i]); - FETerrainComponent& TerrainComponent = Terrain->GetComponent(); - - if (TerrainComponent.HeightMap->GetObjectID() == Texture->GetObjectID()) - return false; - - if (TerrainComponent.LayerMaps[0] != nullptr && TerrainComponent.LayerMaps[0]->GetObjectID() == Texture->GetObjectID()) - return false; - - if (TerrainComponent.LayerMaps[1] != nullptr && TerrainComponent.LayerMaps[1]->GetObjectID() == Texture->GetObjectID()) - return false; - } - - return true; -} - void FEProject::SetProjectFolder(const std::string NewValue) { if (!FILE_SYSTEM.CheckDirectory(NewValue.c_str())) diff --git a/FEProject.h b/FEProject.h index 13de173..d7ed548 100644 --- a/FEProject.h +++ b/FEProject.h @@ -43,7 +43,6 @@ class FEProject std::vector FilesToDelete; - bool ShouldIncludeInSceneFile(const FETexture* Texture); void SetProjectFolder(std::string NewValue); }; diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 8d64959..d25b853 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 8d6495906e184bdfb603907e141784607df16e01 +Subproject commit d25b853cecba86913c4b3e4cfabbf4f9a936dbee From b9651250d3f2e626b63fdb3278f344c9275def21 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Sat, 31 Aug 2024 21:14:35 -0400 Subject: [PATCH 32/46] Engine update with a new native script system; VisualNodeSystem update supports more advanced CMake project generation; CMake now supports engine as a DLL to facilitate native script system; Updated singleton usage to align with the new singleton system in the engine; Updated to use the new FEScene flag system; Inspector window now exposes extensive functionality for working with FENativeScriptComponent; Reimplemented entity rename and delete functionality to work with the updated engine; Updated scene graph tree rendering to make it more visually appealing; Editor camera is now added for each opened project to distinguish between user-defined cameras and the editor camera; FEDearImguiWrapper was updated to better support DLL mode; Added a draft of FEEditorScriptingSystem to manage the creation of project native script modules through monitoring user-defined scripts in Visual Studio project; Editor now supports game mode more appropriately, with game mode scenes decoupled from original scenes, and scripts running differently based on the scene type. --- CMakeLists.txt | 93 +++++- .../CombineChannelsToTexturePopUp.cpp | 1 - EditorWindows/ContentBrowserWindow.cpp | 35 +- EditorWindows/ContentBrowserWindow.h | 2 +- EditorWindows/DeletePopups.cpp | 15 +- EditorWindows/EditPopups.cpp | 74 ++++- EditorWindows/EditPopups.h | 4 +- .../FEEditorSceneWindow.cpp | 18 +- EditorWindows/InspectorWindow.cpp | 157 ++++++++- EditorWindows/InspectorWindow.h | 5 +- EditorWindows/PrefabEditorManager.cpp | 64 +++- EditorWindows/PrefabEditorManager.h | 3 +- EditorWindows/ProjectWasModifiedPopUp.cpp | 2 - EditorWindows/RenamePopups.cpp | 14 +- EditorWindows/ResizeTexturePopup.cpp | 2 - EditorWindows/SceneGraphWindow.cpp | 312 ++++++++++++------ EditorWindows/SceneGraphWindow.h | 38 ++- EditorWindows/SelectPopups.cpp | 3 +- EditorWindows/SelectPopups.h | 2 +- EditorWindows/ShaderEditorWindow.cpp | 15 +- FEDearImguiWrapper/FEDearImguiWrapper.cpp | 66 ++-- FEDearImguiWrapper/FEDearImguiWrapper.h | 5 +- FEEditor.cpp | 218 +++++++++--- FEEditor.h | 13 +- FEEditorDragAndDropManager.cpp | 1 - FEEditorDragAndDropManager.h | 2 +- FEEditorGizmoManager.cpp | 1 - FEEditorGizmoManager.h | 2 +- FEEditorHaloSelectionEffect.cpp | 1 - FEEditorHaloSelectionEffect.h | 2 +- FEEditorPreviewManager.cpp | 10 +- FEEditorPreviewManager.h | 2 +- FEEditorScriptingSystem.cpp | 54 +++ FEEditorScriptingSystem.h | 19 ++ FEEditorSelectedObject.cpp | 15 +- FEEditorSelectedObject.h | 2 +- FEEditorVirtualFileSystem.cpp | 1 - FEEditorVirtualFileSystem.h | 2 +- FEProject.cpp | 122 +++++-- FEProject.h | 3 +- SubSystems/FocalEngine | 2 +- SubSystems/NodeSystem/VisualNodeSystem | 2 +- 42 files changed, 1054 insertions(+), 350 deletions(-) create mode 100644 FEEditorScriptingSystem.cpp create mode 100644 FEEditorScriptingSystem.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c94654..c3e952c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,16 +12,58 @@ project(FocalEngineEditor) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS_DEBUG "/MP /ZI /W3 /Od /MTd /JMC /sdl /FC /D IMGUI_IMPL_OPENGL_LOADER_GLEW /D WIN32 /D _WINDOWS /D _DEBUG /D FE_DEBUG_ENABLED") -set(CMAKE_CXX_FLAGS_RELEASE "/MP /W3 /O2 /Oi /MT /Gy /sdl /FC /GL /OPT:REF /OPT:ICF /D IMGUI_IMPL_OPENGL_LOADER_GLEW /D NDEBUG /D WIN32 /D _WINDOWS") +# Set compiler flags based on USE_STATIC_RUNTIME +if(MSVC) + # Disable C4251 warning + add_compile_options(/wd4251) + + if(USE_STATIC_RUNTIME) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") + set(VISUAL_NODE_SYSTEM_USE_STATIC_RUNTIME ON CACHE BOOL "Use static runtime (/MT) instead of dynamic (/MD) for VisualNodeSystem" FORCE) + else() + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD") + set(VISUAL_NODE_SYSTEM_USE_STATIC_RUNTIME OFF CACHE BOOL "Use static runtime (/MT) instead of dynamic (/MD) for VisualNodeSystem" FORCE) + endif() + + # Always add /MP for multi-processor compilation + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") +endif() + +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /ZI /W3 /Od /JMC /sdl /FC /D IMGUI_IMPL_OPENGL_LOADER_GLEW /D WIN32 /D _WINDOWS /D _DEBUG /D FE_DEBUG_ENABLED") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /W3 /O2 /Oi /Gy /sdl /FC /GL /OPT:REF /OPT:ICF /D IMGUI_IMPL_OPENGL_LOADER_GLEW /D NDEBUG /D WIN32 /D _WINDOWS") # Turn on the ability to create folders to organize projects (.vcproj) # It creates "CMakePredefinedTargets" folder by default and adds CMake # defined projects like INSTALL.vcproj and ZERO_CHECK.vcproj set_property(GLOBAL PROPERTY USE_FOLDERS ON) -# Force your path to Dear ImGui +# Set up Visual node system set(DEAR_IMGUI_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/imgui CACHE PATH "Path to Dear ImGui directory." FORCE) +if(BUILD_SHARED_LIBS) + set(VISUAL_NODE_SYSTEM_BUILD_SHARED_LIBS ON CACHE BOOL "Build VisualNodeSystem as a shared library" FORCE) + # Set options for VisualNodeSystem + set(VISUAL_NODE_SYSTEM_USE_EXTERNAL_IMGUI ON CACHE BOOL "Use external ImGui from FEBasicApplication" FORCE) + set(EXTERNAL_IMGUI_LIBRARY FEBasicApplication CACHE FILEPATH "Path to external ImGui library" FORCE) + + if(USE_STATIC_RUNTIME) + message(WARNING "Building a shared library with static runtime is uncommon and may lead to issues.") + set(VISUAL_NODE_SYSTEM_GLFW_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/GLFW/lib/x64/glfw3_mt.lib CACHE PATH "Path to GLFW library." FORCE) + else() + set(VISUAL_NODE_SYSTEM_GLFW_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/GLFW/lib/x64/glfw3dll.lib CACHE PATH "Path to GLFW library." FORCE) + endif() + + set(VISUAL_NODE_SYSTEM_GLFW_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/ CACHE PATH "Path to GLFW include directory.") +else() + set(VISUAL_NODE_SYSTEM_BUILD_SHARED_LIBS OFF CACHE BOOL "Build VisualNodeSystem as a shared library" FORCE) + + if(USE_STATIC_RUNTIME) + set(VISUAL_NODE_SYSTEM_GLFW_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/GLFW/lib/x64/glfw3_mt.lib CACHE PATH "Path to GLFW library." FORCE) + else() + set(VISUAL_NODE_SYSTEM_GLFW_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/GLFW/lib/x64/glfw3.lib CACHE PATH "Path to GLFW library." FORCE) + endif() +endif() if(NOT TARGET VisualNodeSystem) add_subdirectory(SubSystems/NodeSystem/VisualNodeSystem) @@ -56,6 +98,8 @@ file(GLOB Editor_SRC "FEEditorSelectedObject.h" "FEEditorVirtualFileSystem.cpp" "FEEditorVirtualFileSystem.h" + "FEEditorScriptingSystem.cpp" + "FEEditorScriptingSystem.h" "FEProject.cpp" "FEProject.h" ) @@ -149,8 +193,15 @@ add_executable(FocalEngineEditor WIN32 ${textEditor_SRC} ) -target_link_libraries(FocalEngineEditor PRIVATE VisualNodeSystem) -target_link_libraries(FocalEngineEditor PRIVATE FocalEngine) +target_link_libraries(FocalEngineEditor + PRIVATE + FEBasicApplication + VisualNodeSystem + FocalEngine + ${GLFW_LIBRARY} + ${GLEW_LIBRARY} + opengl32.lib +) source_group("Source Files" FILES ${Application_SRC}) # *************** EDITOR *************** @@ -175,4 +226,34 @@ include_directories( ${BASICAPP_DIR} ${FOCAL_ENGINE_INCLUDES} ${VISUAL_NODE_SYSTEM_DIR} -) \ No newline at end of file +) + +# If building as DLL, copy necessary DLLs to output directory +if(BUILD_SHARED_LIBS) + add_custom_command(TARGET FocalEngineEditor POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "$/glfw3.dll" + "$" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "$/FEBasicApplication.dll" + "$" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "$/VisualNodeSystem.dll" + "$" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "$/FocalEngine.dll" + "$" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${OpenXRLoader_DLL} + "$" + ) +endif() + +# If using dynamic runtime, copy necessary DLLs to output directory +if(NOT USE_STATIC_RUNTIME) + add_custom_command(TARGET FocalEngineEditor POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${GLEW_LIB_DIR}/glew32.dll" + "$" + ) +endif() \ No newline at end of file diff --git a/EditorWindows/CombineChannelsToTexturePopUp.cpp b/EditorWindows/CombineChannelsToTexturePopUp.cpp index 7ca5c19..79c60ea 100644 --- a/EditorWindows/CombineChannelsToTexturePopUp.cpp +++ b/EditorWindows/CombineChannelsToTexturePopUp.cpp @@ -1,7 +1,6 @@ #include "CombineChannelsToTexturePopUp.h" using namespace VisNodeSys; -CombineChannelsToTexturePopUp* CombineChannelsToTexturePopUp::Instance = nullptr; ImVec2 CombineChannelsToTexturePopUp::NodeGridRelativePosition = ImVec2(5, 30); ImVec2 CombineChannelsToTexturePopUp::WindowPosition = ImVec2(0, 0); ImVec2 CombineChannelsToTexturePopUp::MousePositionWhenContextMenuWasOpened = ImVec2(0, 0); diff --git a/EditorWindows/ContentBrowserWindow.cpp b/EditorWindows/ContentBrowserWindow.cpp index 8b13520..6dd0b07 100644 --- a/EditorWindows/ContentBrowserWindow.cpp +++ b/EditorWindows/ContentBrowserWindow.cpp @@ -2,14 +2,13 @@ #include "../FEEditor.h" using namespace FocalEngine; -FEEditorContentBrowserWindow* FEEditorContentBrowserWindow::Instance = nullptr; FEObject* FEEditorContentBrowserWindow::ItemInFocus = nullptr; FEEditorContentBrowserWindow::FEEditorContentBrowserWindow() { strcpy_s(FilterForResources, ""); - ENGINE.AddMouseButtonCallback(&FEEditorContentBrowserWindow::MouseButtonCallback); + INPUT.AddMouseButtonCallback(&FEEditorContentBrowserWindow::MouseButtonCallback); } static FETexture* TempTexture = nullptr; @@ -197,7 +196,7 @@ void FEEditorContentBrowserWindow::Render() if (ImGui::BeginMenu("Texture")) { if (ImGui::MenuItem("Combine channels...")) - CombineChannelsToTexturePopUp::getInstance().Show(); + CombineChannelsToTexturePopUp::GetInstance().Show(); ImGui::EndMenu(); } @@ -267,7 +266,7 @@ void FEEditorContentBrowserWindow::Render() { if (ImGui::MenuItem("Edit")) { - EditGameModelPopup::getInstance().Show(RESOURCE_MANAGER.GetGameModel(FilteredResources[ItemUnderMouse]->GetObjectID())); + EditGameModelPopup::GetInstance().Show(RESOURCE_MANAGER.GetGameModel(FilteredResources[ItemUnderMouse]->GetObjectID())); } if (ImGui::MenuItem("Create Prefab out of this Game Model")) @@ -291,7 +290,7 @@ void FEEditorContentBrowserWindow::Render() { if (ImGui::MenuItem("Edit")) { - ShaderEditorWindow::getInstance().Show(RESOURCE_MANAGER.GetShader(FilteredResources[ItemUnderMouse]->GetObjectID())); + ShaderEditorWindow::GetInstance().Show(RESOURCE_MANAGER.GetShader(FilteredResources[ItemUnderMouse]->GetObjectID())); } } @@ -301,27 +300,27 @@ void FEEditorContentBrowserWindow::Render() { if (FilteredResources[ItemUnderMouse]->GetType() == FE_NULL) { - DeleteDirectoryPopup::getInstance().Show(FilteredResources[ItemUnderMouse]->GetName()); + DeleteDirectoryPopup::GetInstance().Show(FilteredResources[ItemUnderMouse]->GetName()); } else if (FilteredResources[ItemUnderMouse]->GetType() == FE_MESH) { - DeleteMeshPopup::getInstance().Show(RESOURCE_MANAGER.GetMesh(FilteredResources[ItemUnderMouse]->GetObjectID())); + DeleteMeshPopup::GetInstance().Show(RESOURCE_MANAGER.GetMesh(FilteredResources[ItemUnderMouse]->GetObjectID())); } else if (FilteredResources[ItemUnderMouse]->GetType() == FE_TEXTURE) { - DeleteTexturePopup::getInstance().Show(RESOURCE_MANAGER.GetTexture(FilteredResources[ItemUnderMouse]->GetObjectID())); + DeleteTexturePopup::GetInstance().Show(RESOURCE_MANAGER.GetTexture(FilteredResources[ItemUnderMouse]->GetObjectID())); } else if (FilteredResources[ItemUnderMouse]->GetType() == FE_MATERIAL) { - DeleteMaterialPopup::getInstance().Show(RESOURCE_MANAGER.GetMaterial(FilteredResources[ItemUnderMouse]->GetObjectID())); + DeleteMaterialPopup::GetInstance().Show(RESOURCE_MANAGER.GetMaterial(FilteredResources[ItemUnderMouse]->GetObjectID())); } else if (FilteredResources[ItemUnderMouse]->GetType() == FE_GAMEMODEL) { - DeleteGameModelPopup::getInstance().Show(RESOURCE_MANAGER.GetGameModel(FilteredResources[ItemUnderMouse]->GetObjectID())); + DeleteGameModelPopup::GetInstance().Show(RESOURCE_MANAGER.GetGameModel(FilteredResources[ItemUnderMouse]->GetObjectID())); } else if (FilteredResources[ItemUnderMouse]->GetType() == FE_PREFAB) { - DeletePrefabPopup::getInstance().Show(RESOURCE_MANAGER.GetPrefab(FilteredResources[ItemUnderMouse]->GetObjectID())); + DeletePrefabPopup::GetInstance().Show(RESOURCE_MANAGER.GetPrefab(FilteredResources[ItemUnderMouse]->GetObjectID())); } } } @@ -350,7 +349,7 @@ void FEEditorContentBrowserWindow::Render() if (ImGui::MenuItem("Resize")) { FETexture* TextureToResize = RESOURCE_MANAGER.GetTexture(FilteredResources[ItemUnderMouse]->GetObjectID()); - ResizeTexturePopup::getInstance().Show(TextureToResize); + ResizeTexturePopup::GetInstance().Show(TextureToResize); } ImGui::EndMenu(); @@ -615,7 +614,7 @@ void FEEditorContentBrowserWindow::RenderFilterMenu() int DirectoryIndex = 0; // ************** Drag&Drop END ************** - int IconsPerWindowWidth = (int)(ImGui::GetCurrentContext()->CurrentWindow->Rect().GetWidth() / (ItemIconSize + 8 + 32)); + int IconsPerWindowWidth = (int)(FE_IMGUI_WINDOW_MANAGER.GetCurrentWindowImpl()->Rect().GetWidth() / (ItemIconSize + 8 + 32)); // Possibly window is minimized anyway ImGui::Columns can't take 0 as columns count! if (IconsPerWindowWidth == 0) return; @@ -704,14 +703,14 @@ void FEEditorContentBrowserWindow::RenderFilterMenu() if (!bLastFrameRenameEditWasVisiable) { ImGui::SetKeyboardFocusHere(0); - ImGui::SetFocusID(ImGui::GetID("##newNameEditor"), ImGui::GetCurrentWindow()); + ImGui::SetFocusID(ImGui::GetID("##newNameEditor"), FE_IMGUI_WINDOW_MANAGER.GetCurrentWindowImpl()); ImGui::SetItemDefaultFocus(); bLastFrameRenameEditWasVisiable = true; } ImGui::SetNextItemWidth(ItemIconSize + 8.0f + 8.0f); if (ImGui::InputText("##newNameEditor", RenameBuffer, IM_ARRAYSIZE(RenameBuffer), ImGuiInputTextFlags_EnterReturnsTrue) || - ImGui::IsMouseClicked(0) && !ImGui::IsItemHovered() || ImGui::GetFocusID() != ImGui::GetID("##newNameEditor")) + ImGui::IsMouseClicked(0) && !ImGui::IsItemHovered() || !ImGui::IsItemFocused()) { if (FilteredResources[RenameIndex]->GetType() == FE_NULL) { @@ -769,7 +768,7 @@ void FEEditorContentBrowserWindow::RenderFilterMenu() MeshInfo += "\n"; MeshInfo += "Sub material socket: "; MeshInfo += RESOURCE_MANAGER.GetMesh(FilteredResources[ItemUnderMouse]->GetObjectID())->GetMaterialCount() == 2 ? "Yes" : "No"; - MessagePopUp::getInstance().Show("Mesh info", MeshInfo.c_str()); + MessagePopUp::GetInstance().Show("Mesh info", MeshInfo.c_str()); } else if (FilteredResources[ItemUnderMouse]->GetType() == FE_MATERIAL) { @@ -777,9 +776,9 @@ void FEEditorContentBrowserWindow::RenderFilterMenu() } else if (FilteredResources[ItemUnderMouse]->GetType() == FE_GAMEMODEL) { - if (!bShouldOpenContextMenu && !EditGameModelPopup::getInstance().IsVisible()) + if (!bShouldOpenContextMenu && !EditGameModelPopup::GetInstance().IsVisible()) { - EditGameModelPopup::getInstance().Show(RESOURCE_MANAGER.GetGameModel(FilteredResources[ItemUnderMouse]->GetObjectID())); + EditGameModelPopup::GetInstance().Show(RESOURCE_MANAGER.GetGameModel(FilteredResources[ItemUnderMouse]->GetObjectID())); } } else if (FilteredResources[ItemUnderMouse]->GetType() == FE_PREFAB) diff --git a/EditorWindows/ContentBrowserWindow.h b/EditorWindows/ContentBrowserWindow.h index a6a4d1f..deb498b 100644 --- a/EditorWindows/ContentBrowserWindow.h +++ b/EditorWindows/ContentBrowserWindow.h @@ -110,4 +110,4 @@ SINGLETON_PUBLIC_PART(FEEditorContentBrowserWindow) }; -#define CONTENT_BROWSER_WINDOW FEEditorContentBrowserWindow::getInstance() \ No newline at end of file +#define CONTENT_BROWSER_WINDOW FEEditorContentBrowserWindow::GetInstance() \ No newline at end of file diff --git a/EditorWindows/DeletePopups.cpp b/EditorWindows/DeletePopups.cpp index d02650b..c01ed70 100644 --- a/EditorWindows/DeletePopups.cpp +++ b/EditorWindows/DeletePopups.cpp @@ -1,8 +1,6 @@ #include "DeletePopups.h" #include "../FEEditor.h" -DeleteTexturePopup* DeleteTexturePopup::Instance = nullptr; - DeleteTexturePopup::DeleteTexturePopup() { PopupCaption = "Delete texture"; @@ -84,7 +82,7 @@ std::vector DeleteTexturePopup::MaterialsThatUsesTexture(const FETe if (EDITOR.GetFocusedScene() != nullptr) { - const std::vector TerrainList = EDITOR.GetFocusedScene()->GetEntityIDListWith(); + const std::vector TerrainList = EDITOR.GetFocusedScene()->GetEntityIDListWithComponent(); for (size_t i = 0; i < TerrainList.size(); i++) { /*FEEntity* CurrentTerrain = SCENE.GetEntity(TerrainList[i]); @@ -134,8 +132,6 @@ void DeleteTexturePopup::DeleteTexture(FETexture* Texture) PREVIEW_MANAGER.CreateGameModelPreview(GameModelListToUpdate[i]); } -DeleteMeshPopup* DeleteMeshPopup::Instance = nullptr; - DeleteMeshPopup::DeleteMeshPopup() { PopupCaption = "Delete mesh"; @@ -240,8 +236,6 @@ void DeleteMeshPopup::DeleteMesh(FEMesh* Mesh) PREVIEW_MANAGER.MeshPreviewTextures.erase(name); } -DeleteGameModelPopup* DeleteGameModelPopup::Instance = nullptr; - DeleteGameModelPopup::DeleteGameModelPopup() { PopupCaption = "Delete game model"; @@ -334,9 +328,6 @@ void DeleteGameModelPopup::DeleteGameModel(FEGameModel* GameModel) PROJECT_MANAGER.GetCurrent()->SetModified(true); } - -DeletePrefabPopup* DeletePrefabPopup::Instance = nullptr; - DeletePrefabPopup::DeletePrefabPopup() { PopupCaption = "Delete prefab"; @@ -426,8 +417,6 @@ void DeletePrefabPopup::DeletePrefab(FEPrefab* Prefab) PROJECT_MANAGER.GetCurrent()->SetModified(true); } -DeleteMaterialPopup* DeleteMaterialPopup::Instance = nullptr; - DeleteMaterialPopup::DeleteMaterialPopup() { PopupCaption = "Delete material"; @@ -531,8 +520,6 @@ void DeleteMaterialPopup::DeleteMaterial(FEMaterial* Material) PREVIEW_MANAGER.MaterialPreviewTextures.erase(name); } -DeleteDirectoryPopup* DeleteDirectoryPopup::Instance = nullptr; - DeleteDirectoryPopup::DeleteDirectoryPopup() { PopupCaption = "Delete folder"; diff --git a/EditorWindows/EditPopups.cpp b/EditorWindows/EditPopups.cpp index 6825fe4..bcb75f1 100644 --- a/EditorWindows/EditPopups.cpp +++ b/EditorWindows/EditPopups.cpp @@ -1,7 +1,6 @@ #include "EditPopups.h" #include "../FEEditor.h" -EditGameModelPopup* EditGameModelPopup::Instance = nullptr; FEMesh** EditGameModelPopup::MeshToModify = nullptr; FEMaterial** EditGameModelPopup::MaterialToModify = nullptr; @@ -718,7 +717,47 @@ bool EditGameModelPopup::IsLastSetupLOD(const size_t LODIndex) return true; } -EditMaterialWindow* EditMaterialWindow::Instance = nullptr; +FEEntity* EditMaterialWindow::InjectModelViewCamera(FEScene* Scene) +{ + FEEntity* CameraEntity = nullptr; + std::vector CameraPrefab = RESOURCE_MANAGER.GetPrefabByName("Model view camera prefab"); + if (CameraPrefab.size() == 0) + { + LOG.Add("EditMaterialWindow::InjectModelViewCamera: Camera prefab not found! Inserting camera manually.", "FE_LOG_LOADING", FE_LOG_WARNING); + + CameraEntity = Scene->CreateEntity("Prefab scene camera"); + CameraEntity->AddComponent(); + } + else + { + FEPrefab* CameraPrefabToUse = CameraPrefab[0]; + std::vector AddedEntities = SCENE_MANAGER.InstantiatePrefab(CameraPrefabToUse, Scene, true); + if (AddedEntities.empty()) + { + LOG.Add("EditMaterialWindow::InjectModelViewCamera: Camera prefab was not instantiated correctly. Inserting camera manually.", "FE_LOG_LOADING", FE_LOG_WARNING); + + CameraEntity = Scene->CreateEntity("Prefab scene camera"); + CameraEntity->AddComponent(); + } + else + { + CameraEntity = AddedEntities[0]; + } + + if (CameraEntity == nullptr) + { + LOG.Add("EditMaterialWindow::InjectModelViewCamera: Camera prefab was not instantiated correctly. Inserting camera manually.", "FE_LOG_LOADING", FE_LOG_WARNING); + + CameraEntity = Scene->CreateEntity("Prefab scene camera"); + CameraEntity->AddComponent(); + } + } + + RESOURCE_MANAGER.SetTag(CameraEntity, EDITOR_RESOURCE_TAG); + CAMERA_SYSTEM.SetMainCamera(CameraEntity); + + return CameraEntity; +} EditMaterialWindow::EditMaterialWindow() { @@ -731,7 +770,7 @@ EditMaterialWindow::EditMaterialWindow() CancelButton->SetActiveColor(ImVec4(0.1f, 1.0f, 0.1f, 1.0f)); NodeAreaTarget = DRAG_AND_DROP_MANAGER.AddTarget(FE_TEXTURE, DragAndDropnodeAreaTargetCallback, reinterpret_cast(&DragAndDropCallbackInfo), "Drop to add texture"); - PreviewScene = SCENE_MANAGER.CreateScene("MaterialEditor_Scene"); + PreviewScene = SCENE_MANAGER.CreateScene("MaterialEditor_Scene", "", FESceneFlag::Active); RESOURCE_MANAGER.SetTag(PreviewScene, EDITOR_RESOURCE_TAG); PreviewGameModel = new FEGameModel(nullptr, nullptr, "MaterialEditor_Preview_GameModel"); @@ -743,11 +782,13 @@ EditMaterialWindow::EditMaterialWindow() PreviewEntity->GetComponent().SetScale(glm::vec3(0.1f)); RESOURCE_MANAGER.SetTag(PreviewEntity, EDITOR_RESOURCE_TAG); - PreviewCameraEntity = PreviewScene->CreateEntity("MaterialEditor_Scene_CameraEntity"); - PreviewCameraEntity->AddComponent(); + PreviewCameraEntity = InjectModelViewCamera(PreviewScene); + PreviewCameraEntity->SetName("MaterialEditor_Scene_CameraEntity"); + //PreviewCameraEntity = PreviewScene->CreateEntity("MaterialEditor_Scene_CameraEntity"); + //PreviewCameraEntity->AddComponent(); FECameraComponent& CameraComponent = PreviewCameraEntity->GetComponent(); - CameraComponent.Type = 1; - CameraComponent.DistanceToModel = 10.0; + //CameraComponent.Type = 1; + //CameraComponent.DistanceToModel = 10.0; CameraComponent.SetRenderTargetSize(512, 1020); CameraComponent.SetDistanceFogEnabled(false); CAMERA_SYSTEM.SetMainCamera(PreviewCameraEntity); @@ -763,8 +804,9 @@ EditMaterialWindow::EditMaterialWindow() SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); SkyDome->AddComponent(); - SCENE_MANAGER.DeactivateScene(PreviewScene); - ENGINE.AddMouseButtonCallback(MouseButtonCallback); + PreviewScene->SetFlag(FESceneFlag::Active, false); + PreviewScene->SetFlag(FESceneFlag::Renderable, false); + INPUT.AddMouseButtonCallback(MouseButtonCallback); } void EditMaterialWindow::MouseButtonCallback(const int Button, const int Action, int Mods) @@ -775,16 +817,19 @@ void EditMaterialWindow::MouseButtonCallback(const int Button, const int Action, if (ImGui::GetIO().WantCaptureMouse && (!EDITOR_MATERIAL_WINDOW.bWindowHovered || !EDITOR_MATERIAL_WINDOW.bCameraOutputHovered)) { - CAMERA_SYSTEM.SetIsIndividualInputActive(EDITOR_MATERIAL_WINDOW.PreviewCameraEntity, false); + EDITOR_MATERIAL_WINDOW.PreviewCameraEntity->GetComponent().SetActive(false); + //CAMERA_SYSTEM.SetIsIndividualInputActive(EDITOR_MATERIAL_WINDOW.PreviewCameraEntity, false); } if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_PRESS && EDITOR_MATERIAL_WINDOW.bWindowHovered && EDITOR_MATERIAL_WINDOW.bCameraOutputHovered) { - CAMERA_SYSTEM.SetIsIndividualInputActive(EDITOR_MATERIAL_WINDOW.PreviewCameraEntity, true); + EDITOR_MATERIAL_WINDOW.PreviewCameraEntity->GetComponent().SetActive(true); + //CAMERA_SYSTEM.SetIsIndividualInputActive(EDITOR_MATERIAL_WINDOW.PreviewCameraEntity, true); } else if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_RELEASE) { - CAMERA_SYSTEM.SetIsIndividualInputActive(EDITOR_MATERIAL_WINDOW.PreviewCameraEntity, false); + EDITOR_MATERIAL_WINDOW.PreviewCameraEntity->GetComponent().SetActive(false); + //CAMERA_SYSTEM.SetIsIndividualInputActive(EDITOR_MATERIAL_WINDOW.PreviewCameraEntity, false); } } @@ -806,7 +851,7 @@ void EditMaterialWindow::Show(FEMaterial* Material) if (Material != nullptr) { PreviewGameModel->SetMaterial(Material); - SCENE_MANAGER.ActivateScene(PreviewScene); + PreviewScene->SetFlag(FESceneFlag::Active | FESceneFlag::Renderable, true); TempContainer = RESOURCE_MANAGER.NoTexture; ObjToWorkWith = Material; @@ -973,7 +1018,8 @@ void EditMaterialWindow::Close() void EditMaterialWindow::Stop() { - SCENE_MANAGER.DeactivateScene(PreviewScene); + PreviewScene->SetFlag(FESceneFlag::Active, false); + PreviewScene->SetFlag(FESceneFlag::Renderable, false); PreviewGameModel->SetMaterial(nullptr); } diff --git a/EditorWindows/EditPopups.h b/EditorWindows/EditPopups.h index 11e8521..206c59c 100644 --- a/EditorWindows/EditPopups.h +++ b/EditorWindows/EditPopups.h @@ -137,6 +137,8 @@ class EditMaterialWindow : public FEImGuiWindow // ************** Scene END ************** void Stop(); + + FEEntity* InjectModelViewCamera(FEScene* Scene); public: SINGLETON_PUBLIC_PART(EditMaterialWindow) @@ -145,4 +147,4 @@ class EditMaterialWindow : public FEImGuiWindow void Close(); }; -#define EDITOR_MATERIAL_WINDOW EditMaterialWindow::getInstance() \ No newline at end of file +#define EDITOR_MATERIAL_WINDOW EditMaterialWindow::GetInstance() \ No newline at end of file diff --git a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp index b3b87d3..7d6b3e6 100644 --- a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp +++ b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp @@ -68,24 +68,14 @@ bool FEEditorSceneWindow::DragAndDropCallBack(FEObject* Object, void** UserData) FEScene* PrefabScene = Prefab->GetScene(); FENaiveSceneGraphNode* RootNode = PrefabScene->SceneGraph.GetRoot(); - FEEntity* NewEntity = EditorSceneWindow->GetScene()->CreateEntity(Object->GetName()); - FENaiveSceneGraphNode* NewNode = EditorSceneWindow->GetScene()->SceneGraph.GetNodeByEntityID(NewEntity->GetObjectID()); - - std::vector NewNodes = SCENE_MANAGER.ImportSceneAsNode(PrefabScene, EditorSceneWindow->GetScene(), NewNode); - if (!NewNodes.empty()) + std::vector AddedEntities = SCENE_MANAGER.InstantiatePrefab(Prefab, EditorSceneWindow->GetScene()); + if (!AddedEntities.empty()) { - NewEntity->AddComponent(Prefab); - SELECTED.SetSelected(NewEntity); + AddedEntities[0]->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); + SELECTED.SetSelected(AddedEntities[0]); PROJECT_MANAGER.GetCurrent()->SetModified(true); - - NewEntity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); return true; } - else - { - EditorSceneWindow->GetScene()->DeleteEntity(NewEntity); - return false; - } } return false; diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index 3b0e41a..46caa4b 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -1,7 +1,6 @@ #include "InspectorWindow.h" #include "../FEEditor.h" -FEEditorInspectorWindow* FEEditorInspectorWindow::Instance = nullptr; FEEntity* FEEditorInspectorWindow::EntityToModify = nullptr; FEEntity* FEEditorInspectorWindow::TerrainToWorkWith = nullptr; @@ -14,6 +13,7 @@ FEEditorInspectorWindow::FEEditorInspectorWindow() AddComponentHandlers[typeid(FEInstancedComponent)] = &FEEditorInspectorWindow::AddInstancedComponent; AddComponentHandlers[typeid(FETerrainComponent)] = &FEEditorInspectorWindow::AddTerrainComponent; AddComponentHandlers[typeid(FEVirtualUIComponent)] = &FEEditorInspectorWindow::AddVirtualUIComponent; + AddComponentHandlers[typeid(FENativeScriptComponent)] = &FEEditorInspectorWindow::AddNativeScriptComponent; RemoveComponentHandlers[typeid(FECameraComponent)] = [](FEEntity* ParentEntity) -> void { ParentEntity->RemoveComponent(); @@ -39,6 +39,9 @@ FEEditorInspectorWindow::FEEditorInspectorWindow() RemoveComponentHandlers[typeid(FEVirtualUIComponent)] = [](FEEntity* ParentEntity) -> void { ParentEntity->RemoveComponent(); }; + RemoveComponentHandlers[typeid(FENativeScriptComponent)] = [](FEEntity* ParentEntity) -> void { + ParentEntity->RemoveComponent(); + }; } void FEEditorInspectorWindow::InitializeResources() @@ -454,13 +457,6 @@ void FEEditorInspectorWindow::DisplayCameraProperties(FEEntity* CameraEntity) co bool bIsMainCamera = CameraComponent.IsMainCamera(); if (ImGui::Checkbox("Main camera", &bIsMainCamera)) CAMERA_SYSTEM.SetMainCamera(CameraEntity); - - float CameraSpeed = CameraComponent.GetMovementSpeed(); - ImGui::Text("Camera speed in m/s : "); - ImGui::SameLine(); - ImGui::SetNextItemWidth(70); - ImGui::DragFloat("##Camera_speed", &CameraSpeed, 0.01f, 0.01f, 100.0f); - CameraComponent.SetMovementSpeed(CameraSpeed); float FOV = CameraComponent.GetFOV(); ImGui::Text("Field of view : "); @@ -1191,7 +1187,7 @@ void FEEditorInspectorWindow::Render() ImGui::Text("Snapped to: "); ImGui::SameLine(); - const std::vector TerrainList = CurrentScene->GetEntityIDListWith(); + const std::vector TerrainList = CurrentScene->GetEntityIDListWithComponent(); static std::string CurrentTerrain = "none"; if (InstancedComponent.GetSnappedToTerrain() == nullptr) @@ -1504,6 +1500,21 @@ void FEEditorInspectorWindow::Render() } } + if (EntitySelected->HasComponent()) + { + if (RenderComponentDeleteButton(EntitySelected, COMPONENTS_TOOL.GetComponentInfo())) + { + ImGui::PopStyleVar(); + ImGui::End(); + return; + } + + if (ImGui::CollapsingHeader("Native Script", ImGuiTreeNodeFlags_DefaultOpen)) + { + DisplayNativeScriptProperties(SELECTED.GetSelected(CurrentScene)); + } + } + std::vector AvailableComponentTypes = GetAvailableComponentsToAdd(EntitySelected); ImGui::SetNextItemWidth(220.0f); @@ -1816,7 +1827,7 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) if (!bLastFrameTerrainLayerRenameEditWasVisiable) { ImGui::SetKeyboardFocusHere(0); - ImGui::SetFocusID(ImGui::GetID("##newNameTerrainLayerEditor"), ImGui::GetCurrentWindow()); + ImGui::SetFocusID(ImGui::GetID("##newNameTerrainLayerEditor"), FE_IMGUI_WINDOW_MANAGER.GetCurrentWindowImpl()); ImGui::SetItemDefaultFocus(); bLastFrameTerrainLayerRenameEditWasVisiable = true; } @@ -1824,7 +1835,7 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) ImGui::SetNextItemWidth(350.0f); ImGui::SetCursorPos(ImVec2(PostionBeforeDraw.x + 64.0f + (ImGui::GetContentRegionAvail().x - 64.0f) / 2.0f - 350.0f / 2.0f, PostionBeforeDraw.y + 12)); if (ImGui::InputText("##newNameTerrainLayerEditor", TerrainLayerRename, IM_ARRAYSIZE(TerrainLayerRename), ImGuiInputTextFlags_EnterReturnsTrue) || - ImGui::IsMouseClicked(0) && !ImGui::IsItemHovered() || ImGui::GetFocusID() != ImGui::GetID("##newNameTerrainLayerEditor")) + ImGui::IsMouseClicked(0) && !ImGui::IsItemHovered() || ImGui::IsItemFocused()/*FE_IMGUI_WINDOW_MANAGER.GetCurrentFocusID() != ImGui::GetID("##newNameTerrainLayerEditor")*/) { PROJECT_MANAGER.GetCurrent()->SetModified(true); Layer->SetName(TerrainLayerRename); @@ -1890,7 +1901,7 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) if (FinalMaterialList.empty()) { - MessagePopUp::getInstance().Show("No suitable material", "There are no materials with compack packing."); + MessagePopUp::GetInstance().Show("No suitable material", "There are no materials with compack packing."); } else { @@ -1951,7 +1962,7 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) if (FinalMaterialList.empty()) { - MessagePopUp::getInstance().Show("No suitable material", "There are no materials with compack packing."); + MessagePopUp::GetInstance().Show("No suitable material", "There are no materials with compack packing."); } else { @@ -2001,6 +2012,8 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) void FEEditorInspectorWindow::AddVirtualUIComponent(FEEntity* Entity) { Entity->AddComponent(); + FEVirtualUIComponent& VirtualUIComponent = Entity->GetComponent(); + VirtualUIComponent.SetWindowToListen(APPLICATION.GetMainWindow()); } void FEEditorInspectorWindow::DisplayVirtualUIProperties(FEEntity* VirtualUIEntity) const @@ -2086,4 +2099,122 @@ void FEEditorInspectorWindow::AddTerrainComponent(FEEntity* Entity) void FEEditorInspectorWindow::AddInstancedComponent(FEEntity* Entity) { Entity->AddComponent(); +} + +void FEEditorInspectorWindow::AddNativeScriptComponent(FEEntity* Entity) +{ + Entity->AddComponent(); +} + +void FEEditorInspectorWindow::DisplayNativeScriptProperties(FEEntity* NativeScriptEntity) const +{ + FENativeScriptComponent& NativeScriptComponent = NativeScriptEntity->GetComponent(); + + if (!NativeScriptComponent.IsInitialized()) + { + std::vector ModuleList = NATIVE_SCRIPT_SYSTEM.GetActiveModuleIDList(); + + for (size_t i = 0; i < ModuleList.size(); i++) + { + ImGui::Text(("Module ID: " + ModuleList[i]).c_str()); + ImGui::Text(("DLL Module ID: " + NATIVE_SCRIPT_SYSTEM.GetDLLMoudleIDByNativeScriptModuleID(ModuleList[i])).c_str()); + + ImGui::Text("Script list: "); + std::vector ScriptList = NATIVE_SCRIPT_SYSTEM.GetActiveModuleScriptNameList(ModuleList[i]); + for (size_t j = 0; j < ScriptList.size(); j++) + { + ImGui::Text(ScriptList[j].c_str()); + ImGui::SameLine(); + if (ImGui::Button(("Add##" + ModuleList[i] + "_" + ScriptList[j]).c_str())) + { + NATIVE_SCRIPT_SYSTEM.InitializeScriptComponent(NativeScriptEntity, ModuleList[i], ScriptList[j]); + } + } + } + } + else + { + std::string ModuleID = NativeScriptComponent.GetModuleID(); + const FEScriptData* ScriptData = NativeScriptComponent.GetScriptData(); + + // Showing general information. + ImGui::Text(("Module: " + ModuleID).c_str()); + ImGui::Text(("DLL Module ID: " + NATIVE_SCRIPT_SYSTEM.GetDLLMoudleIDByNativeScriptModuleID(ModuleID)).c_str()); + ImGui::Text(("Script name: " + ScriptData->Name).c_str()); + ImGui::Text((std::string("Run in editor: ") + std::string(ScriptData->bRunInEditor ? "Yes" : "No")).c_str()); + + // Showing script variables. + std::unordered_map VariablesRegistry = ScriptData->VariablesRegistry; + auto VariablesIterator = VariablesRegistry.begin(); + while (VariablesIterator != VariablesRegistry.end()) + { + std::string VariableName = VariablesIterator->first; + std::string VariableType = VariablesIterator->second.Type; + + std::any VariableValue = VariablesIterator->second.Getter(NativeScriptComponent.GetCoreInstance()); + if (VariableType == "int") + { + int Value = std::any_cast(VariableValue); + ImGui::DragInt(VariableName.c_str(), &Value); + VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); + } + else if (VariableType == "float") + { + float Value = std::any_cast(VariableValue); + ImGui::DragFloat(VariableName.c_str(), &Value); + VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); + } + else if (VariableType == "double") + { + double Value = std::any_cast(VariableValue); + ImGui::DragFloat(VariableName.c_str(), (float*)&Value); + VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); + } + else if (VariableType == "bool") + { + bool Value = std::any_cast(VariableValue); + ImGui::Checkbox(VariableName.c_str(), &Value); + VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); + } + else if (VariableType == "glm::vec2") + { + glm::vec2 Value = std::any_cast(VariableValue); + ImGui::DragFloat2(VariableName.c_str(), &Value[0]); + VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); + } + else if (VariableType == "glm::vec3") + { + glm::vec3 Value = std::any_cast(VariableValue); + ImGui::DragFloat3(VariableName.c_str(), &Value[0]); + VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); + } + else if (VariableType == "glm::vec4") + { + glm::vec4 Value = std::any_cast(VariableValue); + ImGui::DragFloat4(VariableName.c_str(), &Value[0]); + VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); + } + else if (VariableType == "glm::quat") + { + glm::quat Value = std::any_cast(VariableValue); + ImGui::DragFloat4(VariableName.c_str(), &Value[0]); + VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); + } + else if (VariableType == "std::string") + { + std::string Value = std::any_cast(VariableValue); + + char Buffer[1024]; + memset(Buffer, 0, 1024); + strcpy_s(Buffer, Value.c_str()); + if (ImGui::InputText(("##String_Variable_" + VariableName).c_str(), Buffer, 1024)) + { + Value = Buffer; + VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); + } + } + + VariablesIterator++; + } + } } \ No newline at end of file diff --git a/EditorWindows/InspectorWindow.h b/EditorWindows/InspectorWindow.h index 0398432..7fc9309 100644 --- a/EditorWindows/InspectorWindow.h +++ b/EditorWindows/InspectorWindow.h @@ -1,6 +1,7 @@ #pragma once #include "ContentBrowserWindow.h" +#include "../FEEditorScriptingSystem.h" class FEEditorInspectorWindow { @@ -15,6 +16,7 @@ class FEEditorInspectorWindow void DisplayLightProperties(FEEntity* LightEntity) const; void DisplayCameraProperties(FEEntity* CameraEntity) const; void DisplayVirtualUIProperties(FEEntity* VirtualUIEntity) const; + void DisplayNativeScriptProperties(FEEntity* NativeScriptEntity) const; // Terrain settings static FEEntity* TerrainToWorkWith; @@ -76,8 +78,9 @@ class FEEditorInspectorWindow static void AddTerrainComponent(FEEntity* Entity); static void AddInstancedComponent(FEEntity* Entity); static void AddVirtualUIComponent(FEEntity* Entity); + static void AddNativeScriptComponent(FEEntity* Entity); public: SINGLETON_PUBLIC_PART(FEEditorInspectorWindow) }; -#define INSPECTOR_WINDOW FEEditorInspectorWindow::getInstance() \ No newline at end of file +#define INSPECTOR_WINDOW FEEditorInspectorWindow::GetInstance() \ No newline at end of file diff --git a/EditorWindows/PrefabEditorManager.cpp b/EditorWindows/PrefabEditorManager.cpp index c9e73c8..ef202ac 100644 --- a/EditorWindows/PrefabEditorManager.cpp +++ b/EditorWindows/PrefabEditorManager.cpp @@ -1,7 +1,6 @@ #include "PrefabEditorManager.h" #include "SceneGraphWindow.h" #include "../FEEditor.h" -FEPrefabEditorManager* FEPrefabEditorManager::Instance = nullptr; FEPrefabSceneEditorWindow::FEPrefabSceneEditorWindow(FEScene* Scene) : FEEditorSceneWindow(Scene, false) { @@ -56,8 +55,6 @@ void FEPrefabSceneEditorWindow::Render() if (ApplyButton->IsClicked()) { PREFAB_EDITOR_MANAGER.ApplyModificationsToPrefabScene(this); - //bWaitingForRemoval = true; - //Close(); } CloseButton->SetSize(ApplyButton->GetSize()); @@ -133,6 +130,48 @@ void FEPrefabEditorManager::Clear() bClearing = false; } +FEEntity* FEPrefabEditorManager::InjectModelViewCamera(FEScene* Scene) +{ + FEEntity* CameraEntity = nullptr; + std::vector CameraPrefab = RESOURCE_MANAGER.GetPrefabByName("Model view camera prefab"); + if (CameraPrefab.size() == 0) + { + LOG.Add("FEPrefabEditorManager::InjectModelViewCamera: Camera prefab not found! Inserting camera manually.", "FE_LOG_LOADING", FE_LOG_WARNING); + + CameraEntity = Scene->CreateEntity("Prefab scene camera"); + CameraEntity->AddComponent(); + } + else + { + FEPrefab* CameraPrefabToUse = CameraPrefab[0]; + std::vector AddedEntities = SCENE_MANAGER.InstantiatePrefab(CameraPrefabToUse, Scene, true); + if (AddedEntities.empty()) + { + LOG.Add("FEPrefabEditorManager::InjectModelViewCamera: Camera prefab was not instantiated correctly. Inserting camera manually.", "FE_LOG_LOADING", FE_LOG_WARNING); + + CameraEntity = Scene->CreateEntity("Prefab scene camera"); + CameraEntity->AddComponent(); + } + else + { + CameraEntity = AddedEntities[0]; + } + + if (CameraEntity == nullptr) + { + LOG.Add("FEPrefabEditorManager::InjectModelViewCamera: Camera prefab was not instantiated correctly. Inserting camera manually.", "FE_LOG_LOADING", FE_LOG_WARNING); + + CameraEntity = Scene->CreateEntity("Prefab scene camera"); + CameraEntity->AddComponent(); + } + } + + RESOURCE_MANAGER.SetTag(CameraEntity, EDITOR_RESOURCE_TAG); + CAMERA_SYSTEM.SetMainCamera(CameraEntity); + + return CameraEntity; +} + void FEPrefabEditorManager::PrepareEditWinow(FEPrefab* Prefab) { if (Prefab->GetScene() == nullptr) @@ -143,6 +182,7 @@ void FEPrefabEditorManager::PrepareEditWinow(FEPrefab* Prefab) return; FEScene* CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->GetScene(), "Scene: " + Prefab->GetName()); + CurrentPrefabScene->SetFlag(FESceneFlag::Active | FESceneFlag::EditorMode | FESceneFlag::Renderable, true); // Because by default camera is looking at 0,0,0 we need to place "empty" entity at 0,0,0. // To ensure that scene AABB would include some entity at 0,0,0. @@ -163,20 +203,18 @@ void FEPrefabEditorManager::PrepareEditWinow(FEPrefab* Prefab) CurrentPrefabScene->DeleteEntity(EmptyEntity); - FEEntity* Camera = CurrentPrefabScene->CreateEntity("Prefab scene camera"); - RESOURCE_MANAGER.SetTag(Camera, EDITOR_RESOURCE_TAG); - Camera->AddComponent(); + FEEntity* Camera = InjectModelViewCamera(CurrentPrefabScene); FECameraComponent& CameraComponent = Camera->GetComponent(); - CameraComponent.Type = 1; - // We want to make sure that distance to model is at least 1.0 - double CalculatedDistance = SceneAABB.GetLongestAxisLength() * 2.5; - CameraComponent.DistanceToModel = CalculatedDistance > 1.0 ? SceneAABB.GetLongestAxisLength() * 2.5 : 1.0; CameraComponent.SetSSAOEnabled(false); - CAMERA_SYSTEM.SetMainCamera(Camera); - FETransformComponent& CameraTransform = Camera->GetComponent(); + + // We want to make sure that distance to model is at least 1.0 + float CalculatedDistance = SceneAABB.GetLongestAxisLength() * 2.5f; + FENativeScriptComponent& ScriptComponent = Camera->GetComponent(); + ScriptComponent.SetVariableValue("DistanceToModel", CalculatedDistance > 1.0f ? SceneAABB.GetLongestAxisLength() * 2.5f : 1.0f); + // To make sure that next scene FEAABB calculation will include correct camera position. CAMERA_SYSTEM.IndividualUpdate(Camera, 0.0); - + FEEntity* SkyDomeEntity = CurrentPrefabScene->CreateEntity("Prefab scene skydome"); RESOURCE_MANAGER.SetTag(SkyDomeEntity, EDITOR_RESOURCE_TAG); SkyDomeEntity->GetComponent().SetScale(glm::vec3(100.0f)); diff --git a/EditorWindows/PrefabEditorManager.h b/EditorWindows/PrefabEditorManager.h index 2a691f9..b480e6f 100644 --- a/EditorWindows/PrefabEditorManager.h +++ b/EditorWindows/PrefabEditorManager.h @@ -29,6 +29,7 @@ class FEPrefabEditorManager bool bClearing = false; void ApplyModificationsToPrefabScene(FEPrefabSceneEditorWindow* Window); + FEEntity* InjectModelViewCamera(FEScene* Scene); public: SINGLETON_PUBLIC_PART(FEPrefabEditorManager) @@ -36,4 +37,4 @@ class FEPrefabEditorManager void Clear(); }; -#define PREFAB_EDITOR_MANAGER FEPrefabEditorManager::getInstance() \ No newline at end of file +#define PREFAB_EDITOR_MANAGER FEPrefabEditorManager::GetInstance() \ No newline at end of file diff --git a/EditorWindows/ProjectWasModifiedPopUp.cpp b/EditorWindows/ProjectWasModifiedPopUp.cpp index 219d9e8..13b1a0d 100644 --- a/EditorWindows/ProjectWasModifiedPopUp.cpp +++ b/EditorWindows/ProjectWasModifiedPopUp.cpp @@ -1,7 +1,5 @@ #include "ProjectWasModifiedPopUp.h" -ProjectWasModifiedPopUp* ProjectWasModifiedPopUp::Instance = nullptr; - ProjectWasModifiedPopUp::ProjectWasModifiedPopUp() { PopupCaption = "Save project ?"; diff --git a/EditorWindows/RenamePopups.cpp b/EditorWindows/RenamePopups.cpp index 961560f..fb35ce5 100644 --- a/EditorWindows/RenamePopups.cpp +++ b/EditorWindows/RenamePopups.cpp @@ -1,7 +1,5 @@ #include "RenamePopups.h" -RenameFailedPopUp* RenameFailedPopUp::Instance = nullptr; - RenameFailedPopUp::RenameFailedPopUp() { PopupCaption = "Invalid name"; @@ -42,8 +40,6 @@ void RenameFailedPopUp::Render() } } -RenamePopUp* RenamePopUp::Instance = nullptr; - RenamePopUp::RenamePopUp() { PopupCaption = "Rename object"; @@ -88,6 +84,14 @@ void RenamePopUp::Render() ObjToWorkWith->SetName(NewName); + if (ObjToWorkWith->GetType() == FE_SCENE_GRAPH_NODE) + { + FENaiveSceneGraphNode* Node = reinterpret_cast(ObjToWorkWith); + FEEntity* Entity = Node->GetEntity(); + if (Entity != nullptr) + Entity->SetName(NewName); + } + ImGuiModalPopup::Close(); strcpy_s(NewName, ""); } @@ -95,7 +99,7 @@ void RenamePopUp::Render() { ObjToWorkWith = nullptr; ImGuiModalPopup::Close(); - RenameFailedPopUp::getInstance().Show(); + RenameFailedPopUp::GetInstance().Show(); } } ImGui::SetItemDefaultFocus(); diff --git a/EditorWindows/ResizeTexturePopup.cpp b/EditorWindows/ResizeTexturePopup.cpp index 2db42a2..9ad6644 100644 --- a/EditorWindows/ResizeTexturePopup.cpp +++ b/EditorWindows/ResizeTexturePopup.cpp @@ -1,7 +1,5 @@ #include "ResizeTexturePopup.h" -ResizeTexturePopup* ResizeTexturePopup::Instance = nullptr; - ResizeTexturePopup::ResizeTexturePopup() { PopupCaption = "Resize texture"; diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 1f8195f..77a398a 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -1,12 +1,11 @@ #include "SceneGraphWindow.h" #include "../FEEditor.h" -FEEditorSceneGraphWindow* FEEditorSceneGraphWindow::Instance = nullptr; FEEntity* FEEditorSceneGraphWindow::EntityToModify = nullptr; FEEditorSceneGraphWindow::FEEditorSceneGraphWindow() { - strcpy_s(FilterForEntities, ""); + strcpy_s(FilterForEntities, "Filter entities..."); } void FEEditorSceneGraphWindow::InitializeResources() @@ -33,6 +32,7 @@ void FEEditorSceneGraphWindow::InitializeResources() void FEEditorSceneGraphWindow::Clear() { strcpy_s(FilterForEntities, ""); + bLastFrameWasInvisible = true; } void FEEditorSceneGraphWindow::SetCorrectItemColor(FEObject* SceneObject) const @@ -215,16 +215,35 @@ DragAndDropTarget* FEEditorSceneGraphWindow::GetSceneNodeDragAndDropTarget(FENai return SceneNodeDragAndDropTargets[UniqueID]; } -void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) +void FEEditorSceneGraphWindow::RenderNodeBackground() +{ + // Calculate the expected height of the node. + float NodeHeight = ImGui::GetFrameHeight(); + NodeHeight += BackgroundHeightModifier; + + ImRect BackgroundRect = ImRect(ImVec2(bIndintationAwareNodeBackground ? ImGui::GetCursorScreenPos().x : ImGui::GetWindowContentRegionMin().x, ImGui::GetCursorScreenPos().y), + ImVec2(ImGui::GetWindowContentRegionMax().x, ImGui::GetCursorScreenPos().y + NodeHeight)); + + // Shift the background rectangle + BackgroundRect.Min.y += BackgroundColorYShift; + BackgroundRect.Max.y += BackgroundColorYShift; + + // Render + ImColor BackgroundColor = bBackgroundColorSwitch ? ImColor(EvenNodeBackgroundColor) : ImColor(OddNodeBackgroundColor); + ImGui::GetWindowDrawList()->AddRectFilled(BackgroundRect.Min, BackgroundRect.Max, BackgroundColor); + bBackgroundColorSwitch = !bBackgroundColorSwitch; +} + +ImRect FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) { if (SubTreeRoot == nullptr) - return; + return ImRect(); FEEntity* CurrentEntity = SubTreeRoot->GetEntity(); if (CurrentEntity != nullptr) { if (CurrentEntity->GetTag() == EDITOR_RESOURCE_TAG) - return; + return ImRect(); } SceneNodeDragAndDropTargetIndex++; @@ -251,8 +270,21 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) UniqueID = static_cast(std::hash{}(CurrentEntity->GetObjectID().c_str())); } + // If last frame scene graph was invisible, open root node. + if (bLastFrameWasInvisible && CurrentEntity == nullptr) + ImGui::SetNextItemOpen(true); + + if (bUseNodeBackground) + RenderNodeBackground(); + bool bOpened = ImGui::TreeNodeEx((void*)UniqueID, NodeFlags, Name.c_str(), 0); GetSceneNodeDragAndDropTarget(SubTreeRoot)->StickToItem(); + const ImRect NodeRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); + + ImVec2 VerticalLineStart = ImGui::GetCursorScreenPos(); + VerticalLineStart.x += VerticalTreeLineXOffset; + VerticalLineStart.y += VerticalTreeLineYOffset; + ImVec2 VerticalLineEnd = VerticalLineStart; if (ImGui::IsItemClicked()) { @@ -283,6 +315,8 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) ImGui::PopTextWrapPos(); ImGui::EndTooltip();*/ + SceneGraphNodeHoveredID = SubTreeRoot->GetObjectID(); + ItemUnderMouse = UniqueID; if (ImGui::IsMouseDragging(0)) @@ -296,14 +330,104 @@ void FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot) if (!Children.empty()) { for (size_t i = 0; i < Children.size(); i++) - RenderSubTree(Children[i]); + { + // Double check if we need to draw child to make sure we don't draw internal editor resources. + FEEntity* ChildEntity = Children[i]->GetEntity(); + if (ChildEntity != nullptr) + { + if (ChildEntity->GetTag() == EDITOR_RESOURCE_TAG) + continue; + } + + const ImRect ChildRect = RenderSubTree(Children[i]); + + // Draw horizontal line. + const float MiddlePoint = (ChildRect.Min.y + ChildRect.Max.y) / 2.0f; + bool bChildHaveChildren = Children[i]->GetChildren().size() > 0; + ImVec2 HorizontalLineStart = ImVec2(VerticalLineStart.x, MiddlePoint); + ImVec2 HorizontalLineEnd = ImVec2(VerticalLineStart.x + HorizontalTreeLineLength, MiddlePoint); + if (bChildHaveChildren) + HorizontalLineEnd.x += HorizontalTreeLineLengthParentOffset; + ImGui::GetWindowDrawList()->AddLine(HorizontalLineStart, HorizontalLineEnd, ImColor(VerticalTreeLineColor)); + + VerticalLineEnd.y = MiddlePoint; + } ImGui::TreePop(); } + + // Draw vertical line. + ImGui::GetWindowDrawList()->AddLine(VerticalLineStart, VerticalLineEnd, ImColor(VerticalTreeLineColor)); } + + SceneGraphBackgroundRect.Max.x = SceneGraphBackgroundRect.Max.x > NodeRect.Max.x ? SceneGraphBackgroundRect.Max.x : NodeRect.Max.x; + SceneGraphBackgroundRect.Max.y = SceneGraphBackgroundRect.Max.y > NodeRect.Max.y ? SceneGraphBackgroundRect.Max.y : NodeRect.Max.y; + + return NodeRect; } -void FEEditorSceneGraphWindow::RenderNewSceneGraph() +int FEEditorSceneGraphWindow::FilterInputTextCallback(ImGuiInputTextCallbackData* Data) +{ + if (Data->EventFlag == ImGuiInputTextFlags_CallbackAlways) + { + bool isFocused = ImGui::IsItemActive(); + if (SCENE_GRAPH_WINDOW.bIsPlaceHolderTextUsed) + { + // Check if the input just gained focus + if (isFocused && !SCENE_GRAPH_WINDOW.bFilterInputWasFocused) + { + strcpy_s(SCENE_GRAPH_WINDOW.FilterForEntities, ""); + + // Update ImGui's buffer. + Data->BufDirty = true; + Data->DeleteChars(0, Data->BufTextLen); + Data->InsertChars(0, SCENE_GRAPH_WINDOW.FilterForEntities); + + SCENE_GRAPH_WINDOW.bIsPlaceHolderTextUsed = false; + } + } + + SCENE_GRAPH_WINDOW.bFilterInputWasFocused = isFocused; + } + + return 0; +} + + +void FEEditorSceneGraphWindow::RenderFilterInput() +{ + bool bIsPlaceHolderTextUsedWasOn = bIsPlaceHolderTextUsed; + + if (bIsPlaceHolderTextUsedWasOn) + ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 255, 255, 150)); + + // Setting up the callback for the input text. + std::function Callback = std::bind(&FEEditorSceneGraphWindow::FilterInputTextCallback, std::placeholders::_1); + auto StaticCallback = [](ImGuiInputTextCallbackData* data) -> int { + auto& callback = *static_cast*>(data->UserData); + return callback(data); + }; + + if (ImGui::InputText("##SceneGraphWindowFilter", FilterForEntities, FilterInputBufferSize, ImGuiInputTextFlags_CallbackAlways, StaticCallback, &Callback)) + { + + } + + if (!ImGui::IsItemActive()) + { + if (strlen(FilterForEntities) == 0) + { + strcpy_s(FilterForEntities, PlaceHolderTextString.c_str()); + bIsPlaceHolderTextUsed = true; + bFilterInputWasFocused = false; + } + } + + if (bIsPlaceHolderTextUsedWasOn) + ImGui::PopStyleColor(); +} + +void FEEditorSceneGraphWindow::RenderSceneGraph() { if (EDITOR.GetFocusedScene() == nullptr) return; @@ -313,23 +437,59 @@ void FEEditorSceneGraphWindow::RenderNewSceneGraph() if (bSceneNodeTargetsDirty) SceneNodeDragAndDropTargets.clear(); + SceneGraphBackgroundRect.Min = ImGui::GetCursorScreenPos(); + SceneGraphBackgroundRect.Max = SceneGraphBackgroundRect.Min; + + RenderFilterInput(); + SceneNodeDragAndDropTargetIndex = -1; + bBackgroundColorSwitch = true; RenderSubTree(Root); + SceneGraphBackgroundRect.Max.x = ImGui::GetWindowContentRegionMax().x; + SceneGraphBackgroundRect.Min -= ImVec2(10.0f, 10.0f); + SceneGraphBackgroundRect.Max += ImVec2(10.0f, 10.0f); + // Render box around the scene graph. + ImGui::GetWindowDrawList()->AddRect(SceneGraphBackgroundRect.Min, SceneGraphBackgroundRect.Max, ImColor(ImVec4(0.0f, 0.0f, 0.0f, 0.7f)), 2.0f); + + ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 15.0f); + + // Uncomment this to tweak the scene graph rendering. + /*ImGui::DragFloat("VerticalTreeLineXOffset", &VerticalTreeLineXOffset, 0.1f); + ImGui::DragFloat("VerticalTreeLineYOffset", &VerticalTreeLineYOffset, 0.1f); + ImGui::DragFloat("HorizontalTreeLineLenght", &HorizontalTreeLineLength, 0.1f); + ImGui::DragFloat("HorizontalTreeLineLenghtOffset", &HorizontalTreeLineLengthParentOffset, 0.1f); + ImGui::DragFloat("BackgroundColorYShift", &BackgroundColorYShift, 0.1f); + ImGui::DragFloat("BackgroundHeightModifier", &BackgroundHeightModifier, 0.1f); + ImGui::ColorEdit4("VerticalTreeLineColor", (float*)&VerticalTreeLineColor); + ImGui::ColorEdit4("EvenNodeBackgroundColor", (float*)&EvenNodeBackgroundColor); + ImGui::ColorEdit4("OddNodeBackgroundColor", (float*)&OddNodeBackgroundColor); + ImGui::Checkbox("Draw node background", &bUseNodeBackground); + ImGui::Checkbox("IndintationAwareNodeBackground", &bIndintationAwareNodeBackground);*/ + if (bSceneNodeTargetsDirty) bSceneNodeTargetsDirty = false; + + bLastFrameWasInvisible = false; } void FEEditorSceneGraphWindow::Render() { if (!bVisible) + { + bLastFrameWasInvisible = true; return; + } FEScene* CurrentScene = EDITOR.GetFocusedScene(); if (CurrentScene == nullptr) + { + bLastFrameWasInvisible = true; return; + } - static int SceneObjectHoveredIndex = -1; + if (!bShouldOpenContextMenu) + SceneGraphNodeHoveredID = ""; ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); ImGui::Begin("Scene Entities", nullptr, ImGuiWindowFlags_None); @@ -338,93 +498,42 @@ void FEEditorSceneGraphWindow::Render() ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::ImColor(0.7f, 0.21f, 0.21f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::ImColor(0.8f, 0.16f, 0.16f)); - RenderNewSceneGraph(); - - /*if (ImGui::Button("Enter game mode", ImVec2(220, 0))) - { - FEEditor::getInstance().SetGameMode(true); - }*/ + RenderSceneGraph(); ImGui::PopStyleColor(); ImGui::PopStyleColor(); ImGui::PopStyleColor(); - std::vector SceneObjectsList; - // FIX ME! - //const std::vector EntityList = SCENE.GetEntityList(); - //for (size_t i = 0; i < EntityList.size(); i++) + //for (size_t i = 0; i < FilteredSceneObjectsList.size(); i++) //{ - // if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(SCENE.GetEntity(EntityList[i]))) - // continue; - // SceneObjectsList.push_back(EntityList[i]); - //} - - /*const std::vector TerrainList = CurrentScene->GetEntityIDListWith(); - for (size_t i = 0; i < TerrainList.size(); i++) - { - SceneObjectsList.push_back(TerrainList[i]); - }*/ - - //SceneObjectsList.push_back(ENGINE.GetCamera()->GetObjectID()); - - // Filtering. - ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5.0f); - ImGui::Text("Filter: "); - ImGui::SameLine(); - - ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 5.0f); - ImGui::InputText("##selectFEObjectPopUpFilter", FilterForEntities, IM_ARRAYSIZE(FilterForEntities)); - - std::vector FilteredSceneObjectsList; - if (strlen(FilterForEntities) == 0) - { - FilteredSceneObjectsList = SceneObjectsList; - } - else - { - FilteredSceneObjectsList.clear(); - for (size_t i = 0; i < SceneObjectsList.size(); i++) - { - if (OBJECT_MANAGER.GetFEObject(SceneObjectsList[i])->GetName().find(FilterForEntities) != -1) - { - FilteredSceneObjectsList.push_back(SceneObjectsList[i]); - } - } - } - - if (!bShouldOpenContextMenu) - SceneObjectHoveredIndex = -1; + // DrawCorrectIcon(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); - for (size_t i = 0; i < FilteredSceneObjectsList.size(); i++) - { - DrawCorrectIcon(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); - - ImGuiTreeNodeFlags NodeFlags = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; - if (SELECTED.GetSelected(CurrentScene) != nullptr) - { - if (SELECTED.GetSelected(CurrentScene)->GetObjectID() == FilteredSceneObjectsList[i]) - { - NodeFlags |= ImGuiTreeNodeFlags_Selected; - } - } + // ImGuiTreeNodeFlags NodeFlags = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; + // if (SELECTED.GetSelected(CurrentScene) != nullptr) + // { + // if (SELECTED.GetSelected(CurrentScene)->GetObjectID() == FilteredSceneObjectsList[i]) + // { + // NodeFlags |= ImGuiTreeNodeFlags_Selected; + // } + // } - SetCorrectItemColor(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); - ImGui::TreeNodeEx((void*)(intptr_t)i, NodeFlags, OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])->GetName().c_str(), i); - PopCorrectItemColor(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); + // SetCorrectItemColor(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); + // ImGui::TreeNodeEx((void*)(intptr_t)i, NodeFlags, OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])->GetName().c_str(), i); + // PopCorrectItemColor(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); - if (ImGui::IsItemClicked()) - { - // FIX ME! - /*FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[i]); - SELECTED.SetSelected(Entity);*/ - //SELECTED.SetDirtyFlag(false); - } + // if (ImGui::IsItemClicked()) + // { + // // FIX ME! + // /*FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[i]); + // SELECTED.SetSelected(Entity);*/ + // //SELECTED.SetDirtyFlag(false); + // } - if (ImGui::IsItemHovered()) - { - SceneObjectHoveredIndex = int(i); - } - } + // if (ImGui::IsItemHovered()) + // { + // SceneObjectHoveredIndex = int(i); + // } + //} bool bOpenContextMenu = false; if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(1)) @@ -439,7 +548,7 @@ void FEEditorSceneGraphWindow::Render() { bShouldOpenContextMenu = true; - if (SceneObjectHoveredIndex == -1) + if (SceneGraphNodeHoveredID.empty()) { if (ImGui::BeginMenu("Add")) { @@ -453,23 +562,24 @@ void FEEditorSceneGraphWindow::Render() } else { - if (ImGui::MenuItem("Rename")) + FENaiveSceneGraphNode* HoveredNode = CurrentScene->SceneGraph.GetNode(SceneGraphNodeHoveredID); + if (HoveredNode != nullptr) { - if (CurrentScene->GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]) != nullptr) + FEEntity* HoveredEntity = CurrentScene->SceneGraph.GetNode(SceneGraphNodeHoveredID)->GetEntity(); + if (HoveredEntity != nullptr) { - RenamePopUp::getInstance().Show(CurrentScene->GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex])); - } - } - - if (ImGui::MenuItem("Delete")) - { - FEEntity* Entity = CurrentScene->GetEntity(FilteredSceneObjectsList[SceneObjectHoveredIndex]); - if (Entity != nullptr) - { - if (SELECTED.GetSelected(CurrentScene) == Entity) - SELECTED.Clear(CurrentScene); - - CurrentScene->DeleteEntity(Entity); + if (ImGui::MenuItem("Rename")) + { + RenamePopUp::GetInstance().Show(HoveredNode); + } + + if (ImGui::MenuItem("Delete")) + { + if (SELECTED.GetSelected(CurrentScene) == HoveredEntity) + SELECTED.Clear(CurrentScene); + + CurrentScene->DeleteEntity(HoveredEntity); + } } } } diff --git a/EditorWindows/SceneGraphWindow.h b/EditorWindows/SceneGraphWindow.h index 208bb59..9f386d8 100644 --- a/EditorWindows/SceneGraphWindow.h +++ b/EditorWindows/SceneGraphWindow.h @@ -30,10 +30,17 @@ class FEEditorSceneGraphWindow FETexture* CameraIcon = nullptr; // Entity filtering - char FilterForEntities[512]; + static const size_t FilterInputBufferSize = 2048; + char FilterForEntities[FilterInputBufferSize]; + bool bIsPlaceHolderTextUsed = true; + bool bFilterInputWasFocused = false; + std::string PlaceHolderTextString = "Filter entities..."; + void RenderFilterInput(); + static int FilterInputTextCallback(ImGuiInputTextCallbackData* data); // Context menu bool bShouldOpenContextMenu = false; + bool bLastFrameWasInvisible = true; // Entity modification static FEEntity* EntityToModify; @@ -60,15 +67,36 @@ class FEEditorSceneGraphWindow //void UpdateSceneNodeDragAndDropTargets(); - // Rendering and initialization + // Rendering and initialization. void Render(); - void RenderNewSceneGraph(); - void RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot); + void RenderSceneGraph(); + ImRect RenderSubTree(FENaiveSceneGraphNode* SubTreeRoot); void Clear(); void InitializeResources(); + bool bBackgroundColorSwitch = true; + ImRect SceneGraphBackgroundRect; + + // Colors + ImVec4 EvenNodeBackgroundColor = ImVec4(50.0f / 255.0f, 50.0f / 255.0f, 50.0f / 255.0f, 1.0f); + ImVec4 OddNodeBackgroundColor = ImVec4(90.0f / 255.0f, 90.0f / 255.0f, 90.0f / 255.0f, 1.0f); + ImVec4 VerticalTreeLineColor = ImVec4(0.5f, 140.0f / 255.0f, 170.0f / 255.0f, 1.0f); + + // Layout + float VerticalTreeLineXOffset = -6.5f; // Used to nicely line up with the arrow symbol. + float VerticalTreeLineYOffset = -8.5f; // Used to nicely line up with the arrow symbol. + float HorizontalTreeLineLength = 32.0f; // Used to make sure the horizontal line is "touching" the arrow symbol of children. + float HorizontalTreeLineLengthParentOffset = -15.6f; // Used to create small gap for nodes that have children. + float BackgroundColorYShift = -2.0f; // Used to shift background color of the scene graph tree. + float BackgroundHeightModifier = -4.0f; // Modifier of the scene graph background height. + bool bUseNodeBackground = true; // Do we want to render the background of the scene graph tree? + bool bIndintationAwareNodeBackground = false; // Used to make sure the background of the scene graph tree is indented properly. + + void RenderNodeBackground(); + + std::string SceneGraphNodeHoveredID = ""; public: SINGLETON_PUBLIC_PART(FEEditorSceneGraphWindow) }; -#define SCENE_GRAPH_WINDOW FEEditorSceneGraphWindow::getInstance() \ No newline at end of file +#define SCENE_GRAPH_WINDOW FEEditorSceneGraphWindow::GetInstance() \ No newline at end of file diff --git a/EditorWindows/SelectPopups.cpp b/EditorWindows/SelectPopups.cpp index 5a01760..f295689 100644 --- a/EditorWindows/SelectPopups.cpp +++ b/EditorWindows/SelectPopups.cpp @@ -1,6 +1,5 @@ #include "SelectPopups.h" -SelectFEObjectPopUp* SelectFEObjectPopUp::Instance = nullptr; bool SelectFEObjectPopUp::ControlButtonPressed = false; bool SelectFEObjectPopUp::bOneObjectSelectonMode = true; @@ -20,7 +19,7 @@ SelectFEObjectPopUp::SelectFEObjectPopUp() CancelButton->SetSize(ImVec2(140, 24)); CancelButton->SetPosition(ImVec2(660, 35)); - ENGINE.AddKeyCallback(SelectFEObjectPopUp::KeyButtonCallback); + INPUT.AddKeyCallback(SelectFEObjectPopUp::KeyButtonCallback); } SelectFEObjectPopUp::~SelectFEObjectPopUp() diff --git a/EditorWindows/SelectPopups.h b/EditorWindows/SelectPopups.h index 74772ba..0c118a9 100644 --- a/EditorWindows/SelectPopups.h +++ b/EditorWindows/SelectPopups.h @@ -41,4 +41,4 @@ class SelectFEObjectPopUp : public ImGuiModalPopup void SetOneObjectSelectonMode(bool NewValue); }; -#define SELECT_FEOBJECT_POPUP SelectFEObjectPopUp::getInstance() \ No newline at end of file +#define SELECT_FEOBJECT_POPUP SelectFEObjectPopUp::GetInstance() \ No newline at end of file diff --git a/EditorWindows/ShaderEditorWindow.cpp b/EditorWindows/ShaderEditorWindow.cpp index 8e13f7c..d21496f 100644 --- a/EditorWindows/ShaderEditorWindow.cpp +++ b/EditorWindows/ShaderEditorWindow.cpp @@ -1,8 +1,6 @@ #include "ShaderEditorWindow.h" #include "../FEEditor.h" -ShaderDebugWindow* ShaderDebugWindow::Instance = nullptr; - ShaderDebugWindow::ShaderDebugWindow() { Flags = ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar; @@ -130,14 +128,10 @@ void ShaderDebugWindow::Render() bUpdateNeeded = true; } - //ImGui::GetCurrentWindow()->Size = ImVec2(ImGui::GetCurrentWindow()->Size.x, ImGui::GetCurrentWindow()->Size.y - 150); - Editor.Render("TextEditor", ImVec2(ImGui::GetCurrentWindow()->Size.x, 250)); - //ImGui::GetCurrentWindow()->Size = ImVec2(ImGui::GetCurrentWindow()->Size.x, ImGui::GetCurrentWindow()->Size.y + 150); + Editor.Render("TextEditor", ImVec2(FE_IMGUI_WINDOW_MANAGER.GetCurrentWindowImpl()->Size.x, 250)); FEImGuiWindow::OnRenderEnd(); } -ShaderEditorWindow* ShaderEditorWindow::Instance = nullptr; - ShaderEditorWindow::ShaderEditorWindow() { Flags = ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar; @@ -384,7 +378,8 @@ void ShaderEditorWindow::Render() } ImGui::PopStyleColor(); - CurrentEditor->Render("Editor", ImVec2(ImGui::GetCurrentWindow()->Size.x - 40, ImGui::GetCurrentWindow()->Size.y - 190)); + ImGuiWindow* CurrentWindow = FE_IMGUI_WINDOW_MANAGER.GetCurrentWindowImpl(); + CurrentEditor->Render("Editor", ImVec2(CurrentWindow->Size.x - 40, CurrentWindow->Size.y - 190)); const float CurrentYPosition = ImGui::GetCursorPosY() + 15; CompileButton->SetPosition(ImVec2(ImGui::GetWindowWidth() / 2.0f - ImGui::GetWindowWidth() / 8.0f - 120.0f / 2.0f, CurrentYPosition)); @@ -430,7 +425,7 @@ void ShaderEditorWindow::Render() if (ShaderToEdit->IsDebugRequest()) { - ShaderDebugWindow::getInstance().Show(ShaderToEdit, "Shader debug info"); + ShaderDebugWindow::GetInstance().Show(ShaderToEdit, "Shader debug info"); } } } @@ -470,7 +465,7 @@ void ShaderEditorWindow::ReplaceShader(FEShader* OldShader, FEShader* NewShader) if (EDITOR.GetFocusedScene() != nullptr) { FEScene* CurrentScene = EDITOR.GetFocusedScene(); - const std::vector TerrainList = CurrentScene->GetEntityIDListWith(); + const std::vector TerrainList = CurrentScene->GetEntityIDListWithComponent(); for (size_t i = 0; i < TerrainList.size(); i++) { FEEntity* TempTerrain = CurrentScene->GetEntity(TerrainList[i]); diff --git a/FEDearImguiWrapper/FEDearImguiWrapper.cpp b/FEDearImguiWrapper/FEDearImguiWrapper.cpp index 9f90091..0bd8ac3 100644 --- a/FEDearImguiWrapper/FEDearImguiWrapper.cpp +++ b/FEDearImguiWrapper/FEDearImguiWrapper.cpp @@ -1,7 +1,5 @@ #include "FEDearImguiWrapper.h" -WindowsManager* WindowsManager::Instance = nullptr; - ImGuiModalPopup::ImGuiModalPopup() { PopupCaption = ""; @@ -343,6 +341,15 @@ bool FEImGuiWindow::IsMouseHovered() const return false; } +ImGuiWindow* WindowsManager::GetCurrentWindowImpl() +{ + ImGuiContext* Context = ImGui::GetCurrentContext(); + if (Context == nullptr) + return nullptr; + + return Context->CurrentWindow; +} + void FEImGuiWindow::Render() { if (bVisible) @@ -362,7 +369,7 @@ void FEImGuiWindow::Render() ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(GetPadding().x, GetPadding().y)); ImGui::Begin(Caption, nullptr, Flags); - Window = ImGui::GetCurrentWindow(); + Window = FE_IMGUI_WINDOW_MANAGER.GetCurrentWindowImpl(); } } @@ -672,8 +679,9 @@ void FERangeConfigurator::NormalizeRanges() void FERangeConfigurator::InputCalculations() { - const float MouseXWindows = ImGui::GetIO().MousePos.x - ImGui::GetCurrentWindow()->Pos.x; - const float MouseYWindows = ImGui::GetIO().MousePos.y - ImGui::GetCurrentWindow()->Pos.y; + ImGuiWindow* CurrentWindow = FE_IMGUI_WINDOW_MANAGER.GetCurrentWindowImpl(); + const float MouseXWindows = ImGui::GetIO().MousePos.x - CurrentWindow->Pos.x; + const float MouseYWindows = ImGui::GetIO().MousePos.y - CurrentWindow->Pos.y; for (size_t i = 0; i < Ranges.size(); i++) { @@ -691,13 +699,13 @@ void FERangeConfigurator::InputCalculations() break; } - ImGui::GetCurrentWindow()->Flags = ImGuiWindowFlags_None; + CurrentWindow->Flags = ImGuiWindowFlags_None; for (size_t i = 0; i < Ranges.size(); i++) { const float NeedToAdd = Ranges[i].Scroller.GetLastFrameDelta() / Size.x; if (NeedToAdd != 0.0f) { - ImGui::GetCurrentWindow()->Flags = ImGuiWindowFlags_NoMove; + CurrentWindow->Flags = ImGuiWindowFlags_NoMove; if (Ranges[i + 1].RangeSpan - NeedToAdd < 0.001f || Ranges[i].RangeSpan + NeedToAdd < 0.001f) break; @@ -715,8 +723,9 @@ void FERangeConfigurator::Render() NormalizeRanges(); InputCalculations(); - ScreenX = ImGui::GetCurrentWindow()->Pos.x + Position.x; - ScreenY = ImGui::GetCurrentWindow()->Pos.y + Position.y; + ImGuiWindow* CurrentWindow = FE_IMGUI_WINDOW_MANAGER.GetCurrentWindowImpl(); + ScreenX = CurrentWindow->Pos.x + Position.x; + ScreenY = CurrentWindow->Pos.y + Position.y; float BeginX = ScreenX; for (size_t i = 0; i < Ranges.size(); i++) @@ -797,8 +806,6 @@ void FERangeConfigurator::Clear() Ranges.clear(); } -MessagePopUp* MessagePopUp::Instance = nullptr; - MessagePopUp::MessagePopUp() {}; void MessagePopUp::Show(const std::string NewWindowCaption, const std::string MessageToShow) @@ -888,8 +895,9 @@ void FEArrowScroller::SetSelected(const bool NewValue) void FEArrowScroller::Render() { - const float MouseXWindows = ImGui::GetIO().MousePos.x - ImGui::GetCurrentWindow()->Pos.x; - const float MouseYWindows = ImGui::GetIO().MousePos.y - ImGui::GetCurrentWindow()->Pos.y; + ImGuiWindow* CurrentWindow = FE_IMGUI_WINDOW_MANAGER.GetCurrentWindowImpl(); + const float MouseXWindows = ImGui::GetIO().MousePos.x - CurrentWindow->Pos.x; + const float MouseYWindows = ImGui::GetIO().MousePos.y - CurrentWindow->Pos.y; bMouseHover = false; if (MouseXWindows >= Area.left && MouseXWindows < Area.right && @@ -901,14 +909,14 @@ void FEArrowScroller::Render() if (!bMouseHover && bWindowFlagWasAdded) { bWindowFlagWasAdded = false; - ImGui::GetCurrentWindow()->Flags = OriginalWindowFlags; + CurrentWindow->Flags = OriginalWindowFlags; } - if (!(ImGui::GetCurrentWindow()->Flags & ImGuiWindowFlags_NoMove) && bMouseHover) + if (!(CurrentWindow->Flags & ImGuiWindowFlags_NoMove) && bMouseHover) { bWindowFlagWasAdded = true; - OriginalWindowFlags = ImGui::GetCurrentWindow()->Flags; - ImGui::GetCurrentWindow()->Flags |= ImGuiWindowFlags_NoMove; + OriginalWindowFlags = CurrentWindow->Flags; + CurrentWindow->Flags |= ImGuiWindowFlags_NoMove; } if (ImGui::GetIO().MouseClicked[0]) @@ -949,21 +957,21 @@ void FEArrowScroller::Render() if (bHorizontal) { - P1 = ImVec2(ImGui::GetCurrentWindow()->Pos.x + Area.left, - ImGui::GetCurrentWindow()->Pos.y + Area.top); - P2 = ImVec2(ImGui::GetCurrentWindow()->Pos.x + Area.right, - ImGui::GetCurrentWindow()->Pos.y + Area.top); - P3 = ImVec2(ImGui::GetCurrentWindow()->Pos.x + Area.left + (Area.right - Area.left) / 2.0f, - ImGui::GetCurrentWindow()->Pos.y + Area.bottom); + P1 = ImVec2(CurrentWindow->Pos.x + Area.left, + CurrentWindow->Pos.y + Area.top); + P2 = ImVec2(CurrentWindow->Pos.x + Area.right, + CurrentWindow->Pos.y + Area.top); + P3 = ImVec2(CurrentWindow->Pos.x + Area.left + (Area.right - Area.left) / 2.0f, + CurrentWindow->Pos.y + Area.bottom); } else { - P1 = ImVec2(ImGui::GetCurrentWindow()->Pos.x + Area.left, - ImGui::GetCurrentWindow()->Pos.y + Area.top); - P2 = ImVec2(ImGui::GetCurrentWindow()->Pos.x + Area.left, - ImGui::GetCurrentWindow()->Pos.y + Area.bottom); - P3 = ImVec2(ImGui::GetCurrentWindow()->Pos.x + Area.right, - ImGui::GetCurrentWindow()->Pos.y + Area.top + (Area.right - Area.left) / 2.0f); + P1 = ImVec2(CurrentWindow->Pos.x + Area.left, + CurrentWindow->Pos.y + Area.top); + P2 = ImVec2(CurrentWindow->Pos.x + Area.left, + CurrentWindow->Pos.y + Area.bottom); + P3 = ImVec2(CurrentWindow->Pos.x + Area.right, + CurrentWindow->Pos.y + Area.top + (Area.right - Area.left) / 2.0f); } if (IsSelected()) diff --git a/FEDearImguiWrapper/FEDearImguiWrapper.h b/FEDearImguiWrapper/FEDearImguiWrapper.h index dbcf355..5c239ea 100644 --- a/FEDearImguiWrapper/FEDearImguiWrapper.h +++ b/FEDearImguiWrapper/FEDearImguiWrapper.h @@ -25,6 +25,9 @@ class WindowsManager void RenderAllWindows() const; void UnRegisterWindow(FEImGuiWindow* Window); + + // FIX ME! Here I am using internal ImGui functions. Need to find a way to avoid it. + ImGuiWindow* GetCurrentWindowImpl(); private: SINGLETON_PRIVATE_PART(WindowsManager) @@ -32,7 +35,7 @@ class WindowsManager std::vector Windows; }; -#define FE_IMGUI_WINDOW_MANAGER WindowsManager::getInstance() +#define FE_IMGUI_WINDOW_MANAGER WindowsManager::GetInstance() class ImGuiModalPopup { diff --git a/FEEditor.cpp b/FEEditor.cpp index fb0f4be..337fd3c 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -1,7 +1,5 @@ #include "FEEditor.h" -FEEditor* FEEditor::Instance = nullptr; - FEEditor::FEEditor() { ImGuiIO& IO = ImGui::GetIO(); @@ -84,7 +82,7 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) if (EDITOR.EditorSceneWindows[i]->Scene != nullptr) { if (CurrentMainCamera != nullptr) - CAMERA_SYSTEM.SetIsIndividualInputActive(CurrentMainCamera, false); + CurrentMainCamera->GetComponent().SetActive(false); } continue; @@ -92,11 +90,11 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_PRESS) { - CAMERA_SYSTEM.SetIsIndividualInputActive(CurrentMainCamera, true); + CurrentMainCamera->GetComponent().SetActive(true); } else if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_RELEASE) { - CAMERA_SYSTEM.SetIsIndividualInputActive(CurrentMainCamera, false); + CurrentMainCamera->GetComponent().SetActive(false); } if (Button == GLFW_MOUSE_BUTTON_1 && Action == GLFW_PRESS) @@ -112,8 +110,11 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) if (!bEditingTerrain) { FESelectionData* CurrentSelectionData = SELECTED.GetSceneData(EDITOR.EditorSceneWindows[i]->Scene->GetObjectID()); - SELECTED.DetermineEntityUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY(), EDITOR.EditorSceneWindows[i]->Scene); - CurrentSelectionData->CheckForSelectionisNeeded = true; + if (CurrentSelectionData != nullptr) + { + SELECTED.DetermineEntityUnderMouse(EDITOR.GetMouseX(), EDITOR.GetMouseY(), EDITOR.EditorSceneWindows[i]->Scene); + CurrentSelectionData->CheckForSelectionisNeeded = true; + } } } @@ -131,16 +132,9 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) { if (Key == GLFW_KEY_ESCAPE && Action == GLFW_PRESS) { - if (EDITOR.IsInGameMode()) - { - EDITOR.SetGameMode(false); - } - else - { - if (PROJECT_MANAGER.GetCurrent() == nullptr) - ENGINE.Terminate(); - ProjectWasModifiedPopUp::getInstance().Show(PROJECT_MANAGER.GetCurrent(), true); - } + if (PROJECT_MANAGER.GetCurrent() == nullptr) + ENGINE.Terminate(); + ProjectWasModifiedPopUp::GetInstance().Show(PROJECT_MANAGER.GetCurrent(), true); } for (size_t i = 0; i < EDITOR.EditorSceneWindows.size(); i++) @@ -221,9 +215,9 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) void FEEditor::InitializeResources() { - ENGINE.AddKeyCallback(KeyButtonCallback); - ENGINE.AddMouseButtonCallback(MouseButtonCallback); - ENGINE.AddMouseMoveCallback(MouseMoveCallback); + INPUT.AddKeyCallback(KeyButtonCallback); + INPUT.AddMouseButtonCallback(MouseButtonCallback); + INPUT.AddMouseMoveCallback(MouseMoveCallback); ENGINE.AddOnViewportResizeCallback(OnViewportResize); ENGINE.AddDropCallback(DropCallback); @@ -231,7 +225,8 @@ void FEEditor::InitializeResources() if (PROJECT_MANAGER.GetCurrent() != nullptr && PROJECT_MANAGER.GetCurrent()->ProjectScene != nullptr) { FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(PROJECT_MANAGER.GetCurrent()->ProjectScene); - CAMERA_SYSTEM.SetIsIndividualInputActive(MainCamera, false); + MainCamera->GetComponent().SetActive(false); + //CAMERA_SYSTEM.SetIsIndividualInputActive(MainCamera, false); } PROJECT_MANAGER.InitializeResources(); PREVIEW_MANAGER.InitializeResources(); @@ -284,7 +279,9 @@ void FEEditor::AfterEngineUpdate() void FEEditor::Render() { - std::vector ActiveScenes = SCENE_MANAGER.GetActiveScenes(); + EDITOR_SCRIPTING_SYSTEM.Update(); + + std::vector ActiveScenes = SCENE_MANAGER.GetScenesByFlagMask(FESceneFlag::Active | FESceneFlag::Renderable); if (ActiveScenes.empty()) { EditorSceneWindows.clear(); @@ -295,9 +292,6 @@ void FEEditor::Render() if (PROJECT_MANAGER.GetCurrent()) { - if (bGameMode) - return; - ImGui::DockSpaceOverViewport(ImGui::GetMainViewport()); DockspaceID = ImGui::GetMainViewport()->ID; @@ -326,7 +320,7 @@ void FEEditor::Render() { if (PROJECT_MANAGER.GetCurrent()->IsModified()) { - ProjectWasModifiedPopUp::getInstance().Show(PROJECT_MANAGER.GetCurrent(), false); + ProjectWasModifiedPopUp::GetInstance().Show(PROJECT_MANAGER.GetCurrent(), false); } else { @@ -345,7 +339,7 @@ void FEEditor::Render() if (PROJECT_MANAGER.GetCurrent()->IsModified()) { APPLICATION.GetMainWindow()->CancelClose(); - ProjectWasModifiedPopUp::getInstance().Show(PROJECT_MANAGER.GetCurrent(), true); + ProjectWasModifiedPopUp::GetInstance().Show(PROJECT_MANAGER.GetCurrent(), true); } else { @@ -436,6 +430,14 @@ void FEEditor::Render() } ImGui::PopStyleVar(); + std::string ButtonText = "Run game mode"; + if (EDITOR.IsInGameMode()) + ButtonText = "Exit game mode"; + if (ImGui::Button(ButtonText.c_str(), ImVec2(220, 0))) + { + EDITOR.SetGameMode(!EDITOR.IsInGameMode()); + } + for (size_t i = 0; i < EditorSceneWindows.size(); i++) { // Rendeting would be done by RenderAllSubWindows(). @@ -507,7 +509,7 @@ void FEEditor::CloseWindowCallBack() if (PROJECT_MANAGER.GetCurrent()->IsModified()) { APPLICATION.GetMainWindow()->CancelClose(); - ProjectWasModifiedPopUp::getInstance().Show(PROJECT_MANAGER.GetCurrent(), true); + ProjectWasModifiedPopUp::GetInstance().Show(PROJECT_MANAGER.GetCurrent(), true); } else { @@ -540,7 +542,7 @@ void FEEditor::DropCallback(const int Count, const char** Paths) { for (size_t i = 0; i < size_t(Count); i++) { - if (FILE_SYSTEM.CheckDirectory(Paths[i]) && Count == 1) + if (FILE_SYSTEM.DoesDirectoryExist(Paths[i]) && Count == 1) { if (PROJECT_MANAGER.GetCurrent() == nullptr) { @@ -574,16 +576,6 @@ void FEEditor::DropCallback(const int Count, const char** Paths) } } -bool FEEditor::IsInGameMode() const -{ - return bGameMode; -} - -void FEEditor::SetGameMode(const bool GameMode) -{ - this->bGameMode = GameMode; -} - void FEEditor::DisplayEffectsWindow() const { if (!bEffectsWindowVisible) @@ -636,21 +628,21 @@ void FEEditor::RenderAllSubWindows() { SELECT_FEOBJECT_POPUP.Render(); - DeleteTexturePopup::getInstance().Render(); - DeleteMeshPopup::getInstance().Render(); - DeleteGameModelPopup::getInstance().Render(); - DeleteMaterialPopup::getInstance().Render(); - DeletePrefabPopup::getInstance().Render(); - DeleteDirectoryPopup::getInstance().Render(); + DeleteTexturePopup::GetInstance().Render(); + DeleteMeshPopup::GetInstance().Render(); + DeleteGameModelPopup::GetInstance().Render(); + DeleteMaterialPopup::GetInstance().Render(); + DeletePrefabPopup::GetInstance().Render(); + DeleteDirectoryPopup::GetInstance().Render(); - ResizeTexturePopup::getInstance().Render(); + ResizeTexturePopup::GetInstance().Render(); JustTextWindowObj.Render(); - RenamePopUp::getInstance().Render(); - RenameFailedPopUp::getInstance().Render(); - MessagePopUp::getInstance().Render(); + RenamePopUp::GetInstance().Render(); + RenameFailedPopUp::GetInstance().Render(); + MessagePopUp::GetInstance().Render(); - ProjectWasModifiedPopUp::getInstance().Render(); + ProjectWasModifiedPopUp::GetInstance().Render(); FE_IMGUI_WINDOW_MANAGER.RenderAllWindows(); } @@ -759,6 +751,17 @@ void FEEditor::OnProjectClose() PREFAB_EDITOR_MANAGER.Clear(); } +FEEditorSceneWindow* FEEditor::GetEditorSceneWindow(std::string SceneID) +{ + for (size_t i = 0; i < EditorSceneWindows.size(); i++) + { + if (EditorSceneWindows[i]->Scene->GetObjectID() == SceneID) + return EditorSceneWindows[i]; + } + + return nullptr; +} + void FEEditor::AddEditorScene(FEScene* Scene, bool bMain) { FEEditorSceneWindow* NewSceneWindow = new FEEditorSceneWindow(Scene, bMain); @@ -800,4 +803,119 @@ void FEEditor::BeforeChangeOfFocusedScene(FEScene* NewSceneInFocus) SELECTED.Clear(EDITOR.GetFocusedScene()); GIZMO_MANAGER.HideAllGizmo(EDITOR.GetFocusedScene()); } +} + +bool FEEditor::IsInGameMode() const +{ + return bGameMode; +} + +void FEEditor::SetGameMode(const bool GameMode) +{ + if (SetGameModeInternal(GameMode)) + bGameMode = GameMode; +} + +bool FEEditor::DuplicateScenesForGameMode() +{ + if (EDITOR.GetFocusedScene() == nullptr) + { + LOG.Add("FEEditor::DuplicateScenesForGameMode: No scene to duplicate for game mode.", "FE_EDITOR_GAME_MODE", FE_LOG_ERROR); + return false; + } + + FEScene* GameModeScene = SCENE_MANAGER.DuplicateScene(EDITOR.GetFocusedScene()->GetObjectID(), "GameMode", [](FEEntity* EntityToCheck) { + return !(EntityToCheck->GetTag() == EDITOR_RESOURCE_TAG); + }); + + if (GameModeScene == nullptr) + { + LOG.Add("FEEditor::DuplicateScenesForGameMode: Failed to duplicate scene for game mode.", "FE_EDITOR_GAME_MODE", FE_LOG_ERROR); + return false; + } + + ParentIDToScenesInGameMode[EDITOR.GetFocusedScene()->GetObjectID()] = GameModeScene; + GameModeScene->SetFlag(FESceneFlag::EditorMode, false); + GameModeScene->SetFlag(FESceneFlag::Active, true); + GameModeScene->SetFlag(FESceneFlag::Renderable, true); + GameModeScene->SetFlag(FESceneFlag::GameMode, true); + + EDITOR.AddEditorScene(GameModeScene, false); + + return true; +} + +bool FEEditor::SetGameModeInternal(bool GameMode) +{ + if (EDITOR.IsInGameMode() == GameMode) + return false; + + if (EDITOR.GetFocusedScene() == nullptr) + { + LOG.Add("FEEditor::SetGameModeInternal: No scene to duplicate for game mode.", "FE_EDITOR_GAME_MODE", FE_LOG_ERROR); + return false; + } + + if (GameMode) + { + if (!DuplicateScenesForGameMode()) + { + LOG.Add("FEEditor::SetGameModeInternal: Failed to set game mode.", "FE_EDITOR_GAME_MODE", FE_LOG_ERROR); + return false; + } + } + else + { + auto SceneIterator = ParentIDToScenesInGameMode.begin(); + while (SceneIterator != ParentIDToScenesInGameMode.end()) + { + DeleteScene(SceneIterator->second->GetObjectID()); + SceneIterator = ParentIDToScenesInGameMode.erase(SceneIterator); + } + } + + return true; +} + +void FEEditor::DeleteScene(std::string SceneID) +{ + FEScene* SceneToDelete = SCENE_MANAGER.GetScene(SceneID); + if (SceneToDelete == nullptr) + { + LOG.Add("FEEditor::DeleteScene: Scene to delete not found.", "FE_EDITOR", FE_LOG_ERROR); + return; + } + + FEEditorSceneWindow* SceneWindow = GetEditorSceneWindow(SceneToDelete->GetObjectID()); + if (SceneWindow != nullptr) + { + if (EDITOR.FocusedEditorSceneID == SceneToDelete->GetObjectID()) + { + for (size_t i = 0; i < EditorSceneWindows.size(); i++) + { + if (EditorSceneWindows[i]->bMain && EditorSceneWindows[i] != SceneWindow) + { + EDITOR.FocusedEditorSceneID = EditorSceneWindows[i]->Scene->GetObjectID(); + } + } + } + + for (size_t i = 0; i < EditorSceneWindows.size(); i++) + { + if (EditorSceneWindows[i] == SceneWindow) + { + EditorSceneWindows.erase(EditorSceneWindows.begin() + i); + delete SceneWindow; + break; + } + } + } + + if (SELECTED.PerSceneData.find(SceneToDelete->GetObjectID()) != SELECTED.PerSceneData.end()) + SELECTED.PerSceneData.erase(SceneToDelete->GetObjectID()); + + if (GIZMO_MANAGER.PerSceneData.find(SceneToDelete->GetObjectID()) != GIZMO_MANAGER.PerSceneData.end()) + GIZMO_MANAGER.PerSceneData.erase(SceneToDelete->GetObjectID()); + + SCENE_MANAGER.DeleteScene(SceneToDelete->GetObjectID()); } \ No newline at end of file diff --git a/FEEditor.h b/FEEditor.h index 20cd993..ee93f50 100644 --- a/FEEditor.h +++ b/FEEditor.h @@ -31,6 +31,9 @@ class FEEditor void SetSceneEntityIDInClipboard(std::string NewValue); FEScene* GetFocusedScene() const; + + bool IsInGameMode() const; + void SetGameMode(bool GameMode); private: SINGLETON_PRIVATE_PART(FEEditor) @@ -41,10 +44,13 @@ class FEEditor std::string FocusedEditorSceneID = ""; ImGuiID DockspaceID = 0; + FEEditorSceneWindow* GetEditorSceneWindow(std::string SceneID); void AddEditorScene(FEScene* Scene, bool bMain = false); void AddCustomEditorScene(FEEditorSceneWindow* SceneWindow); std::vector EditorSceneWindows; + void DeleteScene(std::string SceneID); + // Clipboard std::string SceneEntityIDInClipboard; @@ -75,8 +81,9 @@ class FEEditor // Game mode bool bGameMode = false; - bool IsInGameMode() const; - void SetGameMode(bool GameMode); + bool SetGameModeInternal(bool GameMode); + std::unordered_map ParentIDToScenesInGameMode; + bool DuplicateScenesForGameMode(); // Sub-windows void RenderAllSubWindows(); @@ -91,4 +98,4 @@ class FEEditor void BeforeChangeOfFocusedScene(FEScene* NewSceneInFocus); }; -#define EDITOR FEEditor::getInstance() \ No newline at end of file +#define EDITOR FEEditor::GetInstance() \ No newline at end of file diff --git a/FEEditorDragAndDropManager.cpp b/FEEditorDragAndDropManager.cpp index cd88f14..4f408b6 100644 --- a/FEEditorDragAndDropManager.cpp +++ b/FEEditorDragAndDropManager.cpp @@ -1,7 +1,6 @@ #include "FEEditorDragAndDropManager.h" using namespace FocalEngine; -DragAndDropManager* DragAndDropManager::Instance = nullptr; DragAndDropManager::DragAndDropManager() {} DragAndDropManager::~DragAndDropManager() {} diff --git a/FEEditorDragAndDropManager.h b/FEEditorDragAndDropManager.h index 91cdd90..d5bcd81 100644 --- a/FEEditorDragAndDropManager.h +++ b/FEEditorDragAndDropManager.h @@ -72,4 +72,4 @@ class DragAndDropManager bool ObjectCanBeDroped() const; }; -#define DRAG_AND_DROP_MANAGER DragAndDropManager::getInstance() \ No newline at end of file +#define DRAG_AND_DROP_MANAGER DragAndDropManager::GetInstance() \ No newline at end of file diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index 4a04478..ee503e5 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -2,7 +2,6 @@ using namespace FocalEngine; #include "FEEditor.h" -GizmoManager* GizmoManager::Instance = nullptr; GizmoManager::GizmoManager() {} GizmoManager::~GizmoManager() {} diff --git a/FEEditorGizmoManager.h b/FEEditorGizmoManager.h index 0d8165d..3d15b96 100644 --- a/FEEditorGizmoManager.h +++ b/FEEditorGizmoManager.h @@ -137,4 +137,4 @@ class GizmoManager FETransformComponent DummyTransformComponent; }; -#define GIZMO_MANAGER GizmoManager::getInstance() \ No newline at end of file +#define GIZMO_MANAGER GizmoManager::GetInstance() \ No newline at end of file diff --git a/FEEditorHaloSelectionEffect.cpp b/FEEditorHaloSelectionEffect.cpp index 42b455f..987de99 100644 --- a/FEEditorHaloSelectionEffect.cpp +++ b/FEEditorHaloSelectionEffect.cpp @@ -2,7 +2,6 @@ #include "FEEditor.h" using namespace FocalEngine; -FEEditorHaloSelectionEffect* FEEditorHaloSelectionEffect::Instance = nullptr; FEEditorHaloSelectionEffect::FEEditorHaloSelectionEffect() {} FEEditorHaloSelectionEffect::~FEEditorHaloSelectionEffect() {} diff --git a/FEEditorHaloSelectionEffect.h b/FEEditorHaloSelectionEffect.h index e009693..ccd7e81 100644 --- a/FEEditorHaloSelectionEffect.h +++ b/FEEditorHaloSelectionEffect.h @@ -42,4 +42,4 @@ class FEEditorHaloSelectionEffect FEHaloSelectionData* GetSceneData(const std::string& SceneID); }; -#define HALO_SELECTION_EFFECT FEEditorHaloSelectionEffect::getInstance() \ No newline at end of file +#define HALO_SELECTION_EFFECT FEEditorHaloSelectionEffect::GetInstance() \ No newline at end of file diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index ddf44b0..53fa918 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -2,7 +2,6 @@ #include "FEEditor.h" using namespace FocalEngine; -FEEditorPreviewManager* FEEditorPreviewManager::Instance = nullptr; FEEditorPreviewManager::FEEditorPreviewManager() {} FEEditorPreviewManager::~FEEditorPreviewManager() {} @@ -11,7 +10,7 @@ FETransformComponent FEEditorPreviewManager::OriginalTransform = FETransformComp void FEEditorPreviewManager::InitializeResources() { - PreviewScene = SCENE_MANAGER.CreateScene("EditorPreviewScene"); + PreviewScene = SCENE_MANAGER.CreateScene("EditorPreviewScene", "", FESceneFlag::Active); RESOURCE_MANAGER.SetTag(PreviewScene, EDITOR_RESOURCE_TAG); PreviewGameModel = new FEGameModel(nullptr, nullptr, "editorPreviewGameModel"); @@ -50,7 +49,8 @@ void FEEditorPreviewManager::InitializeResources() SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); SkyDome->AddComponent(); - SCENE_MANAGER.DeactivateScene(PreviewScene); + PreviewScene->SetFlag(FESceneFlag::Active | FESceneFlag::Renderable, false); + PreviewScene->SetFlag(FESceneFlag::EditorMode, true); } void FEEditorPreviewManager::UpdateAll() @@ -82,6 +82,8 @@ void FEEditorPreviewManager::UpdateAll() void FEEditorPreviewManager::BeforePreviewActions() { + PreviewScene->SetFlag(FESceneFlag::Active | FESceneFlag::Renderable, true); + // The transform impacts the AABB. Therefore, the necessary values must be set prior to any calculations. PreviewEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, 0.0)); PreviewEntity->GetComponent().SetScale(glm::vec3(1.0, 1.0, 1.0)); @@ -90,6 +92,8 @@ void FEEditorPreviewManager::BeforePreviewActions() void FEEditorPreviewManager::AfterPreviewActions() { + PreviewScene->SetFlag(FESceneFlag::Active | FESceneFlag::Renderable, false); + PreviewGameModel->Mesh = nullptr; PreviewGameModel->Material = nullptr; } diff --git a/FEEditorPreviewManager.h b/FEEditorPreviewManager.h index bc84c5b..cef1fc1 100644 --- a/FEEditorPreviewManager.h +++ b/FEEditorPreviewManager.h @@ -72,4 +72,4 @@ class FEEditorPreviewManager void Clear(); }; -#define PREVIEW_MANAGER FEEditorPreviewManager::getInstance() \ No newline at end of file +#define PREVIEW_MANAGER FEEditorPreviewManager::GetInstance() \ No newline at end of file diff --git a/FEEditorScriptingSystem.cpp b/FEEditorScriptingSystem.cpp new file mode 100644 index 0000000..5525855 --- /dev/null +++ b/FEEditorScriptingSystem.cpp @@ -0,0 +1,54 @@ +#include "FEEditorScriptingSystem.h" +using namespace FocalEngine; + +FEEditorScriptingSystem::FEEditorScriptingSystem() +{ + +} + +FEEditorScriptingSystem::~FEEditorScriptingSystem() +{ +} + +void FEEditorScriptingSystem::Update() +{ + //std::string StartOfPath = "D:/Script__08_28_2024/Debug/"; + ////std::string StartOfPath = "C:/Users/kberegovyi/Downloads/Script__08_27_2024/Debug/"; + + //uint64_t NewWriteTime = FILE_SYSTEM.GetFileLastWriteTime(StartOfPath + "UserScriptTest.dll"); + //if (NewWriteTime != LastWriteTime && NewWriteTime != 0) + //{ + // // FIX ME! It is called 2 times. + // uint64_t Differece = NewWriteTime >= LastWriteTime ? NewWriteTime - LastWriteTime : LastWriteTime - NewWriteTime; + // LastWriteTime = NewWriteTime; + + // if (Differece > 1'000'000) + // { + // //std::string NewWriteTimeStr = TIME.NanosecondTimeStampToDate(FILE_SYSTEM.GetFileLastWriteTime(StartOfPath + "UserScriptTest.dll")); + // //std::string OldWriteTimeStr = TIME.NanosecondTimeStampToDate(LastWriteTime); + + // LastWriteTime = NewWriteTime; + + // if (!FILE_SYSTEM.DoesDirectoryExist(FILE_SYSTEM.GetCurrentWorkingPath() + "/NativeScriptsTemp")) + // FILE_SYSTEM.CreateDirectory(FILE_SYSTEM.GetCurrentWorkingPath() + "/NativeScriptsTemp"); + + // FILE_SYSTEM.WaitForFileAccess(StartOfPath + "UserScriptTest.dll", 2000); + // FILE_SYSTEM.WaitForFileAccess(StartOfPath + "UserScriptTest.pdb", 2000); + + // FENativeScriptModule* NewNativeScriptModule = RESOURCE_MANAGER.CreateNativeScriptModule(StartOfPath + "UserScriptTest.dll", StartOfPath + "UserScriptTest.pdb"); + // if (ExternalEditorActiveModule != nullptr) + // { + // NATIVE_SCRIPT_SYSTEM.UpdateNativeScriptModule(ExternalEditorActiveModule->GetObjectID(), NewNativeScriptModule->GetObjectID()); + // } + // else + // { + // NATIVE_SCRIPT_SYSTEM.ActivateNativeScriptModule(NewNativeScriptModule); + // } + + // ExternalEditorActiveModule = NewNativeScriptModule; + // + // int y = 0; + // y++; + // } + //} +} diff --git a/FEEditorScriptingSystem.h b/FEEditorScriptingSystem.h new file mode 100644 index 0000000..865db91 --- /dev/null +++ b/FEEditorScriptingSystem.h @@ -0,0 +1,19 @@ +#pragma once + +#include "../FEngine.h" +using namespace FocalEngine; + +class FEEditorScriptingSystem +{ +public: + SINGLETON_PUBLIC_PART(FEEditorScriptingSystem) + + void Update(); +private: + SINGLETON_PRIVATE_PART(FEEditorScriptingSystem) + + uint64_t LastWriteTime = 0; + FENativeScriptModule* ExternalEditorActiveModule = nullptr; +}; + +#define EDITOR_SCRIPTING_SYSTEM FEEditorScriptingSystem::GetInstance() diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index 15b9b18..33f98b4 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -3,7 +3,6 @@ #include "FEEditor.h" using namespace FocalEngine; -FEEditorSelectedObject* FEEditorSelectedObject::Instance = nullptr; FEEditorSelectedObject::FEEditorSelectedObject() {} FEEditorSelectedObject::~FEEditorSelectedObject() {} @@ -89,6 +88,13 @@ void FEEditorSelectedObject::SetSelected(FEEntity* SelectedObject) { AddSceneData(CurrentScene->GetObjectID()); CurrentSelectionData = GetSceneData(CurrentScene->GetObjectID()); + + // If the data is still null log error and return + if (CurrentSelectionData == nullptr) + { + LOG.Add("FEEditorSelectedObject::SetSelected: Could not create selection data for scene: " + CurrentScene->GetObjectID(), "FE_LOG_ERROR", FE_LOG_ERROR); + return; + } } if (CurrentSelectionData->Container != nullptr && CurrentSelectionData->Container->HasComponent() && CurrentSelectionData->Container != SelectedObject) @@ -116,7 +122,7 @@ void FEEditorSelectedObject::Clear(FEScene* Scene) CurrentSelectionData->InstancedSubObjectIndexSelected = -1; CurrentSelectionData->Container = nullptr; - if (!SCENE_MANAGER.GetActiveScenes().empty()) + if (!SCENE_MANAGER.GetScenesByFlagMask(FESceneFlag::Active).empty()) if (OnUpdateFunction != nullptr) OnUpdateFunction(Scene); } @@ -693,10 +699,13 @@ void FEEditorSelectedObject::AddSceneData(const std::string& SceneID) if (PerSceneData.find(SceneID) != PerSceneData.end()) return; + FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(CurrentScene); + if (MainCamera == nullptr) + return; + PerSceneData[SceneID] = new FESelectionData(); PerSceneData[SceneID]->SceneID = SceneID; - FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(CurrentScene); FETransformComponent& CameraTransformComponent = MainCamera->GetComponent(); FECameraComponent& CameraComponent = MainCamera->GetComponent(); diff --git a/FEEditorSelectedObject.h b/FEEditorSelectedObject.h index 2faf931..580fa81 100644 --- a/FEEditorSelectedObject.h +++ b/FEEditorSelectedObject.h @@ -82,4 +82,4 @@ class FEEditorSelectedObject void RenderEntityHaloEffectInternal(FEEntity* Entity, glm::vec3 Color, FEEntity* CameraEntity, FESelectionData* CurrentSelectionData); }; -#define SELECTED FEEditorSelectedObject::getInstance() \ No newline at end of file +#define SELECTED FEEditorSelectedObject::GetInstance() \ No newline at end of file diff --git a/FEEditorVirtualFileSystem.cpp b/FEEditorVirtualFileSystem.cpp index a2aabbf..cd9e933 100644 --- a/FEEditorVirtualFileSystem.cpp +++ b/FEEditorVirtualFileSystem.cpp @@ -152,7 +152,6 @@ void FEVFSDirectory::SetReadOnly(const bool NewValue) bReadOnly = NewValue; } -FEVirtualFileSystem* FEVirtualFileSystem::Instance = nullptr; FEVirtualFileSystem::FEVirtualFileSystem() { Root = new FEVFSDirectory(); diff --git a/FEEditorVirtualFileSystem.h b/FEEditorVirtualFileSystem.h index 320bbaf..29c2c29 100644 --- a/FEEditorVirtualFileSystem.h +++ b/FEEditorVirtualFileSystem.h @@ -89,4 +89,4 @@ class FEVirtualFileSystem }; #define VIRTUAL_FILE_SYSTEM_VERSION 0.01f -#define VIRTUAL_FILE_SYSTEM FEVirtualFileSystem::getInstance() +#define VIRTUAL_FILE_SYSTEM FEVirtualFileSystem::GetInstance() diff --git a/FEProject.cpp b/FEProject.cpp index 049d947..dced369 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -1,7 +1,6 @@ #include "FEProject.h" #include "FEEditor.h" -FEProjectManager* FEProjectManager::Instance = nullptr; FEProjectManager::FEProjectManager() {} FEProjectManager::~FEProjectManager() {} @@ -28,7 +27,7 @@ std::vector FEProjectManager::GetList() void FEProjectManager::LoadProjectList() { - if (!FILE_SYSTEM.CheckDirectory(PROJECTS_FOLDER)) + if (!FILE_SYSTEM.DoesDirectoryExist(PROJECTS_FOLDER)) CustomProjectFolder = ""; const std::vector ProjectNameList = FILE_SYSTEM.GetDirectoryList(PROJECTS_FOLDER); @@ -43,8 +42,8 @@ void FEProjectManager::LoadProjectList() void FEProjectManager::CloseCurrentProject() { //closing all windows or popups. - WindowsManager::getInstance().CloseAllWindows(); - WindowsManager::getInstance().CloseAllPopups(); + WindowsManager::GetInstance().CloseAllWindows(); + WindowsManager::GetInstance().CloseAllPopups(); SELECTED.ClearAll(); PREVIEW_MANAGER.Clear(); @@ -64,11 +63,16 @@ void FEProjectManager::OpenProject(const int ProjectIndex) { PROJECT_MANAGER.SetCurrent(List[ProjectIndex]); PROJECT_MANAGER.GetCurrent()->LoadProject(); + PROJECT_MANAGER.GetCurrent()->ProjectScene->SetFlag(FESceneFlag::Renderable, true); + PROJECT_MANAGER.GetCurrent()->ProjectScene->SetFlag(FESceneFlag::EditorMode, true); EDITOR.AddEditorScene(PROJECT_MANAGER.GetCurrent()->ProjectScene, true); EDITOR.FocusedEditorSceneID = PROJECT_MANAGER.GetCurrent()->ProjectScene->GetObjectID(); IndexChosen = -1; - // after loading project we should update our previews + // In each loaded project we need to inject editor camera. + InjectEditorCamera(PROJECT_MANAGER.GetCurrent()->ProjectScene); + + // After loading project we should update our previews PREVIEW_MANAGER.UpdateAll(); SELECTED.ClearAll(); } @@ -278,17 +282,8 @@ void FEProjectManager::CreateNewProject(std::string ProjectName, std::string Pro std::ofstream ProjectFile; Root["version"] = PROJECTS_FILE_VER; - FEScene* NewScene = SCENE_MANAGER.CreateScene(ProjectName, "", false); + FEScene* NewScene = SCENE_MANAGER.CreateScene(ProjectName, "", FESceneFlag::None); - FEEntity* CameraEntity = NewScene->CreateEntity("Camera"); - CameraEntity->AddComponent(); - FECameraComponent& CameraComponent = CameraEntity->GetComponent(); - CameraComponent.SetRenderTargetSize(128, 128); - CameraComponent.SetDistanceFogEnabled(false); - CAMERA_SYSTEM.SetMainCamera(CameraEntity); - FETransformComponent& CameraTransform = CameraEntity->GetComponent(); - CameraTransform.SetPosition(glm::vec3(-4.2269f, 15.7178f, 19.6429f)); - FEEntity* SunEntity = NewScene->CreateEntity("Sun"); SunEntity->AddComponent(FE_DIRECTIONAL_LIGHT); FELightComponent& LightComponent = SunEntity->GetComponent(); @@ -323,16 +318,15 @@ void FEProjectManager::CreateNewProject(std::string ProjectName, std::string Pro ProjectFile << JsonFile; ProjectFile.close(); - SCENE_MANAGER.DeactivateScene(NewScene); SCENE_MANAGER.DeleteScene(NewScene); } bool FEProjectManager::ContainProject(const std::string Path) { - if (!FILE_SYSTEM.CheckDirectory(Path.c_str())) + if (!FILE_SYSTEM.DoesDirectoryExist(Path.c_str())) return false; - if (!FILE_SYSTEM.CheckFile((Path + "/scene.txt").c_str())) + if (!FILE_SYSTEM.DoesFileExist((Path + "/scene.txt").c_str())) return false; return true; @@ -601,6 +595,43 @@ void FEProject::SaveProject(bool bFullSave) bModified = false; } +#include +#pragma comment(lib, "dbghelp.lib") +std::string ListExportedFunctions(const std::string& dllPath) { + std::stringstream result; + HMODULE hModule = LoadLibraryA(dllPath.c_str()); + if (hModule == NULL) { + return "Failed to load DLL."; + } + + ULONG size; + PIMAGE_EXPORT_DIRECTORY exportDir; + + exportDir = (PIMAGE_EXPORT_DIRECTORY)ImageDirectoryEntryToData( + hModule, TRUE, IMAGE_DIRECTORY_ENTRY_EXPORT, &size); + + if (exportDir == NULL) { + FreeLibrary(hModule); + return "Failed to get export directory."; + } + + DWORD* names = (DWORD*)((BYTE*)hModule + exportDir->AddressOfNames); + WORD* ordinals = (WORD*)((BYTE*)hModule + exportDir->AddressOfNameOrdinals); + DWORD* functions = (DWORD*)((BYTE*)hModule + exportDir->AddressOfFunctions); + + for (DWORD i = 0; i < exportDir->NumberOfNames; i++) { + char* name = (char*)((BYTE*)hModule + names[i]); + WORD ordinal = ordinals[i]; + DWORD rva = functions[ordinal]; + + result << "Function: " << name << ", Ordinal: " << ordinal << ", RVA: 0x" + << std::hex << rva << std::dec << "\n"; + } + + FreeLibrary(hModule); + return result.str(); +} + void FEProject::LoadProject() { std::ifstream SceneFile; @@ -778,7 +809,7 @@ void FEProject::LoadProject() if (!bPrefabScene) continue; - FEScene* NewScene = SCENE_MANAGER.CreateScene(LoadedObjectData.Name, LoadedObjectData.ID, false); + FEScene* NewScene = SCENE_MANAGER.CreateScene(LoadedObjectData.Name, LoadedObjectData.ID, FESceneFlag::None); RESOURCE_MANAGER.SetTag(NewScene, LoadedObjectData.Tag); NewScene->SceneGraph.FromJson(Root["Scenes"][SceneList[i]]["Scene hierarchy"]); @@ -800,7 +831,7 @@ void FEProject::LoadProject() continue; bool bShouldBeActive = LoadedObjectData.ID == MainSceneID; - FEScene* NewScene = SCENE_MANAGER.CreateScene(LoadedObjectData.Name, LoadedObjectData.ID, bShouldBeActive); + FEScene* NewScene = SCENE_MANAGER.CreateScene(LoadedObjectData.Name, LoadedObjectData.ID, bShouldBeActive ? FESceneFlag::Active : FESceneFlag::None); RESOURCE_MANAGER.SetTag(NewScene, LoadedObjectData.Tag); NewScene->SceneGraph.FromJson(Root["Scenes"][SceneList[i]]["Scene hierarchy"]); @@ -809,7 +840,7 @@ void FEProject::LoadProject() ProjectScene = SCENE_MANAGER.GetScene(MainSceneID); // VFS - if (FILE_SYSTEM.CheckFile((ProjectFolder + "VFS.txt").c_str())) // _error + if (FILE_SYSTEM.DoesFileExist((ProjectFolder + "VFS.txt").c_str())) // _error { VIRTUAL_FILE_SYSTEM.LoadState(ProjectFolder + "VFS.txt"); @@ -924,7 +955,7 @@ void FEProject::AddUnSavedObject(FEObject* Object) void FEProject::SetProjectFolder(const std::string NewValue) { - if (!FILE_SYSTEM.CheckDirectory(NewValue.c_str())) + if (!FILE_SYSTEM.DoesDirectoryExist(NewValue.c_str())) return; ProjectFolder = NewValue; @@ -932,7 +963,7 @@ void FEProject::SetProjectFolder(const std::string NewValue) void FEProject::SaveSceneTo(const std::string NewPath) { - if (!FILE_SYSTEM.CheckDirectory(NewPath.c_str())) + if (!FILE_SYSTEM.DoesDirectoryExist(NewPath.c_str())) return; SetProjectFolder(NewPath); @@ -943,4 +974,49 @@ void FEProject::SaveSceneTo(const std::string NewPath) FEScene* FEProject::GetScene() { return ProjectScene; +} + +void FEProjectManager::InjectEditorCamera(FEScene* Scene) +{ + FEEntity* CameraEntity = nullptr; + std::vector CameraPrefab = RESOURCE_MANAGER.GetPrefabByName("Free camera prefab"); + if (CameraPrefab.size() == 0) + { + LOG.Add("FEProjectManager::InjectEditorCamera: Camera prefab not found! Inserting camera manually.", "FE_LOG_LOADING", FE_LOG_WARNING); + + CameraEntity = Scene->CreateEntity("Camera"); + CameraEntity->AddComponent(); + } + else + { + FEPrefab* CameraPrefabToUse = CameraPrefab[0]; + std::vector AddedEntities = SCENE_MANAGER.InstantiatePrefab(CameraPrefabToUse, Scene, true); + if (AddedEntities.empty()) + { + LOG.Add("FEProjectManager::InjectEditorCamera: Camera prefab was not instantiated correctly. Inserting camera manually.", "FE_LOG_LOADING", FE_LOG_WARNING); + + CameraEntity = Scene->CreateEntity("Camera"); + CameraEntity->AddComponent(); + } + else + { + CameraEntity = AddedEntities[0]; + } + + if (CameraEntity == nullptr) + { + LOG.Add("FEProjectManager::InjectEditorCamera: Camera prefab was not instantiated correctly. Inserting camera manually.", "FE_LOG_LOADING", FE_LOG_WARNING); + + CameraEntity = Scene->CreateEntity("Camera"); + CameraEntity->AddComponent(); + } + } + + RESOURCE_MANAGER.SetTag(CameraEntity, EDITOR_RESOURCE_TAG); + FECameraComponent& CameraComponent = CameraEntity->GetComponent(); + CameraComponent.SetRenderTargetSize(128, 128); + CameraComponent.SetDistanceFogEnabled(false); + CAMERA_SYSTEM.SetMainCamera(CameraEntity); + FETransformComponent& CameraTransform = CameraEntity->GetComponent(); + CameraTransform.SetPosition(glm::vec3(-4.2269f, 15.7178f, 19.6429f)); } \ No newline at end of file diff --git a/FEProject.h b/FEProject.h index d7ed548..4d89a18 100644 --- a/FEProject.h +++ b/FEProject.h @@ -56,6 +56,7 @@ class FEProjectManager std::string CustomProjectFolder = "../FocalEngineProjects-master"; void CreateNewProject(std::string ProjectName, std::string ProjectPath); + void InjectEditorCamera(FEScene* Scene); public: SINGLETON_PUBLIC_PART(FEProjectManager) SINGLETON_PRIVATE_PART(FEProjectManager) @@ -78,4 +79,4 @@ class FEProjectManager }; #define PROJECTS_FOLDER PROJECT_MANAGER.CustomProjectFolder.c_str() -#define PROJECT_MANAGER FEProjectManager::getInstance() \ No newline at end of file +#define PROJECT_MANAGER FEProjectManager::GetInstance() \ No newline at end of file diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index d25b853..7c4faf8 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit d25b853cecba86913c4b3e4cfabbf4f9a936dbee +Subproject commit 7c4faf852e85ea4913a5de21ea586e5bf81fe46a diff --git a/SubSystems/NodeSystem/VisualNodeSystem b/SubSystems/NodeSystem/VisualNodeSystem index 252484d..e9a34a4 160000 --- a/SubSystems/NodeSystem/VisualNodeSystem +++ b/SubSystems/NodeSystem/VisualNodeSystem @@ -1 +1 @@ -Subproject commit 252484de4a10e773802475250535df3e3fb53b0d +Subproject commit e9a34a44c99d0ea9562bb945efb8c2ceebe0055f From d88301b20112f48b05e981b64e70207372cd35a3 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Sun, 8 Sep 2024 19:54:01 -0400 Subject: [PATCH 33/46] Engine Update; Selected objects are now stored as IDs to eliminate errors if the selected entity is deleted through scripts or other non-editor changes; The editor scripting system remains in a draft state; Fixed issues that prevented correct game mode creation when the prefab window was active; Extended functionality of FEPrefabEditorManager; The inspector window now supports a vast array of additional script variable types and std::vector of script variables. --- EditorWindows/InspectorWindow.cpp | 265 +++++++++++++++++++------- EditorWindows/PrefabEditorManager.cpp | 24 ++- EditorWindows/PrefabEditorManager.h | 3 + EditorWindows/SelectPopups.cpp | 2 +- FEEditor.cpp | 45 ++++- FEEditorHaloSelectionEffect.cpp | 2 +- FEEditorPreviewManager.cpp | 12 +- FEEditorScriptingSystem.cpp | 81 ++++---- FEEditorSelectedObject.cpp | 31 +-- FEEditorSelectedObject.h | 3 +- FEProject.cpp | 2 +- SubSystems/FocalEngine | 2 +- 12 files changed, 334 insertions(+), 138 deletions(-) diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index 46caa4b..d9eb9eb 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -1040,10 +1040,10 @@ void FEEditorInspectorWindow::Render() if (ImGui::CollapsingHeader("Tag", ImGuiTreeNodeFlags_DefaultOpen)) { FETagComponent& TagComponent = EntitySelected->GetComponent(); - char Buffer[256]; - memset(Buffer, 0, 256); + char Buffer[1024]; + memset(Buffer, 0, 1024); strcpy_s(Buffer, TagComponent.GetTag().c_str()); - if (ImGui::InputText("##Tag Edit", Buffer, 256)) + if (ImGui::InputText("##Tag Edit", Buffer, 1024)) { std::string NewTag = Buffer; TagComponent.SetTag(NewTag); @@ -2106,6 +2106,156 @@ void FEEditorInspectorWindow::AddNativeScriptComponent(FEEntity* Entity) Entity->AddComponent(); } +// TO-DO: Make it more general with more templated magic. +template +void HandleScriptVariable(FENativeScriptComponent& Component, const std::string VariableName) +{ + T Value; + if (Component.GetVariableValue(VariableName, Value)) + { + if constexpr (std::is_same_v || std::is_same_v) + { + if (ImGui::InputScalar(VariableName.c_str(), ImGuiDataType_Float, &Value)) + Component.SetVariableValue(VariableName, Value); + } + else if constexpr (std::is_same_v) + { + if (ImGui::InputInt(VariableName.c_str(), &Value)) + Component.SetVariableValue(VariableName, Value); + } + else if constexpr (std::is_same_v) + { + if (ImGui::Checkbox(VariableName.c_str(), &Value)) + Component.SetVariableValue(VariableName, Value); + } + else if constexpr (std::is_same_v) + { + char Buffer[1024]; + strcpy_s(Buffer, sizeof(Buffer), Value.c_str()); + if (ImGui::InputText(VariableName.c_str(), Buffer, sizeof(Buffer))) + { + Value = Buffer; + Component.SetVariableValue(VariableName, Value); + } + } + else if constexpr (std::is_same_v || std::is_same_v || std::is_same_v) + { + int VectorCardinality = std::is_same_v ? 2 : std::is_same_v ? 3 : 4; + if (ImGui::InputScalarN(VariableName.c_str(), ImGuiDataType_Float, glm::value_ptr(Value), VectorCardinality)) + Component.SetVariableValue(VariableName, Value); + } + else if constexpr (std::is_same_v) + { + std::string PrefabName = ""; + if (Value != nullptr) + PrefabName = Value->GetName(); + if (ImGui::BeginCombo(VariableName.c_str(), PrefabName.c_str())) + { + std::vector PrefabIDList = RESOURCE_MANAGER.GetPrefabIDList(); + for (size_t i = 0; i < PrefabIDList.size(); i++) + { + FEPrefab* CurrentPrefab = RESOURCE_MANAGER.GetPrefab(PrefabIDList[i]); + bool bIsSelected = PrefabName == CurrentPrefab->GetName(); + if (ImGui::Selectable(CurrentPrefab->GetName().c_str(), bIsSelected)) + { + Value = RESOURCE_MANAGER.GetPrefab(PrefabIDList[i]); + Component.SetVariableValue(VariableName, Value); + } + + if (bIsSelected) + ImGui::SetItemDefaultFocus(); + } + + ImGui::EndCombo(); + } + } + } +} + +// TO-DO: Make it more general with more templated magic. +template +void HandleScriptArrayVariable(FENativeScriptComponent& Component, const std::string VariableName) +{ + std::vector Value; + if (Component.GetVariableValue(VariableName, Value)) + { + for (size_t i = 0; i < Value.size(); i++) + { + ImGui::Text((VariableName + "[" + std::to_string(i) + "]").c_str()); + ImGui::SameLine(); + + std::string ElementName = "##" + VariableName + "[" + std::to_string(i) + "]"; + if constexpr (std::is_same_v || std::is_same_v) + { + if (ImGui::InputScalar(ElementName.c_str(), ImGuiDataType_Float, &Value[i])) + Component.SetVariableValue(VariableName, Value); + } + else if constexpr (std::is_same_v) + { + if (ImGui::InputInt(ElementName.c_str(), &Value[i])) + Component.SetVariableValue(VariableName, Value); + } + else if constexpr (std::is_same_v) + { + // std::vector is a special case. + bool bTemporaryValue = Value[i]; + if (ImGui::Checkbox(ElementName.c_str(), &bTemporaryValue)) + { + Value[i] = bTemporaryValue; + Component.SetVariableValue(VariableName, Value); + } + } + else if constexpr (std::is_same_v) + { + char Buffer[1024]; + strcpy_s(Buffer, sizeof(Buffer), Value[i].c_str()); + if (ImGui::InputText(ElementName.c_str(), Buffer, sizeof(Buffer))) + { + Value[i] = Buffer; + Component.SetVariableValue(VariableName, Value); + } + } + else if constexpr (std::is_same_v || std::is_same_v || std::is_same_v) + { + int VectorCardinality = std::is_same_v ? 2 : std::is_same_v ? 3 : 4; + if (ImGui::InputScalarN(ElementName.c_str(), ImGuiDataType_Float, glm::value_ptr(Value[i]), VectorCardinality)) + Component.SetVariableValue(VariableName, Value); + } + else if constexpr (std::is_same_v) + { + std::string PrefabName = ""; + if (Value[i] != nullptr) + PrefabName = Value[i]->GetName(); + if (ImGui::BeginCombo((VariableName + "[" + std::to_string(i) + "]").c_str(), PrefabName.c_str())) + { + std::vector PrefabIDList = RESOURCE_MANAGER.GetPrefabIDList(); + for (size_t j = 0; j < PrefabIDList.size(); j++) + { + FEPrefab* CurrentPrefab = RESOURCE_MANAGER.GetPrefab(PrefabIDList[j]); + bool bIsSelected = PrefabName == CurrentPrefab->GetName(); + if (ImGui::Selectable(CurrentPrefab->GetName().c_str(), bIsSelected)) + { + Value[i] = RESOURCE_MANAGER.GetPrefab(PrefabIDList[j]); + Component.SetVariableValue(VariableName, Value); + } + + if (bIsSelected) + ImGui::SetItemDefaultFocus(); + } + + ImGui::EndCombo(); + } + } + } + + if (ImGui::Button(("Add##" + VariableName).c_str())) + { + Value.push_back(T()); + Component.SetVariableValue(VariableName, Value); + } + } +} + void FEEditorInspectorWindow::DisplayNativeScriptProperties(FEEntity* NativeScriptEntity) const { FENativeScriptComponent& NativeScriptComponent = NativeScriptEntity->GetComponent(); @@ -2117,7 +2267,7 @@ void FEEditorInspectorWindow::DisplayNativeScriptProperties(FEEntity* NativeScri for (size_t i = 0; i < ModuleList.size(); i++) { ImGui::Text(("Module ID: " + ModuleList[i]).c_str()); - ImGui::Text(("DLL Module ID: " + NATIVE_SCRIPT_SYSTEM.GetDLLMoudleIDByNativeScriptModuleID(ModuleList[i])).c_str()); + ImGui::Text(("DLL Module ID: " + NATIVE_SCRIPT_SYSTEM.GetAssociatedDLLID(ModuleList[i])).c_str()); ImGui::Text("Script list: "); std::vector ScriptList = NATIVE_SCRIPT_SYSTEM.GetActiveModuleScriptNameList(ModuleList[i]); @@ -2139,7 +2289,7 @@ void FEEditorInspectorWindow::DisplayNativeScriptProperties(FEEntity* NativeScri // Showing general information. ImGui::Text(("Module: " + ModuleID).c_str()); - ImGui::Text(("DLL Module ID: " + NATIVE_SCRIPT_SYSTEM.GetDLLMoudleIDByNativeScriptModuleID(ModuleID)).c_str()); + ImGui::Text(("DLL Module ID: " + NATIVE_SCRIPT_SYSTEM.GetAssociatedDLLID(ModuleID)).c_str()); ImGui::Text(("Script name: " + ScriptData->Name).c_str()); ImGui::Text((std::string("Run in editor: ") + std::string(ScriptData->bRunInEditor ? "Yes" : "No")).c_str()); @@ -2150,68 +2300,55 @@ void FEEditorInspectorWindow::DisplayNativeScriptProperties(FEEntity* NativeScri { std::string VariableName = VariablesIterator->first; std::string VariableType = VariablesIterator->second.Type; - - std::any VariableValue = VariablesIterator->second.Getter(NativeScriptComponent.GetCoreInstance()); - if (VariableType == "int") - { - int Value = std::any_cast(VariableValue); - ImGui::DragInt(VariableName.c_str(), &Value); - VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); - } - else if (VariableType == "float") - { - float Value = std::any_cast(VariableValue); - ImGui::DragFloat(VariableName.c_str(), &Value); - VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); - } - else if (VariableType == "double") - { - double Value = std::any_cast(VariableValue); - ImGui::DragFloat(VariableName.c_str(), (float*)&Value); - VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); - } - else if (VariableType == "bool") - { - bool Value = std::any_cast(VariableValue); - ImGui::Checkbox(VariableName.c_str(), &Value); - VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); - } - else if (VariableType == "glm::vec2") - { - glm::vec2 Value = std::any_cast(VariableValue); - ImGui::DragFloat2(VariableName.c_str(), &Value[0]); - VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); - } - else if (VariableType == "glm::vec3") - { - glm::vec3 Value = std::any_cast(VariableValue); - ImGui::DragFloat3(VariableName.c_str(), &Value[0]); - VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); - } - else if (VariableType == "glm::vec4") - { - glm::vec4 Value = std::any_cast(VariableValue); - ImGui::DragFloat4(VariableName.c_str(), &Value[0]); - VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); - } - else if (VariableType == "glm::quat") + + // TO-DO: Make it more general with more templated magic. + if (VariableType.find("vector<") != std::string::npos || VariableType.find("std::vector<") != std::string::npos) { - glm::quat Value = std::any_cast(VariableValue); - ImGui::DragFloat4(VariableName.c_str(), &Value[0]); - VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); + if (VariableType.find("float>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("int>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("bool>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("std::string>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("glm::vec2>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("glm::vec3>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("glm::vec4>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("FEShader*>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("FEMesh*>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("FETexture*>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("FEMaterial*>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("FEGameModel*>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + // TO-DO: Think how to make it work with enitity. Right now it is not consistent between editor and game mode scenes. + //else if (VariableType.find("FEEntity*>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("FEFramebuffer*>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("FEPostProcess*>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("FEPrefab*>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + // TO-DO: Check if it is working. + else if (VariableType.find("FEScene*>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("FEAssetPackage*>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); + else if (VariableType.find("FENativeScriptModule*>") != std::string::npos) HandleScriptArrayVariable(NativeScriptComponent, VariableName); } - else if (VariableType == "std::string") + else { - std::string Value = std::any_cast(VariableValue); - - char Buffer[1024]; - memset(Buffer, 0, 1024); - strcpy_s(Buffer, Value.c_str()); - if (ImGui::InputText(("##String_Variable_" + VariableName).c_str(), Buffer, 1024)) - { - Value = Buffer; - VariablesIterator->second.Setter(NativeScriptComponent.GetCoreInstance(), Value); - } + if (VariableType == "float") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "int") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "bool") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "std::string") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "glm::vec2") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "glm::vec3") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "glm::vec4") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "FEShader*") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "FEMesh*") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "FETexture*") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "FEMaterial*") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "FEGameModel*") HandleScriptVariable(NativeScriptComponent, VariableName); + // TO-DO: Think how to make it work with enitity. Right now it is not consistent between editor and game mode scenes. + //else if (VariableType == "FEEntity*") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "FEFramebuffer*") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "FEPostProcess*") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "FEPrefab*") HandleScriptVariable(NativeScriptComponent, VariableName); + // TO-DO: Check if it is working. + else if (VariableType == "FEScene*") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "FEAssetPackage*") HandleScriptVariable(NativeScriptComponent, VariableName); + else if (VariableType == "FENativeScriptModule*") HandleScriptVariable(NativeScriptComponent, VariableName); } VariablesIterator++; diff --git a/EditorWindows/PrefabEditorManager.cpp b/EditorWindows/PrefabEditorManager.cpp index ef202ac..4463f71 100644 --- a/EditorWindows/PrefabEditorManager.cpp +++ b/EditorWindows/PrefabEditorManager.cpp @@ -178,11 +178,10 @@ void FEPrefabEditorManager::PrepareEditWinow(FEPrefab* Prefab) return; // We don't want to open the same prefab scene twice - if (PrefabWindows.find(Prefab) != PrefabWindows.end()) + if (IsPrefabWindowOpen(Prefab)) return; - FEScene* CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->GetScene(), "Scene: " + Prefab->GetName()); - CurrentPrefabScene->SetFlag(FESceneFlag::Active | FESceneFlag::EditorMode | FESceneFlag::Renderable, true); + FEScene* CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->GetScene(), "Scene: " + Prefab->GetName(), nullptr, FESceneFlag::Active | FESceneFlag::EditorMode | FESceneFlag::Renderable); // Because by default camera is looking at 0,0,0 we need to place "empty" entity at 0,0,0. // To ensure that scene AABB would include some entity at 0,0,0. @@ -270,4 +269,23 @@ void FEPrefabEditorManager::ApplyModificationsToPrefabScene(FEPrefabSceneEditorW Prefab->SetDirtyFlag(true); PREVIEW_MANAGER.GetPrefabPreview(Prefab->GetObjectID()); +} + +bool FEPrefabEditorManager::IsPrefabWindowOpen(FEPrefab* Prefab) +{ + return PrefabWindows.find(Prefab) != PrefabWindows.end(); +} + +bool FEPrefabEditorManager::IsEditorWindowIsPrefabWindow(FEEditorSceneWindow* Window) +{ + auto WindowIterator = PrefabWindows.begin(); + while (WindowIterator != PrefabWindows.end()) + { + if (WindowIterator->second == Window) + return true; + + WindowIterator++; + } + + return false; } \ No newline at end of file diff --git a/EditorWindows/PrefabEditorManager.h b/EditorWindows/PrefabEditorManager.h index b480e6f..77a608a 100644 --- a/EditorWindows/PrefabEditorManager.h +++ b/EditorWindows/PrefabEditorManager.h @@ -35,6 +35,9 @@ class FEPrefabEditorManager void PrepareEditWinow(FEPrefab* Prefab); void Clear(); + + bool IsPrefabWindowOpen(FEPrefab* Prefab); + bool IsEditorWindowIsPrefabWindow(FEEditorSceneWindow* Window); }; #define PREFAB_EDITOR_MANAGER FEPrefabEditorManager::GetInstance() \ No newline at end of file diff --git a/EditorWindows/SelectPopups.cpp b/EditorWindows/SelectPopups.cpp index f295689..e1ba848 100644 --- a/EditorWindows/SelectPopups.cpp +++ b/EditorWindows/SelectPopups.cpp @@ -91,7 +91,7 @@ void SelectFEObjectPopUp::Show(const FE_OBJECT_TYPE Type, void(*CallBack)(std::v case FE_PREFAB: { - TempList = RESOURCE_MANAGER.GetPrefabList(); + TempList = RESOURCE_MANAGER.GetPrefabIDList(); break; } } diff --git a/FEEditor.cpp b/FEEditor.cpp index 337fd3c..d760f04 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -76,10 +76,10 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) EDITOR.EditorSceneWindows[i]->bWindowHovered = ImGui::GetCurrentContext()->HoveredWindow->Name == EDITOR.EditorSceneWindows[i]->GetWindow()->Name; FEEntity* CurrentMainCamera = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.EditorSceneWindows[i]->Scene); - + if (ImGui::GetIO().WantCaptureMouse && !EDITOR.EditorSceneWindows[i]->bWindowHovered) { - if (EDITOR.EditorSceneWindows[i]->Scene != nullptr) + if (EDITOR.EditorSceneWindows[i]->Scene != nullptr && CurrentMainCamera != nullptr) { if (CurrentMainCamera != nullptr) CurrentMainCamera->GetComponent().SetActive(false); @@ -90,11 +90,13 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_PRESS) { - CurrentMainCamera->GetComponent().SetActive(true); + if (CurrentMainCamera != nullptr) + CurrentMainCamera->GetComponent().SetActive(true); } else if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_RELEASE) { - CurrentMainCamera->GetComponent().SetActive(false); + if (CurrentMainCamera != nullptr) + CurrentMainCamera->GetComponent().SetActive(false); } if (Button == GLFW_MOUSE_BUTTON_1 && Action == GLFW_PRESS) @@ -226,7 +228,6 @@ void FEEditor::InitializeResources() { FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(PROJECT_MANAGER.GetCurrent()->ProjectScene); MainCamera->GetComponent().SetActive(false); - //CAMERA_SYSTEM.SetIsIndividualInputActive(MainCamera, false); } PROJECT_MANAGER.InitializeResources(); PREVIEW_MANAGER.InitializeResources(); @@ -430,14 +431,41 @@ void FEEditor::Render() } ImGui::PopStyleVar(); + bool bFocusedSceneCouldBeUsedForGameMode = false; + if (EDITOR.GetFocusedScene() != nullptr) + { + FEEditorSceneWindow* SceneWindow = GetEditorSceneWindow(EDITOR.GetFocusedScene()->GetObjectID()); + // Focused scene could be prefab scene + if (!PREFAB_EDITOR_MANAGER.IsEditorWindowIsPrefabWindow(SceneWindow)) + bFocusedSceneCouldBeUsedForGameMode = true; + } + + std::string ButtonText = "Run game mode"; + if (EDITOR.IsInGameMode()) + { ButtonText = "Exit game mode"; + } + else + { + if (!bFocusedSceneCouldBeUsedForGameMode) + { + ButtonText = "Can not run game mode (focused scene is prefab scene)."; + } + } + + if (!bFocusedSceneCouldBeUsedForGameMode) + ImGui::BeginDisabled(); + if (ImGui::Button(ButtonText.c_str(), ImVec2(220, 0))) { EDITOR.SetGameMode(!EDITOR.IsInGameMode()); } + if (!bFocusedSceneCouldBeUsedForGameMode) + ImGui::EndDisabled(); + for (size_t i = 0; i < EditorSceneWindows.size(); i++) { // Rendeting would be done by RenderAllSubWindows(). @@ -824,9 +852,10 @@ bool FEEditor::DuplicateScenesForGameMode() return false; } + // Here we are setting flag right away, because we want to make sure that scripts are started. FEScene* GameModeScene = SCENE_MANAGER.DuplicateScene(EDITOR.GetFocusedScene()->GetObjectID(), "GameMode", [](FEEntity* EntityToCheck) { return !(EntityToCheck->GetTag() == EDITOR_RESOURCE_TAG); - }); + }, FESceneFlag::Active | FESceneFlag::GameMode | FESceneFlag::Renderable); if (GameModeScene == nullptr) { @@ -835,10 +864,6 @@ bool FEEditor::DuplicateScenesForGameMode() } ParentIDToScenesInGameMode[EDITOR.GetFocusedScene()->GetObjectID()] = GameModeScene; - GameModeScene->SetFlag(FESceneFlag::EditorMode, false); - GameModeScene->SetFlag(FESceneFlag::Active, true); - GameModeScene->SetFlag(FESceneFlag::Renderable, true); - GameModeScene->SetFlag(FESceneFlag::GameMode, true); EDITOR.AddEditorScene(GameModeScene, false); diff --git a/FEEditorHaloSelectionEffect.cpp b/FEEditorHaloSelectionEffect.cpp index 987de99..e330112 100644 --- a/FEEditorHaloSelectionEffect.cpp +++ b/FEEditorHaloSelectionEffect.cpp @@ -50,7 +50,7 @@ void FEEditorHaloSelectionEffect::UpdateResources(FEScene* Scene) if (CurrentHaloSelectionData == nullptr) return; - FECameraRenderingData* CameraData = RENDERER.GetCameraRenderingData(CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())); + FECameraRenderingData* CameraData = RENDERER.GetCameraRenderingData(CAMERA_SYSTEM.GetMainCameraEntity(Scene)); if (CameraData == nullptr) return; diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index 53fa918..76b60fc 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -205,7 +205,7 @@ void FEEditorPreviewManager::CreateMaterialPreview(const std::string MaterialID) } // Looking for all prefabs that uses this material to also update them. - const std::vector PrefabList = RESOURCE_MANAGER.GetPrefabList(); + const std::vector PrefabList = RESOURCE_MANAGER.GetPrefabIDList(); for (size_t i = 0; i < PrefabList.size(); i++) { FEPrefab* CurrentPrefab = RESOURCE_MANAGER.GetPrefab(PrefabList[i]); @@ -231,7 +231,7 @@ FETexture* FEEditorPreviewManager::GetMaterialPreview(const std::string Material CreateGameModelPreview(CurrentGameModel->GetObjectID()); // If some Prefab uses this game model we should also update it's preview. - std::vector PrefabList = RESOURCE_MANAGER.GetPrefabList(); + std::vector PrefabList = RESOURCE_MANAGER.GetPrefabIDList(); for (size_t j = 0; j < PrefabList.size(); j++) { FEPrefab* CurrentPrefab = RESOURCE_MANAGER.GetPrefab(PrefabList[j]); @@ -331,6 +331,12 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel FETexture* FEEditorPreviewManager::GetGameModelPreview(const std::string GameModelID) { + if (RESOURCE_MANAGER.GetGameModel(GameModelID) == nullptr) + { + LOG.Add("FEEditorPreviewManager::GetGameModelPreview could not find game model with ID: " + GameModelID, "FE_LOG_RENDERING", FE_LOG_ERROR); + return RESOURCE_MANAGER.NoTexture; + } + // if game model's dirty flag is set we need to update preview if (RESOURCE_MANAGER.GetGameModel(GameModelID)->IsDirty()) { @@ -375,7 +381,7 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) if (Prefab == nullptr || Prefab->GetScene() == nullptr) return; - FEScene* CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->GetScene(), "Scene: " + Prefab->GetName()); + FEScene* CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->GetScene(), "Scene: " + Prefab->GetName(), nullptr, FESceneFlag::Active); // Because by default camera is looking at 0,0,0 we need to place "empty" entity at 0,0,0. // To ensure that scene AABB would include some entity at 0,0,0. diff --git a/FEEditorScriptingSystem.cpp b/FEEditorScriptingSystem.cpp index 5525855..b9126e6 100644 --- a/FEEditorScriptingSystem.cpp +++ b/FEEditorScriptingSystem.cpp @@ -12,43 +12,46 @@ FEEditorScriptingSystem::~FEEditorScriptingSystem() void FEEditorScriptingSystem::Update() { - //std::string StartOfPath = "D:/Script__08_28_2024/Debug/"; - ////std::string StartOfPath = "C:/Users/kberegovyi/Downloads/Script__08_27_2024/Debug/"; - - //uint64_t NewWriteTime = FILE_SYSTEM.GetFileLastWriteTime(StartOfPath + "UserScriptTest.dll"); - //if (NewWriteTime != LastWriteTime && NewWriteTime != 0) - //{ - // // FIX ME! It is called 2 times. - // uint64_t Differece = NewWriteTime >= LastWriteTime ? NewWriteTime - LastWriteTime : LastWriteTime - NewWriteTime; - // LastWriteTime = NewWriteTime; - - // if (Differece > 1'000'000) - // { - // //std::string NewWriteTimeStr = TIME.NanosecondTimeStampToDate(FILE_SYSTEM.GetFileLastWriteTime(StartOfPath + "UserScriptTest.dll")); - // //std::string OldWriteTimeStr = TIME.NanosecondTimeStampToDate(LastWriteTime); - - // LastWriteTime = NewWriteTime; - - // if (!FILE_SYSTEM.DoesDirectoryExist(FILE_SYSTEM.GetCurrentWorkingPath() + "/NativeScriptsTemp")) - // FILE_SYSTEM.CreateDirectory(FILE_SYSTEM.GetCurrentWorkingPath() + "/NativeScriptsTemp"); - - // FILE_SYSTEM.WaitForFileAccess(StartOfPath + "UserScriptTest.dll", 2000); - // FILE_SYSTEM.WaitForFileAccess(StartOfPath + "UserScriptTest.pdb", 2000); - - // FENativeScriptModule* NewNativeScriptModule = RESOURCE_MANAGER.CreateNativeScriptModule(StartOfPath + "UserScriptTest.dll", StartOfPath + "UserScriptTest.pdb"); - // if (ExternalEditorActiveModule != nullptr) - // { - // NATIVE_SCRIPT_SYSTEM.UpdateNativeScriptModule(ExternalEditorActiveModule->GetObjectID(), NewNativeScriptModule->GetObjectID()); - // } - // else - // { - // NATIVE_SCRIPT_SYSTEM.ActivateNativeScriptModule(NewNativeScriptModule); - // } - - // ExternalEditorActiveModule = NewNativeScriptModule; - // - // int y = 0; - // y++; - // } - //} + std::string StartOfPath = "D:/Script__09_03_2024/Debug/"; + //std::string StartOfPath = "C:/Users/kberegovyi/Downloads/Script__09_02_2024/Debug/"; + + uint64_t NewWriteTime = FILE_SYSTEM.GetFileLastWriteTime(StartOfPath + "UserScriptTest.dll"); + if (NewWriteTime != LastWriteTime && NewWriteTime != 0) + { + // FIX ME! It is called 2 times. + uint64_t Differece = NewWriteTime >= LastWriteTime ? NewWriteTime - LastWriteTime : LastWriteTime - NewWriteTime; + LastWriteTime = NewWriteTime; + + if (Differece > 1'000'000) + { + //std::string NewWriteTimeStr = TIME.NanosecondTimeStampToDate(FILE_SYSTEM.GetFileLastWriteTime(StartOfPath + "UserScriptTest.dll")); + //std::string OldWriteTimeStr = TIME.NanosecondTimeStampToDate(LastWriteTime); + + LastWriteTime = NewWriteTime; + + if (!FILE_SYSTEM.DoesDirectoryExist(FILE_SYSTEM.GetCurrentWorkingPath() + "/NativeScriptsTemp")) + FILE_SYSTEM.CreateDirectory(FILE_SYSTEM.GetCurrentWorkingPath() + "/NativeScriptsTemp"); + + FILE_SYSTEM.WaitForFileAccess(StartOfPath + "UserScriptTest.dll", 2000); + FILE_SYSTEM.WaitForFileAccess(StartOfPath + "UserScriptTest.pdb", 2000); + + FENativeScriptModule* NewNativeScriptModule = RESOURCE_MANAGER.CreateNativeScriptModule(StartOfPath + "UserScriptTest.dll", StartOfPath + "UserScriptTest.pdb"); + if (NewNativeScriptModule == nullptr) + { + LOG.Add("FEEditorScriptingSystem::Update: Error creating native script module after project files update", "FE_SCRIPT_SYSTEM", FE_LOG_ERROR); + return; + } + + if (ExternalEditorActiveModule != nullptr) + { + NATIVE_SCRIPT_SYSTEM.UpdateNativeScriptModule(ExternalEditorActiveModule->GetObjectID(), NewNativeScriptModule->GetObjectID()); + } + else + { + NATIVE_SCRIPT_SYSTEM.ActivateNativeScriptModule(NewNativeScriptModule); + } + + ExternalEditorActiveModule = NewNativeScriptModule; + } + } } diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index 33f98b4..b2ded14 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -71,7 +71,7 @@ FEEntity* FEEditorSelectedObject::GetSelected(FEScene* Scene) if (CurrentSelectionData == nullptr) return nullptr; - return CurrentSelectionData->Container; + return Scene->GetEntity(CurrentSelectionData->SelectedEntityID); } void FEEditorSelectedObject::SetSelected(FEEntity* SelectedObject) @@ -97,10 +97,12 @@ void FEEditorSelectedObject::SetSelected(FEEntity* SelectedObject) } } - if (CurrentSelectionData->Container != nullptr && CurrentSelectionData->Container->HasComponent() && CurrentSelectionData->Container != SelectedObject) - TERRAIN_SYSTEM.SetBrushMode(CurrentSelectionData->Container, FE_TERRAIN_BRUSH_NONE); + FEEntity* CurrentlySelectedEntity = CurrentScene->GetEntity(CurrentSelectionData->SelectedEntityID); - CurrentSelectionData->Container = SelectedObject; + if (CurrentlySelectedEntity != nullptr && CurrentlySelectedEntity->HasComponent() && CurrentlySelectedEntity != SelectedObject) + TERRAIN_SYSTEM.SetBrushMode(CurrentlySelectedEntity, FE_TERRAIN_BRUSH_NONE); + + CurrentSelectionData->SelectedEntityID = SelectedObject->GetObjectID(); if (OnUpdateFunction != nullptr) OnUpdateFunction(CurrentScene); } @@ -114,13 +116,14 @@ void FEEditorSelectedObject::Clear(FEScene* Scene) if (CurrentSelectionData == nullptr) return; - if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1 && CurrentSelectionData->Container->HasComponent()) + FEEntity* CurrentlySelectedEntity = Scene->GetEntity(CurrentSelectionData->SelectedEntityID); + if (CurrentSelectionData->InstancedSubObjectIndexSelected != -1 && CurrentlySelectedEntity->HasComponent()) { - INSTANCED_RENDERING_SYSTEM.SetIndividualSelectMode(CurrentSelectionData->Container, false); + INSTANCED_RENDERING_SYSTEM.SetIndividualSelectMode(CurrentlySelectedEntity, false); } CurrentSelectionData->InstancedSubObjectIndexSelected = -1; - CurrentSelectionData->Container = nullptr; + CurrentSelectionData->SelectedEntityID = ""; if (!SCENE_MANAGER.GetScenesByFlagMask(FESceneFlag::Active).empty()) if (OnUpdateFunction != nullptr) @@ -575,8 +578,7 @@ void FEEditorSelectedObject::OnCameraUpdate() const glClearColor(0.0f, 0.0f, 0.0f, 0.0f); FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT)); - FEEntity* SelectedEntity = CurrentSelectionData->Container; - + FEEntity* SelectedEntity = CurrentScene->GetEntity(CurrentSelectionData->SelectedEntityID); if (SelectedEntity == nullptr) { HaloSelectionData->HaloObjectsFB->UnBind(); @@ -651,19 +653,20 @@ void FEEditorSelectedObject::SetSelectedByIndex(const size_t Index, FEScene* Sce if (Index < 0 || Index >= CurrentSelectionData->SceneEntitiesUnderMouse.size()) return; - if (CurrentSelectionData->Container != nullptr) + FEEntity* CurrentlySelectedEntity = Scene->GetEntity(CurrentSelectionData->SelectedEntityID); + if (CurrentlySelectedEntity != nullptr) { - if (CurrentSelectionData->Container->HasComponent()) + if (CurrentlySelectedEntity->HasComponent()) { - if (CurrentSelectionData->SceneEntitiesUnderMouse[Index]->GetObjectID() != CurrentSelectionData->Container->GetObjectID()) + if (CurrentSelectionData->SceneEntitiesUnderMouse[Index]->GetObjectID() != CurrentlySelectedEntity->GetObjectID()) { - INSTANCED_RENDERING_SYSTEM.SetIndividualSelectMode(CurrentSelectionData->Container, false); + INSTANCED_RENDERING_SYSTEM.SetIndividualSelectMode(CurrentlySelectedEntity, false); CurrentSelectionData->InstancedSubObjectIndexSelected = -1; } } } - CurrentSelectionData->Container = CurrentSelectionData->SceneEntitiesUnderMouse[Index]; + CurrentSelectionData->SelectedEntityID = CurrentSelectionData->SceneEntitiesUnderMouse[Index]->GetObjectID(); if (OnUpdateFunction != nullptr) OnUpdateFunction(Scene); } diff --git a/FEEditorSelectedObject.h b/FEEditorSelectedObject.h index 580fa81..59e5398 100644 --- a/FEEditorSelectedObject.h +++ b/FEEditorSelectedObject.h @@ -18,7 +18,8 @@ class FESelectionData std::vector SceneEntitiesUnderMouse; FEEntity* PotentiallySelectedEntity = nullptr; - FEEntity* Container = nullptr; + + std::string SelectedEntityID = ""; FEEntity* DummyEntity = nullptr; bool CheckForSelectionisNeeded = false; diff --git a/FEProject.cpp b/FEProject.cpp index dced369..fb989ac 100644 --- a/FEProject.cpp +++ b/FEProject.cpp @@ -535,7 +535,7 @@ void FEProject::SaveProject(bool bFullSave) Root["GameModels"] = GameModelData; // Saving Prefabs. - std::vector PrefabList = RESOURCE_MANAGER.GetPrefabList(); + std::vector PrefabList = RESOURCE_MANAGER.GetPrefabIDList(); Json::Value PrefabData; for (size_t i = 0; i < PrefabList.size(); i++) { diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 7c4faf8..2e67d9b 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 7c4faf852e85ea4913a5de21ea586e5bf81fe46a +Subproject commit 2e67d9b1b4a124ef4520eaa6fb9cb5204eedd719 From a249a6ec2cce12f283cd7d2d11e656a124fdb235 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Sat, 28 Sep 2024 14:25:50 -0400 Subject: [PATCH 34/46] FEProject was refactored into three separate classes: FEProject, FEProjectManager, and FENativeScriptProject, which were placed in the ProjectManager folder; Fixed several old issues introduced at the beginning of the transition to ECS; Removed the bMain flag from FEEditorSceneWindow, as it is no longer needed; Added FEPrefabEditorManager::GetPrefabFromEditorWindow; Extended FEEditor functionality related to the EditorScene; Fixed FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel, FETexture** ResultingTexture); Added FENativeScriptProject to manage the creation and recreation of Visual Studio projects for user native scripts; Changed the FEProject save process to use separate files for resources.txt (formerly scene.txt) and the new project.txt, which now includes editor camera information and other project-related data; Added multiple CMake files to ensure the correct build process for user native scripts; Added temporary buttons to test the native script system; The current implementation of the native script system is still very raw and lacks many features to be considered production-ready, but this commit has moved it significantly closer to that goal. --- CMakeLists.txt | 15 +- EditorWindows/ContentBrowserWindow.cpp | 31 +- EditorWindows/DeletePopups.cpp | 36 +- EditorWindows/DeletePopups.h | 2 +- EditorWindows/EditPopups.cpp | 5 +- .../FEEditorSceneWindow.cpp | 6 +- .../FEEditorSceneWindow.h | 4 +- EditorWindows/PrefabEditorManager.cpp | 20 +- EditorWindows/PrefabEditorManager.h | 2 + EditorWindows/ProjectWasModifiedPopUp.cpp | 2 +- FEEditor.cpp | 101 +- FEEditor.h | 12 +- FEEditorPreviewManager.cpp | 11 +- FEEditorScriptingSystem.cpp | 113 +- FEEditorScriptingSystem.h | 7 +- FEEditorSelectedObject.cpp | 2 +- FEProject.h | 82 -- SubSystems/FocalEngine | 2 +- .../FENativeScriptProject.cpp | 1069 +++++++++++++++++ .../ProjectManagment/FENativeScriptProject.h | 72 ++ .../ProjectManagment/FEProject.cpp | 961 +++++++-------- SubSystems/ProjectManagment/FEProject.h | 62 + .../ProjectManagment/FEProjectManager.cpp | 325 +++++ .../ProjectManagment/FEProjectManager.h | 41 + .../BuildManagement/DebugBuildActions.cmake | 22 + .../EnsureBuildCompletion.cmake | 9 + .../BuildManagement/ReleaseBuildActions.cmake | 22 + .../NativeScriptProjectData/CMakeLists.txt | 83 ++ main.cpp | 17 + 29 files changed, 2383 insertions(+), 753 deletions(-) delete mode 100644 FEProject.h create mode 100644 SubSystems/ProjectManagment/FENativeScriptProject.cpp create mode 100644 SubSystems/ProjectManagment/FENativeScriptProject.h rename FEProject.cpp => SubSystems/ProjectManagment/FEProject.cpp (50%) create mode 100644 SubSystems/ProjectManagment/FEProject.h create mode 100644 SubSystems/ProjectManagment/FEProjectManager.cpp create mode 100644 SubSystems/ProjectManagment/FEProjectManager.h create mode 100644 UserScripts/NativeScriptProjectData/BuildManagement/DebugBuildActions.cmake create mode 100644 UserScripts/NativeScriptProjectData/BuildManagement/EnsureBuildCompletion.cmake create mode 100644 UserScripts/NativeScriptProjectData/BuildManagement/ReleaseBuildActions.cmake create mode 100644 UserScripts/NativeScriptProjectData/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index c3e952c..3acc3c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,8 +100,15 @@ file(GLOB Editor_SRC "FEEditorVirtualFileSystem.h" "FEEditorScriptingSystem.cpp" "FEEditorScriptingSystem.h" - "FEProject.cpp" - "FEProject.h" +) + +file(GLOB ProjectManagment_SRC + "SubSystems/ProjectManagment/FEProjectManager.cpp" + "SubSystems/ProjectManagment/FEProjectManager.h" + "SubSystems/ProjectManagment/FEProject.cpp" + "SubSystems/ProjectManagment/FEProject.h" + "SubSystems/ProjectManagment/FENativeScriptProject.cpp" + "SubSystems/ProjectManagment/FENativeScriptProject.h" ) file(GLOB FEDearImguiWrapper_SRC @@ -188,7 +195,7 @@ add_executable(FocalEngineEditor WIN32 ${Editor_Materials_SRC} ${VisualNodeSystem_CustomNodes_SRC} # *************** SUB_SYSTEM *************** - + ${ProjectManagment_SRC} # *************** THIRD_PARTY *************** ${textEditor_SRC} ) @@ -212,7 +219,7 @@ source_group("Source Files/EditorWindows" FILES ${EditorWindows_SRC}) source_group("Source Files/Materials" FILES ${Editor_Materials_SRC}) source_group("Source Files/NodeSystem/CustomNodes" FILES ${VisualNodeSystem_CustomNodes_SRC}) # *************** SUB_SYSTEM *************** - +source_group("Source Files/ProjectManagment" FILES ${ProjectManagment_SRC}) # *************** THIRD_PARTY *************** source_group("Source Files/ThirdParty/textEditor" FILES ${textEditor_SRC}) diff --git a/EditorWindows/ContentBrowserWindow.cpp b/EditorWindows/ContentBrowserWindow.cpp index 6dd0b07..ff86b4d 100644 --- a/EditorWindows/ContentBrowserWindow.cpp +++ b/EditorWindows/ContentBrowserWindow.cpp @@ -48,24 +48,16 @@ static void CreateNewPrefabCallBack(const std::vector SelectionsResul { if (!SelectionsResult.empty() && SelectionsResult[0]->GetType() == FE_GAMEMODEL) { - // FIX ME! FEPrefab* NewPrefab = RESOURCE_MANAGER.CreatePrefab(); - - if (SelectionsResult.size() > 1) + for (int i = 0; i < SelectionsResult.size(); i++) { - for (int i = 1; i < SelectionsResult.size(); i++) + if (SelectionsResult[i]->GetType() == FE_GAMEMODEL) { - // FIX ME! It should be here - if (SelectionsResult[i]->GetType() == FE_GAMEMODEL) - { - //FEGameModel* CurrentGameModel = reinterpret_cast(SelectionsResult[i]); - //NewPrefab->GetScene()->CreateEntity(); - - //NewPrefab->AddComponent(reinterpret_cast(SelectionsResult[i])); - } + FEEntity* NewEntity = NewPrefab->GetScene()->CreateEntity(SelectionsResult[i]->GetName()); + NewEntity->AddComponent(reinterpret_cast(SelectionsResult[i])); } } - + PROJECT_MANAGER.GetCurrent()->SetModified(true); VIRTUAL_FILE_SYSTEM.CreateFile(NewPrefab, VIRTUAL_FILE_SYSTEM.GetCurrentPath()); } @@ -271,10 +263,15 @@ void FEEditorContentBrowserWindow::Render() if (ImGui::MenuItem("Create Prefab out of this Game Model")) { - // FIX ME ! - /*FEPrefab* NewPrefab = RESOURCE_MANAGER.CreatePrefab(RESOURCE_MANAGER.GetGameModel(FilteredResources[ItemUnderMouse]->GetObjectID())); - PROJECT_MANAGER.GetCurrent()->SetModified(true); - VIRTUAL_FILE_SYSTEM.CreateFile(NewPrefab, VIRTUAL_FILE_SYSTEM.GetCurrentPath());*/ + FEGameModel* GameModel = RESOURCE_MANAGER.GetGameModel(FilteredResources[ItemUnderMouse]->GetObjectID()); + if (GameModel != nullptr) + { + FEPrefab* NewPrefab = RESOURCE_MANAGER.CreatePrefab(); + FEEntity* NewEntity = NewPrefab->GetScene()->CreateEntity(GameModel->GetName()); + NewEntity->AddComponent(GameModel); + PROJECT_MANAGER.GetCurrent()->SetModified(true); + VIRTUAL_FILE_SYSTEM.CreateFile(NewPrefab, VIRTUAL_FILE_SYSTEM.GetCurrentPath()); + } } } diff --git a/EditorWindows/DeletePopups.cpp b/EditorWindows/DeletePopups.cpp index c01ed70..3a1431a 100644 --- a/EditorWindows/DeletePopups.cpp +++ b/EditorWindows/DeletePopups.cpp @@ -300,18 +300,20 @@ void DeleteGameModelPopup::Render() int DeleteGameModelPopup::TimesGameModelUsed(const FEGameModel* GameModel) { int Result = 0; - // FIX ME! - /*const std::vector PrefabList = RESOURCE_MANAGER.GetPrefabList(); - for (int i = 0; i < PrefabList.size(); i++) + std::vector SceneList = SCENE_MANAGER.GetSceneIDList(); + for (size_t i = 0; i < SceneList.size(); i++) { - FEPrefab* CurrentPrefab = RESOURCE_MANAGER.GetPrefab(PrefabList[i]); - for (int j = 0; j < CurrentPrefab->ComponentsCount(); j++) + FEScene* CurrentScene = SCENE_MANAGER.GetScene(SceneList[i]); + std::vector EntitiesList = CurrentScene->GetEntityIDListWithComponent(); + for (size_t j = 0; j < EntitiesList.size(); j++) { - if (CurrentPrefab->GetComponent(j)->GameModel == GameModel) + FEEntity* CurrentEntity = CurrentScene->GetEntity(EntitiesList[j]); + FEGameModelComponent& GameModelComponent = CurrentEntity->GetComponent(); + if (GameModelComponent.GetGameModel() == GameModel) Result++; } - }*/ + } return Result; } @@ -392,15 +394,19 @@ void DeletePrefabPopup::Render() int DeletePrefabPopup::TimesPrefabUsed(const FEPrefab* Prefab) { int Result = 0; - // FIX ME! Prefabs - /*const std::vector EntitiesList = SCENE.GetEntityList(); - - for (size_t i = 0; i < EntitiesList.size(); i++) + std::vector SceneList = SCENE_MANAGER.GetSceneIDList(); + for (size_t i = 0; i < SceneList.size(); i++) { - const FEEntity* CurrentEntity = SCENE.GetEntity(EntitiesList[i]); - if (CurrentEntity->Prefab == Prefab) - Result++; - }*/ + FEScene* CurrentScene = SCENE_MANAGER.GetScene(SceneList[i]); + std::vector EntitiesList = CurrentScene->GetEntityIDListWithComponent(); + for (size_t j = 0; j < EntitiesList.size(); j++) + { + FEEntity* CurrentEntity = CurrentScene->GetEntity(EntitiesList[j]); + FEPrefabInstanceComponent& PrefabInstanceComponent = CurrentEntity->GetComponent(); + if (PrefabInstanceComponent.GetPrefab() == Prefab) + Result++; + } + } return Result; } diff --git a/EditorWindows/DeletePopups.h b/EditorWindows/DeletePopups.h index 60177bd..02c0fd7 100644 --- a/EditorWindows/DeletePopups.h +++ b/EditorWindows/DeletePopups.h @@ -1,6 +1,6 @@ #pragma once -#include "../FEProject.h" +#include "../SubSystems/ProjectManagment/FEProjectManager.h" #include "VisualNodeSystem.h" #include "../SubSystems/NodeSystem/CustomNodes/FEEditorStandardNodes.h" diff --git a/EditorWindows/EditPopups.cpp b/EditorWindows/EditPopups.cpp index bcb75f1..d4a9513 100644 --- a/EditorWindows/EditPopups.cpp +++ b/EditorWindows/EditPopups.cpp @@ -380,8 +380,9 @@ void EditGameModelPopup::Render() ImGui::Text("Preview of game model:"); ImGui::SetCursorPosX(Size.x / 2 - 128 / 2); ImGui::SetCursorPosY(CurrentY + 50); - // FIX ME! - //ImGui::Image((void*)static_cast(TempPreview->GetTextureID()), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); + + if (TempPreview != nullptr) + ImGui::Image((void*)static_cast(TempPreview->GetTextureID()), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); if (CurrentMode == NO_LOD_MODE) { diff --git a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp index 7d6b3e6..7cba5b5 100644 --- a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp +++ b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp @@ -1,20 +1,18 @@ #include "FEEditorSceneWindow.h" #include "../../FEEditor.h" -FEEditorSceneWindow::FEEditorSceneWindow(FEScene* Scene, bool bMain) +FEEditorSceneWindow::FEEditorSceneWindow(FEScene* Scene) { if (Scene == nullptr) return; this->Scene = Scene; - this->bMain = bMain; + SceneID = Scene->GetObjectID(); Flags = ImGuiWindowFlags_None | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; std::string WindowName = Scene->GetName(); // Window name must be unique. WindowName += "##" + Scene->GetObjectID(); - if (bMain) - WindowName = "Main Scene"; SetCaption(WindowName); SetBorderSize(0.0f); diff --git a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.h b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.h index 1f54f36..0aaae87 100644 --- a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.h +++ b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.h @@ -10,14 +10,14 @@ class FEEditorSceneWindow : public FEImGuiWindow private: static bool DragAndDropCallBack(FEObject* Object, void** UserData); protected: - FEEditorSceneWindow(FEScene* Scene, bool bMain = false); + FEEditorSceneWindow(FEScene* Scene); ~FEEditorSceneWindow(); FEScene* Scene = nullptr; + std::string SceneID = ""; DragAndDropTarget* SceneWindowTarget = nullptr; bool bJustAdded = true; - bool bMain = false; bool bWindowHovered = false; bool bSelfContained = true; diff --git a/EditorWindows/PrefabEditorManager.cpp b/EditorWindows/PrefabEditorManager.cpp index 4463f71..c003fe4 100644 --- a/EditorWindows/PrefabEditorManager.cpp +++ b/EditorWindows/PrefabEditorManager.cpp @@ -2,7 +2,7 @@ #include "SceneGraphWindow.h" #include "../FEEditor.h" -FEPrefabSceneEditorWindow::FEPrefabSceneEditorWindow(FEScene* Scene) : FEEditorSceneWindow(Scene, false) +FEPrefabSceneEditorWindow::FEPrefabSceneEditorWindow(FEScene* Scene) : FEEditorSceneWindow(Scene) { bSelfContained = false; @@ -24,7 +24,8 @@ FEPrefabSceneEditorWindow::FEPrefabSceneEditorWindow(FEScene* Scene) : FEEditorS FEPrefabSceneEditorWindow::~FEPrefabSceneEditorWindow() { delete CloseButton; - SCENE_MANAGER.DeleteScene(Scene); + // Using ID instead of Scene pointer because it's possible that scene was already deleted. + SCENE_MANAGER.DeleteScene(SceneID); if (!PREFAB_EDITOR_MANAGER.bClearing) { @@ -182,6 +183,7 @@ void FEPrefabEditorManager::PrepareEditWinow(FEPrefab* Prefab) return; FEScene* CurrentPrefabScene = SCENE_MANAGER.DuplicateScene(Prefab->GetScene(), "Scene: " + Prefab->GetName(), nullptr, FESceneFlag::Active | FESceneFlag::EditorMode | FESceneFlag::Renderable); + RESOURCE_MANAGER.SetTag(CurrentPrefabScene, EDITOR_RESOURCE_TAG); // Because by default camera is looking at 0,0,0 we need to place "empty" entity at 0,0,0. // To ensure that scene AABB would include some entity at 0,0,0. @@ -288,4 +290,18 @@ bool FEPrefabEditorManager::IsEditorWindowIsPrefabWindow(FEEditorSceneWindow* Wi } return false; +} + +FEPrefab* FEPrefabEditorManager::GetPrefabFromEditorWindow(FEEditorSceneWindow* Window) +{ + auto WindowIterator = PrefabWindows.begin(); + while (WindowIterator != PrefabWindows.end()) + { + if (WindowIterator->second == Window) + return WindowIterator->first; + + WindowIterator++; + } + + return nullptr; } \ No newline at end of file diff --git a/EditorWindows/PrefabEditorManager.h b/EditorWindows/PrefabEditorManager.h index 77a608a..a74a15b 100644 --- a/EditorWindows/PrefabEditorManager.h +++ b/EditorWindows/PrefabEditorManager.h @@ -38,6 +38,8 @@ class FEPrefabEditorManager bool IsPrefabWindowOpen(FEPrefab* Prefab); bool IsEditorWindowIsPrefabWindow(FEEditorSceneWindow* Window); + + FEPrefab* GetPrefabFromEditorWindow(FEEditorSceneWindow* Window); }; #define PREFAB_EDITOR_MANAGER FEPrefabEditorManager::GetInstance() \ No newline at end of file diff --git a/EditorWindows/ProjectWasModifiedPopUp.cpp b/EditorWindows/ProjectWasModifiedPopUp.cpp index 13b1a0d..bfd7669 100644 --- a/EditorWindows/ProjectWasModifiedPopUp.cpp +++ b/EditorWindows/ProjectWasModifiedPopUp.cpp @@ -37,7 +37,7 @@ void ProjectWasModifiedPopUp::Render() if (ImGui::Button("Save", ImVec2(140, 0))) { PROJECT_MANAGER.GetCurrent()->SaveProject(); - ENGINE.SaveScreenshot((PROJECT_MANAGER.GetCurrent()->GetProjectFolder() + "projectScreenShot.texture").c_str(), PROJECT_MANAGER.GetCurrent()->GetScene()); + //ENGINE.SaveScreenshot((PROJECT_MANAGER.GetCurrent()->GetProjectFolder() + "projectScreenShot.texture").c_str(), PROJECT_MANAGER.GetCurrent()->GetScene()); ObjToWorkWith = nullptr; ImGuiModalPopup::Close(); ButtonPressed = true; diff --git a/FEEditor.cpp b/FEEditor.cpp index d760f04..cff12bd 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -224,11 +224,6 @@ void FEEditor::InitializeResources() ENGINE.AddDropCallback(DropCallback); SELECTED.InitializeResources(); - if (PROJECT_MANAGER.GetCurrent() != nullptr && PROJECT_MANAGER.GetCurrent()->ProjectScene != nullptr) - { - FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(PROJECT_MANAGER.GetCurrent()->ProjectScene); - MainCamera->GetComponent().SetActive(false); - } PROJECT_MANAGER.InitializeResources(); PREVIEW_MANAGER.InitializeResources(); DRAG_AND_DROP_MANAGER.InitializeResources(); @@ -304,16 +299,15 @@ void FEEditor::Render() if (ImGui::MenuItem("Save project")) { PROJECT_MANAGER.GetCurrent()->SaveProject(); - ENGINE.SaveScreenshot((PROJECT_MANAGER.GetCurrent()->GetProjectFolder() + "projectScreenShot.texture").c_str(), PROJECT_MANAGER.GetCurrent()->GetScene()); } if (ImGui::MenuItem("Save project as...")) { - std::string path; - FILE_SYSTEM.ShowFolderOpenDialog(path); - if (!path.empty()) + std::string Path; + FILE_SYSTEM.ShowFolderOpenDialog(Path); + if (!Path.empty()) { - PROJECT_MANAGER.GetCurrent()->SaveSceneTo(path + "\\"); + PROJECT_MANAGER.GetCurrent()->SaveProjectTo(Path + "\\"); } } @@ -469,7 +463,7 @@ void FEEditor::Render() for (size_t i = 0; i < EditorSceneWindows.size(); i++) { // Rendeting would be done by RenderAllSubWindows(). - + // // Check if some window is waiting for removal if (EditorSceneWindows[i]->bWaitingForRemoval) { @@ -478,9 +472,9 @@ void FEEditor::Render() FocusedEditorSceneID = ""; for (size_t j = 0; j < EditorSceneWindows.size(); j++) { - if (EditorSceneWindows[j]->bMain && EditorSceneWindows[j] != EditorSceneWindows[i]) + if (EditorSceneWindows[j] != EditorSceneWindows[i]) { - FocusedEditorSceneID = EditorSceneWindows[j]->Scene->GetObjectID(); + SetFocusedScene(EditorSceneWindows[j]->Scene->GetObjectID()); break; } } @@ -790,9 +784,9 @@ FEEditorSceneWindow* FEEditor::GetEditorSceneWindow(std::string SceneID) return nullptr; } -void FEEditor::AddEditorScene(FEScene* Scene, bool bMain) +void FEEditor::AddEditorScene(FEScene* Scene) { - FEEditorSceneWindow* NewSceneWindow = new FEEditorSceneWindow(Scene, bMain); + FEEditorSceneWindow* NewSceneWindow = new FEEditorSceneWindow(Scene); NewSceneWindow->SetVisible(true); EditorSceneWindows.push_back(NewSceneWindow); } @@ -806,24 +800,6 @@ void FEEditor::AddCustomEditorScene(FEEditorSceneWindow* SceneWindow) EditorSceneWindows.push_back(SceneWindow); } -FEScene* FEEditor::GetFocusedScene() const -{ - return SCENE_MANAGER.GetScene(FocusedEditorSceneID); -} - -void FEEditor::SetFocusedScene(FEScene* NewSceneInFocus) -{ - if (NewSceneInFocus == nullptr) - { - FocusedEditorSceneID = ""; - return; - } - - BeforeChangeOfFocusedScene(NewSceneInFocus); - - FocusedEditorSceneID = NewSceneInFocus->GetObjectID(); -} - void FEEditor::BeforeChangeOfFocusedScene(FEScene* NewSceneInFocus) { if (!FocusedEditorSceneID.empty() && NewSceneInFocus != EDITOR.GetFocusedScene()) @@ -865,7 +841,7 @@ bool FEEditor::DuplicateScenesForGameMode() ParentIDToScenesInGameMode[EDITOR.GetFocusedScene()->GetObjectID()] = GameModeScene; - EDITOR.AddEditorScene(GameModeScene, false); + EDITOR.AddEditorScene(GameModeScene); return true; } @@ -915,15 +891,7 @@ void FEEditor::DeleteScene(std::string SceneID) if (SceneWindow != nullptr) { if (EDITOR.FocusedEditorSceneID == SceneToDelete->GetObjectID()) - { - for (size_t i = 0; i < EditorSceneWindows.size(); i++) - { - if (EditorSceneWindows[i]->bMain && EditorSceneWindows[i] != SceneWindow) - { - EDITOR.FocusedEditorSceneID = EditorSceneWindows[i]->Scene->GetObjectID(); - } - } - } + EDITOR.FocusedEditorSceneID = ""; for (size_t i = 0; i < EditorSceneWindows.size(); i++) { @@ -943,4 +911,51 @@ void FEEditor::DeleteScene(std::string SceneID) GIZMO_MANAGER.PerSceneData.erase(SceneToDelete->GetObjectID()); SCENE_MANAGER.DeleteScene(SceneToDelete->GetObjectID()); +} + +std::vector FEEditor::GetEditorOpenedScenesIDs() const +{ + std::vector OpenedScenesIDs; + for (size_t i = 0; i < EditorSceneWindows.size(); i++) + { + OpenedScenesIDs.push_back(EditorSceneWindows[i]->Scene->GetObjectID()); + } + + return OpenedScenesIDs; +} + +FEScene* FEEditor::GetFocusedScene() const +{ + return SCENE_MANAGER.GetScene(FocusedEditorSceneID); +} + +bool FEEditor::SetFocusedScene(FEScene* NewSceneInFocus) +{ + if (NewSceneInFocus == nullptr) + { + FocusedEditorSceneID = ""; + return true; + } + + BeforeChangeOfFocusedScene(NewSceneInFocus); + + return SetFocusedScene(NewSceneInFocus->GetObjectID()); +} + +bool FEEditor::SetFocusedScene(std::string NewSceneInFocusID) +{ + if (SCENE_MANAGER.GetScene(NewSceneInFocusID) == nullptr) + { + LOG.Add("FEEditor::SetFocusedEditorScene: Scene not found.", "FE_EDITOR", FE_LOG_ERROR); + return false; + } + + if (GetEditorSceneWindow(NewSceneInFocusID) == nullptr) + { + LOG.Add("FEEditor::SetFocusedEditorScene: Scene window not found.", "FE_EDITOR", FE_LOG_ERROR); + return false; + } + + FocusedEditorSceneID = NewSceneInFocusID; + return true; } \ No newline at end of file diff --git a/FEEditor.h b/FEEditor.h index ee93f50..4dcedac 100644 --- a/FEEditor.h +++ b/FEEditor.h @@ -30,6 +30,14 @@ class FEEditor std::string GetSceneEntityIDInClipboard(); void SetSceneEntityIDInClipboard(std::string NewValue); + void AddEditorScene(FEScene* Scene); + void AddCustomEditorScene(FEEditorSceneWindow* SceneWindow); + FEEditorSceneWindow* GetEditorSceneWindow(std::string SceneID); + + std::vector GetEditorOpenedScenesIDs() const; + + bool SetFocusedScene(FEScene* NewSceneInFocus); + bool SetFocusedScene(std::string NewSceneInFocusID); FEScene* GetFocusedScene() const; bool IsInGameMode() const; @@ -44,9 +52,6 @@ class FEEditor std::string FocusedEditorSceneID = ""; ImGuiID DockspaceID = 0; - FEEditorSceneWindow* GetEditorSceneWindow(std::string SceneID); - void AddEditorScene(FEScene* Scene, bool bMain = false); - void AddCustomEditorScene(FEEditorSceneWindow* SceneWindow); std::vector EditorSceneWindows; void DeleteScene(std::string SceneID); @@ -94,7 +99,6 @@ class FEEditor void OnProjectClose(); - void SetFocusedScene(FEScene* NewSceneInFocus); void BeforeChangeOfFocusedScene(FEScene* NewSceneInFocus); }; diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index 76b60fc..6ff02ae 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -294,7 +294,6 @@ void FEEditorPreviewManager::CreateGameModelPreview(const std::string GameModelI GameModelPreviewTextures[GameModelID] = RESOURCE_MANAGER.CreateCopyOfTexture(CameraResult); } -// FIX ME! Should not be needed as now there will be scene for new game model. void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel, FETexture** ResultingTexture) { if (GameModel == nullptr) @@ -303,10 +302,6 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel PreviewGameModel->Mesh = GameModel->Mesh; PreviewGameModel->Material = GameModel->Material; PreviewEntity->GetComponent().SetReceivingShadows(false); - //if (*ResultingTexture == nullptr) - // *ResultingTexture = RESOURCE_MANAGER.CreateSameFormatTexture(PreviewFB->GetColorAttachment()); - //FETexture* TempTexture = PreviewFB->GetColorAttachment(); - //PreviewFB->SetColorAttachment(*ResultingTexture); BeforePreviewActions(); @@ -319,7 +314,7 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel const float YSize = sqrt((max.y - min.y) * (max.y - min.y)); const float ZSize = sqrt((max.z - min.z) * (max.z - min.z)); - // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. + // Invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. PreviewEntity->GetComponent().SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); CAMERA_SYSTEM.IndividualUpdate(LocalCameraEntity, 0.0); @@ -327,6 +322,10 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel RENDERER.Render(PreviewScene); AfterPreviewActions(); + + FETexture* CameraResult = RENDERER.GetCameraResult(LocalCameraEntity); + if (CameraResult != nullptr) + *ResultingTexture = RESOURCE_MANAGER.CreateCopyOfTexture(CameraResult); } FETexture* FEEditorPreviewManager::GetGameModelPreview(const std::string GameModelID) diff --git a/FEEditorScriptingSystem.cpp b/FEEditorScriptingSystem.cpp index b9126e6..d37165d 100644 --- a/FEEditorScriptingSystem.cpp +++ b/FEEditorScriptingSystem.cpp @@ -12,46 +12,77 @@ FEEditorScriptingSystem::~FEEditorScriptingSystem() void FEEditorScriptingSystem::Update() { - std::string StartOfPath = "D:/Script__09_03_2024/Debug/"; - //std::string StartOfPath = "C:/Users/kberegovyi/Downloads/Script__09_02_2024/Debug/"; - - uint64_t NewWriteTime = FILE_SYSTEM.GetFileLastWriteTime(StartOfPath + "UserScriptTest.dll"); - if (NewWriteTime != LastWriteTime && NewWriteTime != 0) - { - // FIX ME! It is called 2 times. - uint64_t Differece = NewWriteTime >= LastWriteTime ? NewWriteTime - LastWriteTime : LastWriteTime - NewWriteTime; - LastWriteTime = NewWriteTime; - - if (Differece > 1'000'000) - { - //std::string NewWriteTimeStr = TIME.NanosecondTimeStampToDate(FILE_SYSTEM.GetFileLastWriteTime(StartOfPath + "UserScriptTest.dll")); - //std::string OldWriteTimeStr = TIME.NanosecondTimeStampToDate(LastWriteTime); - - LastWriteTime = NewWriteTime; - - if (!FILE_SYSTEM.DoesDirectoryExist(FILE_SYSTEM.GetCurrentWorkingPath() + "/NativeScriptsTemp")) - FILE_SYSTEM.CreateDirectory(FILE_SYSTEM.GetCurrentWorkingPath() + "/NativeScriptsTemp"); - - FILE_SYSTEM.WaitForFileAccess(StartOfPath + "UserScriptTest.dll", 2000); - FILE_SYSTEM.WaitForFileAccess(StartOfPath + "UserScriptTest.pdb", 2000); - - FENativeScriptModule* NewNativeScriptModule = RESOURCE_MANAGER.CreateNativeScriptModule(StartOfPath + "UserScriptTest.dll", StartOfPath + "UserScriptTest.pdb"); - if (NewNativeScriptModule == nullptr) - { - LOG.Add("FEEditorScriptingSystem::Update: Error creating native script module after project files update", "FE_SCRIPT_SYSTEM", FE_LOG_ERROR); - return; - } - - if (ExternalEditorActiveModule != nullptr) - { - NATIVE_SCRIPT_SYSTEM.UpdateNativeScriptModule(ExternalEditorActiveModule->GetObjectID(), NewNativeScriptModule->GetObjectID()); - } - else - { - NATIVE_SCRIPT_SYSTEM.ActivateNativeScriptModule(NewNativeScriptModule); - } - - ExternalEditorActiveModule = NewNativeScriptModule; - } + FEProject* CurrentProject = PROJECT_MANAGER.GetCurrent(); + if (CurrentProject == nullptr) + return; + + if (CurrentProject->NativeScriptProject == nullptr) + return; + + CurrentProject->NativeScriptProject->Update(); +} + +bool FEEditorScriptingSystem::IsCurrentProjectHaveVSProjectInitialized() +{ + FEProject* CurrentProject = PROJECT_MANAGER.GetCurrent(); + if (CurrentProject == nullptr) + { + LOG.Add("FEEditorScriptingSystem::IsCurrentProjectHaveVSProjectInitialized: Current project is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; } + + std::string ProjectPath = CurrentProject->GetProjectFolder(); + if (ProjectPath.empty()) + { + LOG.Add("FEEditorScriptingSystem::IsCurrentProjectHaveVSProjectInitialized: Project path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (CurrentProject->NativeScriptProject == nullptr) + { + LOG.Add("FEEditorScriptingSystem::IsCurrentProjectHaveVSProjectInitialized: Native script project data is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + return CurrentProject->NativeScriptProject->IsVSProjectValid(); } + +bool FEEditorScriptingSystem::GenerateNewNativeScriptProject(std::string FirstScriptName) +{ + if (FirstScriptName.empty()) + { + LOG.Add("FEEditorScriptingSystem::GenerateNewNativeScriptProject: First script name is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + FEProject* CurrentProject = PROJECT_MANAGER.GetCurrent(); + if (CurrentProject == nullptr) + { + LOG.Add("FEEditorScriptingSystem::GenerateNewNativeScriptProject: Current project is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (CurrentProject->NativeScriptProject != nullptr) + { + LOG.Add("FEEditorScriptingSystem::GenerateNewNativeScriptProject: Native script project already exists", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + // Replace all spaces with underscores. + for (size_t i = 0; i < FirstScriptName.size(); i++) + { + if (FirstScriptName[i] == ' ') + FirstScriptName[i] = '_'; + } + + CurrentProject->NativeScriptProject = new FENativeScriptProject(CurrentProject); + if (!CurrentProject->NativeScriptProject->GenerateNewVSProject(FirstScriptName)) + { + LOG.Add("FEEditorScriptingSystem::GenerateNewNativeScriptProject: Error initializing native script project", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + delete CurrentProject->NativeScriptProject; + CurrentProject->NativeScriptProject = nullptr; + return false; + } + + return true; +} \ No newline at end of file diff --git a/FEEditorScriptingSystem.h b/FEEditorScriptingSystem.h index 865db91..c236e36 100644 --- a/FEEditorScriptingSystem.h +++ b/FEEditorScriptingSystem.h @@ -1,6 +1,6 @@ #pragma once -#include "../FEngine.h" +#include "FEEditor.h" using namespace FocalEngine; class FEEditorScriptingSystem @@ -9,11 +9,10 @@ class FEEditorScriptingSystem SINGLETON_PUBLIC_PART(FEEditorScriptingSystem) void Update(); + bool IsCurrentProjectHaveVSProjectInitialized(); + bool GenerateNewNativeScriptProject(std::string FirstScriptName); private: SINGLETON_PRIVATE_PART(FEEditorScriptingSystem) - - uint64_t LastWriteTime = 0; - FENativeScriptModule* ExternalEditorActiveModule = nullptr; }; #define EDITOR_SCRIPTING_SYSTEM FEEditorScriptingSystem::GetInstance() diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index b2ded14..a07f273 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -1,5 +1,5 @@ #include "FEEditorSelectedObject.h" -#include "FEProject.h" +#include "SubSystems/ProjectManagment/FEProjectManager.h" #include "FEEditor.h" using namespace FocalEngine; diff --git a/FEProject.h b/FEProject.h deleted file mode 100644 index 4d89a18..0000000 --- a/FEProject.h +++ /dev/null @@ -1,82 +0,0 @@ -#pragma once - -#include "../FEngine.h" -#include "FEEditorDragAndDropManager.h" -#include "FEDearImguiWrapper/FEDearImguiWrapper.h" -#include "FEEditorGizmoManager.h" -#include "FEEditorPreviewManager.h" -#include "FEEditorVirtualFileSystem.h" - -class FEProject -{ - friend class FEProjectManager; - friend class FEEditor; -public: - FEProject(std::string Name, std::string ProjectFolder); - ~FEProject(); - - std::string GetName(); - void SetName(std::string NewValue); - - std::string GetProjectFolder(); - void SaveProject(bool bFullSave = false); - void SaveSceneTo(std::string NewPath); - void LoadProject(); - - FETexture* SceneScreenshot; - void CreateDummyScreenshot(); - - void AddFileToDeleteList(std::string FileName); - - bool IsModified(); - void SetModified(bool NewValue); - - void AddUnSavedObject(FEObject* Object); - - FEScene* GetScene(); -private: - FEScene* ProjectScene = nullptr; - std::string Name; - std::string ProjectFolder; - bool bModified = false; - std::vector UnSavedObjects; - - std::vector FilesToDelete; - - void SetProjectFolder(std::string NewValue); -}; - -#define PROJECTS_FILE_VER 0.04f - -class FEProjectManager -{ - std::vector List; - int IndexChosen = -1; - FEProject* Current = nullptr; - std::string CustomProjectFolder = "../FocalEngineProjects-master"; - - void CreateNewProject(std::string ProjectName, std::string ProjectPath); - void InjectEditorCamera(FEScene* Scene); -public: - SINGLETON_PUBLIC_PART(FEProjectManager) - SINGLETON_PRIVATE_PART(FEProjectManager) - - void InitializeResources(); - - FEProject* GetCurrent(); - void SetCurrent(FEProject* Project); - - std::vector GetList(); - - void OpenProject(int ProjectIndex); - void LoadProjectList(); - void CloseCurrentProject(); - - void DisplayProjectSelection(); - - bool ContainProject(std::string Path); - void SetProjectsFolder(std::string FolderPath); -}; - -#define PROJECTS_FOLDER PROJECT_MANAGER.CustomProjectFolder.c_str() -#define PROJECT_MANAGER FEProjectManager::GetInstance() \ No newline at end of file diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 2e67d9b..bf1623b 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 2e67d9b1b4a124ef4520eaa6fb9cb5204eedd719 +Subproject commit bf1623b70d9c830d7a2b01cfc9c12796c2a743e5 diff --git a/SubSystems/ProjectManagment/FENativeScriptProject.cpp b/SubSystems/ProjectManagment/FENativeScriptProject.cpp new file mode 100644 index 0000000..cbe3bb1 --- /dev/null +++ b/SubSystems/ProjectManagment/FENativeScriptProject.cpp @@ -0,0 +1,1069 @@ +#include "FENativeScriptProject.h" +#include "FEProject.h" +#include + +std::string FENativeScriptProject::GetCorrectProjectName() +{ + if (Parent == nullptr) + { + LOG.Add("FENativeScriptProject::GetCorrectProjectName: Parent is nullptr!", "FE_LOG_LOADING", FE_LOG_ERROR); + return ""; + } + + std::string ProjectName = Parent->GetName(); + std::string CorrectProjectName = ""; + for (size_t i = 0; i < ProjectName.size(); i++) + { + if (ProjectName[i] == ' ') + CorrectProjectName += "_"; + else + CorrectProjectName += ProjectName[i]; + } + + return CorrectProjectName; +} + +FENativeScriptProject::FENativeScriptProject(FEProject* Parent) +{ + this->Parent = Parent; + ProjectPath = Parent->GetProjectFolder() + "NativeScriptProject/"; +} + +FENativeScriptProject::~FENativeScriptProject() +{ + if (PackageData != nullptr) + delete PackageData; +} + +bool FENativeScriptProject::Load(Json::Value Root, std::string FolderPath) +{ + if (!Root.isMember("ModuleID")) + { + LOG.Add("FENativeScriptProject::Load: ModuleID is missing!", "FE_LOG_LOADING", FE_LOG_ERROR); + return false; + } + + ModuleID = Root["ModuleID"].asCString(); + + if (!FILE_SYSTEM.DoesDirectoryExist(FolderPath)) + { + LOG.Add("FENativeScriptProject::Load: Folder does not exist!", "FE_LOG_LOADING", FE_LOG_ERROR); + return false; + } + + if (!FILE_SYSTEM.DoesFileExist(FolderPath + "NativeScriptProjectData.feassetpackage")) + { + LOG.Add("FENativeScriptProject::Load: File does not exist!", "FE_LOG_LOADING", FE_LOG_ERROR); + return false; + } + + PackageData = new FEAssetPackage(); + if (!PackageData->LoadFromFile(FolderPath + "NativeScriptProjectData.feassetpackage")) + { + LOG.Add("FENativeScriptProject::Load: Failed to load native script project data!", "FE_LOG_LOADING", FE_LOG_ERROR); + delete PackageData; + PackageData = nullptr; + return false; + } + + std::vector SourceFilesList = PackageData->GetEntryList(); + for (size_t i = 0; i < SourceFilesList.size(); i++) + { + SourceFileList.push_back(SourceFilesList[i].Name); + } + + SetFileTracking(); + return true; +} + +void FENativeScriptProject::Save(Json::Value& Root, std::string FolderPath) +{ + Root["ModuleID"] = ModuleID; + + if (!FILE_SYSTEM.DoesDirectoryExist(FolderPath)) + { + LOG.Add("FENativeScriptProject::Save: Folder does not exist!", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + + if (PackageData == nullptr) + { + PackageData = new FEAssetPackage(); + for (size_t i = 0; i < SourceFileList.size(); i++) + { + std::string FullFilePath = FolderPath + "NativeScriptProject/" + SourceFileList[i]; + if (!FILE_SYSTEM.DoesFileExist(FullFilePath)) + { + LOG.Add("FENativeScriptProject::Save: File does not exist!", "FE_LOG_LOADING", FE_LOG_ERROR); + continue; + } + + FEAssetPackageEntryIntializeData EntryData; + EntryData.Name = SourceFileList[i]; + EntryData.Type = "Text"; + PackageData->ImportAssetFromFile(FullFilePath, EntryData); + } + } + else + { + std::vector OldSourceFilesList = PackageData->GetEntryList(); + for (size_t i = 0; i < SourceFileList.size(); i++) + { + std::string FullFilePath = FolderPath + "NativeScriptProject/" + SourceFileList[i]; + if (!FILE_SYSTEM.DoesFileExist(FullFilePath)) + { + LOG.Add("FENativeScriptProject::Save: File does not exist!", "FE_LOG_LOADING", FE_LOG_ERROR); + continue; + } + + for (size_t j = 0; j < OldSourceFilesList.size(); j++) + { + if (OldSourceFilesList[j].Name == SourceFileList[i]) + { + if (!PackageData->UpdateAssetFromFile(OldSourceFilesList[j].ID, FullFilePath)) + { + LOG.Add("FENativeScriptProject::Save: Failed to update asset!", "FE_LOG_LOADING", FE_LOG_ERROR); + } + break; + } + } + } + } + + PackageData->SaveToFile(FolderPath + "NativeScriptProjectData.feassetpackage"); +} + +bool FENativeScriptProject::GenerateScriptModule() +{ + std::string DebugDllPath = DebugDllFileData.Path; + std::string DebugPdbPath = DebugPdbFileData.Path; + std::string ReleaseDllPath = ReleaseDllFileData.Path; + + FENativeScriptModule* NewNativeScriptModule = RESOURCE_MANAGER.CreateNativeScriptModule(DebugDllPath, DebugPdbPath, ReleaseDllPath); + if (NewNativeScriptModule == nullptr) + { + LOG.Add("FENativeScriptProject::GenerateScriptModule: Error creating native script module after external project files update.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + if (LastGeneratedScriptModule != nullptr) + { + NATIVE_SCRIPT_SYSTEM.UpdateNativeScriptModule(LastGeneratedScriptModule->GetObjectID(), NewNativeScriptModule->GetObjectID()); + } + else + { + NATIVE_SCRIPT_SYSTEM.ActivateNativeScriptModule(NewNativeScriptModule); + } + + LastGeneratedScriptModule = NewNativeScriptModule; + return true; +} + +bool FENativeScriptProject::IsVSProjectValid() +{ + if (Parent == nullptr) + { + LOG.Add("FENativeScriptProject::IsVSProjectValid: Parent is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (ProjectPath.empty()) + { + LOG.Add("FENativeScriptProject::IsVSProjectValid: Path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (!FILE_SYSTEM.DoesDirectoryExist(ProjectPath)) + { + LOG.Add("FENativeScriptProject::IsVSProjectValid: Path does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + std::vector InitialFilesToCheck = { + "CMakeLists.txt", + "SubSystems/FocalEngine/FENativeScriptConnector.h", "SubSystems/FocalEngine/FENativeScriptConnector.cpp", + "FocalEngine.lib", "FEBasicApplication.lib", + "BuildManagement/EnsureBuildCompletion.cmake", + "BuildManagement/DebugBuildActions.cmake", "BuildManagement/ReleaseBuildActions.cmake" + }; + + for (size_t i = 0; i < InitialFilesToCheck.size(); i++) + { + if (!FILE_SYSTEM.DoesFileExist(ProjectPath + InitialFilesToCheck[i])) + { + LOG.Add("FENativeScriptProject::IsVSProjectValid: File " + InitialFilesToCheck[i] + " does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + } + + std::string AppropriateProjectName = GetCorrectProjectName(); + std::vector VSProjectFilesToCheck = { + AppropriateProjectName + ".sln", AppropriateProjectName + ".vcxproj", AppropriateProjectName + ".vcxproj.filters" + }; + + for (size_t i = 0; i < VSProjectFilesToCheck.size(); i++) + { + if (!FILE_SYSTEM.DoesFileExist(ProjectPath + VSProjectFilesToCheck[i])) + { + LOG.Add("FENativeScriptProject::IsVSProjectValid: File " + VSProjectFilesToCheck[i] + " does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + } + + if (SourceFileList.empty()) + return false; + + for (size_t i = 0; i < SourceFileList.size(); i++) + { + if (!FILE_SYSTEM.DoesFileExist(ProjectPath + SourceFileList[i])) + { + LOG.Add("FENativeScriptProject::IsVSProjectValid: File " + SourceFileList[i] + " does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + } + + return true; +} + +bool FENativeScriptProject::RegenerateVSProject() +{ + if (PackageData == nullptr) + { + LOG.Add("FENativeScriptProject::RegenerateVSProject: PackageData is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + std::vector AssetPackageContent = PackageData->GetEntryList(); + if (AssetPackageContent.empty()) + { + LOG.Add("FENativeScriptProject::RegenerateVSProject: Asset package is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (Parent == nullptr) + { + LOG.Add("FENativeScriptProject::RegenerateVSProject: Parent is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (ProjectPath.empty()) + { + LOG.Add("FENativeScriptProject::RegenerateVSProject: Project path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (!FILE_SYSTEM.CreateDirectory(ProjectPath)) + { + LOG.Add("FENativeScriptProject::RegenerateVSProject: Error creating directory", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + std::vector SourceFileFullPathList; + for (size_t i = 0; i < AssetPackageContent.size(); i++) + { + PackageData->ExportAssetToFile(AssetPackageContent[i].ID, ProjectPath + AssetPackageContent[i].Name); + SourceFileFullPathList.push_back(ProjectPath + AssetPackageContent[i].Name); + } + + if (!InitializeProject(SourceFileFullPathList)) + return false; + + if (!ConfigureAndBuildCMake()) + return false; + + // FIX ME! that should not be part of this function. + return RunProjectVSSolution(); +} + +bool FENativeScriptProject::InitializeProject(std::vector SourceFileFullPathList) +{ + if (Parent == nullptr) + { + LOG.Add("FENativeScriptProject::InitializeProject: Parent is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (ProjectPath.empty()) + { + LOG.Add("FENativeScriptProject::InitializeProject: Project path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (SourceFileFullPathList.empty()) + { + LOG.Add("FENativeScriptProject::InitializeProject: source file list are empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (!SourceFileFullPathList.empty()) + { + for (size_t i = 0; i < SourceFileFullPathList.size(); i++) + { + if (!FILE_SYSTEM.DoesFileExist(SourceFileFullPathList[i])) + { + LOG.Add("FENativeScriptProject::InitializeProject: Source file " + SourceFileFullPathList[i] + " does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + } + } + + // Create all needed folders. + std::vector FoldersToCreate = { "SubSystems/", "SubSystems/FocalEngine", "BuildManagement/" }; + for (size_t i = 0; i < FoldersToCreate.size(); i++) + { + if (!FILE_SYSTEM.CreateDirectory(ProjectPath + FoldersToCreate[i])) + { + LOG.Add("FENativeScriptProject::InitializeProject: Error creating " + FoldersToCreate[i] + " directory", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + } + + // Place required files in the destination directory. + std::string EditorFolder = FILE_SYSTEM.GetCurrentWorkingPath(); + std::vector> FilesToCopy; + FilesToCopy.push_back({ EditorFolder + "/UserScripts/NativeScriptProjectData/BuildManagement/EnsureBuildCompletion.cmake", ProjectPath + "BuildManagement/EnsureBuildCompletion.cmake" }); + FilesToCopy.push_back({ EditorFolder + "/UserScripts/NativeScriptProjectData/BuildManagement/DebugBuildActions.cmake", ProjectPath + "BuildManagement/DebugBuildActions.cmake" }); + FilesToCopy.push_back({ EditorFolder + "/UserScripts/NativeScriptProjectData/BuildManagement/ReleaseBuildActions.cmake", ProjectPath + "BuildManagement/ReleaseBuildActions.cmake" }); + FilesToCopy.push_back({ EditorFolder + "/UserScripts/NativeScriptProjectData/CMakeLists.txt", ProjectPath + "CMakeLists.txt" }); + std::string EnginePath = FILE_SYSTEM.GetCurrentWorkingPath() + "/" + std::string(ENGINE_FOLDER); + FilesToCopy.push_back({ EnginePath + "/Resources/UserScriptsData/FENativeScriptConnector.h", ProjectPath + "SubSystems/FocalEngine/FENativeScriptConnector.h" }); + FilesToCopy.push_back({ EnginePath + "/Resources/UserScriptsData/FENativeScriptConnector.cpp", ProjectPath + "SubSystems/FocalEngine/FENativeScriptConnector.cpp" }); + + for (size_t i = 0; i < SourceFileFullPathList.size(); i++) + { + FilesToCopy.push_back({ SourceFileFullPathList[i], ProjectPath + FILE_SYSTEM.GetFileName(SourceFileFullPathList[i]) }); + if (FilesToCopy.back().first == FilesToCopy.back().second) + FilesToCopy.pop_back(); + } + + for (size_t i = 0; i < FilesToCopy.size(); i++) + { + if (!FILE_SYSTEM.CopyFile(FilesToCopy[i].first, FilesToCopy[i].second)) + { + LOG.Add("FENativeScriptProject::InitializeProject: Error copying file " + FilesToCopy[i].first + " to " + FilesToCopy[i].second, "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + } + + SourceFileList.clear(); + for (size_t i = 0; i < SourceFileFullPathList.size(); i++) + { + SourceFileList.push_back(FILE_SYSTEM.GetFileName(SourceFileFullPathList[i])); + } + + if (!InitializeCMakeFileAndScriptFiles(SourceFileFullPathList)) + { + LOG.Add("FENativeScriptProject::InitializeProject: Error initializing CMakeLists.txt", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + if (!UpdateEngineFiles()) + { + LOG.Add("FENativeScriptProject::InitializeProject: Error updating engine files in user native script project", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + SetFileTracking(); + return true; +} + +bool FENativeScriptProject::InitializeCMakeFileAndScriptFiles(std::vector SourceFileFullPathList) +{ + if (ProjectPath.empty()) + { + LOG.Add("FENativeScriptProject::InitializeCMakeFileAndScriptFiles: path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (ModuleID.empty()) + { + LOG.Add("FENativeScriptProject::InitializeCMakeFileAndScriptFiles: DLL module ID is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + std::string ProjectName = GetCorrectProjectName(); + + std::string CMakeFilePath = ProjectPath + "CMakeLists.txt"; + + std::vector Instructions; + InstructionWhatToReplaceInFile CurrentInstruction; + CurrentInstruction.SubStringInLineToTrigger = "set(PROJECT_NAME PLACE_HOLDER)"; + CurrentInstruction.What = "PLACE_HOLDER"; + CurrentInstruction.ReplaceWith = ProjectName; + Instructions.push_back(CurrentInstruction); + + std::string SourceFilesList = "file(GLOB Main_SRC\n"; + for (size_t i = 0; i < SourceFileFullPathList.size(); i++) + { + SourceFilesList += "\t\"" + FILE_SYSTEM.GetFileName(SourceFileFullPathList[i]) + "\"\n"; + } + SourceFilesList += ")"; + + CurrentInstruction.SubStringInLineToTrigger = "file(GLOB Main_SRC PLACE_HOLDER)"; + CurrentInstruction.What = "file(GLOB Main_SRC PLACE_HOLDER)"; + CurrentInstruction.ReplaceWith = SourceFilesList; + Instructions.push_back(CurrentInstruction); + + if (!ReplaceInFile(CMakeFilePath, Instructions)) + { + LOG.Add("FENativeScriptProject::InitializeCMakeFileAndScriptFiles: Error initializing CMakeLists.txt", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + Instructions.clear(); + + CurrentInstruction.SubStringInLineToTrigger = "--target PLACE_HOLDER --config Release"; + CurrentInstruction.What = "PLACE_HOLDER"; + CurrentInstruction.ReplaceWith = ProjectName; + Instructions.push_back(CurrentInstruction); + + std::string DebugBuildActionsCMake = ProjectPath + "BuildManagement/DebugBuildActions.cmake"; + if (!ReplaceInFile(DebugBuildActionsCMake, Instructions)) + { + LOG.Add("FENativeScriptProject::InitializeCMakeFileAndScriptFiles: Error initializing BuildManagement/DebugBuildActions.cmake", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + Instructions.clear(); + + CurrentInstruction.SubStringInLineToTrigger = "--target PLACE_HOLDER --config Debug"; + CurrentInstruction.What = "PLACE_HOLDER"; + CurrentInstruction.ReplaceWith = ProjectName; + Instructions.push_back(CurrentInstruction); + + std::string ReleaseBuildActionsCMake = ProjectPath + "BuildManagement/ReleaseBuildActions.cmake"; + if (!ReplaceInFile(ReleaseBuildActionsCMake, Instructions)) + { + LOG.Add("FENativeScriptProject::InitializeCMakeFileAndScriptFiles: Error initializing BuildManagement/ReleaseBuildActions.cmake", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + Instructions.clear(); + + CurrentInstruction.SubStringInLineToTrigger = "SET_MODULE_ID(\"PLACE_HOLDER\");"; + CurrentInstruction.What = "PLACE_HOLDER"; + CurrentInstruction.ReplaceWith = ModuleID; + Instructions.push_back(CurrentInstruction); + + std::string FENativeScriptConnectorHeaderFilePath = ProjectPath + "SubSystems/FocalEngine/FENativeScriptConnector.h"; + if (!ReplaceInFile(FENativeScriptConnectorHeaderFilePath, Instructions)) + { + LOG.Add("FENativeScriptProject::InitializeCMakeFileAndScriptFiles: Error initializing FENativeScriptConnector.h", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + Instructions.clear(); + + return true; +} + +bool FENativeScriptProject::ReplaceInFile(std::string Path, std::vector Instructions) +{ + if (Path.empty()) + { + LOG.Add("FENativeScriptProject::ReplaceInFile: File path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + std::fstream File(Path, std::ios::in); + if (!File.is_open()) + { + LOG.Add("FENativeScriptProject::ReplaceInFile: Error opening file " + Path, "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + std::vector FileContent; + std::string Line; + while (std::getline(File, Line)) + FileContent.push_back(Line); + + File.close(); + + for (size_t i = 0; i < FileContent.size(); i++) + { + for (size_t j = 0; j < Instructions.size(); j++) + { + if (FileContent[i].find(Instructions[j].SubStringInLineToTrigger) != std::string::npos) + { + FileContent[i].replace(FileContent[i].find(Instructions[j].What), Instructions[j].What.size(), Instructions[j].ReplaceWith); + } + } + } + + File.open(Path, std::ios::out | std::ios::trunc); + if (!File.is_open()) + { + LOG.Add("FENativeScriptProject::ReplaceInFile: Error opening file " + Path, "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + // Write the modified content back to the file + for (size_t i = 0; i < FileContent.size(); i++) + File << FileContent[i] + "\n"; + + File.close(); + return true; +} + +bool FENativeScriptProject::UpdateEngineFiles() +{ + if (ProjectPath.empty()) + { + LOG.Add("FENativeScriptProject::UpdateEngineFiles: ProjectPath is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (!FILE_SYSTEM.DoesDirectoryExist(ProjectPath)) + { + LOG.Add("FENativeScriptProject::UpdateEngineFiles: ProjectPath does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + FEAssetPackage* EngineHeadersPackage = CreateEngineHeadersAssetPackage(); + if (EngineHeadersPackage == nullptr) + { + LOG.Add("FENativeScriptProject::UpdateEngineFiles: Error creating engine headers asset package.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + if (!UnPackEngineHeadersAssetPackage(EngineHeadersPackage, ProjectPath + "SubSystems/FocalEngine/")) + { + LOG.Add("FENativeScriptProject::UpdateEngineFiles: Error unpacking engine headers asset package.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + FEAssetPackage* EngineLIBPackage = CreateEngineLIBAssetPackage(); + if (EngineLIBPackage == nullptr) + { + LOG.Add("FENativeScriptProject::UpdateEngineFiles: Error creating engine lib asset package.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + if (!UnPackEngineLIBAssetPackage(EngineLIBPackage, ProjectPath)) + { + LOG.Add("FENativeScriptProject::UpdateEngineFiles: Error unpacking engine lib asset package.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + return true; +} + +FEAssetPackage* FENativeScriptProject::CreateEngineHeadersAssetPackage() +{ + FEAssetPackage* EngineHeadersAssetPackage = new FEAssetPackage(); + EngineHeadersAssetPackage->SetName("EngineHeaders"); + if (EngineHeadersAssetPackage == nullptr) + { + LOG.Add("FENativeScriptProject::CreateEngineHeadersAssetPackage: Error creating asset package", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return nullptr; + } + + std::string EnginePath = FILE_SYSTEM.GetCurrentWorkingPath() + "/" + std::string(ENGINE_FOLDER) + "/"; + if (!FILE_SYSTEM.DoesDirectoryExist(EnginePath)) + { + LOG.Add("FENativeScriptProject::CreateEngineHeadersAssetPackage: Engine folder does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return nullptr; + } + + std::vector AllFiles = FILE_SYSTEM.GetFilesInDirectory(EnginePath, true); + // After having all files in the engine folder, we need to filter out only the header files. + for (size_t i = 0; i < AllFiles.size(); i++) + { + if (AllFiles[i].find(".h") != std::string::npos || AllFiles[i].find(".inl") != std::string::npos) + { + FEAssetPackageEntryIntializeData EntryData; + // Also since FEAssetPackage does not support folders, we need to save folder structure in the file name. + // But we will erase the engine folder path from the file name. + EntryData.Name = AllFiles[i].substr(EnginePath.size()); + EntryData.Type = "Text"; + EntryData.Tag = EDITOR_RESOURCE_TAG; + EntryData.Comment = "Engine header file"; + + EngineHeadersAssetPackage->ImportAssetFromFile(AllFiles[i], EntryData); + } + } + + return EngineHeadersAssetPackage; +} + +bool FENativeScriptProject::UnPackEngineHeadersAssetPackage(FEAssetPackage* AssetPackage, std::string Path) +{ + if (AssetPackage == nullptr) + { + LOG.Add("FENativeScriptProject::UnPackEngineHeadersAssetPackage: Asset package is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (Path.empty()) + { + LOG.Add("FENativeScriptProject::UnPackEngineHeadersAssetPackage: Destination path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (!FILE_SYSTEM.DoesDirectoryExist(Path)) + { + LOG.Add("FENativeScriptProject::UnPackEngineHeadersAssetPackage: Destination path does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + std::vector AssetPackageContent = AssetPackage->GetEntryList(); + if (AssetPackageContent.empty()) + { + LOG.Add("FENativeScriptProject::UnPackEngineHeadersAssetPackage: Asset package is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + for (size_t i = 0; i < AssetPackageContent.size(); i++) + { + std::string LocalPath = std::filesystem::path(AssetPackageContent[i].Name).parent_path().string(); + // Since we are not using folders in FEAssetPackage, we need to create all folders in the file path. + // First we need to get chain of folders. + std::vector FolderChain; + try + { + std::filesystem::path Directory(LocalPath); + while (!Directory.string().empty()) + { + if (!FolderChain.empty()) + { + if (FolderChain.back() == Directory.string()) + break; + } + FolderChain.push_back(Directory.string()); + Directory = Directory.parent_path(); + } + + std::reverse(FolderChain.begin(), FolderChain.end()); + } + catch (const std::exception& Exception) + { + LOG.Add("Error in FENativeScriptProject::UnPackEngineHeadersAssetPackage: " + std::string(Exception.what()), "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + // Then we will go from the root folder to the last folder and create them if they do not exist. + for (size_t i = 0; i < FolderChain.size(); i++) + { + std::string FinalPath = Path + FolderChain[i]; + if (!FILE_SYSTEM.DoesDirectoryExist(FinalPath)) + { + if (!FILE_SYSTEM.CreateDirectory(FinalPath)) + { + LOG.Add("FENativeScriptProject::UnPackEngineHeadersAssetPackage: Error creating directory " + FinalPath, "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + } + } + + // Now we are ready to write the file. + if (!AssetPackage->ExportAssetToFile(AssetPackageContent[i].ID, Path + AssetPackageContent[i].Name)) + { + LOG.Add("FENativeScriptProject::UnPackEngineHeadersAssetPackage: Error exporting asset " + AssetPackageContent[i].ID + " to " + Path + AssetPackageContent[i].Name, "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + } + + return true; +} + +FEAssetPackage* FENativeScriptProject::CreateEngineLIBAssetPackage() +{ + FEAssetPackage* EngineLIBAssetPackage = new FEAssetPackage(); + EngineLIBAssetPackage->SetName("EngineHeaders"); + if (EngineLIBAssetPackage == nullptr) + { + LOG.Add("FENativeScriptProject::CreateEngineLIBAssetPackage: Error creating asset package", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return nullptr; + } + + std::string EnginePath = FILE_SYSTEM.GetCurrentWorkingPath() + "/" + std::string(ENGINE_FOLDER) + "/"; + if (!FILE_SYSTEM.DoesDirectoryExist(EnginePath)) + { + LOG.Add("FENativeScriptProject::CreateEngineLIBAssetPackage: Engine folder does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return nullptr; + } + + std::vector AllFiles = FILE_SYSTEM.GetFilesInDirectory(EnginePath, true); + + std::vector DebugStrings; + // After having all files in the engine folder, we need to filter out only the lib files. + for (size_t i = 0; i < AllFiles.size(); i++) + { + if (AllFiles[i].find(".lib") != std::string::npos) + { + // FIX ME! Currently projects would need only debug lib files. Is it correct? + // And only FocalEngine.lib and FEBasicApplication.lib are needed. + if (AllFiles[i].find("FocalEngine.lib") == std::string::npos && AllFiles[i].find("FEBasicApplication.lib") == std::string::npos) + continue; + + FEAssetPackageEntryIntializeData EntryData; + EntryData.Name = FILE_SYSTEM.GetFileName(AllFiles[i]); + DebugStrings.push_back(EntryData.Name); + EntryData.Type = "BINARY"; + EntryData.Tag = EDITOR_RESOURCE_TAG; + EntryData.Comment = "Engine lib file"; + + EngineLIBAssetPackage->ImportAssetFromFile(AllFiles[i], EntryData); + } + } + + return EngineLIBAssetPackage; +} + +bool FENativeScriptProject::UnPackEngineLIBAssetPackage(FEAssetPackage* AssetPackage, std::string Path) +{ + if (AssetPackage == nullptr) + { + LOG.Add("FENativeScriptProject::UnPackEngineLIBAssetPackage: Asset package is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (Path.empty()) + { + LOG.Add("FENativeScriptProject::UnPackEngineLIBAssetPackage: Destination path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (!FILE_SYSTEM.DoesDirectoryExist(Path)) + { + LOG.Add("FENativeScriptProject::UnPackEngineLIBAssetPackage: Destination path does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + std::vector AssetPackageContent = AssetPackage->GetEntryList(); + if (AssetPackageContent.empty()) + { + LOG.Add("FENativeScriptProject::UnPackEngineLIBAssetPackage: Asset package is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + for (size_t i = 0; i < AssetPackageContent.size(); i++) + { + // Now we are ready to write the file. + if (!AssetPackage->ExportAssetToFile(AssetPackageContent[i].ID, Path + AssetPackageContent[i].Name)) + { + LOG.Add("FENativeScriptProject::UnPackEngineHeadersAssetPackage: Error exporting asset " + AssetPackageContent[i].ID + " to " + Path + AssetPackageContent[i].Name, "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + } + + return true; +} + +bool FENativeScriptProject::ConfigureAndBuildCMake() +{ + if (ProjectPath.empty()) + { + LOG.Add("FENativeScriptProject::RunCMake: ProjectPath is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + std::string Generator = "Visual Studio 17 2022"; + + // CMake configure command. + std::string ConfigureCommand = "cmake -S \"" + ProjectPath + "\" -B \"" + ProjectPath + "\" -G \"" + Generator + "\""; + + // Execute CMake configure command. + int ConfigureResult = std::system(ConfigureCommand.c_str()); + if (ConfigureResult != 0) + { + LOG.Add("FENativeScriptProject::RunCMake: Error running CMake configure command", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + // Construct the CMake build command + std::string BuildCommand = "cmake --build \"" + ProjectPath + "\" --config Debug"; + + // Execute CMake build command + int BuildResult = std::system(BuildCommand.c_str()); + if (BuildResult != 0) + { + LOG.Add("FENativeScriptProject::RunCMake: Error running CMake build command", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + return true; +} + +bool FENativeScriptProject::RunProjectVSSolution() +{ + if (ProjectPath.empty()) + { + LOG.Add("FENativeScriptProject::RunProjectVSSolution: ProjectPath is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + std::string ProjectName = GetCorrectProjectName(); + if (ProjectName.empty()) + { + LOG.Add("FENativeScriptProject::RunProjectVSSolution: Project name is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + std::string SolutionPath = ProjectPath + ProjectName + ".sln"; + + // Use ShellExecute to open the solution file + HINSTANCE Result = ShellExecuteA( + NULL, + "open", + SolutionPath.c_str(), + NULL, + NULL, + SW_SHOWNORMAL + ); + + // Check if ShellExecute was successful + if ((INT_PTR)Result <= 32) + { + LOG.Add("FENativeScriptProject::RunProjectVSSolution: Error running solution", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + return true; +} + +void FENativeScriptProject::SetFileTracking() +{ + std::string AppropriateProjectName = GetCorrectProjectName(); + + DebugDllFileData.Path = ProjectPath + "Debug/" + AppropriateProjectName + ".dll"; + DebugDllFileData.WriteTime = FILE_SYSTEM.GetFileLastWriteTime(DebugDllFileData.Path); + + DebugPdbFileData.Path = ProjectPath + "Debug/" + AppropriateProjectName + ".pdb"; + DebugPdbFileData.WriteTime = FILE_SYSTEM.GetFileLastWriteTime(DebugPdbFileData.Path); + + ReleaseDllFileData.Path = ProjectPath + "Release/" + AppropriateProjectName + ".dll"; + ReleaseDllFileData.WriteTime = FILE_SYSTEM.GetFileLastWriteTime(ReleaseDllFileData.Path); +} + +bool FENativeScriptProject::GenerateScriptFilesFromTemplate(std::string ScriptName) +{ + if (!FILE_SYSTEM.DoesDirectoryExist(ProjectPath)) + { + LOG.Add("FENativeScriptProject::GenerateScriptFilesFromTemplate: ProjectPath does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (ScriptName.empty()) + { + LOG.Add("FENativeScriptProject::GenerateScriptFilesFromTemplate: Script name is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + std::string EnginePath = FILE_SYSTEM.GetCurrentWorkingPath() + "/" + std::string(ENGINE_FOLDER); + std::string TemplateHeaderFilePath = EnginePath + "/Resources/UserScriptsData/NativeScriptTemplate.h"; + std::string TemplateCPPFilePath = EnginePath + "/Resources/UserScriptsData/NativeScriptTemplate.cpp"; + + if (!FILE_SYSTEM.CopyFile(TemplateHeaderFilePath, ProjectPath + ScriptName + ".h")) + { + LOG.Add("FENativeScriptProject::GenerateScriptFilesFromTemplate: Error copying file " + TemplateHeaderFilePath + " to " + ProjectPath + ScriptName + ".h", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + if (!FILE_SYSTEM.CopyFile(TemplateCPPFilePath, ProjectPath + ScriptName + ".cpp")) + { + LOG.Add("FENativeScriptProject::GenerateScriptFilesFromTemplate: Error copying file " + TemplateCPPFilePath + " to " + ProjectPath + ScriptName + ".cpp", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + std::vector Instructions; + InstructionWhatToReplaceInFile CurrentInstruction; + CurrentInstruction.SubStringInLineToTrigger = "SET_MODULE_ID(\"PLACE_HOLDER\")"; + CurrentInstruction.What = "PLACE_HOLDER"; + CurrentInstruction.ReplaceWith = "2342HA"; + Instructions.push_back(CurrentInstruction); + + CurrentInstruction.SubStringInLineToTrigger = "class PLACE_HOLDER : public FENativeScriptCore"; + CurrentInstruction.What = "PLACE_HOLDER"; + CurrentInstruction.ReplaceWith = ScriptName; + Instructions.push_back(CurrentInstruction); + + CurrentInstruction.SubStringInLineToTrigger = "REGISTER_SCRIPT(PLACE_HOLDER)"; + CurrentInstruction.What = "PLACE_HOLDER"; + CurrentInstruction.ReplaceWith = ScriptName; + Instructions.push_back(CurrentInstruction); + + CurrentInstruction.SubStringInLineToTrigger = "REGISTER_SCRIPT_FIELD(PLACE_HOLDER, int, ExampleVariable)"; + CurrentInstruction.What = "PLACE_HOLDER"; + CurrentInstruction.ReplaceWith = ScriptName; + Instructions.push_back(CurrentInstruction); + + std::string ScriptHeaderFilePath = ProjectPath + ScriptName + ".h"; + if (!ReplaceInFile(ScriptHeaderFilePath, Instructions)) + { + LOG.Add("FENativeScriptProject::GenerateScriptFilesFromTemplate: Error initializing " + ScriptName + ".h", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + Instructions.clear(); + + CurrentInstruction.SubStringInLineToTrigger = "#include \"NativeScriptTemplate.h\""; + CurrentInstruction.What = "NativeScriptTemplate"; + CurrentInstruction.ReplaceWith = ScriptName; + Instructions.push_back(CurrentInstruction); + + CurrentInstruction.SubStringInLineToTrigger = "void PLACE_HOLDER::Awake()"; + CurrentInstruction.What = "PLACE_HOLDER"; + CurrentInstruction.ReplaceWith = ScriptName; + Instructions.push_back(CurrentInstruction); + + CurrentInstruction.SubStringInLineToTrigger = "void PLACE_HOLDER::OnDestroy()"; + CurrentInstruction.What = "PLACE_HOLDER"; + CurrentInstruction.ReplaceWith = ScriptName; + Instructions.push_back(CurrentInstruction); + + CurrentInstruction.SubStringInLineToTrigger = "void PLACE_HOLDER::OnUpdate(double DeltaTime)"; + CurrentInstruction.What = "PLACE_HOLDER"; + CurrentInstruction.ReplaceWith = ScriptName; + Instructions.push_back(CurrentInstruction); + + std::string ScriptSourceFilePath = ProjectPath + ScriptName + ".cpp"; + if (!ReplaceInFile(ScriptSourceFilePath, Instructions)) + { + LOG.Add("FENativeScriptProject::GenerateScriptFilesFromTemplate: Error initializing " + ScriptName + ".cpp", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + Instructions.clear(); + + return true; +} + +bool FENativeScriptProject::GenerateNewVSProject(std::string FirstScriptName) +{ + if (FirstScriptName.empty()) + { + LOG.Add("FENativeScriptProject::GenerateNewVSProject: First script name is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (Parent == nullptr) + { + LOG.Add("FENativeScriptProject::GenerateNewVSProject: Parent is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + // Replace all spaces with underscores. + for (size_t i = 0; i < FirstScriptName.size(); i++) + { + if (FirstScriptName[i] == ' ') + FirstScriptName[i] = '_'; + } + + if (FILE_SYSTEM.DoesDirectoryExist(ProjectPath)) + { + LOG.Add("FENativeScriptProject::GenerateNewVSProject: VS project already exists", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + return false; + } + + if (!FILE_SYSTEM.CreateDirectory(ProjectPath)) + { + LOG.Add("FENativeScriptProject::GenerateNewVSProject: Error creating directory", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + ModuleID = APPLICATION.GetUniqueHexID(); + + if (!GenerateScriptFilesFromTemplate(FirstScriptName)) + { + LOG.Add("FENativeScriptProject::GenerateNewVSProject: Error generating script files from template", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); + return false; + } + + if (!InitializeProject({ ProjectPath + FirstScriptName + ".h", ProjectPath + FirstScriptName + ".cpp" })) + return false; + + if (!ConfigureAndBuildCMake()) + return false; + + // FIX ME! that should not be part of this function. + return RunProjectVSSolution(); +} + +bool FENativeScriptProject::IsFileChanged(const TrackedFileData& FileData) +{ + uint64_t NewWriteTime = FILE_SYSTEM.GetFileLastWriteTime(FileData.Path); + if (NewWriteTime != FileData.WriteTime && NewWriteTime != 0) + { + uint64_t Differece = NewWriteTime >= FileData.WriteTime ? NewWriteTime - FileData.WriteTime : FileData.WriteTime - NewWriteTime; + if (Differece > DifferenceThreshold) + return true; + } + + return false; +} + +void FENativeScriptProject::UpdateTrackedFileWriteTime(TrackedFileData& FileData) +{ + uint64_t NewTimeStamp = FILE_SYSTEM.GetFileLastWriteTime(FileData.Path); + + if (NewTimeStamp > FileData.WriteTime) + FileData.WriteTime = NewTimeStamp; +} + +bool FENativeScriptProject::Update() +{ + if (!IsVSProjectValid()) + return false; + + bool CheckForReload = false; + if (IsFileChanged(DebugDllFileData) && IsFileChanged(DebugPdbFileData) || IsFileChanged(ReleaseDllFileData)) + CheckForReload = true; + + if (!CheckForReload) + return false; + + // Waiting for external build system to finish. + FILE_SYSTEM.WaitForFileAccess(ProjectPath + "BuildManagement/Force_Build_Finished.txt", 1000); + + if (FILE_SYSTEM.DoesFileExist(ProjectPath + "BuildManagement/Force_Build_Finished.txt")) + { + FILE_SYSTEM.DeleteFile(ProjectPath + "BuildManagement/Force_Build_Finished.txt"); + } + else + { + LOG.Add("FENativeScriptProject::Update: Force_Build_Finished.txt does not exist, script reload aborted.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + + UpdateTrackedFileWriteTime(DebugDllFileData); + UpdateTrackedFileWriteTime(DebugPdbFileData); + UpdateTrackedFileWriteTime(ReleaseDllFileData); + + return false; + } + + // Waiting for all files to be accessible. + if (!FILE_SYSTEM.WaitForFileAccess(DebugDllFileData.Path, 2000)) + { + LOG.Add("FENativeScriptProject::Update: File " + DebugDllFileData.Path + "does not exist, script reload aborted.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + + UpdateTrackedFileWriteTime(DebugDllFileData); + UpdateTrackedFileWriteTime(DebugPdbFileData); + UpdateTrackedFileWriteTime(ReleaseDllFileData); + + return false; + } + + if (!FILE_SYSTEM.WaitForFileAccess(DebugPdbFileData.Path, 2000)) + { + LOG.Add("FENativeScriptProject::Update: File " + DebugPdbFileData.Path + "does not exist, script reload aborted.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + + UpdateTrackedFileWriteTime(DebugDllFileData); + UpdateTrackedFileWriteTime(DebugPdbFileData); + UpdateTrackedFileWriteTime(ReleaseDllFileData); + + return false; + } + + if (!FILE_SYSTEM.WaitForFileAccess(ReleaseDllFileData.Path, 2000)) + { + LOG.Add("FENativeScriptProject::Update: File " + ReleaseDllFileData.Path + "does not exist, script reload aborted.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); + + UpdateTrackedFileWriteTime(DebugDllFileData); + UpdateTrackedFileWriteTime(DebugPdbFileData); + UpdateTrackedFileWriteTime(ReleaseDllFileData); + + return false; + } + + bool bResult = GenerateScriptModule(); + + UpdateTrackedFileWriteTime(DebugDllFileData); + UpdateTrackedFileWriteTime(DebugPdbFileData); + UpdateTrackedFileWriteTime(ReleaseDllFileData); + + return bResult; +} \ No newline at end of file diff --git a/SubSystems/ProjectManagment/FENativeScriptProject.h b/SubSystems/ProjectManagment/FENativeScriptProject.h new file mode 100644 index 0000000..5c7b748 --- /dev/null +++ b/SubSystems/ProjectManagment/FENativeScriptProject.h @@ -0,0 +1,72 @@ +#pragma once +#include "../FEngine.h" +using namespace FocalEngine; + +struct TrackedFileData +{ + std::string Path; + uint64_t WriteTime; +}; + +class FENativeScriptProject +{ + friend class FEProject; + + FEProject* Parent = nullptr; + std::string ProjectPath = ""; + std::vector SourceFileList; + FEAssetPackage* PackageData = nullptr; + + TrackedFileData DebugDllFileData; + TrackedFileData DebugPdbFileData; + TrackedFileData ReleaseDllFileData; + + const uint64_t DifferenceThreshold = 1'000'000; + + FENativeScriptModule* LastGeneratedScriptModule = nullptr; + + bool InitializeProject(std::vector SourceFileFullPathList); + bool ConfigureAndBuildCMake(); + bool RunProjectVSSolution(); + + bool InitializeCMakeFileAndScriptFiles(std::vector SourceFileFullPathList); + + struct InstructionWhatToReplaceInFile + { + std::string SubStringInLineToTrigger; + std::string What; + std::string ReplaceWith; + }; + + bool ReplaceInFile(std::string FilePath, std::vector Instructions); + bool UpdateEngineFiles(); + + FEAssetPackage* CreateEngineHeadersAssetPackage(); + bool UnPackEngineHeadersAssetPackage(FEAssetPackage* AssetPackage, std::string Path); + + FEAssetPackage* CreateEngineLIBAssetPackage(); + bool UnPackEngineLIBAssetPackage(FEAssetPackage* AssetPackage, std::string Path); + + void SetFileTracking(); + bool GenerateScriptFilesFromTemplate(std::string ScriptName); + + bool IsFileChanged(const TrackedFileData& FileData); + void UpdateTrackedFileWriteTime(TrackedFileData& FileData); +public: + FENativeScriptProject(FEProject* Parent); + ~FENativeScriptProject(); + + bool GenerateNewVSProject(std::string FirstScriptName); + bool IsVSProjectValid(); + bool RegenerateVSProject(); + + bool Load(Json::Value Root, std::string FolderPath); + void Save(Json::Value& Root, std::string FolderPath); + + bool GenerateScriptModule(); + + std::string GetCorrectProjectName(); + std::string ModuleID = ""; + + bool Update(); +}; \ No newline at end of file diff --git a/FEProject.cpp b/SubSystems/ProjectManagment/FEProject.cpp similarity index 50% rename from FEProject.cpp rename to SubSystems/ProjectManagment/FEProject.cpp index fb989ac..bac9b02 100644 --- a/FEProject.cpp +++ b/SubSystems/ProjectManagment/FEProject.cpp @@ -1,367 +1,22 @@ #include "FEProject.h" -#include "FEEditor.h" - -FEProjectManager::FEProjectManager() {} -FEProjectManager::~FEProjectManager() {} - -void FEProjectManager::InitializeResources() -{ - IndexChosen = -1; - LoadProjectList(); -} - -FEProject* FEProjectManager::GetCurrent() -{ - return Current; -} - -void FEProjectManager::SetCurrent(FEProject* Project) -{ - Current = Project; -} - -std::vector FEProjectManager::GetList() -{ - return List; -} - -void FEProjectManager::LoadProjectList() -{ - if (!FILE_SYSTEM.DoesDirectoryExist(PROJECTS_FOLDER)) - CustomProjectFolder = ""; - - const std::vector ProjectNameList = FILE_SYSTEM.GetDirectoryList(PROJECTS_FOLDER); - - for (size_t i = 0; i < ProjectNameList.size(); i++) - { - if (ContainProject(std::string(PROJECTS_FOLDER) + std::string("/") + ProjectNameList[i])) - List.push_back(new FEProject(ProjectNameList[i].c_str(), std::string(PROJECTS_FOLDER) + std::string("/") + ProjectNameList[i].c_str() + "/")); - } -} - -void FEProjectManager::CloseCurrentProject() -{ - //closing all windows or popups. - WindowsManager::GetInstance().CloseAllWindows(); - WindowsManager::GetInstance().CloseAllPopups(); - - SELECTED.ClearAll(); - PREVIEW_MANAGER.Clear(); - SCENE_MANAGER.DeleteScene(PROJECT_MANAGER.GetCurrent()->ProjectScene); - for (size_t i = 0; i < List.size(); i++) - { - delete List[i]; - } - List.clear(); - PROJECT_MANAGER.SetCurrent(nullptr); - LoadProjectList(); - - VIRTUAL_FILE_SYSTEM.SetCurrentPath("/"); -} - -void FEProjectManager::OpenProject(const int ProjectIndex) -{ - PROJECT_MANAGER.SetCurrent(List[ProjectIndex]); - PROJECT_MANAGER.GetCurrent()->LoadProject(); - PROJECT_MANAGER.GetCurrent()->ProjectScene->SetFlag(FESceneFlag::Renderable, true); - PROJECT_MANAGER.GetCurrent()->ProjectScene->SetFlag(FESceneFlag::EditorMode, true); - EDITOR.AddEditorScene(PROJECT_MANAGER.GetCurrent()->ProjectScene, true); - EDITOR.FocusedEditorSceneID = PROJECT_MANAGER.GetCurrent()->ProjectScene->GetObjectID(); - IndexChosen = -1; - - // In each loaded project we need to inject editor camera. - InjectEditorCamera(PROJECT_MANAGER.GetCurrent()->ProjectScene); - - // After loading project we should update our previews - PREVIEW_MANAGER.UpdateAll(); - SELECTED.ClearAll(); -} - -void FEProjectManager::DisplayProjectSelection() -{ - static float LowerPanelHight = 90.0f; - const float MainWindowW = static_cast(APPLICATION.GetMainWindow()->GetWidth()); - const float MainWindowH = static_cast(APPLICATION.GetMainWindow()->GetHeight()); - - ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 1.0f); - ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f)); - ImGui::SetNextWindowSize(ImVec2(MainWindowW, MainWindowH - LowerPanelHight)); - ImGui::Begin("Project Browser", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse); - { - ImGui::SetWindowFontScale(2.0f); - ImGui::Text("CHOOSE WHAT PROJECT TO LOAD :"); - ImGui::SetWindowFontScale(1.0f); - - ImGui::PushStyleColor(ImGuiCol_Button, static_cast(ImColor(0.5f, 0.5f, 0.5f))); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, static_cast(ImColor::ImColor(0.95f, 0.90f, 0.0f))); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, static_cast(ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f))); - - const int ColumnCount = static_cast(MainWindowW / (512.0f + 32.0f)); - ImGui::Columns(ColumnCount, "projectColumns", false); - static bool bPushedStyle = false; - for (size_t i = 0; i < List.size(); i++) - { - ImGui::PushID(static_cast(i)); - bPushedStyle = false; - if (IndexChosen == i) - { - bPushedStyle = true; - ImGui::PushStyleColor(ImGuiCol_Button, static_cast(ImColor(0.1f, 1.0f, 0.1f, 1.0f))); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, static_cast(ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f))); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, static_cast(ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f))); - } - - if (ImGui::IsMouseDoubleClicked(0)) - { - if (IndexChosen != -1) - { - OpenProject(IndexChosen); - } - } - - if (ImGui::ImageButton((void*)static_cast(List[i]->SceneScreenshot->GetTextureID()), ImVec2(512.0f, 288.0f), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) - { - IndexChosen = static_cast(i); - } - - ImGui::Text(List[i]->GetName().c_str()); - - if (bPushedStyle) - { - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - } - - ImGui::PopID(); - ImGui::NextColumn(); - } - - ImGui::Columns(1); - - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - } - ImGui::End(); - ImGui::PopStyleVar(); - - ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 1.0f); - ImGui::SetNextWindowPos(ImVec2(0.0f, MainWindowH - LowerPanelHight)); - ImGui::SetNextWindowSize(ImVec2(MainWindowW, LowerPanelHight)); - ImGui::Begin("##create project", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar); - { - ImGui::PushStyleColor(ImGuiCol_Button, static_cast(ImColor(0.0f, 162.0f / 255.0f, 232.0f / 255.0f, 1.0f))); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, static_cast(ImColor::ImColor(23.0f / 255.0f, 186.0f / 255.0f, 1.0f, 1.0f))); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, static_cast(ImColor::ImColor(0.0f, 125.0f / 255.0f, 179.0f / 255.0f, 1.0f))); - - if (ImGui::Button("Create New Project", ImVec2(200.0f, 64.0f))) - ImGui::OpenPopup("New Project"); - - ImGui::SameLine(); - if (ImGui::Button("Open Project", ImVec2(200.0f, 64.0f)) && IndexChosen != -1) - { - OpenProject(IndexChosen); - } - - ImGui::SameLine(); - if (ImGui::Button("Delete Project", ImVec2(200.0f, 64.0f)) && IndexChosen != -1 && IndexChosen < static_cast(List.size())) - { - std::string ProjectFolder = List[IndexChosen]->GetProjectFolder(); - ProjectFolder.erase(ProjectFolder.begin() + ProjectFolder.size() - 1); - - // Getting list of all files in project folder. - const auto FileList = FILE_SYSTEM.GetFileList(List[IndexChosen]->GetProjectFolder().c_str()); - // We would delete all files in project folder, editor would not create folders there - // so we are deleting only files. - for (size_t i = 0; i < FileList.size(); i++) - { - FILE_SYSTEM.DeleteFile((List[IndexChosen]->GetProjectFolder() + FileList[i]).c_str()); - } - // Then we can try to delete project folder, but if user created some folders in it we will fail. - FILE_SYSTEM.DeleteDirectory(ProjectFolder.c_str()); - - for (size_t i = 0; i < List.size(); i++) - { - delete List[i]; - } - List.clear(); - PROJECT_MANAGER.SetCurrent(nullptr); - - LoadProjectList(); - } - - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PushStyleColor(ImGuiCol_Button, static_cast(ImColor(0.0f, 242.0f / 255.0f, 79.0f / 255.0f, 1.0f))); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, static_cast(ImColor::ImColor(34.0f / 255.0f, 1.0f, 106.0f / 255.0f, 1.0f))); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, static_cast(ImColor::ImColor(0.0f, 202.0f / 255.0f, 66.0f / 255.0f, 1.0f))); - - ImGui::SameLine(); - ImGui::SetCursorPos(ImVec2(ImGui::GetContentRegionAvail().x + 280.0f + 64.0f, ImGui::GetCursorPos().y)); - if (ImGui::Button("Choose projects directory", ImVec2(280.0f, 64.0f))) - { - std::string Path; - FILE_SYSTEM.ShowFolderOpenDialog(Path); - SetProjectsFolder(Path); - } - - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); - if (ImGui::BeginPopupModal("New Project", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) - { - ImGui::SetWindowPos(ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, APPLICATION.GetMainWindow()->GetHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); - ImGui::Text("Insert name of new project :"); - static char ProjectName[512] = ""; - - ImGui::InputText("##newProjectName", ProjectName, IM_ARRAYSIZE(ProjectName)); - - ImGui::SetCursorPosX(ImGui::GetWindowWidth() / 4.0f - 120.0f / 2.0f); - ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10.0f); - if (ImGui::Button("Create", ImVec2(120, 0))) - { - bool bAlreadyCreated = false; - for (size_t i = 0; i < List.size(); i++) - { - if (List[i]->GetName() == std::string(ProjectName)) - { - bAlreadyCreated = true; - break; - } - } - - if (strlen(ProjectName) != 0 && !bAlreadyCreated) - { - FILE_SYSTEM.CreateDirectory((std::string(PROJECTS_FOLDER) + std::string("/") + ProjectName + "/").c_str()); - List.push_back(new FEProject(ProjectName, std::string(PROJECTS_FOLDER) + std::string("/") + ProjectName + "/")); - List.back()->CreateDummyScreenshot(); - - CreateNewProject(ProjectName, std::string(PROJECTS_FOLDER) + std::string("/") + ProjectName + "/"); - - ImGui::CloseCurrentPopup(); - strcpy_s(ProjectName, ""); - } - } - - ImGui::SetItemDefaultFocus(); - ImGui::SameLine(); - ImGui::SetCursorPosX(ImGui::GetWindowWidth() / 2.0f + ImGui::GetWindowWidth() / 4.0f - 120.0f / 2.0f); - if (ImGui::Button("Cancel", ImVec2(120, 0))) - { - ImGui::CloseCurrentPopup(); - } - - ImGui::EndPopup(); - } - } - - ImGui::PopStyleVar(); - ImGui::End(); - ImGui::PopStyleVar(); -} - -void FEProjectManager::CreateNewProject(std::string ProjectName, std::string ProjectPath) -{ - if (ProjectName.empty() || ProjectPath.empty()) - { - LOG.Add("FEProjectManager::CreateNewProject: Project name or path is empty!", "FE_LOG_LOADING", FE_LOG_ERROR); - return; - } - - if (ContainProject(ProjectPath)) - { - LOG.Add("FEProjectManager::CreateNewProject: Project already exists!", "FE_LOG_LOADING", FE_LOG_ERROR); - return; - } - - Json::Value Root; - std::ofstream ProjectFile; - Root["version"] = PROJECTS_FILE_VER; - - FEScene* NewScene = SCENE_MANAGER.CreateScene(ProjectName, "", FESceneFlag::None); - - FEEntity* SunEntity = NewScene->CreateEntity("Sun"); - SunEntity->AddComponent(FE_DIRECTIONAL_LIGHT); - FELightComponent& LightComponent = SunEntity->GetComponent(); - SunEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); - LightComponent.SetIntensity(4.0f); - LightComponent.SetCastShadows(true); - - FEEntity* SkyDome = NewScene->CreateEntity("SkyDome"); - SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); - SkyDome->AddComponent(); - - Json::Value SceneData; - Json::Value SceneDataNode; - SceneDataNode["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(NewScene); - Json::Value SceneHierarchy = NewScene->SceneGraph.ToJson([](FEEntity* Entity) -> bool { - if (Entity->GetTag() == EDITOR_RESOURCE_TAG) - return false; - - return true; - }); - SceneDataNode["Scene hierarchy"] = SceneHierarchy; - - SceneData[NewScene->GetObjectID()] = SceneDataNode; - Root["Scenes"] = SceneData; - Root["Main scene"] = NewScene->GetObjectID(); - - // Saving into file. - Json::StreamWriterBuilder Builder; - const std::string JsonFile = Json::writeString(Builder, Root); - - ProjectFile.open(ProjectPath + "scene.txt"); - ProjectFile << JsonFile; - ProjectFile.close(); - - SCENE_MANAGER.DeleteScene(NewScene); -} - -bool FEProjectManager::ContainProject(const std::string Path) -{ - if (!FILE_SYSTEM.DoesDirectoryExist(Path.c_str())) - return false; - - if (!FILE_SYSTEM.DoesFileExist((Path + "/scene.txt").c_str())) - return false; - - return true; -} - -void FEProjectManager::SetProjectsFolder(const std::string FolderPath) -{ - if (FolderPath != "") - { - CustomProjectFolder = FolderPath; - for (size_t i = 0; i < List.size(); i++) - { - delete List[i]; - } - List.clear(); - LoadProjectList(); - } -} +#include "../../FEEditor.h" FEProject::FEProject(const std::string Name, const std::string ProjectFolder) { + ID = APPLICATION.GetUniqueHexID(); this->Name = Name; this->ProjectFolder = ProjectFolder; - std::ifstream ScreenshotFile((this->GetProjectFolder() + "projectScreenShot.texture").c_str()); + std::ifstream ScreenshotFile((this->GetProjectFolder() + "Thumbnail.texture").c_str()); if (!ScreenshotFile.good()) { SceneScreenshot = RESOURCE_MANAGER.NoTexture; - } +} else { - SceneScreenshot = RESOURCE_MANAGER.LoadFETextureUnmanaged((this->GetProjectFolder() + "projectScreenShot.texture").c_str()); + SceneScreenshot = RESOURCE_MANAGER.LoadFETextureUnmanaged((this->GetProjectFolder() + "Thumbnail.texture").c_str()); } - ScreenshotFile.close(); } @@ -372,6 +27,7 @@ FEProject::~FEProject() RESOURCE_MANAGER.Clear(); VIRTUAL_FILE_SYSTEM.Clear(); + SCENE_MANAGER.Clear(); } std::string FEProject::GetName() @@ -389,13 +45,14 @@ std::string FEProject::GetProjectFolder() return ProjectFolder; } -void FEProject::SaveProject(bool bFullSave) +void FEProject::SaveResourcesTo(std::string FilePath, bool bFullSave) { Json::Value Root; - std::ofstream ProjectFile; + std::ofstream ResourcesFile; + + Root["Version"] = PROJECT_RESOURCE_FILE_VERSION; + Root["ProjectID"] = ID; - Root["version"] = PROJECTS_FILE_VER; - if (!bFullSave) { // Saving all unsaved objects. @@ -403,21 +60,21 @@ void FEProject::SaveProject(bool bFullSave) { switch (UnSavedObjects[i]->GetType()) { - case FE_MESH: - { - FEMesh* MeshToSave = RESOURCE_MANAGER.GetMesh(UnSavedObjects[i]->GetObjectID()); - if (MeshToSave != nullptr) - RESOURCE_MANAGER.SaveFEMesh(MeshToSave, (GetProjectFolder() + MeshToSave->GetObjectID() + std::string(".model")).c_str()); - break; - } + case FE_MESH: + { + FEMesh* MeshToSave = RESOURCE_MANAGER.GetMesh(UnSavedObjects[i]->GetObjectID()); + if (MeshToSave != nullptr) + RESOURCE_MANAGER.SaveFEMesh(MeshToSave, (GetProjectFolder() + MeshToSave->GetObjectID() + std::string(".model")).c_str()); + break; + } - case FE_TEXTURE: - { - FETexture* TextureToSave = RESOURCE_MANAGER.GetTexture(UnSavedObjects[i]->GetObjectID()); - if (TextureToSave != nullptr) - RESOURCE_MANAGER.SaveFETexture(TextureToSave, (GetProjectFolder() + TextureToSave->GetObjectID() + std::string(".texture")).c_str()); - break; - } + case FE_TEXTURE: + { + FETexture* TextureToSave = RESOURCE_MANAGER.GetTexture(UnSavedObjects[i]->GetObjectID()); + if (TextureToSave != nullptr) + RESOURCE_MANAGER.SaveFETexture(TextureToSave, (GetProjectFolder() + TextureToSave->GetObjectID() + std::string(".texture")).c_str()); + break; + } } } } @@ -545,12 +202,14 @@ void FEProject::SaveProject(bool bFullSave) continue; PrefabData[Prefab->GetObjectID()]["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(Prefab); + if (Prefab->GetScene() == nullptr) + { + LOG.Add("FEProject::SaveResourcesTo: Prefab scene is nullptr!", "FE_LOG_LOADING", FE_LOG_ERROR); + PrefabData[Prefab->GetObjectID()]["SceneID"] = ""; + continue; + } - Json::Value PrefabSceneData; - PrefabSceneData["ID"] = Prefab->GetScene()->GetObjectID(); - Json::Value SceneHierarchy = Prefab->GetScene()->SceneGraph.ToJson(); - PrefabSceneData["Scene hierarchy"] = SceneHierarchy; - PrefabData[Prefab->GetObjectID()]["Scene"] = PrefabSceneData; + PrefabData[Prefab->GetObjectID()]["SceneID"] = Prefab->GetScene()->GetObjectID(); } Root["Prefabs"] = PrefabData; @@ -559,10 +218,43 @@ void FEProject::SaveProject(bool bFullSave) Json::Value SceneData; for (size_t i = 0; i < SceneList.size(); i++) { - if (SceneList[i]->GetTag() == ENGINE_RESOURCE_TAG || - SceneList[i]->GetTag() == EDITOR_RESOURCE_TAG) + bool bShouldProceed = true; + + std::vector Tags = RESOURCE_MANAGER.GetTagsThatWillPreventDeletion(); + for (size_t j = 0; j < Tags.size(); j++) + { + if (SceneList[i]->GetTag() == Tags[j]) + { + bShouldProceed = false; + break; + } + } + + if (SceneList[i]->GetTag() == PREFAB_SCENE_DESCRIPTION_TAG) + { + for (size_t j = 0; j < PrefabList.size(); j++) + { + FEPrefab* Prefab = RESOURCE_MANAGER.GetPrefab(PrefabList[j]); + if (Prefab->GetScene() != SceneList[i]) + continue; + + for (size_t k = 0; k < Tags.size(); k++) + { + if (Tags[k] == Prefab->GetTag()) + { + bShouldProceed = false; + break; + } + } + + if (!bShouldProceed) + break; + } + } + + if (!bShouldProceed) continue; - + Json::Value SceneDataNode; SceneDataNode["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(SceneList[i]); Json::Value SceneHierarchy = SceneList[i]->SceneGraph.ToJson([](FEEntity* Entity) -> bool { @@ -576,69 +268,137 @@ void FEProject::SaveProject(bool bFullSave) SceneData[SceneList[i]->GetObjectID()] = SceneDataNode; } Root["Scenes"] = SceneData; - Root["Main scene"] = ProjectScene->GetObjectID(); // Saving into file. Json::StreamWriterBuilder Builder; const std::string JsonFile = Json::writeString(Builder, Root); - ProjectFile.open(ProjectFolder + "scene.txt"); - ProjectFile << JsonFile; - ProjectFile.close(); + ResourcesFile.open(FilePath); + ResourcesFile << JsonFile; + ResourcesFile.close(); +} - for (size_t i = 0; i < FilesToDelete.size(); i++) +void FEProject::SaveProject(bool bFullSave) +{ + Json::Value Root; + std::ofstream ProjectFile; + + Root["Version"] = PROJECTS_FILE_VER; + Root["ID"] = ID; + Root["Name"] = Name; + + if (NativeScriptProject != nullptr) + NativeScriptProject->Save(Root["NativeScriptProject"], ProjectFolder); + + FEScene* SceneForScreenshot = EDITOR.GetFocusedScene(); + if (SceneForScreenshot != nullptr) { - FILE_SYSTEM.DeleteFile(FilesToDelete[i].c_str()); + ENGINE.SaveScreenshot((GetProjectFolder() + "Thumbnail.texture").c_str(), SceneForScreenshot); + } + else + { + CreateDummyScreenshot(); } + + // Saving editor scenes information. + std::vector EditorSceneIDs = EDITOR.GetEditorOpenedScenesIDs(); + for (size_t i = 0; i < EditorSceneIDs.size(); i++) + { + FEScene* CurrentScene = SCENE_MANAGER.GetScene(EditorSceneIDs[i]); + if (CurrentScene == nullptr) + continue; - VIRTUAL_FILE_SYSTEM.SaveState(ProjectFolder + "VFS.txt"); - bModified = false; -} + // If scene is editor only it means it is prefab scene. + if (CurrentScene->GetTag() == EDITOR_RESOURCE_TAG) + { + // So we need to find corresponding prefab. + FEEditorSceneWindow* EditorWindow = EDITOR.GetEditorSceneWindow(CurrentScene->GetObjectID()); + if (EditorWindow == nullptr) + continue; + + FEPrefab* Prefab = PREFAB_EDITOR_MANAGER.GetPrefabFromEditorWindow(EditorWindow); + if (Prefab == nullptr) + continue; -#include -#pragma comment(lib, "dbghelp.lib") -std::string ListExportedFunctions(const std::string& dllPath) { - std::stringstream result; - HMODULE hModule = LoadLibraryA(dllPath.c_str()); - if (hModule == NULL) { - return "Failed to load DLL."; + Root["EditorScenes"]["Opened"][std::to_string(i)]["ID"] = Prefab->GetScene()->GetObjectID(); + Root["EditorScenes"]["Opened"][std::to_string(i)]["IsPrefabDescription"] = true; + } + else + { + Root["EditorScenes"]["Opened"][std::to_string(i)]["ID"] = CurrentScene->GetObjectID(); + Root["EditorScenes"]["Opened"][std::to_string(i)]["IsPrefabDescription"] = false; + } } - ULONG size; - PIMAGE_EXPORT_DIRECTORY exportDir; + FEScene* FocusedScene = EDITOR.GetFocusedScene(); + std::string FocusedSceneID = ""; + if (FocusedScene != nullptr) + FocusedSceneID = FocusedScene->GetObjectID(); + + Root["EditorScenes"]["FocusedSceneID"] = FocusedSceneID; + + // Saving resources. + SaveResourcesTo(ProjectFolder + "Resources.txt", bFullSave); + + // All of editor cameras would not be saved because of editor only tag. + // But we need to save their state. + Json::Value EditorCamerasData; + int Index = 0; + auto EditorCameraIterator = SceneIDToEditorCameraID.begin(); + while (EditorCameraIterator != SceneIDToEditorCameraID.end()) + { + FEScene* Scene = SCENE_MANAGER.GetScene(EditorCameraIterator->first); + if (Scene == nullptr) + { + EditorCameraIterator++; + continue; + } - exportDir = (PIMAGE_EXPORT_DIRECTORY)ImageDirectoryEntryToData( - hModule, TRUE, IMAGE_DIRECTORY_ENTRY_EXPORT, &size); + FEEntity* CameraEntity = Scene->GetEntity(EditorCameraIterator->second); + if (CameraEntity == nullptr) + { + EditorCameraIterator++; + continue; + } - if (exportDir == NULL) { - FreeLibrary(hModule); - return "Failed to get export directory."; + if (!CameraEntity->HasComponent()) + { + EditorCameraIterator++; + continue; + } + + EditorCamerasData[Index]["SceneID"] = EditorCameraIterator->first; + EditorCamerasData[Index]["EntityData"] = CameraEntity->ToJson(); + + Index++; + EditorCameraIterator++; } + Root["EditorCameras"] = EditorCamerasData; - DWORD* names = (DWORD*)((BYTE*)hModule + exportDir->AddressOfNames); - WORD* ordinals = (WORD*)((BYTE*)hModule + exportDir->AddressOfNameOrdinals); - DWORD* functions = (DWORD*)((BYTE*)hModule + exportDir->AddressOfFunctions); + // Saving into file. + Json::StreamWriterBuilder Builder; + const std::string JsonFile = Json::writeString(Builder, Root); - for (DWORD i = 0; i < exportDir->NumberOfNames; i++) { - char* name = (char*)((BYTE*)hModule + names[i]); - WORD ordinal = ordinals[i]; - DWORD rva = functions[ordinal]; + ProjectFile.open(ProjectFolder + "Project.txt"); + ProjectFile << JsonFile; + ProjectFile.close(); - result << "Function: " << name << ", Ordinal: " << ordinal << ", RVA: 0x" - << std::hex << rva << std::dec << "\n"; + for (size_t i = 0; i < FilesToDelete.size(); i++) + { + FILE_SYSTEM.DeleteFile(FilesToDelete[i].c_str()); } - FreeLibrary(hModule); - return result.str(); + VIRTUAL_FILE_SYSTEM.SaveState(ProjectFolder + "VFS.txt"); + bModified = false; } -void FEProject::LoadProject() +void FEProject::LoadResources(std::string FilePath) { - std::ifstream SceneFile; - SceneFile.open(ProjectFolder + "Scene.txt"); + std::ifstream ResourcesFile; + ResourcesFile.open(FilePath); - std::string FileData((std::istreambuf_iterator(SceneFile)), std::istreambuf_iterator()); - SceneFile.close(); + std::string FileData((std::istreambuf_iterator(ResourcesFile)), std::istreambuf_iterator()); + ResourcesFile.close(); Json::Value Root; JSONCPP_STRING Error; @@ -648,17 +408,12 @@ void FEProject::LoadProject() if (!Reader->parse(FileData.c_str(), FileData.c_str() + FileData.size(), &Root, &Error)) return; - // Read project file version. - float ProjectVersion = Root["version"].asFloat(); - - // Project file was created before any version was written to project files. - if (ProjectVersion != PROJECTS_FILE_VER) + // Read file version. + float FileVersion = Root["Version"].asFloat(); + if (FileVersion != PROJECT_RESOURCE_FILE_VERSION) { - if (ProjectVersion == 0.0f) - { - LOG.Add("Can't find version in scene file of project from " + ProjectFolder, "FE_LOG_LOADING", FE_LOG_WARNING); - return; - } + LOG.Add("FEProject::LoadResources: File version is not matching!", "FE_LOG_LOADING", FE_LOG_ERROR); + return; } // Loading meshes. @@ -690,7 +445,7 @@ void FEProject::LoadProject() for (size_t i = 0; i < MaterialsList.size(); i++) { FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Materials"][MaterialsList[i]]["FEObjectData"]); - + FEMaterial* NewMaterial = RESOURCE_MANAGER.CreateMaterial(LoadedObjectData.Name, LoadedObjectData.ID); RESOURCE_MANAGER.SetTag(NewMaterial, LoadedObjectData.Tag); NewMaterial->Shader = RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/); @@ -755,10 +510,10 @@ void FEProject::LoadProject() for (size_t i = 0; i < GameModelList.size(); i++) { FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["GameModels"][GameModelList[i]]["FEObjectData"]); - + FEGameModel* NewGameModel = RESOURCE_MANAGER.CreateGameModel(RESOURCE_MANAGER.GetMesh(Root["GameModels"][GameModelList[i]]["Mesh"].asCString()), - RESOURCE_MANAGER.GetMaterial(Root["GameModels"][GameModelList[i]]["Material"].asCString()), - LoadedObjectData.Name, LoadedObjectData.ID); + RESOURCE_MANAGER.GetMaterial(Root["GameModels"][GameModelList[i]]["Material"].asCString()), + LoadedObjectData.Name, LoadedObjectData.ID); RESOURCE_MANAGER.SetTag(NewGameModel, LoadedObjectData.Tag); NewGameModel->SetScaleFactor(Root["GameModels"][GameModelList[i]]["ScaleFactor"].asFloat()); @@ -784,129 +539,267 @@ void FEProject::LoadProject() } } - // Loading prefabs. - std::unordered_map PrefabToSceneMap; - std::vector PrefabList = Root["Prefabs"].getMemberNames(); - for (size_t i = 0; i < PrefabList.size(); i++) - { - FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Prefabs"][PrefabList[i]]["FEObjectData"]); - - FEPrefab* NewPrefab = RESOURCE_MANAGER.CreatePrefab(LoadedObjectData.Name, LoadedObjectData.ID); - RESOURCE_MANAGER.SetTag(NewPrefab, LoadedObjectData.Tag); - - // At this point we are just reading scene ID. - std::string SceneID = Root["Prefabs"][PrefabList[i]]["Scene"]["ID"].asCString(); - // So we need to store them in map and load them later. - PrefabToSceneMap[SceneID] = NewPrefab; - } - - // Loading all prefab scenes. + // Prefabs and Scenes are interconnected so we need to load them in two steps. + // Currently Prefabs can not contain other Prefabs or Scenes, if it will change we need to change this code. + // First load all prefab scenes. std::vector SceneList = Root["Scenes"].getMemberNames(); for (size_t i = 0; i < SceneList.size(); i++) { FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Scenes"][SceneList[i]]["FEObjectData"]); - bool bPrefabScene = PrefabToSceneMap.find(LoadedObjectData.ID) != PrefabToSceneMap.end(); - if (!bPrefabScene) + if (LoadedObjectData.Tag != PREFAB_SCENE_DESCRIPTION_TAG) continue; - FEScene* NewScene = SCENE_MANAGER.CreateScene(LoadedObjectData.Name, LoadedObjectData.ID, FESceneFlag::None); + FEScene* NewScene = SCENE_MANAGER.CreateScene(LoadedObjectData.Name, LoadedObjectData.ID, FESceneFlag::PrefabDescription); RESOURCE_MANAGER.SetTag(NewScene, LoadedObjectData.Tag); NewScene->SceneGraph.FromJson(Root["Scenes"][SceneList[i]]["Scene hierarchy"]); } - // Now we can connect prefabs with scenes. - for (auto& Pair : PrefabToSceneMap) + // Then load Prefabs and initialize them with corresponding scenes. + std::vector PrefabList = Root["Prefabs"].getMemberNames(); + for (size_t i = 0; i < PrefabList.size(); i++) { - Pair.second->SetScene(SCENE_MANAGER.GetScene(Pair.first)); + FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Prefabs"][PrefabList[i]]["FEObjectData"]); + + std::string SceneID; + if (Root["Prefabs"][PrefabList[i]].isMember("Scene")) + { + SceneID = Root["Prefabs"][PrefabList[i]]["Scene"]["ID"].asCString(); + } + else + { + SceneID = Root["Prefabs"][PrefabList[i]]["SceneID"].asCString(); + } + + FEScene* Scene = SCENE_MANAGER.GetScene(SceneID); + if (Scene == nullptr) + { + LOG.Add("FEProject::LoadResources: Prefab scene is missing!", "FE_LOG_LOADING", FE_LOG_ERROR); + continue; + } + + FEPrefab* NewPrefab = RESOURCE_MANAGER.CreatePrefab(LoadedObjectData.Name, LoadedObjectData.ID, Scene); + RESOURCE_MANAGER.SetTag(NewPrefab, LoadedObjectData.Tag); } - - // Only after all prefabs are connected with scenes we can load other scenes. - std::string MainSceneID = Root["Main scene"].asString(); + for (size_t i = 0; i < SceneList.size(); i++) { FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Scenes"][SceneList[i]]["FEObjectData"]); - bool bPrefabScene = PrefabToSceneMap.find(LoadedObjectData.ID) != PrefabToSceneMap.end(); - if (bPrefabScene) + if (LoadedObjectData.Tag == PREFAB_SCENE_DESCRIPTION_TAG) continue; - bool bShouldBeActive = LoadedObjectData.ID == MainSceneID; - FEScene* NewScene = SCENE_MANAGER.CreateScene(LoadedObjectData.Name, LoadedObjectData.ID, bShouldBeActive ? FESceneFlag::Active : FESceneFlag::None); + FEScene* NewScene = SCENE_MANAGER.CreateScene(LoadedObjectData.Name, LoadedObjectData.ID, FESceneFlag::Active); RESOURCE_MANAGER.SetTag(NewScene, LoadedObjectData.Tag); - + NewScene->SceneGraph.FromJson(Root["Scenes"][SceneList[i]]["Scene hierarchy"]); } +} + +void FEProject::LoadNativeScriptProjectData(Json::Value Root) +{ + if (Root.isMember("NativeScriptProject")) + { + NativeScriptProject = new FENativeScriptProject(this); + if (NativeScriptProject->Load(Root["NativeScriptProject"], ProjectFolder)) + { + // Check if VS Project is valid. + if (NativeScriptProject->IsVSProjectValid()) + { + NativeScriptProject->GenerateScriptModule(); + } + else + { + std::string VSProjectPath = ProjectFolder + "NativeScriptProject/"; + if (FILE_SYSTEM.DoesDirectoryExist(VSProjectPath)) + { + if (!FILE_SYSTEM.DeleteDirectory(VSProjectPath)) + { + LOG.Add("FEProject::LoadNativeScriptProjectData: Failed to delete old Visual Studio project!", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + } + + if (NativeScriptProject->RegenerateVSProject()) + { + NativeScriptProject->GenerateScriptModule(); + } + else + { + LOG.Add("FEProject::LoadNativeScriptProjectData: Failed to regenerate Visual Studio project!", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + } + } + } +} + +void FEProject::LoadProject() +{ + std::ifstream ProjectFile; + ProjectFile.open(ProjectFolder + "Project.txt"); - ProjectScene = SCENE_MANAGER.GetScene(MainSceneID); + std::string FileData((std::istreambuf_iterator(ProjectFile)), std::istreambuf_iterator()); + ProjectFile.close(); - // VFS - if (FILE_SYSTEM.DoesFileExist((ProjectFolder + "VFS.txt").c_str())) // _error + Json::Value Root; + JSONCPP_STRING Error; + Json::CharReaderBuilder Builder; + + const std::unique_ptr Reader(Builder.newCharReader()); + if (!Reader->parse(FileData.c_str(), FileData.c_str() + FileData.size(), &Root, &Error)) + return; + + // Check file version. + float FileVersion = Root["Version"].asFloat(); + if (FileVersion != PROJECTS_FILE_VER) { - VIRTUAL_FILE_SYSTEM.LoadState(ProjectFolder + "VFS.txt"); + LOG.Add("FEProject::LoadProject: File version is not matching!", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } - VIRTUAL_FILE_SYSTEM.SetDirectoryReadOnly(false, "/Shaders"); + ID = Root["ID"].asCString(); + Name = Root["Name"].asCString(); - auto Files = VIRTUAL_FILE_SYSTEM.GetDirectoryContent("/Shaders"); - for (size_t i = 0; i < Files.size(); i++) - { - VIRTUAL_FILE_SYSTEM.DeleteFile(Files[i], "/Shaders"); - } + LoadNativeScriptProjectData(Root); + LoadResources(ProjectFolder + "Resources.txt"); - std::vector ShaderList = RESOURCE_MANAGER.GetShadersList(); - for (size_t i = 0; i < ShaderList.size(); i++) - { - if (OBJECT_MANAGER.GetFEObject(ShaderList[i]) == nullptr) - continue; - VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(ShaderList[i]), "/Shaders"); - } + // After we loaded all resources we can load editor cameras. + Json::Value EditorCamerasData = Root["EditorCameras"]; + for (size_t i = 0; i < EditorCamerasData.size(); i++) + { + std::string SceneID = EditorCamerasData[static_cast(i)]["SceneID"].asCString(); + FEScene* Scene = SCENE_MANAGER.GetScene(SceneID); + if (Scene == nullptr) + continue; + + FEEntity* EditorCameraEntity = Scene->CreateEntityFromJson(EditorCamerasData[static_cast(i)]["EntityData"]); + SceneIDToEditorCameraID[SceneID] = EditorCameraEntity->GetObjectID(); + CAMERA_SYSTEM.SetMainCamera(EditorCameraEntity); + } - std::vector StandardShaderList = RESOURCE_MANAGER.GetEnginePrivateShadersList(); - for (size_t i = 0; i < StandardShaderList.size(); i++) + // Now we can restore editor scenes. + if (Root.isMember("EditorScenes")) + { + Json::Value OpenedScenes = Root["EditorScenes"]["Opened"]; + for (size_t i = 0; i < OpenedScenes.size(); i++) { - if (OBJECT_MANAGER.GetFEObject(StandardShaderList[i]) == nullptr) + FEScene* Scene = SCENE_MANAGER.GetScene(OpenedScenes[std::to_string(i)]["ID"].asCString()); + if (Scene == nullptr) continue; - VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(StandardShaderList[i]), "/Shaders"); + + bool bIsPrefabDescription = OpenedScenes[std::to_string(i)]["IsPrefabDescription"].asBool(); + if (bIsPrefabDescription) + { + FEPrefab* PrefabThatHaveThatScene = nullptr; + std::vector PrefabList = RESOURCE_MANAGER.GetPrefabIDList(); + for (size_t j = 0; j < PrefabList.size(); j++) + { + FEPrefab* Prefab = RESOURCE_MANAGER.GetPrefab(PrefabList[j]); + if (Prefab->GetScene() == Scene) + { + PrefabThatHaveThatScene = Prefab; + break; + } + } + + if (PrefabThatHaveThatScene != nullptr) + PREFAB_EDITOR_MANAGER.PrepareEditWinow(PrefabThatHaveThatScene); + } + else + { + Scene->SetFlag(FESceneFlag::Active, true); + Scene->SetFlag(FESceneFlag::Renderable, true); + Scene->SetFlag(FESceneFlag::EditorMode, true); + EDITOR.AddEditorScene(Scene); + } } - VIRTUAL_FILE_SYSTEM.SetDirectoryReadOnly(true, "/Shaders"); + std::string FocusedSceneID = Root["EditorScenes"]["FocusedSceneID"].asCString(); + FEScene* FocusedScene = SCENE_MANAGER.GetScene(FocusedSceneID); + if (FocusedScene != nullptr) + EDITOR.SetFocusedScene(FocusedScene); } - else + + if (!LoadVFSData(ProjectFolder + "VFS.txt")) { LOG.Add("Can't find VIRTUAL_FILE_SYSTEM file in project folder. Creating basic VIRTUAL_FILE_SYSTEM layout.", "FE_LOG_LOADING", FE_LOG_WARNING); - VIRTUAL_FILE_SYSTEM.CreateDirectory("Shaders", "/"); + GenerateVFSData(); + } +} - std::vector ShaderList = RESOURCE_MANAGER.GetShadersList(); - for (size_t i = 0; i < ShaderList.size(); i++) - { - if (OBJECT_MANAGER.GetFEObject(ShaderList[i]) == nullptr) - continue; - VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(ShaderList[i]), "/Shaders"); - } +bool FEProject::LoadVFSData(std::string FilePath) +{ + if (!FILE_SYSTEM.DoesFileExist(FilePath)) + { + LOG.Add("FEProject::LoadVFSData: File " + FilePath + " does not exist!", "FE_LOG_LOADING", FE_LOG_WARNING); + return false; + } - std::vector StandardShaderList = RESOURCE_MANAGER.GetEnginePrivateShadersList(); - for (size_t i = 0; i < StandardShaderList.size(); i++) - { - if (OBJECT_MANAGER.GetFEObject(StandardShaderList[i]) == nullptr) - continue; - VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(StandardShaderList[i]), "/Shaders"); - } + VIRTUAL_FILE_SYSTEM.LoadState(FilePath); + VIRTUAL_FILE_SYSTEM.SetDirectoryReadOnly(false, "/Shaders"); - std::vector OtherResourceList = RESOURCE_MANAGER.GetMeshList(); - std::vector TextureList = RESOURCE_MANAGER.GetTextureList(); - OtherResourceList.insert(OtherResourceList.end(), TextureList.begin(), TextureList.end()); - std::vector MaterialList = RESOURCE_MANAGER.GetMaterialList(); - OtherResourceList.insert(OtherResourceList.end(), MaterialList.begin(), MaterialList.end()); - std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); - OtherResourceList.insert(OtherResourceList.end(), GameModelList.begin(), GameModelList.end()); + auto Files = VIRTUAL_FILE_SYSTEM.GetDirectoryContent("/Shaders"); + for (size_t i = 0; i < Files.size(); i++) + { + VIRTUAL_FILE_SYSTEM.DeleteFile(Files[i], "/Shaders"); + } - for (size_t i = 0; i < OtherResourceList.size(); i++) - { - if (OBJECT_MANAGER.GetFEObject(OtherResourceList[i])->GetTag() == ENGINE_RESOURCE_TAG || - OBJECT_MANAGER.GetFEObject(OtherResourceList[i])->GetTag() == EDITOR_RESOURCE_TAG) - continue; + std::vector ShaderList = RESOURCE_MANAGER.GetShadersList(); + for (size_t i = 0; i < ShaderList.size(); i++) + { + if (OBJECT_MANAGER.GetFEObject(ShaderList[i]) == nullptr) + continue; + VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(ShaderList[i]), "/Shaders"); + } - VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(OtherResourceList[i]), "/"); - } + std::vector StandardShaderList = RESOURCE_MANAGER.GetEnginePrivateShadersList(); + for (size_t i = 0; i < StandardShaderList.size(); i++) + { + if (OBJECT_MANAGER.GetFEObject(StandardShaderList[i]) == nullptr) + continue; + VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(StandardShaderList[i]), "/Shaders"); + } + + VIRTUAL_FILE_SYSTEM.SetDirectoryReadOnly(true, "/Shaders"); + + return true; +} + +void FEProject::GenerateVFSData() +{ + VIRTUAL_FILE_SYSTEM.CreateDirectory("Shaders", "/"); + + std::vector ShaderList = RESOURCE_MANAGER.GetShadersList(); + for (size_t i = 0; i < ShaderList.size(); i++) + { + if (OBJECT_MANAGER.GetFEObject(ShaderList[i]) == nullptr) + continue; + VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(ShaderList[i]), "/Shaders"); + } + + std::vector StandardShaderList = RESOURCE_MANAGER.GetEnginePrivateShadersList(); + for (size_t i = 0; i < StandardShaderList.size(); i++) + { + if (OBJECT_MANAGER.GetFEObject(StandardShaderList[i]) == nullptr) + continue; + VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(StandardShaderList[i]), "/Shaders"); + } + + std::vector OtherResourceList = RESOURCE_MANAGER.GetMeshList(); + std::vector TextureList = RESOURCE_MANAGER.GetTextureList(); + OtherResourceList.insert(OtherResourceList.end(), TextureList.begin(), TextureList.end()); + std::vector MaterialList = RESOURCE_MANAGER.GetMaterialList(); + OtherResourceList.insert(OtherResourceList.end(), MaterialList.begin(), MaterialList.end()); + std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); + OtherResourceList.insert(OtherResourceList.end(), GameModelList.begin(), GameModelList.end()); + + for (size_t i = 0; i < OtherResourceList.size(); i++) + { + if (OBJECT_MANAGER.GetFEObject(OtherResourceList[i])->GetTag() == ENGINE_RESOURCE_TAG || + OBJECT_MANAGER.GetFEObject(OtherResourceList[i])->GetTag() == EDITOR_RESOURCE_TAG) + continue; + + VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(OtherResourceList[i]), "/"); } } @@ -928,7 +821,7 @@ void FEProject::CreateDummyScreenshot() } FETexture* TempTexture = RESOURCE_MANAGER.RawDataToFETexture(Pixels, static_cast(Width), static_cast(Height)); - RESOURCE_MANAGER.SaveFETexture(TempTexture, (GetProjectFolder() + "/projectScreenShot.texture").c_str()); + RESOURCE_MANAGER.SaveFETexture(TempTexture, (GetProjectFolder() + "/Thumbnail.texture").c_str()); RESOURCE_MANAGER.DeleteFETexture(TempTexture); delete[] Pixels; } @@ -956,33 +849,53 @@ void FEProject::AddUnSavedObject(FEObject* Object) void FEProject::SetProjectFolder(const std::string NewValue) { if (!FILE_SYSTEM.DoesDirectoryExist(NewValue.c_str())) + { + LOG.Add("FEProject::SetProjectFolder: Directory " + NewValue + " does not exist!", "FE_LOG_LOADING", FE_LOG_WARNING); return; + } ProjectFolder = NewValue; } -void FEProject::SaveSceneTo(const std::string NewPath) +void FEProject::SaveProjectTo(const std::string NewPath) { if (!FILE_SYSTEM.DoesDirectoryExist(NewPath.c_str())) + { + LOG.Add("FEProject::SaveProjectTo: Directory " + NewPath + " does not exist!", "FE_LOG_SAVING", FE_LOG_WARNING); return; + } SetProjectFolder(NewPath); - ENGINE.SaveScreenshot((GetProjectFolder() + "projectScreenShot.texture").c_str(), GetScene()); SaveProject(true); } -FEScene* FEProject::GetScene() +void FEProject::InjectEditorCamera(FEScene* Scene) { - return ProjectScene; -} + if (Scene == nullptr) + { + LOG.Add("FEProject::InjectEditorCamera: Scene is nullptr!", "FE_LOG_LOADING", FE_LOG_WARNING); + return; + } + + if (SceneIDToEditorCameraID.find(Scene->GetObjectID()) != SceneIDToEditorCameraID.end()) + { + FEEntity* CameraEntity = Scene->GetEntity(SceneIDToEditorCameraID[Scene->GetObjectID()]); + if (CameraEntity != nullptr) + { + LOG.Add("FEProject::InjectEditorCamera: Editor camera already exists in scene " + Scene->GetName(), "FE_LOG_LOADING", FE_LOG_WARNING); + return; + } + else + { + SceneIDToEditorCameraID.erase(Scene->GetObjectID()); + } + } -void FEProjectManager::InjectEditorCamera(FEScene* Scene) -{ FEEntity* CameraEntity = nullptr; std::vector CameraPrefab = RESOURCE_MANAGER.GetPrefabByName("Free camera prefab"); if (CameraPrefab.size() == 0) { - LOG.Add("FEProjectManager::InjectEditorCamera: Camera prefab not found! Inserting camera manually.", "FE_LOG_LOADING", FE_LOG_WARNING); + LOG.Add("FEProject::InjectEditorCamera: Camera prefab not found! Inserting camera manually.", "FE_LOG_LOADING", FE_LOG_WARNING); CameraEntity = Scene->CreateEntity("Camera"); CameraEntity->AddComponent(); @@ -993,7 +906,7 @@ void FEProjectManager::InjectEditorCamera(FEScene* Scene) std::vector AddedEntities = SCENE_MANAGER.InstantiatePrefab(CameraPrefabToUse, Scene, true); if (AddedEntities.empty()) { - LOG.Add("FEProjectManager::InjectEditorCamera: Camera prefab was not instantiated correctly. Inserting camera manually.", "FE_LOG_LOADING", FE_LOG_WARNING); + LOG.Add("FEProject::InjectEditorCamera: Camera prefab was not instantiated correctly. Inserting camera manually.", "FE_LOG_LOADING", FE_LOG_WARNING); CameraEntity = Scene->CreateEntity("Camera"); CameraEntity->AddComponent(); @@ -1005,7 +918,7 @@ void FEProjectManager::InjectEditorCamera(FEScene* Scene) if (CameraEntity == nullptr) { - LOG.Add("FEProjectManager::InjectEditorCamera: Camera prefab was not instantiated correctly. Inserting camera manually.", "FE_LOG_LOADING", FE_LOG_WARNING); + LOG.Add("FEProject::InjectEditorCamera: Camera prefab was not instantiated correctly. Inserting camera manually.", "FE_LOG_LOADING", FE_LOG_WARNING); CameraEntity = Scene->CreateEntity("Camera"); CameraEntity->AddComponent(); @@ -1019,4 +932,6 @@ void FEProjectManager::InjectEditorCamera(FEScene* Scene) CAMERA_SYSTEM.SetMainCamera(CameraEntity); FETransformComponent& CameraTransform = CameraEntity->GetComponent(); CameraTransform.SetPosition(glm::vec3(-4.2269f, 15.7178f, 19.6429f)); + + SceneIDToEditorCameraID[Scene->GetObjectID()] = CameraEntity->GetObjectID(); } \ No newline at end of file diff --git a/SubSystems/ProjectManagment/FEProject.h b/SubSystems/ProjectManagment/FEProject.h new file mode 100644 index 0000000..416e244 --- /dev/null +++ b/SubSystems/ProjectManagment/FEProject.h @@ -0,0 +1,62 @@ +#pragma once + +#include "../../FEEditorDragAndDropManager.h" +#include "../../FEEditorVirtualFileSystem.h" + +#include "FENativeScriptProject.h" + +class FEProject +{ + friend class FEProjectManager; + friend class FEEditor; + friend class FEEditorScriptingSystem; +public: + FEProject(std::string Name, std::string ProjectFolder); + ~FEProject(); + + std::string GetName(); + void SetName(std::string NewValue); + + std::string GetProjectFolder(); + + void LoadProject(); + void SaveProject(bool bFullSave = false); + void SaveProjectTo(std::string NewPath); + + FETexture* SceneScreenshot; + void CreateDummyScreenshot(); + + void AddFileToDeleteList(std::string FileName); + + bool IsModified(); + void SetModified(bool NewValue); + + void AddUnSavedObject(FEObject* Object); +private: + std::string ID; + std::string Name; + std::string ProjectFolder; + + bool bModified = false; + std::vector UnSavedObjects; + + std::vector FilesToDelete; + + void SetProjectFolder(std::string NewValue); + + std::unordered_map SceneIDToEditorCameraID; + void InjectEditorCamera(FEScene* Scene); + + void LoadResources(std::string FilePath); + void SaveResourcesTo(std::string FilePath, bool bFullSave = false); + + void LoadNativeScriptProjectData(Json::Value Root); + + FENativeScriptProject* NativeScriptProject = nullptr; + + bool LoadVFSData(std::string FilePath); + void GenerateVFSData(); +}; + +#define PROJECTS_FILE_VER 0.05f +#define PROJECT_RESOURCE_FILE_VERSION 0.01f \ No newline at end of file diff --git a/SubSystems/ProjectManagment/FEProjectManager.cpp b/SubSystems/ProjectManagment/FEProjectManager.cpp new file mode 100644 index 0000000..9d471d3 --- /dev/null +++ b/SubSystems/ProjectManagment/FEProjectManager.cpp @@ -0,0 +1,325 @@ +#include "FEProjectManager.h" +#include "../../FEEditor.h" + +FEProjectManager::FEProjectManager() {} +FEProjectManager::~FEProjectManager() {} + +void FEProjectManager::InitializeResources() +{ + IndexChosen = -1; + LoadProjectList(); +} + +FEProject* FEProjectManager::GetCurrent() +{ + return Current; +} + +void FEProjectManager::SetCurrent(FEProject* Project) +{ + Current = Project; +} + +std::vector FEProjectManager::GetList() +{ + return List; +} + +void FEProjectManager::LoadProjectList() +{ + if (!FILE_SYSTEM.DoesDirectoryExist(PROJECTS_FOLDER)) + CustomProjectFolder = ""; + + const std::vector ProjectNameList = FILE_SYSTEM.GetDirectoryList(PROJECTS_FOLDER); + + for (size_t i = 0; i < ProjectNameList.size(); i++) + { + if (ContainProject(std::string(PROJECTS_FOLDER) + std::string("/") + ProjectNameList[i])) + List.push_back(new FEProject(ProjectNameList[i].c_str(), std::string(PROJECTS_FOLDER) + std::string("/") + ProjectNameList[i].c_str() + "/")); + } +} + +void FEProjectManager::CloseCurrentProject() +{ + // Closing all windows or popups. + WindowsManager::GetInstance().CloseAllWindows(); + WindowsManager::GetInstance().CloseAllPopups(); + + SELECTED.ClearAll(); + PREVIEW_MANAGER.Clear(); + for (size_t i = 0; i < List.size(); i++) + { + delete List[i]; + } + List.clear(); + PROJECT_MANAGER.SetCurrent(nullptr); + LoadProjectList(); + + VIRTUAL_FILE_SYSTEM.SetCurrentPath("/"); +} + +void FEProjectManager::OpenProject(const int ProjectIndex) +{ + if (ProjectIndex < 0 || ProjectIndex >= static_cast(List.size())) + { + LOG.Add("FEProjectManager::OpenProject: Project index is out of range!", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + + PROJECT_MANAGER.SetCurrent(List[ProjectIndex]); + PROJECT_MANAGER.GetCurrent()->LoadProject(); + IndexChosen = -1; + + // After loading project we should update our previews + PREVIEW_MANAGER.UpdateAll(); + SELECTED.ClearAll(); +} + +void FEProjectManager::DisplayProjectSelection() +{ + static float LowerPanelHight = 90.0f; + const float MainWindowW = static_cast(APPLICATION.GetMainWindow()->GetWidth()); + const float MainWindowH = static_cast(APPLICATION.GetMainWindow()->GetHeight()); + + ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 1.0f); + ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f)); + ImGui::SetNextWindowSize(ImVec2(MainWindowW, MainWindowH - LowerPanelHight)); + ImGui::Begin("Project Browser", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse); + { + ImGui::SetWindowFontScale(2.0f); + ImGui::Text("CHOOSE WHAT PROJECT TO LOAD :"); + ImGui::SetWindowFontScale(1.0f); + + ImGui::PushStyleColor(ImGuiCol_Button, static_cast(ImColor(0.5f, 0.5f, 0.5f))); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, static_cast(ImColor::ImColor(0.95f, 0.90f, 0.0f))); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, static_cast(ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f))); + + const int ColumnCount = static_cast(MainWindowW / (512.0f + 32.0f)); + ImGui::Columns(ColumnCount, "projectColumns", false); + static bool bPushedStyle = false; + for (size_t i = 0; i < List.size(); i++) + { + ImGui::PushID(static_cast(i)); + bPushedStyle = false; + if (IndexChosen == i) + { + bPushedStyle = true; + ImGui::PushStyleColor(ImGuiCol_Button, static_cast(ImColor(0.1f, 1.0f, 0.1f, 1.0f))); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, static_cast(ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f))); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, static_cast(ImColor::ImColor(0.1f, 1.0f, 0.1f, 1.0f))); + } + + if (ImGui::IsMouseDoubleClicked(0)) + { + if (IndexChosen != -1) + { + OpenProject(IndexChosen); + } + } + + if (ImGui::ImageButton((void*)static_cast(List[i]->SceneScreenshot->GetTextureID()), ImVec2(512.0f, 288.0f), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) + { + IndexChosen = static_cast(i); + } + + ImGui::Text(List[i]->GetName().c_str()); + + if (bPushedStyle) + { + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + } + + ImGui::PopID(); + ImGui::NextColumn(); + } + + ImGui::Columns(1); + + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + } + ImGui::End(); + ImGui::PopStyleVar(); + + ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 1.0f); + ImGui::SetNextWindowPos(ImVec2(0.0f, MainWindowH - LowerPanelHight)); + ImGui::SetNextWindowSize(ImVec2(MainWindowW, LowerPanelHight)); + ImGui::Begin("##create project", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar); + { + ImGui::PushStyleColor(ImGuiCol_Button, static_cast(ImColor(0.0f, 162.0f / 255.0f, 232.0f / 255.0f, 1.0f))); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, static_cast(ImColor::ImColor(23.0f / 255.0f, 186.0f / 255.0f, 1.0f, 1.0f))); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, static_cast(ImColor::ImColor(0.0f, 125.0f / 255.0f, 179.0f / 255.0f, 1.0f))); + + if (ImGui::Button("Create New Project", ImVec2(200.0f, 64.0f))) + ImGui::OpenPopup("New Project"); + + ImGui::SameLine(); + if (ImGui::Button("Open Project", ImVec2(200.0f, 64.0f)) && IndexChosen != -1) + { + OpenProject(IndexChosen); + } + + ImGui::SameLine(); + if (ImGui::Button("Delete Project", ImVec2(200.0f, 64.0f)) && IndexChosen != -1 && IndexChosen < static_cast(List.size())) + { + std::string ProjectFolder = List[IndexChosen]->GetProjectFolder(); + ProjectFolder.erase(ProjectFolder.begin() + ProjectFolder.size() - 1); + + // Getting list of all files in project folder. + const auto FileList = FILE_SYSTEM.GetFileList(List[IndexChosen]->GetProjectFolder().c_str()); + // We would delete all files in project folder, editor would not create folders there + // so we are deleting only files. + for (size_t i = 0; i < FileList.size(); i++) + { + FILE_SYSTEM.DeleteFile((List[IndexChosen]->GetProjectFolder() + FileList[i]).c_str()); + } + // Then we can try to delete project folder, but if user created some folders in it we will fail. + FILE_SYSTEM.DeleteDirectory(ProjectFolder.c_str()); + + for (size_t i = 0; i < List.size(); i++) + { + delete List[i]; + } + List.clear(); + PROJECT_MANAGER.SetCurrent(nullptr); + + LoadProjectList(); + } + + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PushStyleColor(ImGuiCol_Button, static_cast(ImColor(0.0f, 242.0f / 255.0f, 79.0f / 255.0f, 1.0f))); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, static_cast(ImColor::ImColor(34.0f / 255.0f, 1.0f, 106.0f / 255.0f, 1.0f))); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, static_cast(ImColor::ImColor(0.0f, 202.0f / 255.0f, 66.0f / 255.0f, 1.0f))); + + ImGui::SameLine(); + ImGui::SetCursorPos(ImVec2(ImGui::GetContentRegionAvail().x + 280.0f + 64.0f, ImGui::GetCursorPos().y)); + if (ImGui::Button("Choose projects directory", ImVec2(280.0f, 64.0f))) + { + std::string Path; + FILE_SYSTEM.ShowFolderOpenDialog(Path); + SetProjectsFolder(Path); + } + + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); + if (ImGui::BeginPopupModal("New Project", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) + { + ImGui::SetWindowPos(ImVec2(APPLICATION.GetMainWindow()->GetWidth() / 2.0f - ImGui::GetWindowWidth() / 2.0f, APPLICATION.GetMainWindow()->GetHeight() / 2.0f - ImGui::GetWindowHeight() / 2.0f)); + ImGui::Text("Insert name of new project :"); + static char ProjectName[512] = ""; + + ImGui::InputText("##newProjectName", ProjectName, IM_ARRAYSIZE(ProjectName)); + + ImGui::SetCursorPosX(ImGui::GetWindowWidth() / 4.0f - 120.0f / 2.0f); + ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10.0f); + if (ImGui::Button("Create", ImVec2(120, 0))) + { + bool bAlreadyCreated = false; + for (size_t i = 0; i < List.size(); i++) + { + if (List[i]->GetName() == std::string(ProjectName)) + { + bAlreadyCreated = true; + break; + } + } + + if (strlen(ProjectName) != 0 && !bAlreadyCreated) + { + FILE_SYSTEM.CreateDirectory((std::string(PROJECTS_FOLDER) + std::string("/") + ProjectName + "/").c_str()); + List.push_back(new FEProject(ProjectName, std::string(PROJECTS_FOLDER) + std::string("/") + ProjectName + "/")); + List.back()->CreateDummyScreenshot(); + + CreateNewProject(ProjectName, std::string(PROJECTS_FOLDER) + std::string("/") + ProjectName + "/"); + + ImGui::CloseCurrentPopup(); + strcpy_s(ProjectName, ""); + } + } + + ImGui::SetItemDefaultFocus(); + ImGui::SameLine(); + ImGui::SetCursorPosX(ImGui::GetWindowWidth() / 2.0f + ImGui::GetWindowWidth() / 4.0f - 120.0f / 2.0f); + if (ImGui::Button("Cancel", ImVec2(120, 0))) + { + ImGui::CloseCurrentPopup(); + } + + ImGui::EndPopup(); + } + } + + ImGui::PopStyleVar(); + ImGui::End(); + ImGui::PopStyleVar(); +} + +void FEProjectManager::CreateNewProject(std::string ProjectName, std::string ProjectPath) +{ + if (ProjectName.empty() || ProjectPath.empty()) + { + LOG.Add("FEProjectManager::CreateNewProject: Project name or path is empty!", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + + if (ContainProject(ProjectPath)) + { + LOG.Add("FEProjectManager::CreateNewProject: Project already exists!", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + + FEProject* NewProject = new FEProject(ProjectName, ProjectPath); + FEScene* NewScene = SCENE_MANAGER.CreateScene(ProjectName + "_main_scene", "", FESceneFlag::Active); + + FEEntity* SunEntity = NewScene->CreateEntity("Sun"); + SunEntity->AddComponent(FE_DIRECTIONAL_LIGHT); + FELightComponent& LightComponent = SunEntity->GetComponent(); + SunEntity->GetComponent().SetRotation(glm::vec3(-40.0f, 10.0f, 0.0f)); + LightComponent.SetIntensity(4.0f); + LightComponent.SetCastShadows(true); + + FEEntity* SkyDome = NewScene->CreateEntity("SkyDome"); + SkyDome->GetComponent().SetScale(glm::vec3(150.0f)); + SkyDome->AddComponent(); + + EDITOR.AddEditorScene(NewScene); + NewProject->InjectEditorCamera(NewScene); + NewProject->GenerateVFSData(); + NewProject->SaveProject(true); + + CloseCurrentProject(); + delete NewProject; +} + +bool FEProjectManager::ContainProject(const std::string Path) +{ + if (!FILE_SYSTEM.DoesDirectoryExist(Path.c_str())) + return false; + + if (!FILE_SYSTEM.DoesFileExist((Path + "/Project.txt").c_str())) + return false; + + return true; +} + +void FEProjectManager::SetProjectsFolder(const std::string FolderPath) +{ + if (FolderPath != "") + { + CustomProjectFolder = FolderPath; + for (size_t i = 0; i < List.size(); i++) + { + delete List[i]; + } + List.clear(); + LoadProjectList(); + } +} \ No newline at end of file diff --git a/SubSystems/ProjectManagment/FEProjectManager.h b/SubSystems/ProjectManagment/FEProjectManager.h new file mode 100644 index 0000000..7549fb7 --- /dev/null +++ b/SubSystems/ProjectManagment/FEProjectManager.h @@ -0,0 +1,41 @@ +#pragma once + +#include "../../FEEditorDragAndDropManager.h" +#include "../../FEDearImguiWrapper/FEDearImguiWrapper.h" +#include "../../FEEditorGizmoManager.h" +#include "../../FEEditorPreviewManager.h" +#include "../../FEEditorVirtualFileSystem.h" + +#include "FEProject.h" + +class FEProjectManager +{ + std::vector List; + int IndexChosen = -1; + FEProject* Current = nullptr; + std::string CustomProjectFolder = "../FocalEngineProjects-master"; + + void CreateNewProject(std::string ProjectName, std::string ProjectPath); +public: + SINGLETON_PUBLIC_PART(FEProjectManager) + SINGLETON_PRIVATE_PART(FEProjectManager) + + void InitializeResources(); + + FEProject* GetCurrent(); + void SetCurrent(FEProject* Project); + + std::vector GetList(); + + void OpenProject(int ProjectIndex); + void LoadProjectList(); + void CloseCurrentProject(); + + void DisplayProjectSelection(); + + bool ContainProject(std::string Path); + void SetProjectsFolder(std::string FolderPath); +}; + +#define PROJECTS_FOLDER PROJECT_MANAGER.CustomProjectFolder.c_str() +#define PROJECT_MANAGER FEProjectManager::GetInstance() \ No newline at end of file diff --git a/UserScripts/NativeScriptProjectData/BuildManagement/DebugBuildActions.cmake b/UserScripts/NativeScriptProjectData/BuildManagement/DebugBuildActions.cmake new file mode 100644 index 0000000..4fe4bea --- /dev/null +++ b/UserScripts/NativeScriptProjectData/BuildManagement/DebugBuildActions.cmake @@ -0,0 +1,22 @@ +if(EXISTS "${CMAKE_BINARY_DIR}/BuildManagement/Build_Recursion_Guard.txt") + file(REMOVE "${CMAKE_BINARY_DIR}/BuildManagement/Build_Recursion_Guard.txt") +else() + if(EXISTS "${CMAKE_BINARY_DIR}/BuildManagement/Force_Build_Finished.txt") + file(REMOVE "${CMAKE_BINARY_DIR}/BuildManagement/Force_Build_Finished.txt") + endif() + + file(TOUCH "${CMAKE_BINARY_DIR}/BuildManagement/Build_Recursion_Guard.txt") + + execute_process( + COMMAND ${CMAKE_COMMAND} --build "${CMAKE_BINARY_DIR}" --target PLACE_HOLDER --config Release + RESULT_VARIABLE BuildResult + OUTPUT_VARIABLE BuildOutput + ) + + if(BuildResult) + message("Release Build failed with error ${BuildResult}: ${BuildOutput}") + else() + message("Release Build succeeded: ${BuildOutput}") + file(TOUCH "${CMAKE_BINARY_DIR}/BuildManagement/Force_Build_Finished.txt") + endif() +endif() \ No newline at end of file diff --git a/UserScripts/NativeScriptProjectData/BuildManagement/EnsureBuildCompletion.cmake b/UserScripts/NativeScriptProjectData/BuildManagement/EnsureBuildCompletion.cmake new file mode 100644 index 0000000..75e1d6e --- /dev/null +++ b/UserScripts/NativeScriptProjectData/BuildManagement/EnsureBuildCompletion.cmake @@ -0,0 +1,9 @@ +if(EXISTS "${CMAKE_BINARY_DIR}/BuildManagement/Debug_Build_Flag.txt") + file(REMOVE "${CMAKE_BINARY_DIR}/BuildManagement/Debug_Build_Flag.txt") + message("Debug build was conducted, forcing release build.") + include("${CMAKE_CURRENT_LIST_DIR}/DebugBuildActions.cmake") +elseif(EXISTS "${CMAKE_BINARY_DIR}/BuildManagement/Release_Build_Flag.txt") + file(REMOVE "${CMAKE_BINARY_DIR}/BuildManagement/Release_Build_Flag.txt") + message("Release build was conducted, forcing debug build.") + include("${CMAKE_CURRENT_LIST_DIR}/ReleaseBuildActions.cmake") +endif() \ No newline at end of file diff --git a/UserScripts/NativeScriptProjectData/BuildManagement/ReleaseBuildActions.cmake b/UserScripts/NativeScriptProjectData/BuildManagement/ReleaseBuildActions.cmake new file mode 100644 index 0000000..5335fd6 --- /dev/null +++ b/UserScripts/NativeScriptProjectData/BuildManagement/ReleaseBuildActions.cmake @@ -0,0 +1,22 @@ +if(EXISTS "${CMAKE_BINARY_DIR}/BuildManagement/Build_Recursion_Guard.txt") + file(REMOVE "${CMAKE_BINARY_DIR}/BuildManagement/Build_Recursion_Guard.txt") +else() + if(EXISTS "${CMAKE_BINARY_DIR}/BuildManagement/Force_Build_Finished.txt") + file(REMOVE "${CMAKE_BINARY_DIR}/BuildManagement/Force_Build_Finished.txt") + endif() + + file(TOUCH "${CMAKE_BINARY_DIR}/BuildManagement/Build_Recursion_Guard.txt") + + execute_process( + COMMAND ${CMAKE_COMMAND} --build "${CMAKE_BINARY_DIR}" --target PLACE_HOLDER --config Debug + RESULT_VARIABLE BuildResult + OUTPUT_VARIABLE BuildOutput + ) + + if(BuildResult) + message("Debug Build failed with error ${BuildResult}: ${BuildOutput}") + else() + message("Debug Build succeeded: ${BuildOutput}") + file(TOUCH "${CMAKE_BINARY_DIR}/BuildManagement/Force_Build_Finished.txt") + endif() +endif() \ No newline at end of file diff --git a/UserScripts/NativeScriptProjectData/CMakeLists.txt b/UserScripts/NativeScriptProjectData/CMakeLists.txt new file mode 100644 index 0000000..38834f8 --- /dev/null +++ b/UserScripts/NativeScriptProjectData/CMakeLists.txt @@ -0,0 +1,83 @@ +cmake_minimum_required(VERSION 3.10) + +set(BUILD_TYPE "Debug and Release" CACHE STRING "Choose Build type") +set(CMAKE_BUILD_TYPE Debug) +set(CMAKE_CONFIGURATION_TYPES Debug Release) + +add_definitions(-DUNICODE) +add_definitions(-D_UNICODE) + +set(PROJECT_NAME PLACE_HOLDER) + +project(${PROJECT_NAME}) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Set compiler flags based on USE_STATIC_RUNTIME +if(MSVC) + # Disable C4251 warning + add_compile_options(/wd4251) + + if(USE_STATIC_RUNTIME) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") + else() + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD") + endif() + + # Always add /MP for multi-processor compilation + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") +endif() + +# Turn on the ability to create folders to organize projects (.vcproj) +# It creates "CMakePredefinedTargets" folder by default and adds CMake +# defined projects like INSTALL.vcproj and ZERO_CHECK.vcproj +set_property(GLOBAL PROPERTY USE_FOLDERS ON) + +file(GLOB Connection_To_Engine_SRC + "SubSystems/FocalEngine/FENativeScriptConnector.cpp" + "SubSystems/FocalEngine/FENativeScriptConnector.h" +) + +file(GLOB Main_SRC PLACE_HOLDER) + +link_directories(${GLEW_LIB_DIR}) +link_directories(${GLFW_LIB_DIR}) + +add_library(${PROJECT_NAME} + SHARED + ${Main_SRC} + ${Connection_To_Engine_SRC} +) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + FEBasicApplication.lib + FocalEngine.lib +) + +# FocalEngine is headers-only, we need to add its include directories +target_include_directories(${PROJECT_NAME} PRIVATE ${FOCAL_ENGINE_INCLUDES}) +target_compile_definitions(${PROJECT_NAME} PRIVATE FOCAL_ENGINE_HEADERS_ONLY) + +source_group("Source Files/" FILES ${Main_SRC}) +source_group("Source Files/Engine/" FILES ${Connection_To_Engine_SRC}) + +# set the startup project +set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME}) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication + ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/SubSystems + ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty + ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/glew2/include + ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine + ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/ThirdParty + ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/ThirdParty/entt +) + +add_custom_command( TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "Build type: $" > $,${CMAKE_CURRENT_BINARY_DIR}/BuildManagement/Debug_Build_Flag.txt,${CMAKE_CURRENT_BINARY_DIR}/BuildManagement/Release_Build_Flag.txt> + COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_LIST_DIR}/BuildManagement/EnsureBuildCompletion.cmake" +) \ No newline at end of file diff --git a/main.cpp b/main.cpp index a207b58..7d48a72 100644 --- a/main.cpp +++ b/main.cpp @@ -57,6 +57,23 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine bPutThisFrameToTimeline = true; } + if (PROJECT_MANAGER.GetCurrent() != nullptr) + { + bool bIsVSProjectPresent = EDITOR_SCRIPTING_SYSTEM.IsCurrentProjectHaveVSProjectInitialized(); + std::string Text = "Is VS project present: "; + Text += bIsVSProjectPresent ? "true" : "false"; + ImGui::Text(Text.c_str()); + + if (!bIsVSProjectPresent) + { + if (ImGui::Button("Initialize VS Project")) + { + EDITOR_SCRIPTING_SYSTEM.GenerateNewNativeScriptProject("FirstScript"); + } + } + } + + //ImGui::ShowDemoWindow(); EDITOR.Render(); ENGINE.EndFrame(); From d5fbebc14d39ffa8c4320d54b7f265e241a5258a Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Sun, 13 Oct 2024 21:33:55 -0400 Subject: [PATCH 35/46] Engine update; Moved FENativeScriptProject to the engine, as its functionality is required for proper static linking integration of native scripts; FENativeScriptModules will now be saved as resources along with the project; On project load, any missing VIRTUAL_FILE_SYSTEM resources will be added, including private engine resources; Content browser now has an option to display private engine resources; Added scene, asset package, and native script module as resource types in the content browser; Included numerous icons for use in the content browser; Fixed logging in VFS, which now supports the new resource types; Added several helpful functions to VFS; Removed temporary script testing code from main.cpp. --- CMakeLists.txt | 2 - EditorWindows/ContentBrowserWindow.cpp | 512 +++++++- EditorWindows/ContentBrowserWindow.h | 17 +- EditorWindows/InspectorWindow.cpp | 41 +- FEEditorScriptingSystem.cpp | 73 +- FEEditorScriptingSystem.h | 2 - FEEditorVirtualFileSystem.cpp | 65 +- FEEditorVirtualFileSystem.h | 7 +- ...AssetPackage_ContentBrowser_32_32_Icon.png | Bin 0 -> 885 bytes .../AssetPackage_ContentBrowser_Icon.png | Bin 0 -> 7526 bytes ...ScriptModule_ContentBrowser_32_32_Icon.png | Bin 0 -> 1111 bytes ...NativeScriptModule_ContentBrowser_Icon.png | Bin 0 -> 12233 bytes .../Images/Scene_ContentBrowser_Icon.png | Bin 0 -> 908 bytes .../Shader_ContentBrowser_32_32_Icon.png | Bin 0 -> 646 bytes Resources/Images/originals/House.png | Bin 0 -> 12961 bytes Resources/Images/originals/Scene.png | Bin 0 -> 7526 bytes Resources/Images/originals/box-open.png | Bin 0 -> 9307 bytes Resources/Images/originals/box-open_2.png | Bin 0 -> 8829 bytes Resources/Images/originals/box-open_c++.png | Bin 0 -> 11975 bytes Resources/Images/originals/c-.png | Bin 0 -> 11252 bytes Resources/Images/originals/script.png | Bin 0 -> 12233 bytes SubSystems/FocalEngine | 2 +- .../FENativeScriptProject.cpp | 1069 ----------------- .../ProjectManagment/FENativeScriptProject.h | 72 -- SubSystems/ProjectManagment/FEProject.cpp | 113 +- SubSystems/ProjectManagment/FEProject.h | 8 +- .../ProjectManagment/FEProjectManager.cpp | 2 +- main.cpp | 17 - 28 files changed, 629 insertions(+), 1373 deletions(-) create mode 100644 Resources/Images/AssetPackage_ContentBrowser_32_32_Icon.png create mode 100644 Resources/Images/AssetPackage_ContentBrowser_Icon.png create mode 100644 Resources/Images/NativeScriptModule_ContentBrowser_32_32_Icon.png create mode 100644 Resources/Images/NativeScriptModule_ContentBrowser_Icon.png create mode 100644 Resources/Images/Scene_ContentBrowser_Icon.png create mode 100644 Resources/Images/Shader_ContentBrowser_32_32_Icon.png create mode 100644 Resources/Images/originals/House.png create mode 100644 Resources/Images/originals/Scene.png create mode 100644 Resources/Images/originals/box-open.png create mode 100644 Resources/Images/originals/box-open_2.png create mode 100644 Resources/Images/originals/box-open_c++.png create mode 100644 Resources/Images/originals/c-.png create mode 100644 Resources/Images/originals/script.png delete mode 100644 SubSystems/ProjectManagment/FENativeScriptProject.cpp delete mode 100644 SubSystems/ProjectManagment/FENativeScriptProject.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3acc3c9..1c8a5d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,8 +107,6 @@ file(GLOB ProjectManagment_SRC "SubSystems/ProjectManagment/FEProjectManager.h" "SubSystems/ProjectManagment/FEProject.cpp" "SubSystems/ProjectManagment/FEProject.h" - "SubSystems/ProjectManagment/FENativeScriptProject.cpp" - "SubSystems/ProjectManagment/FENativeScriptProject.h" ) file(GLOB FEDearImguiWrapper_SRC diff --git a/EditorWindows/ContentBrowserWindow.cpp b/EditorWindows/ContentBrowserWindow.cpp index ff86b4d..39c6292 100644 --- a/EditorWindows/ContentBrowserWindow.cpp +++ b/EditorWindows/ContentBrowserWindow.cpp @@ -6,7 +6,7 @@ FEObject* FEEditorContentBrowserWindow::ItemInFocus = nullptr; FEEditorContentBrowserWindow::FEEditorContentBrowserWindow() { - strcpy_s(FilterForResources, ""); + strcpy_s(NameFilter, ""); INPUT.AddMouseButtonCallback(&FEEditorContentBrowserWindow::MouseButtonCallback); } @@ -74,7 +74,7 @@ void FEEditorContentBrowserWindow::OpenItemParentFolder(FEObject* Object) { VIRTUAL_FILE_SYSTEM.SetCurrentPath(VIRTUAL_FILE_SYSTEM.LocateFile(Object)); ImGui::SetWindowFocus("Content Browser"); - strcpy_s(FilterForResources, ""); + strcpy_s(NameFilter, ""); ItemInFocus = Object; const auto Content = VIRTUAL_FILE_SYSTEM.GetDirectoryContent(VIRTUAL_FILE_SYSTEM.GetCurrentPath()); @@ -220,6 +220,27 @@ void FEEditorContentBrowserWindow::Render() SELECT_FEOBJECT_POPUP.Show(FE_GAMEMODEL, CreateNewPrefabCallBack); } + if (ImGui::MenuItem("Create new scene")) + { + /*FEObject* NewScene = RESOURCE_MANAGER.CreateScene(); + PROJECT_MANAGER.GetCurrent()->SetModified(true); + VIRTUAL_FILE_SYSTEM.CreateFile(NewScene, VIRTUAL_FILE_SYSTEM.GetCurrentPath());*/ + } + + /*if (ImGui::MenuItem("Create new asset package")) + { + FEAssetPackage* NewAssetPackage = RESOURCE_MANAGER.CreateAssetPackage(); + PROJECT_MANAGER.GetCurrent()->SetModified(true); + VIRTUAL_FILE_SYSTEM.CreateFile(NewAssetPackage, VIRTUAL_FILE_SYSTEM.GetCurrentPath()); + }*/ + + if (ImGui::MenuItem("Create new native script module")) + { + FENativeScriptModule* NewNativeScriptModule = RESOURCE_MANAGER.CreateNativeScriptModule(); + PROJECT_MANAGER.GetCurrent()->SetModified(true); + VIRTUAL_FILE_SYSTEM.CreateFile(NewNativeScriptModule, VIRTUAL_FILE_SYSTEM.GetCurrentPath()); + } + ImGui::EndMenu(); } } @@ -246,7 +267,7 @@ void FEEditorContentBrowserWindow::Render() } } - if (FilteredResources[ItemUnderMouse]->GetType() == FE_MATERIAL) + if (!ReadOnlyItem && FilteredResources[ItemUnderMouse]->GetType() == FE_MATERIAL) { if (ImGui::MenuItem("Edit")) { @@ -254,7 +275,7 @@ void FEEditorContentBrowserWindow::Render() } } - if (FilteredResources[ItemUnderMouse]->GetType() == FE_GAMEMODEL) + if (!ReadOnlyItem && FilteredResources[ItemUnderMouse]->GetType() == FE_GAMEMODEL) { if (ImGui::MenuItem("Edit")) { @@ -275,7 +296,7 @@ void FEEditorContentBrowserWindow::Render() } } - if (FilteredResources[ItemUnderMouse]->GetType() == FE_PREFAB) + if (!ReadOnlyItem && FilteredResources[ItemUnderMouse]->GetType() == FE_PREFAB) { if (ImGui::MenuItem("Edit")) { @@ -283,7 +304,7 @@ void FEEditorContentBrowserWindow::Render() } } - if (FilteredResources[ItemUnderMouse]->GetType() == FE_SHADER) + if (!ReadOnlyItem && FilteredResources[ItemUnderMouse]->GetType() == FE_SHADER) { if (ImGui::MenuItem("Edit")) { @@ -291,6 +312,60 @@ void FEEditorContentBrowserWindow::Render() } } + if (!ReadOnlyItem && FilteredResources[ItemUnderMouse]->GetType() == FE_NATIVE_SCRIPT_MODULE) + { + FENativeScriptModule* NativeScriptModule = RESOURCE_MANAGER.GetNativeScriptModule(FilteredResources[ItemUnderMouse]->GetObjectID()); + if (NativeScriptModule != nullptr) + { + bool bHaveVSProjectReady = false; + if (NativeScriptModule->GetProject() != nullptr) + { + bHaveVSProjectReady = NativeScriptModule->GetProject()->IsVSProjectFolderValidAndIntact(); + } + + if (bHaveVSProjectReady) + { + if (ImGui::MenuItem("Open VS Project")) + { + if (!NativeScriptModule->GetProject()->RunVSProject()) + LOG.Add("FEEditorContentBrowserWindow::Render: Failed to run Visual Studio project!", "FE_EDITOR_CONTENT_BROWSER", FE_LOG_ERROR); + } + } + else + { + bool bHaveRecoverableVSProject = NativeScriptModule->GetProject()->HasRecoverableVSProjectData(); + if (bHaveRecoverableVSProject) + { + if (ImGui::MenuItem("Recover VS Project")) + { + std::string ProjectFolder = PROJECT_MANAGER.GetCurrent()->GetProjectFolder(); + NativeScriptModule->GetProject()->SetWorkingDirectory(ProjectFolder); + if (!NativeScriptModule->GetProject()->RecreateVSProject()) + { + LOG.Add("FEEditorContentBrowserWindow::Render: Failed to regenerate Visual Studio project!", "FE_EDITOR_CONTENT_BROWSER", FE_LOG_ERROR); + } + } + } + else + { + if (ImGui::MenuItem("Create VS Project")) + { + std::string ProjectFolder = PROJECT_MANAGER.GetCurrent()->GetProjectFolder(); + NativeScriptModule->GetProject()->SetWorkingDirectory(ProjectFolder); + if (!NativeScriptModule->GetProject()->CreateNewVSProject("FirstScript")) + { + LOG.Add("FEEditorContentBrowserWindow::Render: Failed to create Visual Studio project!", "FE_EDITOR_CONTENT_BROWSER", FE_LOG_ERROR); + } + } + } + } + } + else + { + LOG.Add("FEEditorContentBrowserWindow::Render: Native script module is nullptr", "FE_EDITOR_CONTENT_BROWSER", FE_LOG_WARNING); + } + } + if (!ReadOnlyItem) { if (ImGui::MenuItem("Delete")) @@ -398,7 +473,7 @@ void FEEditorContentBrowserWindow::Clear() FilteredResources.clear(); ItemUnderMouse = -1; RenameIndex = -1; - strcpy_s(FilterForResources, ""); + strcpy_s(NameFilter, ""); } void FEEditorContentBrowserWindow::InitializeResources() @@ -409,6 +484,9 @@ void FEEditorContentBrowserWindow::InitializeResources() ShaderIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/shaderIcon.png", "shaderIcon"); RESOURCE_MANAGER.SetTag(ShaderIcon, EDITOR_RESOURCE_TAG); + ShaderSmallIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/Shader_ContentBrowser_32_32_Icon.png", "Shader_Small_ContentBrowser_Icon"); + RESOURCE_MANAGER.SetTag(ShaderSmallIcon, EDITOR_RESOURCE_TAG); + VFSBackIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/VFSBackIcon.png", "VFSBackIcon"); RESOURCE_MANAGER.SetTag(VFSBackIcon, EDITOR_RESOURCE_TAG); @@ -427,11 +505,29 @@ void FEEditorContentBrowserWindow::InitializeResources() PrefabIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/prefabContentBrowserIcon.png", "prefabContentBrowserIcon"); RESOURCE_MANAGER.SetTag(PrefabIcon, EDITOR_RESOURCE_TAG); + SceneIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/Scene_ContentBrowser_Icon.png", "Scene_ContentBrowser_Icon"); + RESOURCE_MANAGER.SetTag(SceneIcon, EDITOR_RESOURCE_TAG); + + AssetPackageIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/AssetPackage_ContentBrowser_Icon.png", "AssetPackage_ContentBrowser_Icon"); + RESOURCE_MANAGER.SetTag(AssetPackageIcon, EDITOR_RESOURCE_TAG); + + AssetPackageSmallIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/AssetPackage_ContentBrowser_32_32_Icon.png", "AssetPackage_Small_ContentBrowser_Icon"); + RESOURCE_MANAGER.SetTag(AssetPackageSmallIcon, EDITOR_RESOURCE_TAG); + + NativeScriptModuleIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/NativeScriptModule_ContentBrowser_Icon.png", "NativeScriptModule_ContentBrowser_Icon"); + RESOURCE_MANAGER.SetTag(NativeScriptModuleIcon, EDITOR_RESOURCE_TAG); + + NativeScriptModuleSmallIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/NativeScriptModule_ContentBrowser_32_32_Icon.png", "NativeScriptModule_Small_ContentBrowser_Icon"); + RESOURCE_MANAGER.SetTag(NativeScriptModuleSmallIcon, EDITOR_RESOURCE_TAG); + AllIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/allContentBrowserIcon.png", "allIcon"); FilterAllTypesButton = new ImGuiImageButton(AllIcon); RESOURCE_MANAGER.SetTag(AllIcon, EDITOR_RESOURCE_TAG); FilterAllTypesButton->SetSize(ImVec2(32, 32)); + FilterShaderTypeButton = new ImGuiImageButton(ShaderSmallIcon); + FilterShaderTypeButton->SetSize(ImVec2(32, 32)); + FilterTextureTypeButton = new ImGuiImageButton(TextureIcon); FilterTextureTypeButton->SetSize(ImVec2(32, 32)); @@ -446,6 +542,15 @@ void FEEditorContentBrowserWindow::InitializeResources() FilterPrefabTypeButton = new ImGuiImageButton(PrefabIcon); FilterPrefabTypeButton->SetSize(ImVec2(32, 32)); + + FilterSceneTypeButton = new ImGuiImageButton(SceneIcon); + FilterSceneTypeButton->SetSize(ImVec2(32, 32)); + + FilterAssetPackageTypeButton = new ImGuiImageButton(AssetPackageSmallIcon); + FilterAssetPackageTypeButton->SetSize(ImVec2(32, 32)); + + FilterNativeScriptModuleTypeButton = new ImGuiImageButton(NativeScriptModuleSmallIcon); + FilterNativeScriptModuleTypeButton->SetSize(ImVec2(32, 32)); } void FEEditorContentBrowserWindow::ChooseTexturesItem(FETexture*& PreviewTexture, FETexture*& SmallAdditionTypeIcon, ImVec2& UV0, ImVec2& UV1, FEObject* Item) @@ -517,6 +622,45 @@ void FEEditorContentBrowserWindow::ChooseTexturesItem(FETexture*& PreviewTexture PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Item->GetObjectID()); SmallAdditionTypeIcon = PrefabIcon; } + else if (Item->GetType() == FE_SCENE) + { + UV0 = ImVec2(0.0f, 1.0f); + UV1 = ImVec2(1.0f, 0.0f); + + //PreviewTexture = PREVIEW_MANAGER.GetPrefabPreview(Item->GetObjectID()); + PreviewTexture = RESOURCE_MANAGER.NoTexture; + SmallAdditionTypeIcon = SceneIcon; + } + else if (Item->GetType() == FE_ASSET_PACKAGE) + { + UV0 = ImVec2(0.0f, 0.0f); + UV1 = ImVec2(1.0f, 1.0f); + + PreviewTexture = AssetPackageIcon; + + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f, 0.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor(0.95f, 0.90f, 0.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor(0.1f, 1.0f, 0.1f, 1.0f)); + } + else if (Item->GetType() == FE_NATIVE_SCRIPT_MODULE) + { + UV0 = ImVec2(0.0f, 0.0f); + UV1 = ImVec2(1.0f, 1.0f); + + PreviewTexture = NativeScriptModuleIcon; + + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(0.5f, 0.5f, 0.5f, 0.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor(0.95f, 0.90f, 0.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor(0.1f, 1.0f, 0.1f, 1.0f)); + } } void FEEditorContentBrowserWindow::RenderFilterMenu() @@ -530,7 +674,7 @@ void FEEditorContentBrowserWindow::RenderFilterMenu() if (ImGui::ImageButton((void*)(intptr_t)VFSBackIcon->GetTextureID(), ImVec2(64, 64), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) { VIRTUAL_FILE_SYSTEM.SetCurrentPath(VIRTUAL_FILE_SYSTEM.GetDirectoryParent(VIRTUAL_FILE_SYSTEM.GetCurrentPath())); - strcpy_s(FilterForResources, ""); + strcpy_s(NameFilter, ""); } VFSBackButtonTarget->StickToItem(); @@ -542,51 +686,274 @@ void FEEditorContentBrowserWindow::RenderFilterMenu() AllResources.clear(); AllResources = VIRTUAL_FILE_SYSTEM.GetDirectoryContent(VIRTUAL_FILE_SYSTEM.GetCurrentPath()); - ImGui::SetCursorPosX(100); + float CurrentX = 100.0f; + ImGui::SetCursorPosX(CurrentX); ImGui::SetCursorPosY(CurrentY + 5); ImGui::Text("Filter by type: "); - ImGui::SetCursorPosX(120 + 140); + CurrentX += 20.0f + 140.0f; + ImGui::SetCursorPosX(CurrentX); ImGui::SetCursorPosY(CurrentY - 5); - ObjTypeFilterForResources.empty() ? SetSelectedStyle(FilterAllTypesButton) : SetDefaultStyle(FilterAllTypesButton); + ObjectTypeFilters.empty() ? SetSelectedStyle(FilterAllTypesButton) : SetDefaultStyle(FilterAllTypesButton); FilterAllTypesButton->Render(); if (FilterAllTypesButton->IsClicked()) - ObjTypeFilterForResources = ""; + ObjectTypeFilters.clear(); - ImGui::SetCursorPosX(120 + 140 + 48); + CurrentX += 48.0f; + ImGui::SetCursorPosX(CurrentX); ImGui::SetCursorPosY(CurrentY - 5); - ObjTypeFilterForResources == FEObjectTypeToString(FE_TEXTURE) ? SetSelectedStyle(FilterTextureTypeButton) : SetDefaultStyle(FilterTextureTypeButton); + bool bIsCurrentTypeInFilters = false; + for (size_t i = 0; i < ObjectTypeFilters.size(); i++) + { + if (ObjectTypeFilters[i] == FEObjectTypeToString(FE_SHADER)) + { + bIsCurrentTypeInFilters = true; + break; + } + } + bIsCurrentTypeInFilters ? SetSelectedStyle(FilterShaderTypeButton) : SetDefaultStyle(FilterShaderTypeButton); + FilterShaderTypeButton->Render(); + if (FilterShaderTypeButton->IsClicked()) + { + if (bIsCurrentTypeInFilters) + { + ObjectTypeFilters.erase(std::remove(ObjectTypeFilters.begin(), ObjectTypeFilters.end(), FEObjectTypeToString(FE_SHADER)), ObjectTypeFilters.end()); + } + else + { + ObjectTypeFilters.push_back(FEObjectTypeToString(FE_SHADER)); + } + } + + CurrentX += 48.0f; + ImGui::SetCursorPosX(CurrentX); + ImGui::SetCursorPosY(CurrentY - 5); + bIsCurrentTypeInFilters = false; + for (size_t i = 0; i < ObjectTypeFilters.size(); i++) + { + if (ObjectTypeFilters[i] == FEObjectTypeToString(FE_TEXTURE)) + { + bIsCurrentTypeInFilters = true; + break; + } + } + bIsCurrentTypeInFilters ? SetSelectedStyle(FilterTextureTypeButton) : SetDefaultStyle(FilterTextureTypeButton); FilterTextureTypeButton->Render(); if (FilterTextureTypeButton->IsClicked()) - ObjTypeFilterForResources = FEObjectTypeToString(FE_TEXTURE); + { + if (bIsCurrentTypeInFilters) + { + ObjectTypeFilters.erase(std::remove(ObjectTypeFilters.begin(), ObjectTypeFilters.end(), FEObjectTypeToString(FE_TEXTURE)), ObjectTypeFilters.end()); + } + else + { + ObjectTypeFilters.push_back(FEObjectTypeToString(FE_TEXTURE)); + } + } - ImGui::SetCursorPosX(120 + 140 + 48 + 48); + CurrentX += 48.0f; + ImGui::SetCursorPosX(CurrentX); ImGui::SetCursorPosY(CurrentY - 5); - ObjTypeFilterForResources == FEObjectTypeToString(FE_MESH) ? SetSelectedStyle(FilterMeshTypeButton) : SetDefaultStyle(FilterMeshTypeButton); + bIsCurrentTypeInFilters = false; + for (size_t i = 0; i < ObjectTypeFilters.size(); i++) + { + if (ObjectTypeFilters[i] == FEObjectTypeToString(FE_MESH)) + { + bIsCurrentTypeInFilters = true; + break; + } + } + bIsCurrentTypeInFilters ? SetSelectedStyle(FilterMeshTypeButton) : SetDefaultStyle(FilterMeshTypeButton); FilterMeshTypeButton->Render(); if (FilterMeshTypeButton->IsClicked()) - ObjTypeFilterForResources = FEObjectTypeToString(FE_MESH); + { + if (bIsCurrentTypeInFilters) + { + ObjectTypeFilters.erase(std::remove(ObjectTypeFilters.begin(), ObjectTypeFilters.end(), FEObjectTypeToString(FE_MESH)), ObjectTypeFilters.end()); + } + else + { + ObjectTypeFilters.push_back(FEObjectTypeToString(FE_MESH)); + } + } - ImGui::SetCursorPosX(120 + 140 + 48 + 48 + 48); + CurrentX += 48.0f; + ImGui::SetCursorPosX(CurrentX); ImGui::SetCursorPosY(CurrentY - 5); - ObjTypeFilterForResources == FEObjectTypeToString(FE_MATERIAL) ? SetSelectedStyle(FilterMaterialTypeButton) : SetDefaultStyle(FilterMaterialTypeButton); + bIsCurrentTypeInFilters = false; + for (size_t i = 0; i < ObjectTypeFilters.size(); i++) + { + if (ObjectTypeFilters[i] == FEObjectTypeToString(FE_MATERIAL)) + { + bIsCurrentTypeInFilters = true; + break; + } + } + bIsCurrentTypeInFilters ? SetSelectedStyle(FilterMaterialTypeButton) : SetDefaultStyle(FilterMaterialTypeButton); FilterMaterialTypeButton->Render(); if (FilterMaterialTypeButton->IsClicked()) - ObjTypeFilterForResources = FEObjectTypeToString(FE_MATERIAL); + { + if (bIsCurrentTypeInFilters) + { + ObjectTypeFilters.erase(std::remove(ObjectTypeFilters.begin(), ObjectTypeFilters.end(), FEObjectTypeToString(FE_MATERIAL)), ObjectTypeFilters.end()); + } + else + { + ObjectTypeFilters.push_back(FEObjectTypeToString(FE_MATERIAL)); + } + } - ImGui::SetCursorPosX(120 + 140 + 48 + 48 + 48 + 48); + CurrentX += 48.0f; + ImGui::SetCursorPosX(CurrentX); ImGui::SetCursorPosY(CurrentY - 5); - ObjTypeFilterForResources == FEObjectTypeToString(FE_GAMEMODEL) ? SetSelectedStyle(FilterGameModelTypeButton) : SetDefaultStyle(FilterGameModelTypeButton); + bIsCurrentTypeInFilters = false; + for (size_t i = 0; i < ObjectTypeFilters.size(); i++) + { + if (ObjectTypeFilters[i] == FEObjectTypeToString(FE_GAMEMODEL)) + { + bIsCurrentTypeInFilters = true; + break; + } + } + bIsCurrentTypeInFilters ? SetSelectedStyle(FilterGameModelTypeButton) : SetDefaultStyle(FilterGameModelTypeButton); FilterGameModelTypeButton->Render(); if (FilterGameModelTypeButton->IsClicked()) - ObjTypeFilterForResources = FEObjectTypeToString(FE_GAMEMODEL); + { + if (bIsCurrentTypeInFilters) + { + ObjectTypeFilters.erase(std::remove(ObjectTypeFilters.begin(), ObjectTypeFilters.end(), FEObjectTypeToString(FE_GAMEMODEL)), ObjectTypeFilters.end()); + } + else + { + ObjectTypeFilters.push_back(FEObjectTypeToString(FE_GAMEMODEL)); + } + } - ImGui::SetCursorPosX(120 + 140 + 48 + 48 + 48 + 48 + 48); + CurrentX += 48.0f; + ImGui::SetCursorPosX(CurrentX); ImGui::SetCursorPosY(CurrentY - 5); - ObjTypeFilterForResources == FEObjectTypeToString(FE_PREFAB) ? SetSelectedStyle(FilterPrefabTypeButton) : SetDefaultStyle(FilterPrefabTypeButton); + bIsCurrentTypeInFilters = false; + for (size_t i = 0; i < ObjectTypeFilters.size(); i++) + { + if (ObjectTypeFilters[i] == FEObjectTypeToString(FE_PREFAB)) + { + bIsCurrentTypeInFilters = true; + break; + } + } + bIsCurrentTypeInFilters ? SetSelectedStyle(FilterPrefabTypeButton) : SetDefaultStyle(FilterPrefabTypeButton); FilterPrefabTypeButton->Render(); if (FilterPrefabTypeButton->IsClicked()) - ObjTypeFilterForResources = FEObjectTypeToString(FE_PREFAB); + { + if (bIsCurrentTypeInFilters) + { + ObjectTypeFilters.erase(std::remove(ObjectTypeFilters.begin(), ObjectTypeFilters.end(), FEObjectTypeToString(FE_PREFAB)), ObjectTypeFilters.end()); + } + else + { + ObjectTypeFilters.push_back(FEObjectTypeToString(FE_PREFAB)); + } + } + + CurrentX += 48.0f; + ImGui::SetCursorPosX(CurrentX); + ImGui::SetCursorPosY(CurrentY - 5); + bIsCurrentTypeInFilters = false; + for (size_t i = 0; i < ObjectTypeFilters.size(); i++) + { + if (ObjectTypeFilters[i] == FEObjectTypeToString(FE_SCENE)) + { + bIsCurrentTypeInFilters = true; + break; + } + } + bIsCurrentTypeInFilters ? SetSelectedStyle(FilterSceneTypeButton) : SetDefaultStyle(FilterSceneTypeButton); + FilterSceneTypeButton->Render(); + if (FilterSceneTypeButton->IsClicked()) + { + if (bIsCurrentTypeInFilters) + { + ObjectTypeFilters.erase(std::remove(ObjectTypeFilters.begin(), ObjectTypeFilters.end(), FEObjectTypeToString(FE_SCENE)), ObjectTypeFilters.end()); + } + else + { + ObjectTypeFilters.push_back(FEObjectTypeToString(FE_SCENE)); + } + } + + CurrentX += 48.0f; + ImGui::SetCursorPosX(CurrentX); + ImGui::SetCursorPosY(CurrentY - 5); + bIsCurrentTypeInFilters = false; + for (size_t i = 0; i < ObjectTypeFilters.size(); i++) + { + if (ObjectTypeFilters[i] == FEObjectTypeToString(FE_ASSET_PACKAGE)) + { + bIsCurrentTypeInFilters = true; + break; + } + } + bIsCurrentTypeInFilters ? SetSelectedStyle(FilterAssetPackageTypeButton) : SetDefaultStyle(FilterAssetPackageTypeButton); + FilterAssetPackageTypeButton->Render(); + if (FilterAssetPackageTypeButton->IsClicked()) + { + if (bIsCurrentTypeInFilters) + { + ObjectTypeFilters.erase(std::remove(ObjectTypeFilters.begin(), ObjectTypeFilters.end(), FEObjectTypeToString(FE_ASSET_PACKAGE)), ObjectTypeFilters.end()); + } + else + { + ObjectTypeFilters.push_back(FEObjectTypeToString(FE_ASSET_PACKAGE)); + } + } + + CurrentX += 48.0f; + ImGui::SetCursorPosX(CurrentX); + ImGui::SetCursorPosY(CurrentY - 5); + bIsCurrentTypeInFilters = false; + for (size_t i = 0; i < ObjectTypeFilters.size(); i++) + { + if (ObjectTypeFilters[i] == FEObjectTypeToString(FE_NATIVE_SCRIPT_MODULE)) + { + bIsCurrentTypeInFilters = true; + break; + } + } + bIsCurrentTypeInFilters ? SetSelectedStyle(FilterNativeScriptModuleTypeButton) : SetDefaultStyle(FilterNativeScriptModuleTypeButton); + FilterNativeScriptModuleTypeButton->Render(); + if (FilterNativeScriptModuleTypeButton->IsClicked()) + { + if (bIsCurrentTypeInFilters) + { + ObjectTypeFilters.erase(std::remove(ObjectTypeFilters.begin(), ObjectTypeFilters.end(), FEObjectTypeToString(FE_NATIVE_SCRIPT_MODULE)), ObjectTypeFilters.end()); + } + else + { + ObjectTypeFilters.push_back(FEObjectTypeToString(FE_NATIVE_SCRIPT_MODULE)); + } + } + + CurrentX += 48.0f; + ImGui::SetCursorPosX(CurrentX); + ImGui::SetCursorPosY(CurrentY - 5); + static bool bIsPrivateTagsInFilters = true; + if (bIsPrivateTagsInFilters && ObjectTagNegativeFilters.empty()) + { + ObjectTagNegativeFilters.push_back(ENGINE_RESOURCE_TAG); + ObjectTagNegativeFilters.push_back(EDITOR_RESOURCE_TAG); + ObjectTagNegativeFilters.push_back(PREFAB_SCENE_DESCRIPTION_TAG); + } + + if (ImGui::Checkbox("Hide private tags", &bIsPrivateTagsInFilters)) + { + ObjectTagNegativeFilters.clear(); + if (bIsPrivateTagsInFilters) + { + ObjectTagNegativeFilters.push_back(ENGINE_RESOURCE_TAG); + ObjectTagNegativeFilters.push_back(EDITOR_RESOURCE_TAG); + ObjectTagNegativeFilters.push_back(PREFAB_SCENE_DESCRIPTION_TAG); + } + } ImGui::SetCursorPosX(100); ImGui::SetCursorPosY(CurrentY + 50); @@ -594,7 +961,7 @@ void FEEditorContentBrowserWindow::RenderFilterMenu() ImGui::SetCursorPosX(120 + 140); ImGui::SetCursorPosY(CurrentY + 47); - ImGui::InputText("##filter", FilterForResources, IM_ARRAYSIZE(FilterForResources)); + ImGui::InputText("##filter", NameFilter, IM_ARRAYSIZE(NameFilter)); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 25); ImGui::Separator(); @@ -661,6 +1028,10 @@ void FEEditorContentBrowserWindow::RenderFilterMenu() AdditionalTypeInfo += "\nTexture type: "; AdditionalTypeInfo += FETexture::TextureInternalFormatToString(RESOURCE_MANAGER.GetTexture(FilteredResources[i]->GetObjectID())->GetInternalFormat()); } + else if (FilteredResources[i]->GetType() == FE_NATIVE_SCRIPT_MODULE) + { + + } ImGui::BeginTooltip(); ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); @@ -843,36 +1214,87 @@ void FEEditorContentBrowserWindow::UpdateFilterForResources() { FilteredResources.clear(); - // Filter by name. - if (strlen(FilterForResources) == 0) + std::vector TemporaryFilteredList; + TemporaryFilteredList = AllResources; + if (!AnyFilterActive()) { - FilteredResources = AllResources; + FilteredResources = TemporaryFilteredList; + return; } - else + + for (size_t i = 0; i < TemporaryFilteredList.size(); i++) { - for (size_t i = 0; i < AllResources.size(); i++) + if (ShouldPassVisibilityFilter(TemporaryFilteredList[i])) { - if (AllResources[i]->GetName().find(FilterForResources) != -1) + FilteredResources.push_back(TemporaryFilteredList[i]); + } + } +} + +bool FEEditorContentBrowserWindow::AnyFilterActive() +{ + return NameFilter[0] != '\0' || ObjectTypeFilters.size() > 0 || ObjectTagNegativeFilters.size() > 0; +} + +bool FEEditorContentBrowserWindow::ShouldPassVisibilityFilter(FEObject* Object) +{ + if (Object == nullptr) + { + LOG.Add("Object is nullptr in FEEditorContentBrowserWindow::ShouldPassVisibilityFilter", "FE_EDITOR_CONTENT_BROWSER", FE_LOG_WARNING); + return false; + } + + if (strlen(NameFilter) > 0) + { + if (Object->GetName().find(NameFilter) == -1) + return false; + } + + bool bShouldPassTypeFilter = true; + if (!ObjectTypeFilters.empty()) + { + bShouldPassTypeFilter = false; + // Check if object is a folder + if (Object->GetType() == FE_NULL) + { + bShouldPassTypeFilter = true; + } + else + { + for (size_t i = 0; i < ObjectTypeFilters.size(); i++) { - FilteredResources.push_back(AllResources[i]); + if (FEObjectTypeToString(Object->GetType()) == ObjectTypeFilters[i]) + { + bShouldPassTypeFilter = true; + break; + } } } } - // Filter by type. - if (!ObjTypeFilterForResources.empty()) + if (!bShouldPassTypeFilter) + return false; + + bool bShouldPassNegativeTagFilter = true; + if (!ObjectTagNegativeFilters.empty()) { - std::vector FinalFilteredList; - for (size_t i = 0; i < FilteredResources.size(); i++) + // Check if object is not a folder + if (Object->GetType() != FE_NULL) { - if (FEObjectTypeToString(FilteredResources[i]->GetType()) == ObjTypeFilterForResources || - // Add folders - FilteredResources[i]->GetType() == FE_NULL) + + for (size_t i = 0; i < ObjectTagNegativeFilters.size(); i++) { - FinalFilteredList.push_back(FilteredResources[i]); + if (Object->GetTag() == ObjectTagNegativeFilters[i]) + { + bShouldPassNegativeTagFilter = false; + break; + } } } - - FilteredResources = FinalFilteredList; } + + if (!bShouldPassNegativeTagFilter) + return false; + + return true; } \ No newline at end of file diff --git a/EditorWindows/ContentBrowserWindow.h b/EditorWindows/ContentBrowserWindow.h index deb498b..e755d0c 100644 --- a/EditorWindows/ContentBrowserWindow.h +++ b/EditorWindows/ContentBrowserWindow.h @@ -42,12 +42,18 @@ void InitializeResources(); FETexture* FolderIcon = nullptr; FETexture* ShaderIcon = nullptr; + FETexture* ShaderSmallIcon = nullptr; FETexture* VFSBackIcon = nullptr; FETexture* TextureIcon = nullptr; FETexture* MeshIcon = nullptr; FETexture* MaterialIcon = nullptr; FETexture* GameModelIcon = nullptr; FETexture* PrefabIcon = nullptr; + FETexture* SceneIcon = nullptr; + FETexture* AssetPackageIcon = nullptr; + FETexture* AssetPackageSmallIcon = nullptr; + FETexture* NativeScriptModuleIcon = nullptr; + FETexture* NativeScriptModuleSmallIcon = nullptr; FETexture* AllIcon = nullptr; // Item selection and manipulation @@ -65,17 +71,24 @@ // Resource filtering std::vector AllResources; std::vector FilteredResources; - char FilterForResources[512]; - std::string ObjTypeFilterForResources; + char NameFilter[1024]; + std::vector ObjectTypeFilters; + std::vector ObjectTagNegativeFilters; + bool AnyFilterActive(); + bool ShouldPassVisibilityFilter(FEObject* Object); void UpdateFilterForResources(); // Filter buttons ImGuiImageButton* FilterAllTypesButton = nullptr; + ImGuiImageButton* FilterShaderTypeButton = nullptr; ImGuiImageButton* FilterTextureTypeButton = nullptr; ImGuiImageButton* FilterMeshTypeButton = nullptr; ImGuiImageButton* FilterMaterialTypeButton = nullptr; ImGuiImageButton* FilterGameModelTypeButton = nullptr; ImGuiImageButton* FilterPrefabTypeButton = nullptr; + ImGuiImageButton* FilterSceneTypeButton = nullptr; + ImGuiImageButton* FilterAssetPackageTypeButton = nullptr; + ImGuiImageButton* FilterNativeScriptModuleTypeButton = nullptr; // Drag and drop struct DirectoryDragAndDropCallbackInfo diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index d9eb9eb..804dd4c 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -2262,22 +2262,40 @@ void FEEditorInspectorWindow::DisplayNativeScriptProperties(FEEntity* NativeScri if (!NativeScriptComponent.IsInitialized()) { - std::vector ModuleList = NATIVE_SCRIPT_SYSTEM.GetActiveModuleIDList(); + if (NativeScriptComponent.IsFailedToLoad()) + { + ImGui::Text("Script failed to load."); + FENativeScriptFailedToLoadData* FailedToLoadData = NativeScriptComponent.GetFailedToLoadData(); + ImGui::Text(("Module ID: " + FailedToLoadData->GetModuleID()).c_str()); + // And show raw data in multiline text box. + Json::Value Data = FailedToLoadData->GetRawData(); + std::string RawData = Data.toStyledString(); + + static char buffer[10240] = {}; + + strncpy_s(buffer, RawData.c_str(), sizeof(buffer) - 1); - for (size_t i = 0; i < ModuleList.size(); i++) + ImGui::InputTextMultiline("##FailedToLoadData", buffer, sizeof(buffer), ImVec2(500, 500), ImGuiInputTextFlags_ReadOnly); + + } + else { - ImGui::Text(("Module ID: " + ModuleList[i]).c_str()); - ImGui::Text(("DLL Module ID: " + NATIVE_SCRIPT_SYSTEM.GetAssociatedDLLID(ModuleList[i])).c_str()); + std::vector ModuleList = NATIVE_SCRIPT_SYSTEM.GetActiveModuleIDList(); - ImGui::Text("Script list: "); - std::vector ScriptList = NATIVE_SCRIPT_SYSTEM.GetActiveModuleScriptNameList(ModuleList[i]); - for (size_t j = 0; j < ScriptList.size(); j++) + for (size_t i = 0; i < ModuleList.size(); i++) { - ImGui::Text(ScriptList[j].c_str()); - ImGui::SameLine(); - if (ImGui::Button(("Add##" + ModuleList[i] + "_" + ScriptList[j]).c_str())) + ImGui::Text(("Module ID: " + ModuleList[i]).c_str()); + + ImGui::Text("Script list: "); + std::vector ScriptList = NATIVE_SCRIPT_SYSTEM.GetActiveModuleScriptNameList(ModuleList[i]); + for (size_t j = 0; j < ScriptList.size(); j++) { - NATIVE_SCRIPT_SYSTEM.InitializeScriptComponent(NativeScriptEntity, ModuleList[i], ScriptList[j]); + ImGui::Text(ScriptList[j].c_str()); + ImGui::SameLine(); + if (ImGui::Button(("Add##" + ModuleList[i] + "_" + ScriptList[j]).c_str())) + { + NATIVE_SCRIPT_SYSTEM.InitializeScriptComponent(NativeScriptEntity, ModuleList[i], ScriptList[j]); + } } } } @@ -2289,7 +2307,6 @@ void FEEditorInspectorWindow::DisplayNativeScriptProperties(FEEntity* NativeScri // Showing general information. ImGui::Text(("Module: " + ModuleID).c_str()); - ImGui::Text(("DLL Module ID: " + NATIVE_SCRIPT_SYSTEM.GetAssociatedDLLID(ModuleID)).c_str()); ImGui::Text(("Script name: " + ScriptData->Name).c_str()); ImGui::Text((std::string("Run in editor: ") + std::string(ScriptData->bRunInEditor ? "Yes" : "No")).c_str()); diff --git a/FEEditorScriptingSystem.cpp b/FEEditorScriptingSystem.cpp index d37165d..7391d0d 100644 --- a/FEEditorScriptingSystem.cpp +++ b/FEEditorScriptingSystem.cpp @@ -16,73 +16,14 @@ void FEEditorScriptingSystem::Update() if (CurrentProject == nullptr) return; - if (CurrentProject->NativeScriptProject == nullptr) - return; - - CurrentProject->NativeScriptProject->Update(); -} - -bool FEEditorScriptingSystem::IsCurrentProjectHaveVSProjectInitialized() -{ - FEProject* CurrentProject = PROJECT_MANAGER.GetCurrent(); - if (CurrentProject == nullptr) + std::vector IDList = RESOURCE_MANAGER.GetNativeScriptModuleIDList(); + for (size_t i = 0; i < IDList.size(); i++) { - LOG.Add("FEEditorScriptingSystem::IsCurrentProjectHaveVSProjectInitialized: Current project is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } + FENativeScriptModule* CurrentModule = RESOURCE_MANAGER.GetNativeScriptModule(IDList[i]); + if (CurrentModule == nullptr) + continue; - std::string ProjectPath = CurrentProject->GetProjectFolder(); - if (ProjectPath.empty()) - { - LOG.Add("FEEditorScriptingSystem::IsCurrentProjectHaveVSProjectInitialized: Project path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; + if (CurrentModule->GetProject() != nullptr) + CurrentModule->GetProject()->Update(); } - - if (CurrentProject->NativeScriptProject == nullptr) - { - LOG.Add("FEEditorScriptingSystem::IsCurrentProjectHaveVSProjectInitialized: Native script project data is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - return CurrentProject->NativeScriptProject->IsVSProjectValid(); -} - -bool FEEditorScriptingSystem::GenerateNewNativeScriptProject(std::string FirstScriptName) -{ - if (FirstScriptName.empty()) - { - LOG.Add("FEEditorScriptingSystem::GenerateNewNativeScriptProject: First script name is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - FEProject* CurrentProject = PROJECT_MANAGER.GetCurrent(); - if (CurrentProject == nullptr) - { - LOG.Add("FEEditorScriptingSystem::GenerateNewNativeScriptProject: Current project is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (CurrentProject->NativeScriptProject != nullptr) - { - LOG.Add("FEEditorScriptingSystem::GenerateNewNativeScriptProject: Native script project already exists", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - // Replace all spaces with underscores. - for (size_t i = 0; i < FirstScriptName.size(); i++) - { - if (FirstScriptName[i] == ' ') - FirstScriptName[i] = '_'; - } - - CurrentProject->NativeScriptProject = new FENativeScriptProject(CurrentProject); - if (!CurrentProject->NativeScriptProject->GenerateNewVSProject(FirstScriptName)) - { - LOG.Add("FEEditorScriptingSystem::GenerateNewNativeScriptProject: Error initializing native script project", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - delete CurrentProject->NativeScriptProject; - CurrentProject->NativeScriptProject = nullptr; - return false; - } - - return true; } \ No newline at end of file diff --git a/FEEditorScriptingSystem.h b/FEEditorScriptingSystem.h index c236e36..b0608fc 100644 --- a/FEEditorScriptingSystem.h +++ b/FEEditorScriptingSystem.h @@ -9,8 +9,6 @@ class FEEditorScriptingSystem SINGLETON_PUBLIC_PART(FEEditorScriptingSystem) void Update(); - bool IsCurrentProjectHaveVSProjectInitialized(); - bool GenerateNewNativeScriptProject(std::string FirstScriptName); private: SINGLETON_PRIVATE_PART(FEEditorScriptingSystem) }; diff --git a/FEEditorVirtualFileSystem.cpp b/FEEditorVirtualFileSystem.cpp index cd9e933..0657d8d 100644 --- a/FEEditorVirtualFileSystem.cpp +++ b/FEEditorVirtualFileSystem.cpp @@ -43,7 +43,7 @@ bool FEVFSDirectory::HasFile(const FEObject* File) { if (File == nullptr) { - LOG.Add("File is nullptr in function FEVFSDirectory::HasFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("File is nullptr in function FEVFSDirectory::HasFile.", "FE_VIRTUAL_FILE_SYSTEM", FE_LOG_ERROR); return false; } @@ -114,7 +114,7 @@ bool FEVFSDirectory::DeleteFile(const FEObject* File) { if (File == nullptr) { - LOG.Add("file is nullptr in function FEVFSDirectory::deleteFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("File is nullptr in function FEVFSDirectory::deleteFile.", "FE_VIRTUAL_FILE_SYSTEM", FE_LOG_ERROR); return false; } @@ -134,7 +134,7 @@ bool FEVFSDirectory::AddFile(FEObject* File) { if (File == nullptr) { - LOG.Add("file is nullptr in function FEVFSDirectory::addFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("File is nullptr in function FEVFSDirectory::addFile.", "FE_VIRTUAL_FILE_SYSTEM", FE_LOG_ERROR); return false; } @@ -257,7 +257,7 @@ bool FEVirtualFileSystem::CreateFile(FEObject* Data, const std::string Path) { if (Data == nullptr) { - LOG.Add("Data is nullptr in function FEVirtualFileSystem::CreateFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("Data is nullptr in function FEVirtualFileSystem::CreateFile.", "FE_VIRTUAL_FILE_SYSTEM", FE_LOG_ERROR); return false; } @@ -266,21 +266,29 @@ bool FEVirtualFileSystem::CreateFile(FEObject* Data, const std::string Path) Data->GetType() != FE_MESH && Data->GetType() != FE_MATERIAL && Data->GetType() != FE_GAMEMODEL && - Data->GetType() != FE_PREFAB) + Data->GetType() != FE_PREFAB && + Data->GetType() != FE_SCENE && + Data->GetType() != FE_ASSET_PACKAGE && + Data->GetType() != FE_NATIVE_SCRIPT_MODULE) { - LOG.Add("Data type is not supported in function FEVirtualFileSystem::CreateFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("Data type is not supported in function FEVirtualFileSystem::CreateFile.", "FE_VIRTUAL_FILE_SYSTEM", FE_LOG_ERROR); return false; } if (!IsPathCorrect(Path)) + { + LOG.Add("Path is not correct in function FEVirtualFileSystem::CreateFile.", "FE_VIRTUAL_FILE_SYSTEM", FE_LOG_ERROR); return false; + } - FEVFSDirectory* directory = PathToDirectory(Path); - if (directory->HasFile(Data)) + FEVFSDirectory* Directory = PathToDirectory(Path); + if (Directory->HasFile(Data)) + { + LOG.Add("File already exists in function FEVirtualFileSystem::CreateFile.", "FE_VIRTUAL_FILE_SYSTEM", FE_LOG_WARNING); return false; + } - directory->Files.push_back(FEVFSFile(Data, directory)); - + Directory->Files.push_back(FEVFSFile(Data, Directory)); return true; } @@ -397,7 +405,7 @@ bool FEVirtualFileSystem::MoveFile(FEObject* Data, const std::string OldPath, co { if (Data == nullptr) { - LOG.Add("Data is nullptr in function FEVirtualFileSystem::MoveFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("Data is nullptr in function FEVirtualFileSystem::MoveFile.", "FE_VIRTUAL_FILE_SYSTEM", FE_LOG_ERROR); return false; } @@ -466,7 +474,7 @@ void FEVirtualFileSystem::DeleteDirectory(FEVFSDirectory* Directory) { if (Directory == nullptr) { - LOG.Add("Directory is nullptr in function FEVirtualFileSystem::DeleteDirectory.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("Directory is nullptr in function FEVirtualFileSystem::DeleteDirectory.", "FE_VIRTUAL_FILE_SYSTEM", FE_LOG_ERROR); return; } @@ -533,7 +541,7 @@ bool FEVirtualFileSystem::DeleteFile(const FEObject* Data, const std::string Pat { if (Data == nullptr) { - LOG.Add("Data is nullptr in function FEVirtualFileSystem::DeleteFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("Data is nullptr in function FEVirtualFileSystem::DeleteFile.", "FE_VIRTUAL_FILE_SYSTEM", FE_LOG_ERROR); return false; } @@ -558,13 +566,13 @@ std::string FEVirtualFileSystem::LocateFileRecursive(FEVFSDirectory* Directory, if (Directory == nullptr) { - LOG.Add("Directory is nullptr in function FEVirtualFileSystem::LocateFileRecursive.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("Directory is nullptr in function FEVirtualFileSystem::LocateFileRecursive.", "FE_VIRTUAL_FILE_SYSTEM", FE_LOG_ERROR); return Path; } if (File == nullptr) { - LOG.Add("File is nullptr in function FEVirtualFileSystem::LocateFileRecursive.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("File is nullptr in function FEVirtualFileSystem::LocateFileRecursive.", "FE_VIRTUAL_FILE_SYSTEM", FE_LOG_ERROR); return Path; } @@ -591,7 +599,7 @@ std::string FEVirtualFileSystem::LocateFile(FEObject* File) { if (File == nullptr) { - LOG.Add("File is nullptr in function FEVirtualFileSystem::LocateFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("File is nullptr in function FEVirtualFileSystem::LocateFile.", "FE_VIRTUAL_FILE_SYSTEM", FE_LOG_ERROR); return ""; } @@ -602,7 +610,7 @@ void FEVirtualFileSystem::LocateAndDeleteFile(FEObject* File) { if (File == nullptr) { - LOG.Add("File is nullptr in function FEVirtualFileSystem::LocateAndDeleteFile.", "FE_LOG_GENERAL", FE_LOG_ERROR); + LOG.Add("File is nullptr in function FEVirtualFileSystem::LocateAndDeleteFile.", "FE_VIRTUAL_FILE_SYSTEM", FE_LOG_ERROR); return; } @@ -658,10 +666,10 @@ void FEVirtualFileSystem::LoadStateRecursive(Json::Value* LocalRoot, FEVFSDirect Directory->SetName(LocalRoot->operator[]("name").asCString()); Directory->Parent = Parent; - const std::vector files = LocalRoot->operator[]("files").getMemberNames(); - for (size_t j = 0; j < files.size(); j++) + const std::vector Files = LocalRoot->operator[]("files").getMemberNames(); + for (size_t j = 0; j < Files.size(); j++) { - Directory->AddFile(OBJECT_MANAGER.GetFEObject(files[j])); + Directory->AddFile(OBJECT_MANAGER.GetFEObject(Files[j])); } const std::vector SubDirectories = LocalRoot->operator[]("subDirectories").getMemberNames(); @@ -763,4 +771,21 @@ void FEVirtualFileSystem::SetFileReadOnly(const bool NewValue, const FEObject* D return; } } +} + +bool FEVirtualFileSystem::DoesFileExist(FEObject* Data, std::string Path) +{ + FEVFSDirectory* Directory = PathToDirectory(Path); + if (Directory == nullptr) + { + LOG.Add("Directory is nullptr in function FEVirtualFileSystem::DoesFileExist.", "FE_VIRTUAL_FILE_SYSTEM", FE_LOG_ERROR); + return false; + } + + return Directory->HasFile(Data); +} + +bool FEVirtualFileSystem::DoesFileExistAnywhere(FEObject* Data) +{ + return !LocateFile(Data).empty(); } \ No newline at end of file diff --git a/FEEditorVirtualFileSystem.h b/FEEditorVirtualFileSystem.h index 29c2c29..e2193a0 100644 --- a/FEEditorVirtualFileSystem.h +++ b/FEEditorVirtualFileSystem.h @@ -51,6 +51,10 @@ class FEVirtualFileSystem bool MoveFile(FEObject* Data, std::string OldPath, std::string NewPath); bool DeleteFile(const FEObject* Data, std::string Path); void SetFileReadOnly(bool NewValue, const FEObject* Data, std::string Path); + std::string LocateFile(FEObject* File); + void LocateAndDeleteFile(FEObject* File); + bool DoesFileExist(FEObject* Data, std::string Path); + bool DoesFileExistAnywhere(FEObject* Data); bool CreateDirectory(std::string Name, std::string Path); std::string CreateDirectory(std::string Path); @@ -68,9 +72,6 @@ class FEVirtualFileSystem std::string GetCurrentPath(); bool SetCurrentPath(std::string Path); - std::string LocateFile(FEObject* File); - void LocateAndDeleteFile(FEObject* File); - void SaveState(std::string FileName); void LoadState(std::string FileName); diff --git a/Resources/Images/AssetPackage_ContentBrowser_32_32_Icon.png b/Resources/Images/AssetPackage_ContentBrowser_32_32_Icon.png new file mode 100644 index 0000000000000000000000000000000000000000..215bff3366af643a5acd6cddcc7477a3f82b8db3 GIT binary patch literal 885 zcmV-*1B(2KP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vK4^8f)l^8ptNGRyz~02y>eSaefwW^{L9 za%BK_cXuvnZfkR6VQ^(GZ*pgw?mQX*00QMnL_t(oN9~r!uZ=+%hYvy!qHS1dJ0v9f zLX?HxBFaXzrScCTQG$i25n+pH5fUZ-0nri*ZAU`%-ia1G&$-{ooVnk3opY~+#Qh~t z&dmGGyfbHJ-g&3=->X&j`zLjVF|Yy#!#T*)N|;kuEWL!!b;ZW1A1sBF@CtrL?1WU? zA#U>;PQfzh4}VlAm3@S7QzQGSzuOU%JHOk54gu^e|?UH3bo9BV}%Z>g56~- z`tCO=QeM9bdBVdM7-oj$4!EA#VhlC+bq!p|Y%%uHhhZ1ORNrx=RLH@NV;gSJkjR6z z98SXnhzFC0a0a|B2S6&%OE`q}CgD9092tg&Oj{^YtzoFI;ZPWcP9QxvhSech1ic~1 zCH(+#Tk&#o6@%=v5Dr2bwlARGJz&DofqQ-n;tt|I?*bEy_5JV^yg@B%a|>;AKC8#v z2G4|{-US-eOt8~UI1X>JdSDAE?Qfw4Y=*dv_7h+Zus#c_)@-oTfpV=>>I$xo|8BJg z)B#*}b3jK8XcgGTf7wj~+6VfYTdq|pbGn_5m23HOQl14T5eCcCQP9`CaxGEbMO3YH z8WfjnQd1`ISJXU#e|`eq+f9|1Q=y6`&^r6|DQ;r&jnH00q&V%SDcH87zyvf-18S4~ zR;7WEJ|rK34@`4IFYuk`BjY_dU{45lznL-a>jQTX)TB5!gzGfs3YZtfva1k(_Zkm( zzrLER_&t#32J!B1=sl1tlSpIaHSC+g)a*Gr3qDMJH#VyVl}f(=GN&HH%&`t+00000 LNkvXXu0mjfr$K^^ literal 0 HcmV?d00001 diff --git a/Resources/Images/AssetPackage_ContentBrowser_Icon.png b/Resources/Images/AssetPackage_ContentBrowser_Icon.png new file mode 100644 index 0000000000000000000000000000000000000000..4cfe7c0e6b1beeeef6f1903e052611329d38bd5a GIT binary patch literal 7526 zcmeHMc~BEum+wvjge8!$gCGzPK~@(8K_Ms+_>@Iaz$co3sQAzaxUeWB%^rd*J{55V z0YyL21W~~!(m^(n-7W4!)*xGeAV~=icA1@68GH z_r|FhssI3h^Y!uC2>>WWL;+Yd@@cwl@e=ufCw6*o20ymj(h)^D)@RQN0CfHN>jhn_ zLtK&KN`c#Vk&#UK|3CldN8r%W$rL0M?w{Q09|WknpE_4jcH#JDl@k|NJrl|2?``p_ zs#o*B#A{vW)E2OqfkJ1plsaOBo4%vbGf&gpcPoTRk4#%UWIuV7r`@Y% zmbEhq01Q2Ry*zg%UYoq0!d|{Rr7hw7>Ku(0-%8&Y*Ei7cYscBw+wYn&qjWAiHs1E} zta$16*nib+yTZ*las36N*{;x6!_tutOJeR7bV9>Rz^2l22 zq}55Md%ktGe|_F_;%B{-2G6;jp_O9dwG}2_C;E6o-TY`PHMRkrOeAym0nhl+0vy{|&craG$H31% zE_E4iolIql%n1hC_|dVr*yVDSZZanbDBwps;snd+3ZIF*l~9b(DN#{WKv(D>QY}e7 zLZ?tgOg@}OAvkK9x=0L-&_FAk7D9+602UHMHFRk!rST5d1qizhbZtF|!OCtH97t@ne8-ZIsmgn8YS6H;Ew~J%G6PJHb?$ zV9pKHOEirL{oG$l&f4LLb}jyp_98}EHW&c2_$u0m>>NG$8(YCaL9lq z(8G@o!%^L2DldtELCtaE3k&16qT#jb8Xi-=myT?F6-46;_y?Q5*QjeKg*zHeLB+)u zVUT{GgN6~seTTNHu8TBpn^N7dTy%^)lXZ8y`>?KBDngkWx%>m$x!(5P0*xln=#`^%YFG^!0I-Xz8v z`>gNd0?UBaGUhHO#}^3h<3fgjlT622J9R#BHn%~s7wDY{VLPDQz~E!ooqzwseOIvm zQpm=Lh2EOKlm;AcCuDs2Cf_h0{;ci(a`%KzXXBr$jj?speg&U4_8toD|M{k+KD`YJN zakscCxKt*qjYLkwo^4R%07Ek&g?f!+0Ulpx81~@)TE>H=lrom`dWb5uiOS_Y63e4# zq-;Bv4?E(WX_o8QLn~ulj+oz7*>g;qGOg|{+26o zTFCHgp!Jbhs>ae5P7Kyw#?-wXxb79gE@Q>5huTFUraFzEoeTO8;i>P=_pVGcNXaV) zpXukps9V@>@x%u|Meu=0WoSdy7k9cf4+n#lT-2zp@$>~Js9x^Omb5%)JK+46%i|k7 zp%rI1{t&YM9)++(VlGFwF)5+oYb2icRRc1*W-l?URA*;f$qnm>F7!9Q8vb^IE;@Il zoaH$NypTpiOkNti>{+`h=eIY@e005#<#`i*XO0D0rKwKqKWi7R5j^aU(K@?wr_hOK zj5n8G;SdwK{rUZeG^sN*c(4VTvpRIyFhwg6(-4DsKGL>aDc3j!7p3IY1-I5>?LWED zuKGf%Bkn`-rn*QR#*?Jd=#5O?0DZm1Yf+rQb<3&Ff!D`q{Uc52PGIXGE3{^~IcPdA zQM%V}`qX6@fBgNS#iqdfUnhay8lXT{lJjO%?~+I4>3^)JuQ)n3Zrq?bvR+9^+0>Y0 zE6*HU2+0bey{L1Tqfq89G;Q+sa5J5evO;NBgIUVXXQoPoDp#e3H|gmSVA1S0ih#OdH%PGq%i$_y#`GDsHhtRrEW2 zpsZ^!Ch06$Hj|VQsURk1m+hy9)zqpt|Z8%X`Llu&IU1>_zHRG*xlA*mB7$}H;>h8fYS~I76Ds|U{a@&bn@iwUo6tz(!U*Bj3?1;aEF}b2?r8ezc!gD>!>q5Ptf8Yd+(We@ zt|_K~yAA!PxFeahCPGPwm=%@_5#^vwHqjvVYwO#RdB5#n31O%14Ient>Oma~6&+5! z5F?tbPCi0%q8}uEqT(2jEx#Mxh+aI`MKL_y)u_g(w=`>dyu=@2;Z%$n;Km~J;m0pm zewVg{Uvhs71b3WkU6oc7b40%FmG~aIMlS*ZI_K~mn2Nbe+4<14p>g{4@oBY(9~(2=g}r8DPbn*8atRRZP-sgr`94eNXj)V<58(*<8j$&StkCe)xC z)x`%0oKA|uN$2i%penPySO@Ht9t?D7tJ8Xi%YN%!7;48c2uqf$ znZQX|#0QOoJ~-Y(SHdX*r<;P4-Zi=i&Xo6Ou(8mnL$)lm=mlWk7qfX6rgx5;PPZ>O z3e@tQ8y!%Bc~u@d!Gwjeo)1RUcfh{V@+{bgZ zOyv)doO4Pbj+}@ z4r#amL2g4_m#9FZ1CuKS(6owbgzLV^&l8;ho67UADfb$Rf1E$1Sy z%A7fUy28B;5m%d;4L4j}@8%FUA*|y7;pMLCKQhk3X}bwt2>ZC)UbY2E_9n0y4VLG| z20U9Sgr``M7v+3&8i9%!w5@fW54BzY!%WD_vK?!waMXo27T>2A8Iup=yq9kr=qiw0 z3(%~RwEi)k8QHN+)*9Y3)X{2|2S@zcZ6*&8)a?JF7j$U;bDd(M3eYe2iyZrqHvhVs zA?6Azv0>$`n|wezJcyV^TyjHQI=u7|ug^0F;^odh;#;Z12%1O_gBsw=S(a}#_C*=X za~enh`E8VQ?~PLzYGg;*xL952k^E}K%xlhgRzEOX1C1->ou}g#hyb$N*P@LS7{zoP zmk8xIC_YAic@Q}yjTY&ETZK-=#ykrk8_~4E--J#KW8QJ)r$dyco7li|R^vFJ1co9& zQG*pA=ray1Mz`6^uegv&S}C|-rBGGQTDjpTqAAkFUGz~0!+vS>9VUd(%xmgwZ3w~T z4`jT##PEVT``K^)VvnhIeKD7(<5|Uz{+nV&JyU0EnqHJf^Kwmp7dl~$sV6S)d<82$ z#FimMvLDn%SzMyyya)mW;p)+Uu>$@SbGO?j&L^N{$>O=~WvtXG$RB*&C1001cd2R- z-A9VY0-GFVf(U6&wuP$M9;64Gn?K1lW_z?^(Q|s^d$CvpAkVrl*TIb z`=c9X-kvd9PM^=q%CiLBrI{rzMu(UeKaV=3G*1TL!DaMd#VT6d^y>bTi|1=(Umcx_ ze4!JvcatQYu;AI$>+qj#HPH0g7VbC4Uzppn__g2`bq59#hcr(k8=gtTi`bqhJg=5E zeSp>$)NGFuh@;EnNxaD6nEs8ltDex~g(Q<|;voVsN+H}wqsr)vzd3*@M~9;9_D|wY zLTM+(xEu|=w-(hb{0GUvn1m8;V)3)A(kTGqbFaZiCM?r|Z9gHSFwec1s5!1yJTRfT zV)W~#c&*tWPB@8JPq}I6XN{yK%`kM~A={tH2BBfIPW-i(6>G4)T$blrATIpjILid?vfxD1)M%?D zY#%a-O(QVDy7Lzo8+7U?I(yPfI@It?C~|34)UUl%ItMRE9q))zCO-eX_<7|v&H>YJ z@*d3WW6qE7C)mzXbAimIE_AN-YHH6xOe~r7gk~J5gufre4!<`RZ8*ZpuuIw0E=+bL zlP=H|NJ@cTa75zp%I#O(8njP$1?{pqg3$xVBp1VtNl(4nnZvaPwFxP9(kC&+@GceK zKmvY*^1UC7>|?o1+Hs3bdc{qJx%BhGE$jo^;22%a0=N>4esay_r0B*m7r6SBK!shl zSQ#D-J1UJt9-Xm9&CV=1LhB_uCZgk`SMAor*QK|fR`zbv*ghDFA++{)0kiyoxKHnw z91=WUO|{kBd(v%lw{qaPRhrdcObjW5uh;aw!KRgti&A{w#`Ig?)xVGv@0q&^~$M$?EblKi6+j>S2CKM{rp)SooMInYRH`#3PJt@DgB>k7%Bd6 z!}1tlkrYWYYXTU|a1`1>$I1j9{H z;o(WKP|zz~5sY%_ZmK!zBU?{dt*@Ry>U@bR+UKsCc-E_j60s6GpoB+nNH7~JCO->-Ot1+8D*J^c%$Bi(&101DkmAx5XfQan`dg##RXxU~x@PodJC`&NU+rr?j9PM0BVbWu4MSd?7+B%|{&Kb)ZZ{G$|ip#p^=ph^S{i z>X4uZr6Qt6`6z1vZ`uGZY4aYt1@_w-)zDH4fR~E4VWN?)5pQ7-bY6y=3rde04@p#p zqBws}o*&luCfYQYE?EUhC=~&?)(4bL=ps!u!IbtX2vemnlJX#)> zy5%q-^gd;|J?Rp-y#Ko%XuDdsG5bNSICBjIv^?bI?c3I}TH-{6(B8|hx&7Y#B9lIQ zcXB;l-Ha61Swc&09?bf65OZ*Dv<44;DYiP?TFQ@RBcMMOQqgB(0qMF9DD z@CpO4^8y^bfM_qk)eEvDl2i$R8i8Z@KTws(1TLLjdMaMW{RYKH5lS=H0s2J9i3k`I zNm_`C1+uWzJS-_2+v|miGDAUTs8DlMuNi6`0sM^tP#M5`25^!A_<2FP#QzOdJGHRC zEME8Da==!hFaSM9wTAvzHN%;7zFZ5B20z-83)mrNQ`}P{lkn2+zg2`R|B8sG$`$`* z_z)BlTj<}7&up|+2(9n0e_n#p?&z4kby$$^VHl6vzI_r2 zOY^fwS+R3XZv#_(tae`r^%PsC%+p!A(uoNy)$!B@>&q$UZvqOzgkDv==F*jo3V|Fw z@IG)8DIEf#>akb_fI;)Sf|53RK$9wLECT~DXOV8&)g{N7Y+PRq?xn{K>;o#|ud`{_C6oF94% zH-yDp$|p$F;kXO5?18o7rf-k|2OvUNX;44Aq5k>-mB6Y+qmgf_EFz!_I7{AyrI-(N z?@;*QnB+7vRT*cCB7wc-9$i`FOXgF?yP<)Qgzr;u>n&_4rj$WziJf&Te&)Tr^u$k( z{4+q_F#-uo(q3ZfO#h{JO8!B4Q-Z@qu!xMeMNTwr-1qEHI|B%r--NFg!c8J9uaof> zz(JvnfB#RdA#`gAmKUor~*Gl z7=1?}(8~^G10F|aRt;nplY6a6_I<1z3yA1X=p0LI_I>IFTb2Rj3L=$U&*wJlkO<}2 zM7*=a$<{t4pN!vx2$;aI+Bkdh)y!&rb&ashT1>{WYY&o^lQ}CSPS-Gj!o_^3rG}=J zrT2_Q=GaP{)D!}R_p$n0;jHQ1Qvn3QSsIQ4YLDrG{d_JPuD8}}L?AJ_oYJ%(AT!Av zcZt*8FzzF!X(pdrL4=5TL?5JKsY4Wcid+~djMmg5H9p2_=F)I&HXm^?(Z@mJbVQ|; z7lb*2bkVj#n6ZUmv25u|g+gGnZCV8q<@Er$is*xwo`NSK95)4Vo`SLBGfP+YvBu5; zDicKh4q^0ZOH%3{%o0LxPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!TeSaefwW^{L9a%BK_cXuvnZfkR6VQ^(GZ*pgw?mQX*00Xy4L_t(oN41w* zs8&T3$B!4h6kfwynwoe^6BF?UftEg$5+WKssfZSoB4}8N2r6mzASjVyWKb_b2#M)~ zWuS>^7rY?ekTgWYOdq^prK0|R+r19+ZNBrJb3TuM_?w18@KFE8s=7!cd;(lx8QDGzW|NZX!r~q?}A>1in602a{|u5A2~YUI%tTV%u96vGumY~Y+fbsS0WZLWoR`4~WDFGZhR>ZaR_c)%0s53$ z1JNFRaB#ZEQ$n z7#Fn}?7uy$q2dm-g*U++D9Ro999-FWmk1B)1Vco z!{9g#>S04J``G>sxSPxJ`iBte3hs7hXfbEIn(x4v*1-bn--6e3Dnl+?MXm@_+tO!g z_}X4_S=lLepc`z1y=B-5&w@&iz%ABj7t;a$1l#qMcs>M_o^R;JSjql`0Yf2uSj5;@ zFTn=T*myP!)F9BVe3%F8aH?ZyvS(JIf@jpX)AE;tj zDkrtSmsG8a1}Hf4T%!YGyW51a>m!<1g4bO-9Yj#Iql%4sZkXV~X^m;!aGxC3=v$Eh6SM~D}WpK#?g z8O#MM!7rhTa-v7^fpV(qhe=baB-dBc<1(PZ?+qU?(HQGZC4Zduga-XMHEC!>Q)8&s d^Ygr><^iJ`Xv8Wht4sg@002ovPDHLkV1mA#{HOo` literal 0 HcmV?d00001 diff --git a/Resources/Images/NativeScriptModule_ContentBrowser_Icon.png b/Resources/Images/NativeScriptModule_ContentBrowser_Icon.png new file mode 100644 index 0000000000000000000000000000000000000000..cb1210387f0b7e06dd816cd3362bbe39c64a89bd GIT binary patch literal 12233 zcmeHtWmHsO`0klu#$o6V>5@jeV<-tJ1*KCYL{g<=NC9b)?o^Z#Bt)b`2>~UfySsbt z!QWl$e!XAsy8l^g-m~Y~&w1W=-m}l%XYaEkbhK3Pac<)P0D!Nis`L;5pkNUSU}J%Y zwj$PU@Bn%7P(=aq_Xke^_yg&pYWMi59ct$TuVekOQ{-^fO*8+*0+XHW`lM1*XANgr(9{q^Hra{YmiX7>co9gUINW`p;| z@lM&FW3`gx-~Q1lI7@qYvK(2q5FDBwlXguK@IZt8C7`^gQMK(`BHgi}7w zh7lHjC&W!oC-NaVQj-{)nGMEo!l<{_0_YFqkjbyzvR5ZAM~A+7PxK)VdY16~r_*t7 zuhi3%&8*ZJhLid2jMTrqRX)q#gbrlCE_1$=qIdYU(S3C~+PAIzKw5+m^3}gbQPWH4 z`m6unO*tdt$6Py&g6mOoU>%sH3OO$kDsUF{0Mv5EDF+v7f{-hf#{`kh?@Nj_cg$=X;o&`*| zt7V@L!`xVOQxYlg`@|gC{89;t-uhR7A<=u+G-MD7Hn#Av=Q2CML(In)7ibm{n-;6GZ0qeQM%9JnD=3suk@ zngC5C5Lk|bcDsBB=$yU>?7Ga6K&Ueg+WQ|+0IdE4?&6>={{cCGLFWx)2Z^@-2V?+a z|A2BN+Vvlh0vPbq> zjrREmgaD`iX<(z8Pq`sEyAVh?6__Nl>AL{aLOBfGx&ddjxuJSC0I=vL5&-8eCHnoI zJ`^=K1tk)_RtGq~83FVE+<>ie_MeCqB%Jo22se=XPs9Pv=>AXSBLIv2Cqj;1{U?$M zC6fIo@(`H+7l{~7GycDGaN)Bt|0sS?m!5yJk`SFm4F2exJ=`8sPc4Wt9=g%X|*`BWG>2 z0bbO62mHg}qAz9O75zHG(e`cR9iX8yishU-`n3Z_RJcJPKg1Bw{th3>d1`yCtgmrF zvCb4Oe@&>hN|3w7k+5OQ;AZ=fI7WhEiF(rRne8Z|pU)P#c__ zRCg^dJMG6yux%aem_tJKSd`>8pawWWs7$FaoD%B)ZNI)B)ubfeA+ahp7+Rh&oj2EPu*cm+Wnr21nh=(0%Nd$@LKGVso#O_}*P@pPl;) z`|}H^ZqADC9E%~ z^S2@9NvbE{zH4ni>81uW+hVUJ#w_sqxKlgswWMOd6Fs+?|_cW9mg@oumO#N9o_L>Pc zOIt%JvLA4xkf`4e@4FX$Yc1czY+{;s5Z-bWNBu=HbsPK4^73yaXVs|(=UGK1av|yf z-a@t?;f&qPa7--LBgONjg4!-q+gKQWI4x@Gt~Z#nil~4VC7_7`n;gNc98`qgf1Ta8 zRYi4P_-b6G7+8bH85Pk@gwBa+Rdoge@r=eF+5#$$xStN$r_F!H1qTTc$NcF8B80aC z*?MNFz!)yWW#fMB^UNVTa>ja~MCAo-hY4os)uw+=Ggo)!Z8erkk${3)n@wE;P8JRl zt)Ji^yZ4KJ?vLH%ga_tc)9YB+nb7s+%3cfk^OP3k2RPBg!BR7ca!Z@=DsvCpo_9_` z0a(@)==3fI(wlhe0=ZFEkPsf9kw*NS1yq45kz6@1lnZ4Bsq?!OaAkbRstS}3hpK60 z0C`~=VU$Hr|L|-J=_v1__2+-5knKCx)HfXcnP7y66QiER`Oj;9eTAzIW&iWdhgi0j zEkStd$}DwNoQRWz6_x^3!nWw#crsvH3?rFgUU($`h|O;!(8L6+7Xa(ypfK#&)YZxg zg1vla2i5}m*eJO>1WHk`2&N+vS0TRj4#2xJ81om@7AxknnvKW#Hr9zSPcc%jE4$hmc8E>s@jNX zD4L_+E}QkDjoP&J?HxsD9-W9;jwf0c$a&)&$NEPuT1y9oiBsT1WvH;2(Tmr%i)ndI;|NRB4rYu>%*G~GIYSjG>-{w zxC}{kzRGl#oIEJl4BgCqby6vnu=TaBY}RjNB8;*i*uW!GD`e9dRmR)m^ z?>Xi*=dN0AY?#&Oc0|Lm}H15o$ zveRDo95bKdQccs5d(4wG%lHovgv0%o32-N8T~AQOFZn+(X|5U5-1F?0(#!t(^RR(8 z<9b4r;@d|HtY>eTk^uraxT87G#YTmRh*cY5a{}U=Tn*7KNPHT#+a(d1$#PquTyJp2 z+*t6XBkS_)NvE?5a+YeLF(sMmPVx7yoP)Cy_WGjW@eG%^vM&wV#P0k`$9cy1*uIR- zUyOGfP-FU?Yt8qn^Cmt_p;Lx~opj^mz0+u$n;-(l zQ7eHaP|u;pbgp>cUYGkL-~EG3?!2ysJzl^E2GZVfcZu1Gn?# z6d%;;RoZ=^X2t96J0Sr}8JjpAVZ;{Kt5l4XP<^819ZSj>X&kOw!t}r7-o&(uRv`*nnkp_LPYWzolL2dn zO6=C~5Rdy~+cxb<@E0Xqzn?}!4#F~XRyXUTySIGTe%Qt~HzaCrmBhbi7%E~(M?EvJ zX9*zeqS;Ygo+iipdWF6Ck-ugm;Tj(sws7J?ruSuoB|rJT6S7QWv{=DkT(E;B^yn&Qs%Smwq0R z();{f+wxN9zp6+w&xdGI8eIsjU$2e{FCfdp^DT+VZy}|>yuKr{Mxh8WW>*i}^+YQ$ z3tC{=r~la)y{wY#1=`=HD6d(d2}}~wztEHZu1bnCKGaJ?o$+m*d+%u ztq3SIacmrC?dEIqt>3l9mi6RI2hhcC!P|1n+cCRXJtB40G@{jPnZR?xAPQfuM?`Uv zosH<4I-=l-AtdU)1X?V-Z(;swdmEcw-&;{(g8C73557o>KJHP>A$4qm*EO)1OrF5) zbk7Peu;Hv^=w*FcL1ODkuSKRH{a})*gkKMOIDlEs!QodQ>*^V3$*|}U_Qa^k#XE(- z^WR2sxb{ZthO731u~>iSOY9LoaboY)I00TaM!S=K*|au`EbB9Mbaowu5pi7DJuQgc z)-jq#w8>{|iq4XGi?v&)?i3%zqy`5je`UQh9N&`3W#41S(GWY84n6DU0=BwT7z;@# z8QeTnRs$W|{W(dii#SVx>hv6!fb|QrTH$Ya)%N&;kY0H+2*4g>E(<0_M{t4B`e5lg z;JmHmtv+DXMH1IkfH`#gvp~G0da-4++pGKxVpsbUz;Rru_)w`# zh*_#!`~hzgz91xwGL$|Qe~riJm1^fM)Xj^2FM!U-*EQ+igrr`Yy*>-uD7$^jpu%eqiT$O3D)604&z$u+`MI9 z6SP3wD{H#YZtP6}an<{6hKf}G6(+{MmOa9c&Qg92{RCr4ch+D;9wjdi=tyM=K3?F7 zt4s)v=a)zOKuy)S`u*OxNuuI&<(_Ot1p5UWb@g?)n^QnoGqV_`juqZby`q{NpH^I6 z6|x?lA&Y=+Zx-ICzC^TXeQ9rt?te5{U2mQ;xLz~d7))8pSt%Bb@sY`b?V!DfPK} z^@{M*I^Cx(q|`LcI$?T2mnoc1LQ!`UITqZHyVn}!op+^g{71^uoYb-u@&X=Gy>!jC zsf$&Edv(G%orIGjJefA#@>VLM$Ku;9>&?7T*_N3<-==d^x~J1aWL#|h{id zDA9+evH?#mnNQF^xh1`H?-+HC7!W$*n|)y6AZGcyS?cj2K^aml3nve5jo_P1xZSE6 zj{Jqv@z%k9UAjtVqL>m0VRd#n$X7^~$7*1Y$9?ymx1?T&+Z(YUM*?TV3Sdn_(pzkH zb@l$qU9>|DA!Dxa`wa%A3{n6_-R9%9JfoiCx#C5^`JzD369pTZbmE6k!>w9xGaU!` z>PmMR8$<;qp}EAAsOTswRfWy2bcjVcyN4=HXAA# zvRxB-TiICq-k|9gE7*V&Z_a?j4~22AR(w?)euEMr<{M8;Xs3hwfO?@dc6zi_f_UiV zVf+;j6&o{Pue@Ucfnx7S<2?M-Cu-qmm_Dv2anj7Tnk0}CxHKXsUmvs!x=hgrkbPDG zLGMhk$9p7>dPqgwPAXqb4d)`dE3M8M4K4!o%vvvq!0Te+4w=;aW{lZMs~k||cvlV- z&CmH{CVUabkW{2)A4vkOX3-nLLh0c0J+4bCBlzlAQZ4#HU{6{a1y#-fljRpIfqj7uhcE z7O<_H#vZaR2H@Cw(Fm-FQaC(PdIpn?*eRqZHOPM+~tP{LwoOZiN|V_U*>NS z;{1aPo~=|m-`$C7@@?nYoS3z4Qu}mO6VrY&NPQ_GOO1vFW_i z2j^#V)0(&Hp(t?C;NF-@D+8*e>FrCI=_>0nsl+Myynkf9b%O1wM(wyVxyU{uPt`HW z1`@PTt1OAX5Ne^cU}I04n5i{Jj1wXbYKM>jLhBT>rKjDjyT$8u9>c70bcB8d(U~qg z2@F_!#gW5L7^TdJv5f-XsSsqh&rgTa5(ee|=Z3+V>zt`2*B6+MDO=|pzs~tDsAqvE z%XjE_?^qj5D6g=f<&n+QmJA<8#Kvk#RV+_vi@pV!6Ko^28MVNL5o%W&h3R&NpUv63 zxa}v3j@Wa}x(sU)zFM_Wx+(CvQu)(OE(YnIAr{4(|WKChm`^2Rt+p zR0VU{?ueT$9H?Wl!Ps828?H07_N%AR(Azr1wkFhvyg8Vu7ZJ3N#J-amaW47OWyWGx z^5HYf8A+;nM^tQBB|VadF|2O(_hR_qV1?UY!A8>Otm9sZ+qbAspw<*9$R~AxbuGm( z-)k`W7?GfR^<6&IE9_j=0$dS@`E*^Pv0UbH+#E$CTslICmh;>KAD7bcupq_yLsYUuySFf z<_oW&7f;Wr1fnINKOQvJe-tZ-{Ic+Bx+O0`IeSLy`iDLLJ>So(wLb(2vB|&KkAb&S z>rjVc5yTHd9lAC~Ky;R>qWlHybS*5Q?@zFr`K_u^T{*O01C&IGk15))`=lC!I}AI? z5Yo7!vYaD=%Vwygq5V;1kuF>6g~I8UnFvAM0m)K;Owx*U*n}Wk@!1AnFU>^;I6BNM zn5y%_tY|2Q)n+wwE(Fk6p{R*EJMebJttPltXg}tyH1=fRoRFzjFEHRZ0_+BzYK#qZ z`8UQgOO?JLj9}rXb&>CntLecSt&dyw2X+tU7!Ax)XmVr&u^XR(Av>&-!72XDj*|LHB(a0FzY z(Xn{+*=o{V%9tjCqwt6xl6OgReq#cC;P6`y%j~dm$(5#H@JiOi-+RE%7P`FyPu7olviP3XEyJQ zoqoki{}(t|~Z&dB$Gfi+DS`@*YepUh&9I7}jEM2IXIx3e8DD2`AInbiOf*<%YUK9qf!Cq%*EJ;-E6mgFo>!HSXcSFiLxGM59|9^}5O8 z<5*HJA+Q*$8y9+XASIQ6>qRzJS&?YneC?)b1Nmb{VAOlvTcCN@ZeB9bsV=qRsiHkR zN1GnOx$G#0rXAmEDa!3%X<~|dID`YZzjwV>&8nzsKzEo|2{Qe?_mmu!?ilw_2*ba& zhz0pJr6U{h2EwGF2G=PUv3?}-#4%{Xr?s$;Dm>* zL|XQdAN{M(;en)_@Enz(yo1`sRAK=vK+nlj1`3C8W_!MlO$hjGJ ziQJGVsNETL!Jig*tBKEK>ld83hcX|dTPfpo0DbQOY>s!X0q;S#U1DDt3zxN8i&4qi zfIYjs?u7#zI5#z$_a^G^9_Kt3cW36v1cKhgYb7o3%Z`lvmZFk|CE_8o_w*zo)zbu= z!)q~O+Q5NVofvCc;4e?Ebbv2tdsDArU1RZGXxu|&lLf)9>K!!x0TbtlB6l#f!wh(? zyf8ezdZbtnBeKS#BWJN;KD>=)DkY|g?}%%W za=2b=V{TyZt+rXElUfmTaWd&$_0X0a3z28}-$XS2Sfb47Tul z6gseSwU+VfTuYK?Z|s-hBcRZUnw>vE1(+BIaForVnI*=FhmM2EHZ^`}JyDW3%OQcC zJ7H%eNe(y$(~+Y6{JgQiu?SQ0S_L8z&$`~}rNR5@sM(({P2K9;C#Av+ImVR&3A_~V z1YIC#o*C0a01XQC2Za0gU>x=$_UzEKYe}7kbyPv_X7w0X92eudfAc`354fxlp0|xLxS?XUD4;H;k5qt&b@MV7J%+^OYkQ&Z)0~$$Z6$lA8VlpmisY& zxyEjDgaPhf+QZ=7_(*Wn!LJN0hbE3okYOA*C~@~Ad$Z93uSQbDa( z)?jDy#3uMtW}0a$2P3lx&MA{Q@K;S12T#&o#@SNzWPH8t)5RT{EVrA{L?F8sAfFJW z{eTt;ID9Qi;faj994(hVm0DSA4L8f+TIEItoxN=wB?L`vT~;;qK% zikc?hZgK+u80^aiDhta^eBk5ixe-b;&L@TCBlcd9|9yK0yqniR{(lp4Yug9Z!b9wC zv;~~8tF4WK4xF1G%UOS-_|b8(w=-jHpfJ6c|2vq-_ws>5;5X>5){X@kapgUa2Z}MT z+%L;A32j|eGbd;;vbyt_=&y>2gQ9e`b2G^5+hE5Y#cClwrfA*#J!l4)sB?;If3Ex^ zvRO+%pMaklk4=xeu1Y5g^L4n}G3Lhq!2wmpJG~V1X=ju=qI0u=!3vAe_{rEa{O8Yl z(xu(60q?%Ur*^zX;E>W5wO|4Fof6Q8yz;4ZB60pke&U3CuD9p)d^_8L2F8F1$4$`? zNIE3wM14f}?Dg6R^~tq1;`Tgzs#?F=A$%M-wzooxt_3H9DX#d^gmqR@l6Ke)Ot-G} z_?}XAM>yfWY3T~^mDn`O6KM=~)!~@^Emd)Z_2iz_)=SYn>l}O@KZsG{qUv+a9Sa`I zC)hn3K`AEzbsouR%A`6*UyKBNwsE?}ptav~aYO{a;T&e1x%_lZBw?&{oi3_F2uHPD zEB-C@<;Hua*rr#F!Ihs3v3^!{|By;)a2`@6e3>)P=Jwbg*9Wn%8xD1eXB-hH!jIdl zt?}T$rOg4@ir3>vDUw0$E_rw8qO7CkLR+|L>QsqTXt7n_{6dvMKYJn?=KbN%n?ErX z)9m~rMz~xq9T4!be!){g5i1xOANrWMG6I>$kl2!+8+4ogaE+D>m26~nvJFi7+RX>i zU6W?j;& z_Fx1|1l7`vE&QfHRH9n(Txj7jL4T3ApW8S{%JgP5??Yd&AiXb|`3 zJHZnir;66RetT|mj2Tm>v-$hxe4M#tFPU8qNQ-O0ySVRG`!xRX(O^8IFD=K;nd^|= zxlC;}xDz2qfHUV0*73!r_~s9j|2#E0Ioxv0h`!kp;+FHc87<<~qI%gc`>&GgbSXzB zKFK>>viUtMPEpl3jirow4}Ri)nWnYfI2nhru9=)B!IPIlo2HLcQ=qCBn-2Z#9TxLE9?S{cpzA*QDAotEH~ z2-VO$d#^V71));#&HB=|@CueTc@RM^Zc}@P!YyU(Nzo4XT6f87+mo*^uUX5$c^1*p zY7x{py!po~vrb2)HkBX)Dj9+c_nl*!17S)bOH=!8#btG%^Ri)Qx@vU%RE?f#HsaD2 zJXi3n!*t7GMFYN~eKucN*$zDgxQ8YC03=R<#9iH16743vVNy|O%xRVfzf7-Fn~u$- z97;o(Myi5-*Rm7Q7`$fbP7^l7_on&{La9E?p1CBq^?#$cbp2fKyD^b;&=;xgvSXVc z5)^e|{d#=xv3>thMV@P1O4h*KoB!OmA?eMT-$_JH@aApcXlr9OPYXbIn@(-QN^4(b z%V#xOC=Fh8MQSf&9279M(|GbC|?p$_P|}IV7GH)rba91p8=uCa1P)5N0sMr&tozh`@vLcYx>vr?!{fjDXM$ zc|}wslnlz>0>Xh{_}xrEtPkQh%OA%Ss2Xh65R6Hw0lzI?8OQ>oSNS%4fyc@8b|y8?4dFQAlp_zqTCVzR+azjLze^0<&?9k zfsy^cos!<64mKY0S|wS64G8zcK-}K#po~jDaM$J7AkEX1DL5x`SUY_RF6Dh-3i8xP zI#Q;Br4QThj;2l_sJ&LB{>p$0(BsAFQwZc*#Si1<>8}*Sj_?0w#t}Mu-RdSryNj)s z{B4Yjmh$-AyR9Jm7doJ&oHB*`Lmbn7V&jpEriCc=I@!C673584Bl@-#m?WSB&qw_q zc|c+xlwAnlY%q1gH2FI}68J*1KZ|J^HzR?5e#;KPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!2kdb!2!6DYwZ9402y>eSaefwW^{L9 za%BK_cXuvnZfkR6VQ^(GZ*pgw?mQX*00R6;L_t(oN4=L>s7+BEhqs|zDVb*;xP+oa zq9{-1a7{__pgi!55--Y|C_{N8p@>LidLmvtNXZbQWXL>+GJe0c_d2b!&VTQ7&OMi} zzV_PtthLwwta*1x{vR{5>$~jgXrEpG6%%kknoQ>6&@`Eh$AL-|1<(#R;x#;jBe7nV z<9h6Z=kW`6!hPri%VjhE34DaBaWK}yIJ}4cJqNHW7NUr6V;F$PRfC9RSam0DP#~xUO zS}QE`7)!)0plR7ZP1Zy=?3pG_mSQuu;C@th%)?#i24TDo{6_V$rppI>ljB=_iM#O> zdWPUyyz1`KW`2doQ2+iU-p3iJmUxD3MnCie_n;m`9L6PSvh7jjw=nE$D~PISk=TwK z++A&0mA5*Gz32;T(W!=2`RC}q<{&g$H3)sdr`Uvf#FeY!`Pdh?WY4@c1raa3au!-x z|NI1oXqJS(R}Df_CoCZMU`$@0-$gCqVj_OSI8Sa6TFpLTT;Mu}6b(43X?O^==Ucx^ zGlo;np-+!4zDEYfzhy3O9d&Z)9r3&kU4TLbH3l@m8dXQKGIV;eDwo4i zs0HG=-CDIPI{bOyB0fozW#}OJAWb@cWY!jNhB6RrHm(GefXR6v8o>W(7x?V#X7E@9dE&ms;$ zXh$sdQH^L?S$xl~xr71eoUbGKFdUm{1!$3%&#yC8(N_E%+nw!h>mu zz8$Rmr7<8Dqm?Oi6zbo64W5Onzb#&%m0uq=4!u-gK>Bzn;t1+x`qPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!TeSaefwW^{L9a%BK_cXuvnZfkR6VQ^(GZ*pgw?mQX*00HJnL_t(oN6nW@ zFT_w7hKs~42tkk#!N$sh1^$5e5iD#h1v@KSdn+XV0t<n z_jaw(j2ozPtt${j!832yD$2koUb-!xN`I@Nu+6(~wcGMBHE@B03IrI(A4L-b)zqQ4 z>(YV`zI_T9!fK!w6;I;_Hljftc*VS8kIFy|&S5v|`?%;Ur2xdrfDJ-3V2Ut` z+7y;V)DX1eK6bdRWM~K`P**KNhoD#n)G_O~XR+H*l$^>C%#|DdXAzci8zx25yXO5w zw_&*^q6Rd?%77TdF4Xr)xW>d&u?=EppdYn_CPfb)ciyf`tPJ#^;%R)s#5JHFu3(zQ z=meKh#VGz~4g9tkS?4c1@QBK`o(pqC)qtL2XE9hrY0 zsAY5#HB9AHOZ`0RoEZg%P^*^qZ%{9i%76~YdyOhU$HztgS&wFh9Y&WC+(iYA%0RGP gE;TjpAm?NshW|EzfJyO}pnr%kPnr#%a$0SSEY+0uwMTm$9 zla!s2rLq5x&-eNL^Lu`OJ%2r3yqN30&ih>Fy3e`JwTU%0)MIAgVSpfr8H3g_g&+j@ z69LiDfL|LyLp$IXy*K)XF9fl?Kl*{YyozrD;z>VUOFuKO+kSyJ?>R$(fq~~;Jl%Yq zZhAYP_qul{YekI*f=)pg9WC>q?B$93jUpEQRcj5qThzTnS0CgvJ;=W*PA@|r6DJ*) zp+wE$V(cBm)}a&{8=EIBt(A~>T<&sV{sSh42QfTUF*qEP5FMSIQbf$>3C*t?-p%bA zTdi9}{yycpvTMw%tM|WsRSRA%@edqU4#}}?-lDV5xzUQ6-TQ z5DK$!iV?!#RX+ZI$o@4-bAhT||Dpclq)bfR=_#N(;`hJj95J1SAVsnV=`zWc84ynr<%!J1`^0A4 zCSo0rsvG@DjC?%hGD)+GKTr21r{wdAU?gSJ52E_hQ&e85jKP#+gNpN= zga^(7-fUIA4tDIyeB4FtzQ$cbSMfuqcrUC~9qQ;3f5O}Kz0a?zxk?W#L$lOqJWT-8 ze&9s|Zu+|q-fSH9VuyqDHqYwg$EFc9t2hY+&Gp)KdpNYL`{CjaUCgurRW6G=y;{PC z`-+^yM9Sfzw8H`Vhjx=#L-CHBNcqoaNGz6)()|&eca2=v1vi|E&WA{KXUM2&DuBGOX7F@2#-Udrtg{F|-n zVk#SPoyuOgyw&#BsB24x(a!O0SqX&~rP;b||HzIDZwxhUmySuCwhzg(^4M9(RLA7} z4eg%a=!)M(_cwXk?AV|2AHO*hwmNBO)oWOm1@GZoJoclm93uSR`3+tet}`E>PvT(2 z^sjoFF4#->k1&x8|F(G@E8md18}oR- zP(4N}*||{~R71WNU!!uo@ew64yrwZ$Zr<3`&iCwr<=9;tYo8SZZ>sxa0o*~poo~us zC{VX)X14N9y!poyk5;`u>?3=ulfIb;zA@n-rI%9#+sgi zDFW#NL-$DN!BopZ;%!)L@Ris8ug<4(mAI6J6?9wzbxZTiUJ?G=sr!QSXJ3?|bAl_k z)s_CLzJ$8qe&K%KZFc2~q`eP2e>56q_J-grv!w6)%D+Sh7b5Y0Pu9`}W%#*CH!$N0 zab8J$!vAJJY7^fO#!oG#Cm-_doHJe8dpg`l^om)n>WSgS2p$JxZW$6;PbO(l^D%{{ z%Kdv;+Mg?|Go5kxh|N{;OwG|Da+K_xg5+%mL0ro#|3pI&u)#c z5RGCE_cA2HuUHAS7Bgdn8K*?*es6+voaKGi*_rG|3hZdVS(>Oz^gKCcWV(Gj^_$SA zIyw^$X{Jz4%d&@C$qZQrrDqDK&Y1WJS6H7Op72E*t?6Lxn0VTufKQX+rdlsq5C6m@ z{$gk-Ak^^bW_k$jE1Sp(h8bTOzDJ}@we4tnCpt795=^|Z$l$NqM*>OFP%H1pC) zf{0Y%6q7%F9z*hi6CFipEsxQ;^K8(fNkpH>fr0T$Zkhn`p#uE944Q21y*rn_`*4PsgLuZ@v_1o`Hl8wHHX&* z_?WMYt+dF#LG%v?sU^RnA+5tJNO0C2;irfk%?lglz5nYfR($ z44PJ_bfbT%p)5$^)8{4?J|IXTgx{FFf%Wgn)Gkytk2>0u3a5QYZys5jWD?st?B{G_ z&tdeLE62Y+OKEabaCx3R_s`w$2h%ItD#;f8Um8_5=BuyV3uJh5O|_q{m}Hd!k}<)9>Yu_SFReUs_LF7miAi14jkX#Q3!o zE&un&UEuP$e>M}p6nIp)@>4JkqbvjTcTH&#=@74;n9$QD2Z!A`6psTfiDLl6^bV14 zSD#?0ss24jj;%_|PslWuCCM;fizVLB;W#I>`S;Zv_0VhEh}G0*YpgZaxJ_~GL88>xpeu6OB_ zkd|U9tY;&+9A-6Q5^%NvJQ_?b5of4LHO@n6m_remSYizG-`as0G>UY^@`u$Pu)|qP zl^AQ~Lph~m^5Y)}^v=7;m&AIVnT?!Kf1A{K5)R*9M`9gc~A zL0BZY5$;ruXxna_{cCTX$9F2}<933t?Yf#oArJ!)zc3$96^lUs$@mV2_x$# zZ~R`3p!c8NKe&E%18W7H_?J%X_gQDMxDz(mI>8tr8R=^xeGWJEl(N&lvOX&)B@*v> z|5Z|+W3~1Zfvh}LY z!nen-BkGLVb2JYYfBvGHslGvf-%nCup?P>c?=YUss1;ysydta`Wg-{;&Otv#{F|I9 zoW7`{6kltwdFs!d&xLN%bAOwa`wy8ZCzB^`6V;}rF1*i>@N}s9jplG;Acx2K6O&*; z!f1nrA{CEXoI8#A#@?}Cw>4j6=vobU_0Q=L1STLp^q8YnuT1oY-#|D)N+8w$&wGO8 z%}S_EcPzOm<||H-D>R`(1sUY_c4Y3~o`z;H+j16Bic!GYE#nf8VSI%IbKz7YA|qia z@7QtdvV#1is%A*E51u$P8J%>a9rsItB3WGdj3iBO0drEM3#Rrb9V5Z?kwyU655t zi3-BYIbngx+V`e*a6f#I(>^x4N$83vd{RS%N~y%sC?`evA2`4l(md8qTGoxsdf!VA z_I33`FyFKCLqt|VL8a}&l09eY25u9EKM+1;8(Hnxus8El!u{C5Q_G3V#GAlwiG)ZQ z(hbc-MHuOc4M1IAtG*u=N zB|@w3OdtbKX|mS+dykjHb%DwPEZl(x~!; zIW8z7XH8Es;^ck^`{y7v1JxOWSiK>#O`H*(Ejp8{iq_lz?MUgnP2xpj$e92}C+$HY z%#;WRs|K>~lz~vT-37g;bM%8@67T0+8_yayxWl0g6m_FkPR``p?W>tTm9z=N>nj4k zlm^zUNq7H-vR;g<&HEhGl}Wpl^;1dwZDmY5H?y!zy|(R|sHvF7clqiQ6m*djz<$+S z9{nqgza153)-S)X87q*~oH4Xj`iv2nYi42bG?FB)B11peuQG4(SIpxsK?KWb$%@y- z{c3R?LL^>-$CU5n&c&vFwKO=|S*=Zmf?5-N7sbjk^8CEglOcFBBuwq9a{LPqO&*m) z1@cGe{wDt48=`f@rv67P3;7FlUs5QI>b>X@qb|Yx7eD+Y2I!A8SCivFyDM=cs zh)>f@x5u8mJiJEd@*r)@<^2BCy5Kp_S1M~XjgO|6c~r!R{@{pcsK955^8^geHLt;V zFYEA3Wy(vd%%Ad6mT!I<|2{fIk8YRSh;Y zXNgebtsA&G(|XOb>xFxlOk{1babJD7_ERiQ7%FQ%4vZ#!2|{eT%F~)Zd#x@F@)GXf zU#UM^=y5MsmD%A~oVt`7w||m7sT=FDW%k!b>^&j&VdkjKUp1HN2XTr<_ozuF74U(* zADbyA7n)>JJDC%6CDo}hT-gQLY9`xqZ9MF0Ey_C)Gt&nbN8BLx#~v2l=2mu6=9qFa zk6}C$ki(SPHe9OV^@4&XHi-9IIgRl&CQ*)gy#L6ts%`7d6lpIUaL{=|5;18K*3Hvz zNBAvTsL{w=csCR>xMe%|utF9mNOj1#N9*ly%am#i3Q9hxWK}&>OT1MjL<)Ck#f8d8 zXq+yW<==-rxg$GLXD0gU68_*XhIYBV?{S$FPSyJ|8^5AA=WZXU<_tHB(iAFq2^!2jiQg$yY@%FWj_`__B`P8&mN&=rpbAZD;EGX+)kcx~K!{$oEA^7k2xxC!rnqn9;R4%cy=#8lzKu>aCjcmiA9 z8?c0AlnayXkrGfCE8TRkY>=m$J5tjr%tGz?K(H`8!La5(M*qiPZ8%hk(~(9{7=EY! z;o=4pKp4}m(QRvx*HZZavy$~>Umd_>SzEPQYXe5>R>mh$*!bn;0lP2@la?cfm-e#QIpINSJNSpTvRB)=h&$K+y+prwz3ycPM!03Lgr@wR3QeN&s+jY_ zci)M*CdZ>$2 zaWf++I8NbS{+!X2kIupFf(7TizUZyK=GDeQoV{{j{eo|4Z=9DCUU*!G>xsdBE$2CG z7;3i^|IpXIf0H%ekixU(RbTDs`3zetcS`ke1%O&DD@{+``qjx!T<_Wa`l9XocA%65 zV(3Z;93P8~G&r%2US}uV4LF!!j)&^HMTx7iSf@?4JLy9-rj<*3N5l_`F<9+Q_UNZy znFa|+4y0;2qTAY+buL7-URgv0gIRRCyQw!h~ z&e7e=dWmlINiKDm^}5Q*3A;X_ip73Ck)S~`gT>Qx+6UZ#PFRar8$KDWP;~y(r(FKN z&AT6^i*sGIoSr)K#!DQ&>!Wp)ag}M`}=*C#G2*?Fs@m4!bYhH;m z)40bTgq50g#e0vy_}}vc`OU&9Zs(39+4|I`PkmD#`8naz1gYbPQD&|S3r#eg` zj#TcfKrJAAP*5q;mj2@R(6xYrb57D^ABUVvl4Du6I6(_a!?3ah!aO#K4O^|(u`XMi zGuG9Ib+&=kURwHYc`$e@En7c!PXB8`{X;fk|TMyex)z};3 zDD^Qcf~@8)iKqiaQd}qTYn z8x(U^ts7P2cKqecFomoG9_&EN-L6K{QVVm9(W5sFJAFqrz!nTgj@MlEm?$LVkpplw z%1d44p_Ig24%H`H492;bdlu(fS2{tb(d&)a%)+3jAe^PcV7 z`d8f&q~PiCb1HoF#;3bjv8*E^X;l5<-?Ck~RS%!~u+ESBo4FfhmK~q)9000~n9$rq z+PtJ#R{t@N9Nn&bj3jb)X3BPi#CSEUfD^J)PrJtDIWg_&P>e1tWnJ34p5zoKeTx~S$dI+EDW}L4@=h0#d-X;=AvbrO7myXL&!Z} zk8MXU^64@Cs3{e0-%jE`v?Q3g-D2<-TU);I5@0xGM)n^VacY2Un1y1%fm7E#hb+Xh zm7?J3HiJcQqJrZJW7;n)3iNnK<|}xQV)q)0G@HK-72j%zU?Yf5*?w^5X!e#H1S38RckvR^fuQ39Qg&|2VYyyXw&4nhwDK zJwPw_xPeNh)EBN2tTORqW8R#tb!y$H_Zh`{d$g91Q zCa3p^)~=_K62bFqb}GhVH<*N~pRO0>Fpc|Fg|+i&$qh_2%tyBHU&wFbglP4|zOZqc z`tWV_uj1yYuXt9;ht;?K<=+1z7<8M}zaY(`iE{ z_a~Au?RUpGNB;TK$kDBCU+4AUR?$eJ1T0-r63f?0JazEE#hQtV_n!~TkYM}vbwQ06 z-wUCB;br*vM4~Od9^!*ZgEDl@b=#m*FQFTlA!$3!*QiI#x;+TVRC?Gf_gfIkx(vOnY5n&NqNaWNhz#`-9pwHaqRe% zr!9*Y?a+{PhdrN1VtKFzM<#A+Z;@j)gW@;*L2mHU<$+~qB{pOIzBoz6#JTOOch!JL zU@uW{(%K%INU4{(79|YJ%TTLb+S48Qqf|Hh`gt{Yzirhxxz}wK7cYhKo-|_CL%2Ey zPD@4AciF1vF_(YxI@nAKiJ17H8WC|(Cv=?q7qDRRr2Ruz#~wSQn1hdf?aI=Equ8ad zmTyXkcVfKQo&HwQ(FLfiacOZ)Gq>g*hgo(NrPJ_j{(2Yhv`drKr^nyTskiVSpHu9x zhiqf|H-awCC>|Dd-S1f93p(!o58CEg`-#@X^~P$f*~aE=1Q|B<^|kX$=ha^MCD;AW zkMue2@S-qqX3UrBI`TFuI@lb_Ck^%QfV0y^k@uFkkh-UUOce9y8^FFy5o_T$evTD8 zco=wgYks-b4?ndx&i@a}g8~XN=80tyzPL_#O7r8rf!GwBiaQ$Q@B{tW`2T8=%s>+6 z%bX%sace%x9_E765e?Oh#^V9HquctKpT~&Xwcd{TNKM7> zD**@i;E`^jQ%%sQEQMk_yon(8*_*aoU8mOJgtDf`HcSGN3{NHJv=g-IO6g)GAiLv1 zOBLe@wMgF)04824ud8_rChrlQ0w>0ZTLT#L&wUSNR?k5Yo6u1&fW7JY@-qktsHsdJ z*evfHh{E5mLos zEL?7}9v`M}XkB-Ckbt`bGFog$R5u$|U|u{t)Q*8g6v&m*RY7z0^*OZQ*#M6jway7h z79HYt&Mu4L2*iINM(9)lH2Tb(`i!0R|B%df|09WzGI+*iBbWYAfwr~;A()=46S7@*a|5q&d88GvVC(j!DfXd0*qg4r{R0(3QpkwgiHthl6- zSov}Yj2SYo6GxPuhjI-R|2?mKEjocXBKp;xJtAgqdAw$`|B5>VhQ% zhzoJa{}HVnZvRKT_8&2`J02&_h-)&ETdY||3(NUC0QfR-Nkpjxlxy*`dMI!H=$-;p z%u^27f)lEMEWO5Q1gHA!@%SroxYAjuxJ{@(DW@G(Ua@f`WMRSOyGwf_F77WlVG9n( zjLfMyp?d;&$#}WyK`?*;*NetJTqs*W^a6}vvn#B|7BGn&+Pwao4hLX1#X|n0>>uuo zQ(IO(_yuGibg1D3`@+iNdjkxxOETPbH7$@hb|~xl=SxR0e?OX1TS9j&oO8s0y1L7} zk08j8;}Q!UyDeEp0Y|qwD72<8-1NFSWy6dRDSj9 zUN1sHg2EGxSnW@aN0ngRsHO^{`|s&NwM9a+ZldIQn^@4SP@_!#`6;|O4&kuQkoY__ z?(t{~8{4zN8V{JjOl7rgj0lX$o5S}sN996vogLc!ZxBG!N_n2 zg~|M!6hVbc4c>pm$J>5&hK}?EpY(iBfe`((P@tDOm)Sj`?9vre!ya^l4VLD|@T!zi z<5dTmL`cr858)u~{S}SIyA~{2LyPHqJK|k5N3A;D76EY8wNI6m_dbIf9^Sm72G~N8 z_O|Yy_frXJph3e@%?m$t&q4zE>dzV{4po;e4DrOz8sM$^5SmVFEf~|D8_->eTt$rQ z8!)tni^o(syZJOm@;bn+of)~V%&8}K3L}2~JCd0CzvDV{K`bJQsYiGfOPJvBRQDp$ zoCe7VeUOwV(AzNb@#J)5N3iDgM8ER|*(u5}=jC91n>jm=Qrcha31qOH(aK7CBW@Aig zpV&g5yME3TRYS=H7Vw%OF@!=w0|2KgJp=7s{w~4kjvs<8PC#`w2$NrbL%|Sp6X?ga zx6)7g%m35nbzRt7AK7IraIVTBm0$?=6-D>xWBXfYoJa{ffbpbFv+(BQn7x~T^4H-& z5*zf5NU&gDvLui)$Rl@+H1!Qx5z(=l8>`1J>;!>!QiMwLX zlIOD#`Y7W;RVohsp;EN)lVJWcc(mBzl2Qm#&1hQRLz_lhLUa!F-u`}Uc*26YEhJG% z4qBLyC$a-g;!Dk(Ve*AOnaZ-B0`_E-MOiljB0Y#pdN~;?rUHZJCSWt$Zmg}zy=h)M zXh-=Q0&Cmv-Tb{tIlh*;3RR*Fojdfs$XfwffxFW&u65hNu20^;q z!febnMf{1yED&M<_@Y+V@PgVg{E!K_fw*wG;0F4uO#*dnG~N;1KgXb#wEWheVvkfg z4L(C+r2W}5?KEwmHiJ5AcnkKHb>X%eR%PV|^(p)bu^I>`$B^%;PLs`c#Bj|ICfkOx zw7TZO0!Jd8IM)PO!Yvv~(dXX?Qv8l|5Hx^<2<3PClMD-lFFu$$5Wx%;LJ;Ltm7Gd! z8mKqjJ7Nkh)`vlv^Tiy>Y9*3bGY1;IHjUE}&>(q3upsqr$?7i;PRyYAf;pr{_qnq( z;$GIV7IhVRjA`po2>`Qi;Yc30r)rNs(t?yfxRw*CR)9|-(nr-7b41hdmw-4CdeaZ< z3Rd1f$6^MRz-0pMaR*%o9)CSG<=kLJJRYUqSvyB9N)~b8B6$_CyJT<>O^7cBV$sYO znDzotoQWL|Qm}WZ79a1a@{Y2Na%QmNOP<`wVT91@a6QbDXh_hy$db*I^Uz#dALoW{ zPCm%4J^08^oW5x1#8V|-MK#aZeL!p@T+(uVa&~}z!@-tx&!J&Xhlk`&V)k1!>Gr^Z znCJOeQ@R}M7A=v3;I;L}fOZSAV`xb+=R=n@@r{DesVI}m#$aLearG~R!?%3q9}eTk zr?xJ)I-d6CA>VU|S!g}36kA)5@w4XMjOj5xy_hOanPb1vr6ic49Q0Ko6N!`NVZ{B4 zNGOgzN&HC|XBzNu>WD&W(!7pfjMaGNA17OKXp<;&1L8iGywzlx9-L_yT)S;JJ>DHd z&xpJFO~^lZK&+N!4e1!AwAg{jZ?5K}@Kj0nUf@^a49cd|%a$@T;yzCrg7&H~N8xGA zAZ;vgi+Dy-L?`73>IurK10HwHxi}$_QQF36N~*Q<52~f7g=r2^zNQ-%-Hy6$B`3rf}}-yN*Jho@%GIOS)OEs%PM3y zQIu~5TY-wqMJ&UV-LD%!kXngag!bzTnQmyeh)@lcl+T_b33EB@IWa?ii-^3_VX83# ze?M`|LRqu!gtRqI&D~#)3##um(od5#V!hl7vx|RA;_Am(l%CaY+}Vf~lncMivoh2n z0gds`ekqqf4_y2#-tG5@Q^acodhPg_b|^T(K3SBu?&sE34#36x@=Nc(w^MB3^-NYl zbhT$)oSyT>wjcix-xHxd|A*F&l@nTiy!vGsS#eQoPx->%M@Zmk<;fX22&{2+Y7^;+ zzWV#|2SC5cgQuW;@OZ)JZ^@Rs7yh6@-@8T4m=4-ciZ6{8`16rP(s?9do%i6~|Or*0GEm zcapAB^bP~bfSR-3R2S)o{5)xYTv#Pob_SxVbbsFnOcI8cWB=t>^Fb2A2YcL+dXjoj zw)eGMM$G$tyl9{R`THEobwQ8V4mR)>u$m{9rT4Zpo?&S`!I@lkgioCv)AO!%m(j;L z6{H$BgI3WvKUwk{(26rHG{~-R$_cXQLapfmOH0?E{!6_~MR*5p7~MCSwF61Pfr{i| zP-bQUECqY|ARhNuo3GX^ISx|ute(`sQt4>#Gbo({<=#9bjzE_uBAHz9c2Ca_;d&9U zScI@Cse%Z+nPvoOtOYPiw>%s`kz10y37UJ{j|c&vEH3FIUZn;g(gB3HBx*VJ`Eg4#rn&sk??(9UXV!TC#l@rQu0 zM=@#>w8xrStaOOD_jrc@VMLFFsV)?cUM`IQ>o1Mtw@`M!&fIat6@D^DQ-1$7AFk|&9JP&f&Xf~%24bCLt-a~2|Tyxp!HzD%qps*zL)??8dYhn0Utj+8^J#ITQS z(S3X#UxXJmwWG6<|2qZBE~QOS&{=PF@_o`X4nga4%NQQ!Mus30@AG&91cIB8WYJAq zx+T*AY56zm5&98c(=Cjcg(twftV5^nRCIV{`pZA6tpE!4l^0gv$Cz?-OF&yl&r|B( zu79|#+U=$?Z)3~2B#;e4hFi`jpsx|^80~}p^FKE&Dr`Z~KNkc8#_o@q|AgO`sMACB}?rKkLkm7E{t(130uWuCWD3;v&xL=Ij*GE%lmb=nX#* z3{1zJfTU^Yw{YZ^6>?Va_bb2tV#3Wb}vWrg& za|!K-SsnvFWvJPX5%=#&=A$vv#F0l9JfaU*@mCprk1bwfq4}0{#FAylfV=)Q_tBUG z&%Cq=#*}Kq6l!FC62W00$0eP`>^F+4L{wkB21y|M z%7s|#-ksFy+Q0n8N5n-&Kf<>lm0MqG5!#cjDqhkV3Oa@mqvqeGE^XgDg=wV-k;msy z9|rYdGB4?FOMmH_Bo&MBO29xUXa~gS|I#0{3}*?wpc1>b(Zov{!3dHW^*`(O)@Iaz$co3sQAzaxUeWB%^rd*J{55V z0YyL21W~~!(m^(n-7W4!)*xGeAV~=icA1@68GH z_r|FhssI3h^Y!uC2>>WWL;+Yd@@cwl@e=ufCw6*o20ymj(h)^D)@RQN0CfHN>jhn_ zLtK&KN`c#Vk&#UK|3CldN8r%W$rL0M?w{Q09|WknpE_4jcH#JDl@k|NJrl|2?``p_ zs#o*B#A{vW)E2OqfkJ1plsaOBo4%vbGf&gpcPoTRk4#%UWIuV7r`@Y% zmbEhq01Q2Ry*zg%UYoq0!d|{Rr7hw7>Ku(0-%8&Y*Ei7cYscBw+wYn&qjWAiHs1E} zta$16*nib+yTZ*las36N*{;x6!_tutOJeR7bV9>Rz^2l22 zq}55Md%ktGe|_F_;%B{-2G6;jp_O9dwG}2_C;E6o-TY`PHMRkrOeAym0nhl+0vy{|&craG$H31% zE_E4iolIql%n1hC_|dVr*yVDSZZanbDBwps;snd+3ZIF*l~9b(DN#{WKv(D>QY}e7 zLZ?tgOg@}OAvkK9x=0L-&_FAk7D9+602UHMHFRk!rST5d1qizhbZtF|!OCtH97t@ne8-ZIsmgn8YS6H;Ew~J%G6PJHb?$ zV9pKHOEirL{oG$l&f4LLb}jyp_98}EHW&c2_$u0m>>NG$8(YCaL9lq z(8G@o!%^L2DldtELCtaE3k&16qT#jb8Xi-=myT?F6-46;_y?Q5*QjeKg*zHeLB+)u zVUT{GgN6~seTTNHu8TBpn^N7dTy%^)lXZ8y`>?KBDngkWx%>m$x!(5P0*xln=#`^%YFG^!0I-Xz8v z`>gNd0?UBaGUhHO#}^3h<3fgjlT622J9R#BHn%~s7wDY{VLPDQz~E!ooqzwseOIvm zQpm=Lh2EOKlm;AcCuDs2Cf_h0{;ci(a`%KzXXBr$jj?speg&U4_8toD|M{k+KD`YJN zakscCxKt*qjYLkwo^4R%07Ek&g?f!+0Ulpx81~@)TE>H=lrom`dWb5uiOS_Y63e4# zq-;Bv4?E(WX_o8QLn~ulj+oz7*>g;qGOg|{+26o zTFCHgp!Jbhs>ae5P7Kyw#?-wXxb79gE@Q>5huTFUraFzEoeTO8;i>P=_pVGcNXaV) zpXukps9V@>@x%u|Meu=0WoSdy7k9cf4+n#lT-2zp@$>~Js9x^Omb5%)JK+46%i|k7 zp%rI1{t&YM9)++(VlGFwF)5+oYb2icRRc1*W-l?URA*;f$qnm>F7!9Q8vb^IE;@Il zoaH$NypTpiOkNti>{+`h=eIY@e005#<#`i*XO0D0rKwKqKWi7R5j^aU(K@?wr_hOK zj5n8G;SdwK{rUZeG^sN*c(4VTvpRIyFhwg6(-4DsKGL>aDc3j!7p3IY1-I5>?LWED zuKGf%Bkn`-rn*QR#*?Jd=#5O?0DZm1Yf+rQb<3&Ff!D`q{Uc52PGIXGE3{^~IcPdA zQM%V}`qX6@fBgNS#iqdfUnhay8lXT{lJjO%?~+I4>3^)JuQ)n3Zrq?bvR+9^+0>Y0 zE6*HU2+0bey{L1Tqfq89G;Q+sa5J5evO;NBgIUVXXQoPoDp#e3H|gmSVA1S0ih#OdH%PGq%i$_y#`GDsHhtRrEW2 zpsZ^!Ch06$Hj|VQsURk1m+hy9)zqpt|Z8%X`Llu&IU1>_zHRG*xlA*mB7$}H;>h8fYS~I76Ds|U{a@&bn@iwUo6tz(!U*Bj3?1;aEF}b2?r8ezc!gD>!>q5Ptf8Yd+(We@ zt|_K~yAA!PxFeahCPGPwm=%@_5#^vwHqjvVYwO#RdB5#n31O%14Ient>Oma~6&+5! z5F?tbPCi0%q8}uEqT(2jEx#Mxh+aI`MKL_y)u_g(w=`>dyu=@2;Z%$n;Km~J;m0pm zewVg{Uvhs71b3WkU6oc7b40%FmG~aIMlS*ZI_K~mn2Nbe+4<14p>g{4@oBY(9~(2=g}r8DPbn*8atRRZP-sgr`94eNXj)V<58(*<8j$&StkCe)xC z)x`%0oKA|uN$2i%penPySO@Ht9t?D7tJ8Xi%YN%!7;48c2uqf$ znZQX|#0QOoJ~-Y(SHdX*r<;P4-Zi=i&Xo6Ou(8mnL$)lm=mlWk7qfX6rgx5;PPZ>O z3e@tQ8y!%Bc~u@d!Gwjeo)1RUcfh{V@+{bgZ zOyv)doO4Pbj+}@ z4r#amL2g4_m#9FZ1CuKS(6owbgzLV^&l8;ho67UADfb$Rf1E$1Sy z%A7fUy28B;5m%d;4L4j}@8%FUA*|y7;pMLCKQhk3X}bwt2>ZC)UbY2E_9n0y4VLG| z20U9Sgr``M7v+3&8i9%!w5@fW54BzY!%WD_vK?!waMXo27T>2A8Iup=yq9kr=qiw0 z3(%~RwEi)k8QHN+)*9Y3)X{2|2S@zcZ6*&8)a?JF7j$U;bDd(M3eYe2iyZrqHvhVs zA?6Azv0>$`n|wezJcyV^TyjHQI=u7|ug^0F;^odh;#;Z12%1O_gBsw=S(a}#_C*=X za~enh`E8VQ?~PLzYGg;*xL952k^E}K%xlhgRzEOX1C1->ou}g#hyb$N*P@LS7{zoP zmk8xIC_YAic@Q}yjTY&ETZK-=#ykrk8_~4E--J#KW8QJ)r$dyco7li|R^vFJ1co9& zQG*pA=ray1Mz`6^uegv&S}C|-rBGGQTDjpTqAAkFUGz~0!+vS>9VUd(%xmgwZ3w~T z4`jT##PEVT``K^)VvnhIeKD7(<5|Uz{+nV&JyU0EnqHJf^Kwmp7dl~$sV6S)d<82$ z#FimMvLDn%SzMyyya)mW;p)+Uu>$@SbGO?j&L^N{$>O=~WvtXG$RB*&C1001cd2R- z-A9VY0-GFVf(U6&wuP$M9;64Gn?K1lW_z?^(Q|s^d$CvpAkVrl*TIb z`=c9X-kvd9PM^=q%CiLBrI{rzMu(UeKaV=3G*1TL!DaMd#VT6d^y>bTi|1=(Umcx_ ze4!JvcatQYu;AI$>+qj#HPH0g7VbC4Uzppn__g2`bq59#hcr(k8=gtTi`bqhJg=5E zeSp>$)NGFuh@;EnNxaD6nEs8ltDex~g(Q<|;voVsN+H}wqsr)vzd3*@M~9;9_D|wY zLTM+(xEu|=w-(hb{0GUvn1m8;V)3)A(kTGqbFaZiCM?r|Z9gHSFwec1s5!1yJTRfT zV)W~#c&*tWPB@8JPq}I6XN{yK%`kM~A={tH2BBfIPW-i(6>G4)T$blrATIpjILid?vfxD1)M%?D zY#%a-O(QVDy7Lzo8+7U?I(yPfI@It?C~|34)UUl%ItMRE9q))zCO-eX_<7|v&H>YJ z@*d3WW6qE7C)mzXbAimIE_AN-YHH6xOe~r7gk~J5gufre4!<`RZ8*ZpuuIw0E=+bL zlP=H|NJ@cTa75zp%I#O(8njP$1?{pqg3$xVBp1VtNl(4nnZvaPwFxP9(kC&+@GceK zKmvY*^1UC7>|?o1+Hs3bdc{qJx%BhGE$jo^;22%a0=N>4esay_r0B*m7r6SBK!shl zSQ#D-J1UJt9-Xm9&CV=1LhB_uCZgk`SMAor*QK|fR`zbv*ghDFA++{)0kiyoxKHnw z91=WUO|{kBd(v%lw{qaPRhrdcObjW5uh;aw!KRgti&A{w#`Ig?)xVGv@0q&^~$M$?EblKi6+j>S2CKM{rp)SooMInYRH`#3PJt@DgB>k7%Bd6 z!}1tlkrYWYYXTU|a1`1>$I1j9{H z;o(WKP|zz~5sY%_ZmK!zBU?{dt*@Ry>U@bR+UKsCc-E_j60s6GpoB+nNH7~JCO->-Ot1+8D*J^c%$Bi(&101DkmAx5XfQan`dg##RXxU~x@PodJC`&NU+rr?j9PM0BVbWu4MSd?7+B%|{&Kb)ZZ{G$|ip#p^=ph^S{i z>X4uZr6Qt6`6z1vZ`uGZY4aYt1@_w-)zDH4fR~E4VWN?)5pQ7-bY6y=3rde04@p#p zqBws}o*&luCfYQYE?EUhC=~&?)(4bL=ps!u!IbtX2vemnlJX#)> zy5%q-^gd;|J?Rp-y#Ko%XuDdsG5bNSICBjIv^?bI?c3I}TH-{6(B8|hx&7Y#B9lIQ zcXB;l-Ha61Swc&09?bf65OZ*Dv<44;DYiP?TFQ@RBcMMOQqgB(0qMF9DD z@CpO4^8y^bfM_qk)eEvDl2i$R8i8Z@KTws(1TLLjdMaMW{RYKH5lS=H0s2J9i3k`I zNm_`C1+uWzJS-_2+v|miGDAUTs8DlMuNi6`0sM^tP#M5`25^!A_<2FP#QzOdJGHRC zEME8Da==!hFaSM9wTAvzHN%;7zFZ5B20z-83)mrNQ`}P{lkn2+zg2`R|B8sG$`$`* z_z)BlTj<}7&up|+2(9n0e_n#p?&z4kby$$^VHl6vzI_r2 zOY^fwS+R3XZv#_(tae`r^%PsC%+p!A(uoNy)$!B@>&q$UZvqOzgkDv==F*jo3V|Fw z@IG)8DIEf#>akb_fI;)Sf|53RK$9wLECT~DXOV8&)g{N7Y+PRq?xn{K>;o#|ud`{_C6oF94% zH-yDp$|p$F;kXO5?18o7rf-k|2OvUNX;44Aq5k>-mB6Y+qmgf_EFz!_I7{AyrI-(N z?@;*QnB+7vRT*cCB7wc-9$i`FOXgF?yP<)Qgzr;u>n&_4rj$WziJf&Te&)Tr^u$k( z{4+q_F#-uo(q3ZfO#h{JO8!B4Q-Z@qu!xMeMNTwr-1qEHI|B%r--NFg!c8J9uaof> zz(JvnfB#RdA#`gAmKUor~*Gl z7=1?}(8~^G10F|aRt;nplY6a6_I<1z3yA1X=p0LI_I>IFTb2Rj3L=$U&*wJlkO<}2 zM7*=a$<{t4pN!vx2$;aI+Bkdh)y!&rb&ashT1>{WYY&o^lQ}CSPS-Gj!o_^3rG}=J zrT2_Q=GaP{)D!}R_p$n0;jHQ1Qvn3QSsIQ4YLDrG{d_JPuD8}}L?AJ_oYJ%(AT!Av zcZt*8FzzF!X(pdrL4=5TL?5JKsY4Wcid+~djMmg5H9p2_=F)I&HXm^?(Z@mJbVQ|; z7lb*2bkVj#n6ZUmv25u|g+gGnZCV8q<@Er$is*xwo`NSK95)4Vo`SLBGfP+YvBu5; zDicKh4q^0ZOH%3{%o0LxxPOXLX-0`Tg_$^ZxTb$8#JUbDh`s+`rrB{G3;+hudEHQ& z2$FYp+I_79?d7S9c?0Xc zDpzdSwnE2brBU&~z98Q2eUx2)m%ZuC5EK(aJi{$uEoW+}@tH*DC zo_Lnz+cnFR3~3rTXZ{cV^;sLAgE21>AvLHR-60{3Gll6-d zs3K$Tj+J>}Wo9vly8I|AQOoC;SWX-w)Zl+{_AXzGlNIUw(LtCLw=w&Q+in{eufx@e zFjh!W0`sv?@BmzdW+qww6ZDo#F+hEF)0i0AEy0kx2j85l>-f5j9kYM-P8_^eeL$XS z*P?6WZ1x3pRBo`9j}za2jc%h`eN`BAeIGQsGRiz^9e1avdByEwLq~#86~?)0E6P`J zI_Pe-RBE5(<8@0AnJ?U);~E_utfK8jp)FiW@%md#&JpB4<;_jxB&vebQ?GWZxbYPB zU-A9EUa7d`)4$>l|4FIX&d=&!vFVFXK-?TA{I~P=y^9k^f#T&9vIG>jX5qwfm9pb)O=JNmYJ}w2hnvE0j}F_rg0{D+85!x0 z4wgFNO=qn24%0FAG#{jCYmhUN3XIT z9m?5lzS}5HsWyWk;UOA#Y*02pRWQuAxWPlJXU$FA&>PsuB2%L9Y?N}8t&OD0O8c*D zl*7;~M5Mm9z#B2vjMS<`Vv&Yvk7`s6n!gi#=_mik&;5&HbMvpRE0(>8Q$J6 z)j$is?4IOhKG2Fb41U++m$H1mx2_v{PXO#=2ClKyf7v;8o`#jk;&g{pO5;I1kz>IXw{%y-d5@G$BPg@bql8=|UIb%-i z-cDdEDRp)iew}qaX|H$ahvK5B?ku_OF5QA|M)y>I)-}gi%RDr>hYdeX$>W%F`*P69 z?wLbR@6K;accjOivJ&-wg&##GB5Mn`x?c6K=BkmqE7pQN53a_Ll~iF(rN8)vEnElO z8EX&qI?)32Ap?KWksjq|E$WZ4_P|pWR=vZ}p3hCrs2x-Kh-aioOx@5wuJ$DF|IF#n zxmPE01jf+SM2-P((|VE}q&;6<>iJu|Aa;yU^c<_b<}QwulsYc$p#rNY5mOa<)k+YE zI16rz0K=OJd$)yNMqi}l|1&8wGG7|@JF77+bc2moBl>D|mUe(^$ z!%HE{PW4N+C4^38CB_8$@n+PzM-1qlv_v=bOxF(f-|0W;Ursm8mqn-H#DRXf$N^!0 z8`q&xxQ$ZAq)^sF9DmCPq`*R@zjnIXv%<;b;KFNs>GLSq(O>gZBC?W^FP{YgH{h0w5BzW#_(oJ4tq+CIUTEg z2UCdS+Zi)sQ(5fXz#QH3%TiCl0Zo~+xKZ}2IDO5L5%QIcF86k+aW6z!Z%pj`K~P*Z z5;$V{s#&WcP~uk~Xdh}wvS!D6sWe=FK7C4(IBC$}C2T*>i8(NaGp8SJjy!E#$uRd! z&7v>^$M6az2nJ`8ahmv(bXk!8!Gb9K_176?k9|B512|LV(Mq1o7|$q`H9!r_!J8Yw zn%X*P7&r8`PR#^f*em~CqSigF7@CS<2Gl9`2k_r?Jp$= z$?@8?~rRx^4^n0siKwBn%^wQa2^T+d!;}#JOvy? z6ekGtJ>p#6o#0&lxjTdNTuA31$t(<~>nhPcVR#hleI!t5iRAJ&U3eG*-Trr`O=M*S?_cA1F$^Chul-tmhC)%MHGDl@Y8h z5XiF!gt{_AHmxDqY_(Jx;!TJ>5UwzS5ycvNQu8HB0bOhI4rD6ZtTlpZ>`Tp%-21Oa zivs+EX15cdc5l}cdSCHW<`t5ydp_D*LX%gfoiA&JwJ?;B=7pcg{rMTiQGuECr z0;7dZTKT)^4fJ$6itfyaEYk=Y!>b#?o_^@YNL1*{r!)EotE=94yP;pG+er3VE%V^= zW>QjnU>|^%t&CtBQgPy~zHhk>6FiaTuz`b>G=KCY{~i!pwmMUy&%9trutcF%Nbs*l z5Oa)dBzr&?tLj9XM+rq3qBuQ9xyX2c(|>n0aI}t2JS7WCZ^F>Zu-bp6`eJo#jp%&<yaoelw)BOITM4KYpugNaSc@+%HUt`PIApw?A)|1h^@&njq z?+S5^nnZBRQ?b zu!C;!M?pD}@8f*$@wk+H+D;$jwXvg#=BztUs(*h;j%hDUq3skB=^LeuM47YFMkaEq zFvfI)=*^7QlZ1K&EE=m)D^rV#+i>C6T~a&u3rvw5+@c>~2Lk+z9^aY0FF;fCztVy( zmiqRKD{Z$c+E#SSFpZ)D;`*&$IB^w-(zl*GLgr7lc5lm27=7`y+z z+D(v?M}3hemMg**ol?a4^tS_?i=W~3HxI2ix}2I(?yQjm5W(RQ3)uRp>;->uZ#|KI zO`SE{zta@HpY_kV7Lu{(c(VFt9r2H5eL4YHb}d!mPVne(`9mM%oev;%HgPGwTYX?JKzi|isVZbvhPfYLX8VO$%$YR9;&c20LLIp z5b@1Tc;5=yI~by{1GvJSIDv_YDr~eFgEu^5y^-{LgNCC)Ch#Kijw+Kfa_wlM)nm0khVW(>*BvSAhllYbs)8)Y@@bBg zJ)B{DC{^LbTMSL?gFLYcz_n%oJ-}7~p$uo36#r- z`D}EmUpG>bulqpl-jD4_9wGw$6RFUOF?w%I*QA(GT#{#}Eu2ReHuA%|)81Wje-&ga zT0I=k4l531%hA_WGSt7_rGEt$6inwNsW6m*RMIJMgy&6}C%s9ypq z8+L}JNX`Km!x-p+NzvQOC6rS2X<^tNps_cbdkIp9ThYxi|6AX|cZOfs#dS#XB`o#b zx`fDzp2Z2w!H76td+iEFxryglVOqtK%2S33^gANuzNNPJBJ{*>doA!N;k{nei2hP;oh=%f&17Y_9?asR(oT}__G@Y zN4&FG$D;t~%*_sx`1sodyq{_3Hi+(lEn0tUtPo(r*7se@gJXqhQOZRJfR%NHp|2TF zff`a{x&DU%0_1*|cHz}O#zG=RCU^{wE9W(3DHV><4xbU7_t*ci>djvPtn!^t=Dj30Tp>-Em8dC zS`Q3lj|xU%ZWa^{@(&KwPiw~5D}tPxl}}p$)jx%x>O@*r%RZg~kzJ+)5#EBKfqV^c zT$l#X#rx$%;lpUqNh? z%TDYDd7Q)(9pMlHa-Rj{u-<4F_kS603+x9_p zUd{JoUmM^MW@?hB;PZ~=$M@SKZFeNT>@(_uYBKE@4KV|g2U@fi&2?A`AMX=0{nH{1 z8@BDWCocZ8iFvW!Z%Ut(mC|{EZj@~DMAX^C)LM+qh(w>bZAN#b@1-mnPwkwE7k(ao zwZXp7h;*S1=)Ej-jFw16%KrEm1)VcL2aO29^*!W)J%7eaHclq23^T^{*`e z6+Z_?p=cwS21aojxHso&uq8IsTZvZr5Cp@!JW*Rl7A1OsW1drEUj6xX9q7z#lN-7t zV9XvzMgGIU(8!n{^%E#;o*=z!EjS$njoBvw0WfJn{nMW99ycT|qVJ!w$0&79`0_-z zl*JuQ)BKDyM~7=$oM{2Ea{N`(85eR7PPRcXI~S2mzg7vNXNI4V;Rq1YObH`Ywch=z z6emX*x}jS+!-ejq@XMh&x>-+Y%i}cpe@*8N22vGPv^7b2fVrR?-9lPXa{qTlWmNNL>^t+*q}aY=CVbZs%dc7>G_?!}$H0DS+5lHN zI!ks64N}1%6_jb*@6F(R@}ZMP#V*6PV(cYaP$z3#;aOi@CEN_GmM3!AUz!EgiK?R4 z#7(_VsDepk;!*`RZ%uEjmLP~?&ZAq-0Ib}NUnc0^^0VtvJwjkN9ebHuummf5h2mQ& zWZ{!a*@1oMIwuXcqaVx<5V|}MiEq*{{<{|5pPS1MyzL$i(2C^T!Cguq1iLq0V}01% zbA*y4c;z5(9B<7Y#^d*yz@|QV8RgeNnqbCSdo&G$!Td@e zE+Mo5jwP_gB<^PI#~i-Vg|lVeVbTTRc{3>N?TcToy&0 zc%$(qf2NPBQl}-)K0?<~V6STxbSF}cJ9!?kN}2s?{f{H&GZpTKS_&hh%^*EjctlgV zeILOe`E%X&pTA)&J+W1$nH(iT${Vdlc;6&7J83lOr`R{sYCj~%SIT}IC@^T?#AoHkEPYrG7yv0|M_$p^aD z#-+UZ0V-Q9RX#%$K5Zqky{|~tTx++?OX`i>(mnC>X>W#XE_bGo($hWecHQ4$9YCh) z4YI*ucROi^y0RVx;#2*vRQ*bz&p%M>hRZ?5UM?w;1FEotGNw>5)=Wpd*B9yZ7Cf&p z(_MN_2G87hfo_nJ9;y<$@rW}_)=z_sDJaTTZAD2ssI5{BUJno37dle5u9c$@6Z7Y0 zpP?V9G4&KBExyR+cqIW&)R`IL1HBks%aofial*Tb@RVEcP!@kT(QMKvT-#-d8gWKZ zGEqu=qkAUI<8G<`l=btr+`5Rpl)obldMVfIUhqQ-c9mn~kDe{rNZAhZQhE@Yy$dTTv^tv&jx2VX4v1{rby>V zRftJ9g}$2vTi=k{L&D7qgJ~4N>3#5loDkK}`1*dXgBvigslAwJ6L|F0jAal^PyRi; zs8H(>;pEOP7l5NJ<|O3 zf2vGV(Y&=uiKoW7^tEj7ck?CH>vTQ$t`{ucKC_u$TD%zXj`j=U&I%HoGG6=nE=}Z4 z>yzRsO#!xICvAHj8cSyO#fHKvD&?Glgmz@sa&9HTLfG(Ui>e%SGC&pD^u`Tc0JB3J z)v6pY^nu>bdluKA3WCL~o_#qqbveo&fh*$+M@J#%lPD1I}xC!dks=XS0d zLDRjx*IAhN%jFq3Gq0FJ2F|B$peP2;@>S3cgC{#wp-cmdcW{TyVi~ZW%w9b?$T?Hv zI84v^;D!IcmBX|Z8vo>+kEE%CITXJvkZ=4G`k#`HV&k8^7yet;s2%s!98#1SB6&*Z z6!yoB9WJqZBKr}!RNStRxPAOpq}-ct>!oY>w3tr$YKs(k(I>Ytz{*|>ky8g=C$|?m7$?odbwL%!r!3I)~`mCI-@sbim;6Rgd={zVEwtAjeIw@``*TU zJlf7;Cj5j9*c#>@v2K(F|JzORA9IAR7MJx&OFH`xqD@hDP2{b7Px`ImQpsw%w9Bps z^t@zu#NKn_BVF*RBk3t*>E<%^3sBEt{%9V4L?S`4X|S=81hFsH5S#*w?++>-h1cr{ ztk|2`ZQBHqc)g^CDYfJ-_L!(T5KPIhHK`OPIL4krltVbmfFhAbUWUn-!?O)O#OUzl53cL!S748p3N;a;1iwt_fLkOh zYth(HHhF$5`D=x&EC^!GU*3JD=Qxc@Hr315o-8IGi2)%mGvqToQ6{eMUCk_sowSa1 zIivy@@`o7``+jOfm^r^AHNvG->J1Z<5GnreuQu|68kL~}X{G#eJUn!NV%`+GGgq)J zFGOlcQ+VXy_igMkctnlwlKXYSI~Ctdnw*cQ0e33E9We^^la@Eu!*W5kGdNimgNRHp zsW9RH&ReoWlZBo2)&Fr%H{iNG|8d>>U6;(>*08RP+xTUIyQcq#DD!1F$?T+3qu16E zpq&$&C9C3A4xk4W2A65Az}+m?It?3gS}<&MNnJE_c;Z)=yiT2C#m2C$*;FM-M7qhs znc~g)%Z?%j;kJ&V(G%gs3_+~R+GrE#)7TDn7X6kWhH98f8hpIs2qle@0nH;)Qpr3Y z=&|~1H7E>lj#}Lrt2riP7#7^Y)%XeI1MUTdS4pS;(ltCQRE19MYe&()V71@5%#H4- z+&4L6nTDb~^>l$%*a0HMktNCXGQ){ODxo`9bPT`51>0$cIs21^>*NJyOc*S0)KAN>= zH;y~5ddH=Izpr=;=!{J1#zVHjJ1?E+|Jxk|>eP}s^alP3(x z$%A7Hih((vm-6ZO-RAdEW%ltUzt=>0&FOC#A<*G^=fTCK4qEIsr(e8Dq&huS-bYm} z*S<0|t19pp6NGc;=Ti?+V^>O$VTSGqa3~C}h`DJ~;?cc$v^2lCt+TAS?ckhUO=cnP zpU&=$ep)QYFL04MKbL*>#p6#?+E?r@hQ-TI#|Wo&V5C)X#^=^Dee8B8-uia#RIbAA zso-|NcXdb)E+!D+K;(+ z!0)w3nL!s68^e2WnXFSseQgSDtH}z|?M{%3^5aEsZQ8-sMc_01ox-BYGbGsIdk};e zlzt2FiH9q8M^UvJR)%kw=TcDgX~3aHBWq;@y4`X&AN__gQRdxK4R>2IM_(ek6EYDj zaF=QhpDH{5d=et-Xk zHK>H%v50Kf;;9%r1W$k7yV>LHNse?e<6WF#P%k+=KnX<0f4gW*X;Kam@-q z0G3UeYuxsN1TN>!#w*n-)}|B2$rl7|#j3|)9@|O~zqr=gS4frl^BUlysBkrJrj)Hx z37FL%RqqITZE(PM0TT3974$d?MbcIlUc`~o0jE=5;Laq10}P{^OMm!wLJ$sU zNkF#f$x*ghY2SDOn3*0^2U;(7<;!+M}fFWMOgb+56sx!1W+`~RG}YDVd!G6(7#dU7_8_XxKVEfq)($v2&||Q z6mEy+lz00=CzgY8gkVzr7fqp6;G2WvIpqMPUHwjQFpF2NO(Tqd<(L3K91XZt3qbO| zGKI3Ylpr?T#5GD4Gf_%Sf}4^@!I1fXI8)htCE+8`LY5rxbZ0Q$B99e_UkK=ggF z22jh@j2vqK*lq(d_BO7uHw#7SE$m4?Ilys2fY+A+H3e?lrSPu!jFt8{h#9`v%UJzM_u0{J5;RlI)@Q-v?W4e73>KT@R%c zr=hck!%skJCOT*Cxy=AHCO)&+!P9j~($V{cOAnf}pQEMV8V#IVKBE#>#8D$s#AL9X zr@8JCPqag!DHLh>z%uHq1)4oVWW`_2?xEu^KXdz^{L}@E)g+Ld)#Fl{A}j~Mhe43D MqucK1I|I)DA7kx;B>(^b literal 0 HcmV?d00001 diff --git a/Resources/Images/originals/box-open_2.png b/Resources/Images/originals/box-open_2.png new file mode 100644 index 0000000000000000000000000000000000000000..2456144338edc3723e681ca7bbddc2f6d894413f GIT binary patch literal 8829 zcmc(kc~lcwx9BT`25b>fS{WmvpE3vpmC*p9KLk`{5*0-xI3UU_Llh(=w2CMyDgkUj zLX*a*2tg6hFeJ9Ek^n*gnIZ&{Ktux)!jO>Ro!IaG{oY#lyX$7Htg2I0r_QN;_VC;L zTnq5?UiGu#&kzKy+OvDteh5+lrz((!8aRk9^h&@1mbBmd-%#~?<1e708u_d5uMqS! zcct|BPoTXbVfT?F2)0wC{KGu`iM8OOL9*xJP|$>)zJMnLD!pSL+17oBwSctV6t zd}3trw2L7GnF{vo`t`ttFv0NA8-mExf#VDfGvi94+LbkaUwn5X4UNp)ukCJswBh8M z>zRi#8x0Ryo37Xsn&0^RrjA|yN2A|*w+7jl90>Te;?+di*lpTRM77=Jj|qFAp3A#S z_I=Yw;kbjfb&;L&g`$)tla|+WyU~JX=YfkI?IDWAi~U9R+R6|8kNnCo+HUf-Uf;9% zQ+zYB*)IH!v<;F&qAUDGvSKyPu^g?PTe@0yLDb6+WP6m;vs;XZSK};cD3!8v{y8H$ z!-m7UvUvmEB}F57(o6Iym3^^X`mw-m(yWbohf^*sVp0*1;cP2k!mncA5B&0L2FGo+ zt82M$|1P>-zFPyQ0OKL96Lp)@>!F9O)fDM58dB09SbhEM>$Pn9HDOY)q-45S05Mp? zmmfpFju<1-Sls$WFY!!8T(H;7jlHDTj~chqHq%Vg_Ng*7g`P(py=HPBxbfmS?>0q` zrtt_1pB{={7B_x$__%)f7v4(WW`<$7e{_kkfvFQfu}8`)V$>mQz-tS9u_i3#kzfqJ zlLI3JMY;0g^GwUM>M&BDK`qE5ibtgTW)V{AF3h6u3!tv50)H{*l*VCiZ9T>QdboQ} z+D>JM@FUG(QvXO4bbz`TBzG`SDcHt(LnjKLfGcc2WrutHt$KZE4CFw?HE$$ZMr0#|#1sU5+)I zOWw0dPS!~I%L>{8-@kYKA{!Bykr9{UhTz?Xo-i!v9Wg4b5-Ep;ErUBivFBJbmwXv- zz=hMOE_1m1urPD>NMP7^jG?PVxpo#IDO9>VSI6%&M^jC%w-^MP!rgHt!gt#wI-_G; zG$-@A0n|51MArvih4d8L2DJ|S4b^B-()|o$H4a@A7`)qRa~4w<~&a)4JP~bTpDq68e>H zebw(xQGbECwO2tZiWaDA@R;;BCg0|eRc6oIH=J>DU~1O8Mi>_UJT z%8$mO_fSc0Ce79?O4R$bqPIG>q%a#f<=ARhR9cXTY2L7>0)K0W>2GJ89h8BI1uFGg z$F?~PDc@WV$3>vJ3@B3h5YWU`9*kr!+7bz@38o&tDv>o)=>hc7R@FFeJO_VG;En;3 zW?9hbN<(<9Q-ju1bi}Aj+OXk3mvD7|Ti}hd2*WRzX5M4Vs4?oNCx~2((j<;+43q+$ z`{z*=v@!3}xl+yhLe30_eUaSn<$oipApVyFv{m+tY;*2~NDJ`{3m^GqW`9y0eZ_$h zN1@x@#r&pDV%()63+l1dRc+Bn!g`!uuPjdwe~Grlxqt8@-5goN<1pN;qOO^a3PYuZ zcNTwdni!;%>Bf#Elfrj*hZ|o2bEz-{HR+tMP z_e(10*Dm`QiW}igLv-tw+OjI)TpoAbPGaP)MXw6&?7rB)f#rIARCN+JbYjco!jKET zc9&f|(?%Xw0}<`$-ojwg(e?28g{$mE&*A9VU!OOW2p1jy0@v}H_3)JWoWOozvN-=? z@@M;aV8~xmbw|h1TR55X%Tc}a>qgfGe#wfKM5X4+!sea81d~chM{4|#xwQHB50lCE zzJB7isk2I5PmED7_=*T@kh@q8pAi%W$t7v}K*I;G2pH+IBfS;U;~Eu4Plgj&RR1;) zLJsMZIz@8Pn?IMTDi2$O_2Zr)6DNIR^$Y^z#w zKL@?cdN+}N&bLv2A0-`x`^Mg(~6u1qk4jpu6R#1i3TQ&EK z(4O54ZU;u2++4r<)gLh`HXTfo#rVl&w?l<3Z=(dI{Ksd^sniU%o9L<@=G-<%1--8c+?$nWIP>y!^!T`J_DQM_^k_CO*Ic_T-H+ z1gJ~K#?em2P{AmX8(9w*Bnl_9eW9cTmdRF5Ce}%uw7MA5;t{ENgIc{zCTU|agaxhG zXNZTF^3XkgI@=ApE;5Bne!bmd**ylu6f6<`UzBVSQc|i5X zYYUA1X;gx~8D8szZWqP)Zgp;n@WcMe2DrE`x{KS+B<;~xk$iv7U&XGv6Vwudq-V`V zJJTP`MHjCG{+>vI59NKOPkK6f`-!KT8_SQD8XnX>G{+4Bu6AW2k+{vwsPdp8e~L2LS{L-xLi0xud&%#-c=GusJHBLDFrW$P?NF_` zjNH}WnaWlKB*)v8rwbT6$i`~IdCOqW^?CR5a?nO~OGVI!W0jpeWJk2RU1aH8T^<%8$cy$ zsPxEX)3W9g;o#rcG6852P0OZBgwB@*?kF(&&p>&cc{|iOnQ2M0kq5H~^NFm;RlwPg zkNL0FgthUA{=PBleattc$NDN0z)cklXtje84sKW7mlx#b3Ouu$o??aT_)_qL+0oA! z7~$6@Q%m0`JFWa-U2FVd?IdgH;JI0hjlXt)ZnQjQyK2BsAmTkkgs<`wr<~FVKWHOQ zi9j)oON3uLbQqQZ@ZMty9!|W5JX3<_%cX`w0aOfH_d)B$QUgf9`aDm?PwbN$58pK<*Lg-J~e?l1K6-|}T_*T64|N^I189lW${rgFKQLoP0_ zB=;15zUrL?74`JIQ9N%78qyLStm41`TJ20_aVO3idO*Hk#ABEfz(}Iw)q(L%Jpn|Z z39~!?JV$Z19xk(A!~#&JV?mDaTF3o^7k#M^DAb1o%9pehjVYM~I+!?%E*7}sV;cdK z&rqFz&`7{qJ%vp9=of*~cCCT!W|<}oH`FKM)B`LHPaA=W=9 z@dc})uA`yWdU)NQo`S`?rcNFXIdiG5?cKBVeOreMik3fQXT4lPnl-FN-pttg3~~E` z^-NGIm$iI2w)j=7zRF=@or2bcbswS^m9~+tQ{aa$=i!gVsQ+0TEdz5chEDUwFlZ{` z_RvKeyd_YR;{xt_?vb)PkHvtLgvmftgfo`}gtVw$Acq*0dzW+YB=A0Khrg1r63F>~LN8J9+4<&k$Wq&^o2d@GO!3eo4SM?96L;y@jyJPj2-J zTh>`3-{)$jyIJCH&WDbirle~{=yrigc=e6-D-JYo`^{re)ov=dyj%Uj1eo^T zoMP&uwp^I;;}5>>>!B=BE?FJitLOvwSgmFt1yr@Yvd$5fx+>k*j!4RuTLM0g0>tsi zNsK81fN|!WZbCc}NkIIS&yFN_tCuT#Ue8nTYFC8+Y#pZ}x0SS<2@Ez?(EjZAM&qX& zI+ogiAuN-r#)_XCSwYiB-^&VqizYWwWz%d@xTAJXsje)K|Al>$d`Mcw?#CAn|J_eyd*DyWo0tk)57t&Q`nhk(Lt z=p=D0+o!x5o%*d~2*2opaNiSGMM5-NNKW+*tz>piMFcjC=mM5Q4r(P7xz$v69=UtfdXUgPbrSm*`noH;lznu| zr^hRI_&8#FLHOg1qj3%}oPn5#Kh$}hHdhF3Wou5R#7T@K`MM)Y zgcKwXl>^bfPE0$ZAec^eBR$LL|81mI%BB84wj^Nj+(B#~uP3mm8i1*o{s zZcxjr?G0Y037bn|VXC>eXek~5bBo+KnW- zgUKSicH&XFB(Gt#gW|*i+H6Sm9QVlgq1N;3zP+uKeeF1}{%y<5vRHp~?Q)7}W#FPP z(gDB45(hm85s!0DNJSSD+Af|MCt@NMC|2}mo$71TH}{%oQ~?L{dmbJ&s2Vy-#NZcq z1$%m=9z3N|h33G_6zhyqbU|D=Bo?Qp*!_uLKWvikX8V}Bx&iJd7dWuCC~E;AZ|W@n zquE7r`hWy_H0@@jr0l6#@m4*>!q;;et;-=Jlfst5#aG>eL&Lm=Ls*$LzVSjLky{%k zaes6(jidEqX)#D!Nh)ZW-+1$ppG%E~*QJJ($wEeyw}PX8Kn%~`TKlEgnWu?1mL(ER zYSOQq`T~E9jXDbmh#Oz04Fgu5-(TI7#jCTz>#x6f;R1*w6Z{;&>s9rS=TR#`DyN8& zOheRx8LE;1(>crD-uu2i3Y0f}S@Z?~8{F1ub!K)!Zv!Xq+l)9P8zb#i6mLewkDDrkLx~V|5_Gv5r=Io#bWy}H{R}}?$C}wnk!FGr z&~L-Z1iAks5&hV+o-~A#@!Bj%n?Q7~1IbX&8+5*W(dSTi+Ye^*6H^W+g-)#wY}xcF z=hj@oO~G=g=#{yDY*q87kMGLAmK#Uy6=ufz7GBh3E(0JVxk-XhBgU@(VlB&ad3g7p zmS1={blV@I#6_~H0rVcQS~_h5kV&qW?9K}-r2p1bQ)OX@6@`HI$EhS%P6+&uuolZv z*$^VZSyk#?%S>C!&k&OM@joj?q8c1 zoW%{6Gb>-NU2bKQM)%Y8aC0Byf6s$KefHgN6fPdn0R{wpHJBa4mzqL{PD6y08|ky? zP913Lc8CFr5J+29#$HXR#!64&W1tfLlNxmRR*r%PPLG3AP=p)Qgwq(mBl1#(bPx^}$8`IK6OMH8FC@tWQ4W!d$w)6yBC3z(E-r8ne&IHsN}8*MYs~--GB>$Y4{8eOPt0XW z1(u4^uKaasgdU-p;fOxZf1GA!DN9N@>vK#R^o2`5_5goUH?CAZEuZ>dJQx#7#yJ5IuGP6gB_K&V>w^I=n0b22XS-@Bzbi<-McFa_ zN5`+B%3IG)`52{Y+!GS%*I>|=zBwpi=nN;bPO0gON1oZ=*sj_RDC=(s(lt5@IXway zevzKyfCObd7y_)I091RF!`<8omGt#s!v#5bOIdS4jIXOEEc(9CaT~<=TN5gbN<{^{ zR?afcr@nsORf3_PxL6+wKcPmbtphnI511mJzPa*OfrtA|iquyVvfTz}#6=Bj^(N2y zSI|G-{ZL+STDI`d^zXq&ZS7;!qZ)yka+8=*&n9%bhAi;9aA+T>McxMvLE+58$H(r) z_iwK3$Y%p*&rO*M0hKl7ObwukxgV)1yO)#cGAK(s@YVmlmF#}u6EE>gNpN7s^j`cV zu8mqH-BTp4E5IZ*1EmAs(AK(EHqSmvMv=SUo!}($@COgnc5^Q>qY5gQLfZ=EBmY$y ze^^h!Py91d-_x(yQ4TxayYpH|0Bw~|-*2RA!n2t(yDB&d&jNqQK#eV2c`zgo(;FRj znTu#1`xt*Uzw^`Nqwhuh6(ID_fGn)De~mOF*;`Z?xK#*C^0ju&O2>=x*xa1bHLg2p z8zpHX9v|;Xx;1^vs~|TByl3v5r3tmn$N_5qL-aCiyW}L?Hai3}pbE9Of-MO6b_ik+ zG$F`#0~~@h|K~3;_Gkm@DOk?MN1O&5J$@m}w1hXa)b{rOjmi86KEFi7n59O)R4fIb zJ`F*mf7Ve~0<2@T|93=MGERYM{RI|gPc%kPYR9;u4?*GXKwA2@VGyKt3W5kQga6-4 zPE3Ee@nsl9$m?sdSvpHtx$VEP;t6+2YEBwJQ_N(f&zOFp_dELb9m=Mwe5t?A<( zTXZ?1x({TH)U8v~{679XJ8$FA0m(-jgV?lCQ4#+b+p)ZR5?dvFx`wu&110R_WIE)# z75aD?`H_Tk-tq!BlKm;D3{|HMnbjiBcz>B|IMrJ@0T5ObN~To6Mw3Bp*b>)La3k$` zGK))u5vHHJKqc+iGMkD{_T8t|hy2CG+o7)eVZc3uETvN9d}MpUhc*j*kQzkm`3fa$ z=VbEo-L!q)O4D3;@hr&wyq7-Y7m2c^cfZ3i?~P~xmu3L*-)F-a%oz2FK*?dGL65$G zNVkAP!v;9W>Arwrx7UQT`6QZ55;{hJ$*K|BB2hJowYd-I0qG zx!k+wQvJls^X1t;xhyROPb})P5tA8hS}jJnjS_cJ3*Tq8-Z*@s$R#V(%3qAUQJoW} zFbhdC@a(ii2qFZuUS0V z%tUr=GtQI-c3M`t{W5Gczrn<=zqjq=?h!|l0WU<6%077K-Ma{0&;|6GVZ6wU--Yy~ zP{OQ_`g1b71xKG1IP>~HAa_}{UT$o<>ZRBrnI)qGFBO2AB;)0Sg7qFCL7i7;_mG!w z$^YJ%K1 zn$ln|@iCaTvqZPU<}IJ+c~RRPVffE{|L1>Z3EbUoSD(H4PKP30;048^O=N{+^ecwkk9hua zkM6UfvsD83ACVdC=26o7-&4F8D>`%K(ZtH9-3V`i=y!exyDqQ=BMsfFnBH9MlhH0b zS!nWFdbmJ797Rdr*XDbqMJI3X;o=XV0LQ2-Pfr`AY~)&Z)jQK`H<*O>+wo3j2Y*}K zOj@&ifq1p(yqDNb0XF&q=vTcvuM1@YYHm|b`0|5vfqNUA0LnH=kwi?7cwUAIbUWrz z@o{h{uk$|dQiPVOn3ySW=V-~UWmT<$GVX?966^5ZBDpzILb}x_FFNI;MyLk`&B%U% zy8sSy3Ou0fPqzm2K(#cc7V+>L1o%29D1)L2$(|wj{$~LtKp@32p-5pb@@~DxmLZi@ zW#?l(jhld|oO#-cB#hPsGj$1IVc@*9&<|h!|?x zYT7H1HqP)+eiNwgvOrZ&H3)kg1!AO;_l0LO^h?=+zVAYf97@DD)5g^{SPEtK?u-(XPvNmPI% zIK2ad7EYpSY$)kYAWmojmjU)>?}5_?!27HMr{IB!2vm&`CH-(V3@V5~fh;H;%F5$p z8mqgu_Id=2(UpiwI7y^@x>(-*ruNNrPF$`MH)GbrMz@D>wVZfx zhHBJ5$M&efAMNV}L&~FjgepdN+pzmp;(la5Qz_x+azFX1cD=UmihSf!R!T>b(Aad3L7udEEJl`S%~&LgvFr zU4rHhkBrbS!J!WlFpJdrq0 z{*e}6o0un_TGe|!J|1YvjWA>M&@R$q8E0vsQjkvMszJRg`skbsKlFO^6e%a->E#_7 zr3DW-E$gjjP*ca=8Vv@(6G5mq0pe7&FahTVx&CgCbV zEg4Q*7d0*ws%M#IDP81jF<027?Wb0@&3x*@+e zWfmgqwDS123Jn^nf;ljK%?4lMxQnP^a<}!7JXt8IyjOd-GVEsqM^33q1Pf!bho$YY zriT34#98dunqRc9XnGpoG^^TR40$lE?Ou6y@%6crIcg;5T3Pi8JIA@BA5cUh+70dL zqX%t(e2GOT73KHO6no~$Dw8F#eoS_6r=EW#o*xrvk%^QdKaS~&PMs7JLbibtfg@>TRw;W}1$?(dps68?csz(S4buUO+DYF3Nz$i46w+Qmm;4W zWCT`zqCl#o4Z{fuuFy-H+>EC8ZlVpGz+Fz_y5$g4&KL8^K*-{NJ7_3@n6kc@R+kWk z&dH1*6HO*etTTei9!hy9pVK9%+!FsxJtvoO_%6U1Dh``6Lhc5nVLIp-vP zyaXD3CrkTEF>9CgCGtBe3+j1pG0&`T+%QJ;7&Kp>V|3M*FJ$Rw%rT~pGR{+Qs~Nxa zGn>w;P?t1uXLXxL6m&1-4*X{KUd2soNp`s1Hu~cCAdz33b!$v4ahy97eX`iv#pBaq za|iCzh+B#)q=T4`HPLr3Q5vbXB0k8llD!{h9Ag>NZL~O*`Mcg{&DPsvNsivU;Lrye zciVkioLD=Nix&@KzEYA^N_&k_3qYd~@K(=%CbeJSOYWO!B4m7tF=vJuW;P0gg?Cg1 z-cI5)>EQ&KAx3U?P@9lA$8+I-hz}|Q;@Q^Tu*M891KhaX$GLBF=T z;Bdy5s3cT_TA;7N?Mu&mYTt#SG=AS9x>*HSSKXm&b`J4lz7~qbbPr_ERgY))Al0)5 zjT2?^H-TLYDG(jx&ScDDS6IiROWeewZv1F=L;+)czf-bg!B}oM0l$zzv&x!eJXJ6< z0#{xTS7-IGN3hWQVpvMz#KoF1cH~*WY3={*otUL2v7#{~MlD#;CRT*VHvUgEL1q zKBBl1hD<468)k%NH6Lq#8DBfivjVD_I@n<|fT{{$uWi?EefHeNb%WwVFsW z(Re;1(4qkuhp=a#(6E(z`hJixa^0bmUAj>3{B}4&Jv*TAL82BOS=!rUxDA$;(y#3? zj4xp-!3t|Yb3bT4o+tWPuF%@nu~>HRA!Lp*{)@C$qE<8-bm``a?gU+T49-|wD0Cwz zaaY0A)dgXwYGev>%%D>j0skPIX06HyebhYk*&{Arb7j@h+}M*cBQ=xn$W+S=x#Q=k z;w9ZC;vpAE!f);wK0!KEdrFO+KwAft>fo+o&r2@kpzV^QJMetwWg(9g{wue)nlz&0 zv7+kfOOW_22%qH8SvANlmo~q|_Y=WY9Gz`)Wai$C$P+C=Il-B{q3ar!q?uige@FaC z6t?Yh7B-5Z&lI+3SZ>}1^U6tkJ*857NO#f9BZ8N=Hj1oxc+JOBFoN_-aDYM@GA5Ue zitlm06c5sm9sXG3Q&v#+qyAhaba;@fmh1pIn*L7 zoR*UoF54^wj@uEJxt{3`P(Vqqv8j_d+kPfPVH=Do;!E^BX^|;sK{^NI z$g$6L_DG(^-eK|-Ug|-iLyTM7K<_#WQeU?ov@poHg?@q8!B~)XzR-hEpcm7HFCpRi zr;{A8&zS5tnI|m(xO2Fe1hKFK6;wfV0^)jLRn5&t}O{L!C%%b zk@**I0OC0oy+M$(X7-aBdhW$!#*v4XI@VeO&C-H8Fzj9Am5Ahsvc^Yls8@WZ*e&wn z5JSmr9#8JqepV)NFil%+l`VO@IJ-wStKA5Mm-$gm6T|dT{l8dQoPPK#ek#QQyBE(* zT+AJ>7Qyp3hypLIRo7r#ocYu{<_8&fr8bb&Q!=VKxE>7Bdse{{4mt?8?+h3PzV*EO zxK)SS$3q|gZy0cx9fhfq^pbS_LxHDdfB=vkj2J`S`*_^^XiQtgZT6w9i@y(IHilS$ z=%(i?dhRNkdcW@yH!Z-z#UtRbxEJrn<4Aeh`hWe;a{Wrb#sbGLIIa<+3HCTW?zL4E$e!O|=(bX4Lw+8rClG${)0>Mp;yDdV?261PZ%D!( z^4?vm^{`m_vp2R?Ce8YIsf11_fNI87B7Y45q_9~T_7?yrDbMlbo$J%Ab8Ho`Ri(Yo zO2aTksWfW~8wHmzpwBPxxy^1-b9>KgCbs_$^0&5$l)X_L+z5B&em((6iIvNX6K}}PoAv51fF{) zQ5U)rz;Z@8i4Tgm^6+*FWSa&~wPuxw*E(M!rc?rZ)R4~w$o5-l?|`K;EcJ4?wZKG^ z431WX0xeRyseLAzHNc#?fYjKF_gzA0@{AER3WNuppG`DhOZ#HN5%57tRnm_2!wEZq z`MMzB4a(pXfQV$9T<1H&ycuOS!F5*1Za;y0y%LBc0Qe{6MvQ8bZ}_MQG_$=|5&EbZgD6C)Ab0wfPll#Hj_CbA z9=7jDdb1}2o>_Pk04t*F4xkFPN5nz2>!qQoZ_aO`Kz~(EcUuEQ?Y%M90t-z2!$0i& z5(%to$O&Gs(7fWEh2)3Egt!FKd$9B`@odN+;#TG#;+tN)kyij-?JSfXWaQ>z{y@A; zWmQ2p&_vXuVOT4#QSqJ-v_TI3toe1rFxz*%E`Q+6hWFpI2bBsUI!b<&RGi0kcV|1F z{XYCLSxb6z#TcjQ+eiT}j<~+6e{4tCux-XxM*9()S6;j+*5k=&hLsdx)OsD~P7LMl z%K7wH1CVfE_bAB=*xKt!hch^$C)gzflQ#^kC9~;PTrOSomQYiy;{nA%;wrn%R)Oqi zvNRw!Z>Y0tD`U%2U_caPVLyXgS0z$W@%|IT3j9LGDP}EVOY4Kt}oAQ`(YDFgiN7zNGIMOM7ls%C%BZ& zOva|e)gts`wxqzVJsG#r+PwjanLv*BhCNh49ecl+m+CFD(=!jrwE#ESLhII>Q`7gp zbD|(a)QAIFoorx*<5nuJR90*P(XR4aKe$E02a^Ca^AmA)yBm?omfpH3?XU~r5~)H# z&PhcwdU}uKXbA@zH8@x8Q=3Rss0HitEnUD_{WnlhGj4Y^yi1OF z^MGbfq4z$khVOhnN{s=>Sk=CM>B;EWUt#%nB7B=5zMs26EJ@Td@iuHmsu^IOvHheb16kT=5DZ2Svs8Xy>c%S)i_{yvDDmng@lKLf zr{5jUlYQAeX-z=DR}SQA8*3kR~sWJQ>KOzvlU~1>G@U78%AG!VJZFT>uCYLt4-t+>nwc?N*{IJ zQtv{UIlCKInn;BGm1m-PI=SC^%|y~`VmGjpJKW^SriW7E2EyykWf{Q#B%aSrbm-iM z=g!W^23c1c47k@|hvkN076J|T?|Njkbv=h0bHlAN7a4^t#mP7r?*dMdw{Y0#7Jwsr zr<&#~9sfS!a^Az1s&n&F-O(fNvhI%Kr0&ULlA|Gh@sA&3;)XXW#Jw7c5Pc~!uZ(;z9!TCj?;J~F)Ms}LD z5RW`e7Dv{5@T3l0&F-`U&7$thyz>OmH&&gVfQaY(Pe zVx=FRzGQ5Td}c}BveetVp0<(V97nx%IsIojCw6$o035lq!HD7OaF)RBOXS1I@Gp_I z!LN16kw0>?uhX{DkTgEcLrNE5WWVG*+38l!{GNrD&66WK_MQI#*`$4mWkAQWK^mh# zjU>IcoVT4qek+W$tvnfFRPc2ckHGPa7Q+Hg-TfwnYVCszHGrGFy)Rj~yqF9tC8?RB z{yr)S!T}gU0eWm4S|w6x$X8uy-fnvD{eMFOg@Na`nI_^4t9g)`aXZtE0uG?jHrM*f z_MV(eE`pyL#q$Nx#<6cTI?QV6`-O$iAT`0cIm4&tz z6mo4Xn-QnUaDQ`vR#K|csFi-u279O#_5a^al-ged!BC|}pp^Hl^eB}H0$^U7PLmE+rob8yn;9rl?odo4loZ?P{d%0_VB zvkm~#Ck+Q@icwV6y(+8YOs$5>dW2a&O&QjSML^`IUcBag3XlvL4yC4alP)U5uzx8-SPet|*>VX; zw+yQ38BxX+UF>3N1q86d(slj!U{*ips`PuiNlKApeJZ27VsYKo+laXl*Dn(va+(h) z$Y%^Z6l`Xg)6le1TC>VgGQ0%y`RU5|r~0E>_xJ9LxeD-9oFPB0T!PsH?r2vc$c=3g zHzRUhd|W0M71Sj5$7!OpJwHq?JYI$GuSR*IO6%?J1Pw*5Hmj_B-ac$rr`bR_@6zwm zzCI)(Jw6O&i_`buMZ)dhltOt7)TW~Q9EuMBK=p^7INk52+tRI11(Zmf&b>~lcCJRO zqC)Fe9AOaNum|qH6cY1AZQdfwHm zy8iAtKiM;-5M<$T9M+&XoN!VVn1bPUr4w)MvAMqdykY1P)xh~TpW$y0T;Oo;FvV;H9>jD-r@b3Kw4|hKABpO zJgWIm5@qNFEyf~KXhp?Fr;>956+kA}T22fa+%83KV(id77$lrb%@ld?nZ&_||4z0+ z3~LFHo!fEYT(6uA+)!}0`G2L~4{In;t`ey=0>)<^xNWPQDy-!{F+fJLUw$}&>cNY5 zS6cB7+_q~BsqJoSeRkwc%m4BvEgkbK_o=~KX;(N^q;+(DZ zLK%ymQ(rMl-6eRNO#urBvS?@xX;-(OXxT5hhQ9M^i(oA)D~ULl=WzP~ORG19I9J7@ zX9{xCJ>ACEhSh}IuMBmaw$yxjj9bIj+bUk#BX4RRO_`j4Tf5t4oD2$?6)vS_U%&X> z=~txpcIX$u$bpUY`#H;B+faL5KH7b>Z*gap%?C<$)ZOw}m z#8H;W6DVu9I`@vdK6T?&@B7ATH>;ftt8RY=r#u&h;w7v`wqIeJz-sp072gem$XXAj zb+j(QO62D9k{|c&o*u~#Mv5brm-G$3OdZ0Qblf()1cNjK)u0vm*t)<|3ZLhRcXzy( zEKKgR%zpn+x4RWi;o_nRH0LJOG1qs;rOhUFvDQIN*sX zZ9u7BDS;sQUJ>Oe{)W}sh^)yeI07!ODF%_f(mgiBgiWqZEcq~;l74P4o0OBq8fFv` zUgi+KV-y7blQI8$l84b(aDq4eGB-JtAa-k@f69c1dGGBnJzFpqLm+ zL{UWjkd?oUP=aE8BpQBc(}alXpU&7awi&G-%yCHAS#PJJ23yve5CI8oh}>@F$GsL& z3}oLdoP++Hl15%lpM$LzPO?#}x}bhM3@_&;0>sIh(qV*U`|e*>UFdz&Q#!tjn_A=w zsP+nWb5EZ*jJfm^>bCD(JFxsoJ=S+LmaSk_4kn29K(C9~x&I^AY{AyH&jJPwU>IVs;)sWh(z!%(aLF_Wb^3vWjq9w2WVC4U9Qw(~s>= zpZh)IN>j^v2KG}DNSxX;Hr{+aES+OW#MBF_v(&Tm<7gO~z(cD9+7hpsL@_F?ArJ_W z@_+PrpUukN%==e&k7X_+jkW0aKj&wgT@T|^jDI|u;G8mk;z=wUw`gs)5Gw2@O0)ZC zKUnuKX`1@?(j9-X68MQl-}BCNiD8*%r{$?;m_=?-MC;ATt?|zuNUXI#1SGC1KwUd? zh!q5EOv0q;53A#>q$s~Kf?JEb_Xku~Z}tcZ6F{Gr|CPPAl3u^@g0mP_&j}h#8I064 z4V~Tr<3t8MDE}63LT_uMt%OgIBw!r{vpLpZDlMLqJz* zCTM3Dji)x#l(KsUt`2OA&TPCMfLW%t`RP~)=UVVyYrT-nCMnO;aYi^dv|H5(^yTuo z4Klz+KUoC=LE@0Z-+A>x<+dXk&xH&NjTa;PINx6QRqcG1RbOu?A(IZw>cfM$l*#W5 z;}>o6KG4oxZ4*J3*KB^Jh=YBwa^hybyHv~*Q7N|N0K*o^5>j!B zN(e470Na>AfDdG_50GJ#fSo}#0Kh?nRSf0)LiDXA2v(Di?_yw|E`rZT?n zW+>5mv&*x(lyPxi-cp>`%ar(I((;U#wjXVOZWr@MIa!#ki@R1{$1*Mi6^WzfU2O%V zT<#&pX4>8Z2D!*m0W||?$n|EGQh~ll`-6R=PQbN%BO!_T6W!%;_u7tgooUj_xUA~4 z{5zQIztXbjSCk@sN;K|rZob4S0}tjHQN?bf8Sh`d!%dw`YCS8k;r`;B+7gA(M}9tL zqKA7DeQ+4HwJcaj%ChR7Skfiz?^sR`yYwQEq^6q2v0}8c-rC4KLqC2-(^UnlFHt7l zH;nWzmQ!sHB19fDLwH^ftD{+Wk<{rvuisLP56CQnXp5C3mPPZZ*R&Bc>0#%ePjQE{ z=q_5dyeo}&7P8fQ%+$VJeR+5)A8QSEGOIJJGIFNjvA? zfL`!Mh1Qsq+ET)5gOfjl<3>Ceh)za$QwBK&wn7%T*!YlgiT{>X&&(fO%C2GReUZB6}3HrI0dwSWEu#;-t z|H(Jz+9a}*#)<6sOj2u&b;5!JCM$Bjw4?iog@PJ_Z%l0?`{x-9jV=x+25#ezzj0I} zG;AJJ2a2(E)cIo^Arjeh1XDMCUO+;0)O8Ngrm_dA`4;DeF5zNBwInu7xLSY9ZZ)oV za$2f>M%X%TAyn*&cGY4!-+xiPXmx=Qd6H;21~hw3xCBZrGGhbS)?$=zK~n$NG13Ej zuGi(Dw2l6Ug)0bm?w%iz(|p{lYCPKEbHTGc{|oSA4}Mf}_QHW#io^(8c`xseM4OKyDDi#|P0>S)Locje{4YWCmJClppl0YR@P z%MAdYfl6$_R=8+i5?lsax09H!^{#VF#ztj>f;g;9?sKq3#qKeA>f5)~-!)f)>k5k> zomIw7=_Fo(64Jxvb^ZXQb&Rh%osJFCz}lt$55jtXN_}!+Y&9gdfEnb~@%eeM3ht{( zqAx(#qhe&tpXfH#1tLl&hnw2C=@RVdWnTyiXo+VlbWOEDKy`G-D>yYv#wg6sc_UgQ z@vhJAj*o45bmG3e`-U&Xl8ohkEG$w#7c*V^=EZnY zfQ!Z&menyCnC0v=SC79k`TZa5(snHO>bqA_S*RYfk@!;p7;L9{D*3E$Py{;>F?Da& z%EmknAJ#Y47_UO&kE~r)A#~=9XQZjbJo`QiQjD! zd9k(Z^$aOS8l`Qv9!V{Cia*2>jNla;*gvnwQ++MIEyIaPV2h6s*2iV^g&tt|bk7Hq zDt1g1g_i%QCb)zzlcKtPMB7gil!S}-A%xtl%|P~~ht>VloK4+C*J!!OR;bYuu81SL zJxr6X5mU)tWWC)5a&a|mTsHNWJ_OABbysZA3WmFi@ar4BqTrj37%c z%z9FHjDRhn@846;Wd(k!;S`8`lU*ZDR0^MMXwPW zQ0WWiUxfOH{b%n|@%el0Ph*`rQp>XrAeWDCDMC9*%SNVXu0%az36|q1q|f@O?Hwa) zD*l^)z*AFvA?6j!s?FV_V!t98bd=V;xbU?nZ2uqywASA9%k!a4#S`7HtP#%Y6Y9p( z#hP@VY-*8O*nC+Yh5PJNfEpyP@W05!uvNN~WlyZ?cefQ(^%C4~vx8#o1XcH5^8AMT z#>Bpu8Yc6Ly<(nRmKYU-bi~D-F`wv8n59{@TNxjg8R3D%`fdCeb~r+?^Ixd@`nf4^ zzEfZGUzrVEnb6lxY3!Na5(_c_I^rpa3@y6GPfx)x>+P%du`dJ4QYlSbgETv~O}Y^2 zV`bYP#7=R(y*@*md1W@T=+Lc{ID+g*mH!67ve$I`IwAmg<0}T*d;&@tU-y4k8Pn9dwmrc%q?ZO6DD=yQX~H1ocbLty$2}F zK2zV++^-_O}6>?zJ@9Pa!c{Mj)KC2HfS`!?-W#f7-r#Ug?^Xy1$5 z(9pk#_nCuad|}X3+T_z-Dwf+giIPa>`{s|AaCGeEPf4sTqm>ro)^6;OQxkz(?1%m5 zp?bqu76&Bbjoy*=DtLbny`&6f`>SECqU&y4o*i5MTzc-8zI+mCWd11e5G&F|Zj9pi z%Of+|=Wp4Gq}2y*YDf&~&VkBv z81C%z9w&{`AJsA~yD#j*DhD%tp+~GSGU4T8I_js$-OTF2NOjZKx9GAlHz%uJRv(bH zYPL)Ag%C$V#5&J)+-vt_A>EtZGr>wXn!di$#)wgs8bt*Hxp!L62G$gE+AGaNF?eq6)xx`(tg^?$- z+@QYX+0F*r0f#=FI=BC59gY6b5=v(_pBkhp{>L{2A>>;^Dy7HumBj7B|I6XM7jz#~ z?1_m)a4$a(-k1$Yi$N6kIGBkrdn~bbK5$)H?X%uukUCIKf&2e9(e(0RE^jnFosOn@ zBOsT8z^p-S%a1#p#P3M2@dMV~EAPb_9zdm%(_r0^nTetTtQQHu0H1EhDfNSQVEF5B2Ike%!6G|Je z8ad~qUF&cD*@NH9*|xF|CO`6Q{l{ zw$zloTG%RkieV?^QlSLow3@{1My6P6hrzg+*8>G(03(-hM%`H-(bBT9|+JZ+br-%Rrb7wZHf z?)HONhw-ePni5tWd2crQ5|76uT~4jJFg3QH8^?H99(T~De;5|FCnalmcOu%_mwr^% z1zct~OYu1=U#;=fr0ciFD`q?x0YNJsUGqp}Ig~fx%U?8#O+hWYWvZ%;XLxq(ZcRCj zfRYzLn38%r#?*4lUcr;$;AI^*hDEP;&ft9o*LYoHPeNxJPE>ELBKilGIdko{a)Yt; zz<4b$SWKjJhgQ*nTScPdadedg zIw#+eO(f>zT}?t$3pn=+R}qj$^j-GG?(&C&(kauoP+9KTUCPDA9mb{enx^rr`97+p zKz6N7CO+(@bNk_iiazlGU4?6J-%WoP+w07lOVCHOpU?@5?|9UyKC<~@%X;v_s4+Ts zG*{VdSFizQz*^B3mf7($+fKQd&fk;tNa9<4Z=iSt8Uha^iq0wv4zJFyKB7d8=(x6z zvZvyMKYO+6{6dR>GW&@oN^*+|_UkmbQnvpsPd}l843J5D-Yq+vVb5eigs{EnISD@tp&+ znf-3yDZqhT+-51V#db{y)NjqDpbf*Y5(1t(3T~&TKqC!2LOkXQ`5Vc3rn?f7clSF= zRD{MZSrv!B3;wdIFD6k2Vbz_)$%~-mw^&r*7gPy*MZvqK|J?0Kr4>V@lbqO?}2b&zq(Z-OgKo8 z1Mj*C{(BpEFt{&QPMH3_2cE|1w-QQV zAf>nwJY6gA6+aGwlxi2=-wV&}ya}@3jP07KSJ2u_aOD`Z0?wqQS6qnR7t?03mUu2! z4yCKVd9?rfJM+I6xd0H|{WjbAhSK)cGHY=1cHnMc~q$wM%j2}-jm5rxXhYd_s_#Lwk`unE22G9Zac;;Vw*GUXc;QtBK-gJXZp-U bt3Xcen)6S@G{}-A`w~-82BC=%S(8vq6v{S}DMFS>DTIn-Nu)xyX$pl> z5z01Fyt9sok?nWq{r!D@=lss^kMH^Y&iS3gnb+&Sp7*)mdms0C?=>ffL;O5aJP-u& z6Kt%A5CjL0aEJ>HewL&A{(>KFl8t)=1Yuuu{$U+qk4}O{$@A83=Z}V+Iv?d59sor} zMQH_vhD7-Lk^;2C!UOZ>&7~kn0U}uKbB@lR8;QED>_WM^Sf?tWcfbMuIy3R)4ktm} zTU%jwF~O`#g_p^lHo~G8tYKNGDCKM1xMUmQBmK}@TN=*B`7-jF-3R+YONZ4xI(Mf> z%S}tCn_8#JFgrp=)-Sj^jx8L!Yl^`UX#bag!h35F`h)xF?euT-6gm%mgO2nmNN&LK zpFP4{98@g6eXtGtQRgW61Vxtor5aD5Np-??%=6$$@CC#{s}D*9;(#WU=pn!s@JSrp zha;%pC_J@pq)pmG;%`~AqaA;%2SpsmuqCU{%qq}uE^T^H*mEP2!N1==z*!FyDM!h= zHHkJfX9He52}cqg?N=>J2x-SE+| z*7`=cNc>#`WRH%w8XZFrUJtm!4Krk|)DKjJ#qXuxp~C^+;Oqu+Y7O!cDttE-1D9^Y zDwbunBXS`5WLc}}gXt(AFGg|#VY<(aY0fZKD$5GjgbI~4e`*j${?UNRrvW0XP?Qh+ z9%Mt5Y=-46cC%ejT&NcLNH<&^>VjrE zfUxK7&=g!gUDiq}J)egzZamOh9DH3Ro1D>xRpM7Jg;xj7LbRtk!p4a@lQy=;98gRU z5Sz|+8>T8<3+Rt{R|0h-G{w!R#g%Euc)nRFlcc^Uo;>sv4%ufL#(n=rz^eI#7Ro1_ z!^%LItvGtM^34w-q|$~}Pz#Au_Q`l_QoJ1q%PhW>rjSjJ^T%W<6vA~>A|ZlOw{^G@ z>kcr&lZT8exsPFMYr;~x;R=L5Ga9hHY9($#{IBG(gy7Oe?34ikXp$04($C)fD<9^1zk9k zAJ7IxE@0yM?Ljtw0gk4PhWayI-QdUH14mEy#8B*Nkk2>*^fRw>w-j`ys>bOGq?{Kk|XMp*;Sh~j*_ zuL;`?LXW%Pca|B&8H$hefG>!p{S4ucZk#8heq1&g1;}+dZ*`h5{*!?GrY}D;gMPmz z@ifQ$;-{5-p4g_Hk%IgjWz~CasqZdp!miZ`2Y19$iVN*@jbv14z9GxdS7W$GG& zw)F3y-GS47^RF#kxF+$R#~gO$y9GQ^nqnqNr#Oau@l|8;`24EZ?dt%{%ezDwKOs9j zoI_}OSTUd5O(i^imSg_~4;o3u=j-6U@Kc~$+ecUUtyEc@D~G-2jT)pChgsV*nfqJ<*jSW;Px`g`cPAFK4vY(L~jQ zEf{oqR2%j)`d?xqYcb(5?ux0dfUiASxyX*wc)W%=@uU(oeu*;i*&N)L3nmA(LmCpX z8{1HivyheSjG0LFzFCFC0kF*M2lvCIp1`I+^NBloPViA6Py{&e=V@J^E0@>vq3%kB z)R%hKNG3kLfKxl*%Sa350Y9_A?GhZTMD`7>7j`XqzS5>I$*NstG@2 zuKNN371t>xyz@(r%%fr_kC>={Ku^{r>QjJUsxFa7%mx=^m~UvckIW-r629C!IR5&u zvNPXQD>#8U{BOHZJF>|#GBcZ_)ft$nS&1cLP}2DMu(A55XvQ7#Zhs8nCg?SfRqEFD z?&I5kaS-FmYyZWV3HO;9+(!iA%x=6w2|Hi2y-NAQmDrPAaE`u4H>^o42G$U&wMTYq zMQF2N48FuE#FHE$+Y(7TW33?&ZebAaD`Qszg(q_s+70N3xb*nvu^Y&G$>_4KDVJ5S zOu&ZPu(XtdL0Iq}eq%$h?7cG+7`%6XO71|tF@HP9b#r=obt&SW<|5dSFa8` zgl%#Tg!}b4U14}i`*|)Hg_GxHs-tEFi8nz~=$B?u3GwMEvR36O;1fDh#~0U{xY}n5 zJS;UFN-w0ifTf@l*i?M)G2bvUA0L>CA-r2O#Fu@QL&>RB9^KYwp;=14leLTVVJac$ z7E1hDcFpdCBJksqB%GKi{1sOXM|4RxYJiD<98fKiW>(f%_=jZK{ls%X#_|IJz3(68&n*e&+oaz%<6r7iU^9p8C;#K z=B&0sMWr=;R`{$S?JAh-I-_u`9?;Yvzz+RS(;v~f#zdVLWkZ|*3Wn!PnBgyAOkQgVBV+9Q-m$cJ#MlrUbc>BUF_`;^Bv}$qzhKjJ%#Aiw~v@f!ASurgY7L^Fi=x zbTx+6Qh%g490;2qkvGGCFZeZ*J8#IKb(o1v#_o_XO7D~9aKZRvoF0FGpZc?PG+46( zvKfidjD)_-pJ7JT9IzPyAY$YWcayLg^*;N^EJQQ{#zlE4=3|e=H?1GI4&3;%SHz5b z|Ds_eR3;7VF!Ki{6gzOFro9nXD5HQ5tK!#X@w5~$-;a0z<^=UlxWa|7JA*J>*{(o% z_RG59S?JojRJGl#;AB zB;t3@t-j`qlrJ1lq3P^FMcjJ;ux|R#48nw;ThBtYzW{x7F5UyLe_jD`e*i|i>91Z5 z(APD0>F7WZ_J1ipA!7GLCcl}LG9wpLKpOv^MWumw35ihl{;v>6L1rD;tmM7iQHN}7 zvr%~UfqPUjc!Z(&Z4Q2Y1$u=)P9A8nDl7I=!UTY!LqYECaQC@SHfaTk{B?|Js zCaXmA2iV|$HeE-MqdKrhY7cWo?Y9Yr0MYdNozb|7%-9{@oZl4LsPAr%$F z#6*vH2jc+q3|+c4{Y6b;_DKv=)5jUGGM(`DDzosXcncomH{Tn6D|8lDsO*@PE-Btcf0R)K4|b+2?&pECxY1553|?y&veWtXZ&XrMwPJ-$vn6LSRf8##geK zQsBkLFO)H%gMWKOOzb4RRP$G!ba5NB+;Rp~wy)PIt#DP5goDi`+=V`2O8F(HQ)4KB z!LiMGlsg731?2_we5XMXG!c~o9 zNKf8b0Zrnkki+wFTX|$lky9%nGb8)#jxLm>eOZjE6z=bD{fFq$R1vih zTP8eBobt%5wqLwTKSg!iZ0P=BgdG$yZh1Jc<6bsiqDy){sZ`+3TeVV~ymRebO%V=Bj%11$26P<6#zb|7RtK1JA-fMMAAX_9Uz zX1*|G6SiNq%$oyBObbX|0q)`|e0#E`UU9HX*OB?}2gizKkE&>h00I*;xZ5-8lzXa9 z2f1$try$hd^c zlyP=8m-)%Erh^L#4E-+7Jcv^>7QbCVpU8o*mAg`%O#qHS-JocTM{nrTsVPrwZUQj; zIS=a_UAjD=%C~hxstW*-Fe!ojZf2{rD$KH|c3&cK4}b&9$2{Pc_qP|JRDiTJ26Ao6 z>5ssGSKHSpB+h3lQh%M*7`~V3Z#?qkI0LZQ^x!+RR?*gkR3H$qg6_D0x1ja^^W$mf zS%}zH052$X_R**=53$90B3c8A;Z?BbL;3+8^NAM^O%ga`6(Q|WWf zL&~+AYbTkTbPQ!TMYjZZ)A?l(U9+w|Oph`KHzW3F4?m}D%RPO8$HS`W4lm9eh)sECsUMW?nKsnYJQ2O9_0qNWmjuPzIARQ3a@ri zjE$`3eb4SYj~=h$tg7!m&H)4zL_PXKErv=`nQtz#pUbj~t_H zloyb`y+U1B8>vYY)e$jHA-Q+e9<;p-c-Bh{X6l?SzvhLGgjyubY|swq7piF;r|)~i zq+uBVQn^E-L$Xxw)oV=JOFTq zct4R0szsmntHLn={M>J(yyp&au{q)fiFS!ljkXW@Van)JlqJ8U(^^q>-~9^ z;lsa)prCOBh1a#mSlGH%mx49C5n%-ORB$6$qcHl@^G|>1UNr}HIf_GVBn6W7te{wo zB%6x`YFzv)GQM>0Axp(VUKt5c{qTo5jl^T}1px4VyQPTp|i( z366rJ8{w;Hl0B%#0Mu2!BFO3*R1{v63Q9}7jor9RI@AsjKfUn23XcQBaXZcd;{_02 zaAFYEqi1+}ti^PB{9PxF+IGfIHp7l`6aDsu#yG$6!79n-G3n-CqTjbS-(ScxOq=M9 zE`T|GF)vv^CLlc38#&grGgKFV(P-Ag}5cG7q3VrtpbH@=8!xJZ#W(?lR1DqHG{CCrX+wOaLf>93J zQybroDHg^30<JMZ zO|pl`ZJ@Zd4)Q~cm(F}C8?+tBjG!ARpS;*O6k}8}j`c|ebu9}oxRXm$X$;8`_T+s1 z!YBG)=cUOf%RlO=FF+x|$we+hR^eRjKeNv^9l1+40<)zLad%w^I_c64FDgGDzV04c zpv`9Ap^v*Dk9;lwNPO-j=;W0uTLeoPRX&H&63N>sVMA2bgvwJ&A0@3^desqgOxe*o z!J*i<270897KPmQZnt>vt72Y{Q%?1 z>m0`75PAE}npyb7n6e84=mDxbCCSL92UJPbsZ}4n)?<`?lp-Ax z+x*boBocZK2C|F0DiHG6`SVgGw)bZ*!#J5;42=_aFg8UR(&vH8fI9@1$k~w;<<-gZqVd2lWIH|rrIC~FAf38?y_zMj2Q=b3u+h}d)uS~lZHq~ zJp7Vh(PMT_hdDGS1HAlx2y%ITm%Gp$pl+N{j8*(*0L2?hK*S$*^Cbl_R9SP|P+^Ab{<$gbfG@rmeFnhRG7mW`Z)SyvO%D#sI&(Q;=Lfuf zKs&tXWo#mgTif-J;I>qZh&>W}T~_HnijwG`Jdg|O=_OI6D9@@gj>KLP> zz(s_YJbj+4`uMD%!3=EchE7@P)j(0-EA-)8rlW#`8j)N-U&D(`ufyVPyuz+xpu9Hh zC;W_1n8W2AlW2#Iv3KQJmS@U`oSB1zios9i#ThZ!$Pt{!o__H7 z-#T@HCX^CjPSW)a8a9+fZKPET7k28385inYEj~QTn|~-iQT8SmFWE0wo{gAm(DTvv zRd7AgwK@62n;gNND*pTxnp$gR(sTXZTfpe7FEc#1Re0Enp}h=F51+CwqVaxwnHGFU&gxj z;D<2mFuYRQ%;sP}I<(mRN{Bg0YCN)4Wiz&-O%t*u2>8BaR&dSqm!8odxA@a_di!j! z+Ho?;gn62g7t+}e3sulu)KCWQ6>SDP61H$q`o^ee{hiF7)&q-a5Ej0*f5(x++-uZp zMOBKG7)9kaZ!g;~o>a%dI{1*t2ke^{q9pP0O9?}v-e;cv+C~V?eOuM%|z04oLad7jBU&c@i|C+())OQF5CxGE`P3-$Jek`b!YtJ(4V31 znpR>Hz1e-&mAP}!Eig~J+lN_E)R5nLFJtG`=ql7tKjm@RkimdT^H3KRmM8&pg$rC* zYntGia300P?$E}R-P44E%jFp78)rn&$M^CMTh%KsL^8D3k|?U=U-Ss7(ekzCAqIU9 z)s9a?P(>+xek(FJm9%zxeRMmXt6r)eQC}Ao1CK6n5b?o^#S#XQNBVk-OWsphZN z)=~4*`qML^tn4SH)AjiCoC|Y+UP@MbZKjEkI=l;;@jh-T`gvg2eaM*0$@(s)l53W4*l8)G z2dM@1BMdQH&Py``b7z>(eJxh}81=ku6N|(LZjiob6wCu|2CW_fho><tJmNEi!9rSYhcV3p_Q8d6CkEiL1S z!gBoRiZ0brv+NRl@QRK_(LdV0gibKj5NoJvangxd1(YXOlXSf*C{fzpMd3Hsw5oUd zelB>}aDx=ZxB}{p#7<2pcSMs3F(ar#tB3!Kl9F0S*lzG@Zvi?UEmUuHB@cI0aAdntMYwZz3}`gg;qg68pMQr$gV8NVj9c4^1p z&H1W2M`g|K2$}Jh@h<%ev6n1sx&|($k)r4o0aRMCN-gvw$aK7yWEAmF!d2~WMn@rt z_X6iGK=qEE<0Uw$;{v|U+mGqFC(L{P(6>r(v|=>q@{45ZO$gKUr88H_x&bJ4A0Cz^ zwFY+Al)t__-D0w@gq{xt36G^kHmCRvUJ;5S8!gB|`|73qy37Gu+y7%%l#k((TmaH%TeY+>D<;Y-R2cqz&-}aIbOh_kpGkVGEZG4NHfB zV~WGFIs*zB?#WJ~<@xnCG+H3+bn79?QBeEPpie6Ymc2ekrKHRMcpTM`rrI4Fz0>!? zenMw%9qh$e5M2Yc>W(%px~zG@{fdtFt0npvIg1`n^^jC1xIy1SRalAG6|-BX?*5g3 zJ4`nP)jncM6Y^td4s3f@eNPOR-I^`!csKlGXlZ11PmZmlBEdEtRn)vCQD4lo2oXeo zBG8V1fPeJL5x%v#`+F+YWJQ^<8|e2WmDeI(j``XJnT0FqfPZv&B7%m*7muI|@rP)A zO5)_mm+jd zuuJ{24efIP>~vuxR|HeQRiOH!wL6Y*?J4xk@l)@17i`Iu(_M=fzdr23T0E*j0Q%;F z?sB`>(XL%Liuv53Z&Q@Z8Q#xR1Zl<3IB#13mJ-wwFLJt5Et(*o(82i<^TQbA|IW846~9ZyMH@OpEb8{tF=R8_W@aLgG^M>iIf7^ z+p|^+t7HMNsI|i_;r;U8&&fT}=Ua^~^VNjr_JqCauypXMJANIZ1&_CJLw`Nm{U?`e z7CFon8@nT8HM-4Z8Blui7M++xPa+B=Cno~o0*J0-w|4E_$yIu573rm#UF3YoaDjj0 z9(|%!;LNcjw?YpW*WOXx>vit@rKUawaq^0L%D4nX#=NV5x^HC_kd7S zJM7f6a-eU4W#GK`!GBUC@E3S1qlwari$S84{)1FE0w=_@Y<-Ykl^(3cDCo(**~&?` zN{5<&_%WyoR333^M}RO%{z{NXWB(yAYp!5UB%I*n*;8Qfvm>uM#t_5q)`A2gxDqk9 z9M8}%x6b$a&%3_RAQ)ePkX~no62UeLjJOxO+3Z8)v16S4mgB|8oV8p0(wknPl#El` z3&iE}HPtaKT2Y~o6o3M{AY4PGiE-)bd#~WsOu*YZSGCWpxDS}B3eI;$&?3z{OC%M# z)2Cv#zoPXhzc@ob7^qUGt@D&=0k&6<73@wFpwgjZ=z~K22i*{C0p@dX;Ym#ri1QE{ zEKA(PLUOxJ>}2Pmes~LZ*xLApu5A5HmO*pgsrVB#XLVk@T#Nl;E#wG``BZ5Ka|8u5 z0lwe2J;(w=$M$6xpK*tNS1VOVVAeO$?9g}a<$GiYvtEsDtb1be-GihEw)tQR^+va! zuO5>KYUiVXioZnk##a|qR!|pG?Udb)g=7CN8@%`e2lTBO(pU#~AiTxf zD}TS2;_xTZuDfx+F@t=AEzhiIoDpOGo3?R|{2Rs|~A-eK+X)^tMCMs?Bp?#dBa`3fs_Y!@eYK!Kl^8)3vWxH zljn3Ab+GlxPVlPTix|tqx}DQ* zOX(QAN+m4-oGW?)Pn`fa(5(AYT&s0Sye!J#zNX-cIaqpW|%1q@6yLl$@gy zuEq12-=Ggjgv4BVh4D>C#pmK3fSlgC189@b$JrBcpO*wjE5*}gi`xnmhxd|r$DjRk zmWoO$@c$qQbqL>@x(lz|=cea#)<^93o$^b&^eBabA6^XGumcRTSO+7F$74#)M>pk8 z=`wz{RX)7lQv*S>4(yX-JHA*-=>8Bm=SK60!{EHpamiGBKYERR=W#cd}L@(rC{n=u~VZ3|mu1;KZzb5ob zo@-}sox;L7AzI(5TJjT-hx$DQDCXe-p-J+n@PcJd@r#RM;FgP5HA+&tn6Ra2c<5T0cnax%(nf1 jxA*)%Z@`w-Z-a|=m#0%+eY*p0>_P-<2dk?6K9~Oowe^2@ literal 0 HcmV?d00001 diff --git a/Resources/Images/originals/script.png b/Resources/Images/originals/script.png new file mode 100644 index 0000000000000000000000000000000000000000..cb1210387f0b7e06dd816cd3362bbe39c64a89bd GIT binary patch literal 12233 zcmeHtWmHsO`0klu#$o6V>5@jeV<-tJ1*KCYL{g<=NC9b)?o^Z#Bt)b`2>~UfySsbt z!QWl$e!XAsy8l^g-m~Y~&w1W=-m}l%XYaEkbhK3Pac<)P0D!Nis`L;5pkNUSU}J%Y zwj$PU@Bn%7P(=aq_Xke^_yg&pYWMi59ct$TuVekOQ{-^fO*8+*0+XHW`lM1*XANgr(9{q^Hra{YmiX7>co9gUINW`p;| z@lM&FW3`gx-~Q1lI7@qYvK(2q5FDBwlXguK@IZt8C7`^gQMK(`BHgi}7w zh7lHjC&W!oC-NaVQj-{)nGMEo!l<{_0_YFqkjbyzvR5ZAM~A+7PxK)VdY16~r_*t7 zuhi3%&8*ZJhLid2jMTrqRX)q#gbrlCE_1$=qIdYU(S3C~+PAIzKw5+m^3}gbQPWH4 z`m6unO*tdt$6Py&g6mOoU>%sH3OO$kDsUF{0Mv5EDF+v7f{-hf#{`kh?@Nj_cg$=X;o&`*| zt7V@L!`xVOQxYlg`@|gC{89;t-uhR7A<=u+G-MD7Hn#Av=Q2CML(In)7ibm{n-;6GZ0qeQM%9JnD=3suk@ zngC5C5Lk|bcDsBB=$yU>?7Ga6K&Ueg+WQ|+0IdE4?&6>={{cCGLFWx)2Z^@-2V?+a z|A2BN+Vvlh0vPbq> zjrREmgaD`iX<(z8Pq`sEyAVh?6__Nl>AL{aLOBfGx&ddjxuJSC0I=vL5&-8eCHnoI zJ`^=K1tk)_RtGq~83FVE+<>ie_MeCqB%Jo22se=XPs9Pv=>AXSBLIv2Cqj;1{U?$M zC6fIo@(`H+7l{~7GycDGaN)Bt|0sS?m!5yJk`SFm4F2exJ=`8sPc4Wt9=g%X|*`BWG>2 z0bbO62mHg}qAz9O75zHG(e`cR9iX8yishU-`n3Z_RJcJPKg1Bw{th3>d1`yCtgmrF zvCb4Oe@&>hN|3w7k+5OQ;AZ=fI7WhEiF(rRne8Z|pU)P#c__ zRCg^dJMG6yux%aem_tJKSd`>8pawWWs7$FaoD%B)ZNI)B)ubfeA+ahp7+Rh&oj2EPu*cm+Wnr21nh=(0%Nd$@LKGVso#O_}*P@pPl;) z`|}H^ZqADC9E%~ z^S2@9NvbE{zH4ni>81uW+hVUJ#w_sqxKlgswWMOd6Fs+?|_cW9mg@oumO#N9o_L>Pc zOIt%JvLA4xkf`4e@4FX$Yc1czY+{;s5Z-bWNBu=HbsPK4^73yaXVs|(=UGK1av|yf z-a@t?;f&qPa7--LBgONjg4!-q+gKQWI4x@Gt~Z#nil~4VC7_7`n;gNc98`qgf1Ta8 zRYi4P_-b6G7+8bH85Pk@gwBa+Rdoge@r=eF+5#$$xStN$r_F!H1qTTc$NcF8B80aC z*?MNFz!)yWW#fMB^UNVTa>ja~MCAo-hY4os)uw+=Ggo)!Z8erkk${3)n@wE;P8JRl zt)Ji^yZ4KJ?vLH%ga_tc)9YB+nb7s+%3cfk^OP3k2RPBg!BR7ca!Z@=DsvCpo_9_` z0a(@)==3fI(wlhe0=ZFEkPsf9kw*NS1yq45kz6@1lnZ4Bsq?!OaAkbRstS}3hpK60 z0C`~=VU$Hr|L|-J=_v1__2+-5knKCx)HfXcnP7y66QiER`Oj;9eTAzIW&iWdhgi0j zEkStd$}DwNoQRWz6_x^3!nWw#crsvH3?rFgUU($`h|O;!(8L6+7Xa(ypfK#&)YZxg zg1vla2i5}m*eJO>1WHk`2&N+vS0TRj4#2xJ81om@7AxknnvKW#Hr9zSPcc%jE4$hmc8E>s@jNX zD4L_+E}QkDjoP&J?HxsD9-W9;jwf0c$a&)&$NEPuT1y9oiBsT1WvH;2(Tmr%i)ndI;|NRB4rYu>%*G~GIYSjG>-{w zxC}{kzRGl#oIEJl4BgCqby6vnu=TaBY}RjNB8;*i*uW!GD`e9dRmR)m^ z?>Xi*=dN0AY?#&Oc0|Lm}H15o$ zveRDo95bKdQccs5d(4wG%lHovgv0%o32-N8T~AQOFZn+(X|5U5-1F?0(#!t(^RR(8 z<9b4r;@d|HtY>eTk^uraxT87G#YTmRh*cY5a{}U=Tn*7KNPHT#+a(d1$#PquTyJp2 z+*t6XBkS_)NvE?5a+YeLF(sMmPVx7yoP)Cy_WGjW@eG%^vM&wV#P0k`$9cy1*uIR- zUyOGfP-FU?Yt8qn^Cmt_p;Lx~opj^mz0+u$n;-(l zQ7eHaP|u;pbgp>cUYGkL-~EG3?!2ysJzl^E2GZVfcZu1Gn?# z6d%;;RoZ=^X2t96J0Sr}8JjpAVZ;{Kt5l4XP<^819ZSj>X&kOw!t}r7-o&(uRv`*nnkp_LPYWzolL2dn zO6=C~5Rdy~+cxb<@E0Xqzn?}!4#F~XRyXUTySIGTe%Qt~HzaCrmBhbi7%E~(M?EvJ zX9*zeqS;Ygo+iipdWF6Ck-ugm;Tj(sws7J?ruSuoB|rJT6S7QWv{=DkT(E;B^yn&Qs%Smwq0R z();{f+wxN9zp6+w&xdGI8eIsjU$2e{FCfdp^DT+VZy}|>yuKr{Mxh8WW>*i}^+YQ$ z3tC{=r~la)y{wY#1=`=HD6d(d2}}~wztEHZu1bnCKGaJ?o$+m*d+%u ztq3SIacmrC?dEIqt>3l9mi6RI2hhcC!P|1n+cCRXJtB40G@{jPnZR?xAPQfuM?`Uv zosH<4I-=l-AtdU)1X?V-Z(;swdmEcw-&;{(g8C73557o>KJHP>A$4qm*EO)1OrF5) zbk7Peu;Hv^=w*FcL1ODkuSKRH{a})*gkKMOIDlEs!QodQ>*^V3$*|}U_Qa^k#XE(- z^WR2sxb{ZthO731u~>iSOY9LoaboY)I00TaM!S=K*|au`EbB9Mbaowu5pi7DJuQgc z)-jq#w8>{|iq4XGi?v&)?i3%zqy`5je`UQh9N&`3W#41S(GWY84n6DU0=BwT7z;@# z8QeTnRs$W|{W(dii#SVx>hv6!fb|QrTH$Ya)%N&;kY0H+2*4g>E(<0_M{t4B`e5lg z;JmHmtv+DXMH1IkfH`#gvp~G0da-4++pGKxVpsbUz;Rru_)w`# zh*_#!`~hzgz91xwGL$|Qe~riJm1^fM)Xj^2FM!U-*EQ+igrr`Yy*>-uD7$^jpu%eqiT$O3D)604&z$u+`MI9 z6SP3wD{H#YZtP6}an<{6hKf}G6(+{MmOa9c&Qg92{RCr4ch+D;9wjdi=tyM=K3?F7 zt4s)v=a)zOKuy)S`u*OxNuuI&<(_Ot1p5UWb@g?)n^QnoGqV_`juqZby`q{NpH^I6 z6|x?lA&Y=+Zx-ICzC^TXeQ9rt?te5{U2mQ;xLz~d7))8pSt%Bb@sY`b?V!DfPK} z^@{M*I^Cx(q|`LcI$?T2mnoc1LQ!`UITqZHyVn}!op+^g{71^uoYb-u@&X=Gy>!jC zsf$&Edv(G%orIGjJefA#@>VLM$Ku;9>&?7T*_N3<-==d^x~J1aWL#|h{id zDA9+evH?#mnNQF^xh1`H?-+HC7!W$*n|)y6AZGcyS?cj2K^aml3nve5jo_P1xZSE6 zj{Jqv@z%k9UAjtVqL>m0VRd#n$X7^~$7*1Y$9?ymx1?T&+Z(YUM*?TV3Sdn_(pzkH zb@l$qU9>|DA!Dxa`wa%A3{n6_-R9%9JfoiCx#C5^`JzD369pTZbmE6k!>w9xGaU!` z>PmMR8$<;qp}EAAsOTswRfWy2bcjVcyN4=HXAA# zvRxB-TiICq-k|9gE7*V&Z_a?j4~22AR(w?)euEMr<{M8;Xs3hwfO?@dc6zi_f_UiV zVf+;j6&o{Pue@Ucfnx7S<2?M-Cu-qmm_Dv2anj7Tnk0}CxHKXsUmvs!x=hgrkbPDG zLGMhk$9p7>dPqgwPAXqb4d)`dE3M8M4K4!o%vvvq!0Te+4w=;aW{lZMs~k||cvlV- z&CmH{CVUabkW{2)A4vkOX3-nLLh0c0J+4bCBlzlAQZ4#HU{6{a1y#-fljRpIfqj7uhcE z7O<_H#vZaR2H@Cw(Fm-FQaC(PdIpn?*eRqZHOPM+~tP{LwoOZiN|V_U*>NS z;{1aPo~=|m-`$C7@@?nYoS3z4Qu}mO6VrY&NPQ_GOO1vFW_i z2j^#V)0(&Hp(t?C;NF-@D+8*e>FrCI=_>0nsl+Myynkf9b%O1wM(wyVxyU{uPt`HW z1`@PTt1OAX5Ne^cU}I04n5i{Jj1wXbYKM>jLhBT>rKjDjyT$8u9>c70bcB8d(U~qg z2@F_!#gW5L7^TdJv5f-XsSsqh&rgTa5(ee|=Z3+V>zt`2*B6+MDO=|pzs~tDsAqvE z%XjE_?^qj5D6g=f<&n+QmJA<8#Kvk#RV+_vi@pV!6Ko^28MVNL5o%W&h3R&NpUv63 zxa}v3j@Wa}x(sU)zFM_Wx+(CvQu)(OE(YnIAr{4(|WKChm`^2Rt+p zR0VU{?ueT$9H?Wl!Ps828?H07_N%AR(Azr1wkFhvyg8Vu7ZJ3N#J-amaW47OWyWGx z^5HYf8A+;nM^tQBB|VadF|2O(_hR_qV1?UY!A8>Otm9sZ+qbAspw<*9$R~AxbuGm( z-)k`W7?GfR^<6&IE9_j=0$dS@`E*^Pv0UbH+#E$CTslICmh;>KAD7bcupq_yLsYUuySFf z<_oW&7f;Wr1fnINKOQvJe-tZ-{Ic+Bx+O0`IeSLy`iDLLJ>So(wLb(2vB|&KkAb&S z>rjVc5yTHd9lAC~Ky;R>qWlHybS*5Q?@zFr`K_u^T{*O01C&IGk15))`=lC!I}AI? z5Yo7!vYaD=%Vwygq5V;1kuF>6g~I8UnFvAM0m)K;Owx*U*n}Wk@!1AnFU>^;I6BNM zn5y%_tY|2Q)n+wwE(Fk6p{R*EJMebJttPltXg}tyH1=fRoRFzjFEHRZ0_+BzYK#qZ z`8UQgOO?JLj9}rXb&>CntLecSt&dyw2X+tU7!Ax)XmVr&u^XR(Av>&-!72XDj*|LHB(a0FzY z(Xn{+*=o{V%9tjCqwt6xl6OgReq#cC;P6`y%j~dm$(5#H@JiOi-+RE%7P`FyPu7olviP3XEyJQ zoqoki{}(t|~Z&dB$Gfi+DS`@*YepUh&9I7}jEM2IXIx3e8DD2`AInbiOf*<%YUK9qf!Cq%*EJ;-E6mgFo>!HSXcSFiLxGM59|9^}5O8 z<5*HJA+Q*$8y9+XASIQ6>qRzJS&?YneC?)b1Nmb{VAOlvTcCN@ZeB9bsV=qRsiHkR zN1GnOx$G#0rXAmEDa!3%X<~|dID`YZzjwV>&8nzsKzEo|2{Qe?_mmu!?ilw_2*ba& zhz0pJr6U{h2EwGF2G=PUv3?}-#4%{Xr?s$;Dm>* zL|XQdAN{M(;en)_@Enz(yo1`sRAK=vK+nlj1`3C8W_!MlO$hjGJ ziQJGVsNETL!Jig*tBKEK>ld83hcX|dTPfpo0DbQOY>s!X0q;S#U1DDt3zxN8i&4qi zfIYjs?u7#zI5#z$_a^G^9_Kt3cW36v1cKhgYb7o3%Z`lvmZFk|CE_8o_w*zo)zbu= z!)q~O+Q5NVofvCc;4e?Ebbv2tdsDArU1RZGXxu|&lLf)9>K!!x0TbtlB6l#f!wh(? zyf8ezdZbtnBeKS#BWJN;KD>=)DkY|g?}%%W za=2b=V{TyZt+rXElUfmTaWd&$_0X0a3z28}-$XS2Sfb47Tul z6gseSwU+VfTuYK?Z|s-hBcRZUnw>vE1(+BIaForVnI*=FhmM2EHZ^`}JyDW3%OQcC zJ7H%eNe(y$(~+Y6{JgQiu?SQ0S_L8z&$`~}rNR5@sM(({P2K9;C#Av+ImVR&3A_~V z1YIC#o*C0a01XQC2Za0gU>x=$_UzEKYe}7kbyPv_X7w0X92eudfAc`354fxlp0|xLxS?XUD4;H;k5qt&b@MV7J%+^OYkQ&Z)0~$$Z6$lA8VlpmisY& zxyEjDgaPhf+QZ=7_(*Wn!LJN0hbE3okYOA*C~@~Ad$Z93uSQbDa( z)?jDy#3uMtW}0a$2P3lx&MA{Q@K;S12T#&o#@SNzWPH8t)5RT{EVrA{L?F8sAfFJW z{eTt;ID9Qi;faj994(hVm0DSA4L8f+TIEItoxN=wB?L`vT~;;qK% zikc?hZgK+u80^aiDhta^eBk5ixe-b;&L@TCBlcd9|9yK0yqniR{(lp4Yug9Z!b9wC zv;~~8tF4WK4xF1G%UOS-_|b8(w=-jHpfJ6c|2vq-_ws>5;5X>5){X@kapgUa2Z}MT z+%L;A32j|eGbd;;vbyt_=&y>2gQ9e`b2G^5+hE5Y#cClwrfA*#J!l4)sB?;If3Ex^ zvRO+%pMaklk4=xeu1Y5g^L4n}G3Lhq!2wmpJG~V1X=ju=qI0u=!3vAe_{rEa{O8Yl z(xu(60q?%Ur*^zX;E>W5wO|4Fof6Q8yz;4ZB60pke&U3CuD9p)d^_8L2F8F1$4$`? zNIE3wM14f}?Dg6R^~tq1;`Tgzs#?F=A$%M-wzooxt_3H9DX#d^gmqR@l6Ke)Ot-G} z_?}XAM>yfWY3T~^mDn`O6KM=~)!~@^Emd)Z_2iz_)=SYn>l}O@KZsG{qUv+a9Sa`I zC)hn3K`AEzbsouR%A`6*UyKBNwsE?}ptav~aYO{a;T&e1x%_lZBw?&{oi3_F2uHPD zEB-C@<;Hua*rr#F!Ihs3v3^!{|By;)a2`@6e3>)P=Jwbg*9Wn%8xD1eXB-hH!jIdl zt?}T$rOg4@ir3>vDUw0$E_rw8qO7CkLR+|L>QsqTXt7n_{6dvMKYJn?=KbN%n?ErX z)9m~rMz~xq9T4!be!){g5i1xOANrWMG6I>$kl2!+8+4ogaE+D>m26~nvJFi7+RX>i zU6W?j;& z_Fx1|1l7`vE&QfHRH9n(Txj7jL4T3ApW8S{%JgP5??Yd&AiXb|`3 zJHZnir;66RetT|mj2Tm>v-$hxe4M#tFPU8qNQ-O0ySVRG`!xRX(O^8IFD=K;nd^|= zxlC;}xDz2qfHUV0*73!r_~s9j|2#E0Ioxv0h`!kp;+FHc87<<~qI%gc`>&GgbSXzB zKFK>>viUtMPEpl3jirow4}Ri)nWnYfI2nhru9=)B!IPIlo2HLcQ=qCBn-2Z#9TxLE9?S{cpzA*QDAotEH~ z2-VO$d#^V71));#&HB=|@CueTc@RM^Zc}@P!YyU(Nzo4XT6f87+mo*^uUX5$c^1*p zY7x{py!po~vrb2)HkBX)Dj9+c_nl*!17S)bOH=!8#btG%^Ri)Qx@vU%RE?f#HsaD2 zJXi3n!*t7GMFYN~eKucN*$zDgxQ8YC03=R<#9iH16743vVNy|O%xRVfzf7-Fn~u$- z97;o(Myi5-*Rm7Q7`$fbP7^l7_on&{La9E?p1CBq^?#$cbp2fKyD^b;&=;xgvSXVc z5)^e|{d#=xv3>thMV@P1O4h*KoB!OmA?eMT-$_JH@aApcXlr9OPYXbIn@(-QN^4(b z%V#xOC=Fh8MQSf&9279M(|GbC|?p$_P|}IV7GH)rba91p8=uCa1P)5N0sMr&tozh`@vLcYx>vr?!{fjDXM$ zc|}wslnlz>0>Xh{_}xrEtPkQh%OA%Ss2Xh65R6Hw0lzI?8OQ>oSNS%4fyc@8b|y8?4dFQAlp_zqTCVzR+azjLze^0<&?9k zfsy^cos!<64mKY0S|wS64G8zcK-}K#po~jDaM$J7AkEX1DL5x`SUY_RF6Dh-3i8xP zI#Q;Br4QThj;2l_sJ&LB{>p$0(BsAFQwZc*#Si1<>8}*Sj_?0w#t}Mu-RdSryNj)s z{B4Yjmh$-AyR9Jm7doJ&oHB*`Lmbn7V&jpEriCc=I@!C673584Bl@-#m?WSB&qw_q zc|c+xlwAnlY%q1gH2FI}68J*1KZ|J^HzR?5e#;K - -std::string FENativeScriptProject::GetCorrectProjectName() -{ - if (Parent == nullptr) - { - LOG.Add("FENativeScriptProject::GetCorrectProjectName: Parent is nullptr!", "FE_LOG_LOADING", FE_LOG_ERROR); - return ""; - } - - std::string ProjectName = Parent->GetName(); - std::string CorrectProjectName = ""; - for (size_t i = 0; i < ProjectName.size(); i++) - { - if (ProjectName[i] == ' ') - CorrectProjectName += "_"; - else - CorrectProjectName += ProjectName[i]; - } - - return CorrectProjectName; -} - -FENativeScriptProject::FENativeScriptProject(FEProject* Parent) -{ - this->Parent = Parent; - ProjectPath = Parent->GetProjectFolder() + "NativeScriptProject/"; -} - -FENativeScriptProject::~FENativeScriptProject() -{ - if (PackageData != nullptr) - delete PackageData; -} - -bool FENativeScriptProject::Load(Json::Value Root, std::string FolderPath) -{ - if (!Root.isMember("ModuleID")) - { - LOG.Add("FENativeScriptProject::Load: ModuleID is missing!", "FE_LOG_LOADING", FE_LOG_ERROR); - return false; - } - - ModuleID = Root["ModuleID"].asCString(); - - if (!FILE_SYSTEM.DoesDirectoryExist(FolderPath)) - { - LOG.Add("FENativeScriptProject::Load: Folder does not exist!", "FE_LOG_LOADING", FE_LOG_ERROR); - return false; - } - - if (!FILE_SYSTEM.DoesFileExist(FolderPath + "NativeScriptProjectData.feassetpackage")) - { - LOG.Add("FENativeScriptProject::Load: File does not exist!", "FE_LOG_LOADING", FE_LOG_ERROR); - return false; - } - - PackageData = new FEAssetPackage(); - if (!PackageData->LoadFromFile(FolderPath + "NativeScriptProjectData.feassetpackage")) - { - LOG.Add("FENativeScriptProject::Load: Failed to load native script project data!", "FE_LOG_LOADING", FE_LOG_ERROR); - delete PackageData; - PackageData = nullptr; - return false; - } - - std::vector SourceFilesList = PackageData->GetEntryList(); - for (size_t i = 0; i < SourceFilesList.size(); i++) - { - SourceFileList.push_back(SourceFilesList[i].Name); - } - - SetFileTracking(); - return true; -} - -void FENativeScriptProject::Save(Json::Value& Root, std::string FolderPath) -{ - Root["ModuleID"] = ModuleID; - - if (!FILE_SYSTEM.DoesDirectoryExist(FolderPath)) - { - LOG.Add("FENativeScriptProject::Save: Folder does not exist!", "FE_LOG_LOADING", FE_LOG_ERROR); - return; - } - - if (PackageData == nullptr) - { - PackageData = new FEAssetPackage(); - for (size_t i = 0; i < SourceFileList.size(); i++) - { - std::string FullFilePath = FolderPath + "NativeScriptProject/" + SourceFileList[i]; - if (!FILE_SYSTEM.DoesFileExist(FullFilePath)) - { - LOG.Add("FENativeScriptProject::Save: File does not exist!", "FE_LOG_LOADING", FE_LOG_ERROR); - continue; - } - - FEAssetPackageEntryIntializeData EntryData; - EntryData.Name = SourceFileList[i]; - EntryData.Type = "Text"; - PackageData->ImportAssetFromFile(FullFilePath, EntryData); - } - } - else - { - std::vector OldSourceFilesList = PackageData->GetEntryList(); - for (size_t i = 0; i < SourceFileList.size(); i++) - { - std::string FullFilePath = FolderPath + "NativeScriptProject/" + SourceFileList[i]; - if (!FILE_SYSTEM.DoesFileExist(FullFilePath)) - { - LOG.Add("FENativeScriptProject::Save: File does not exist!", "FE_LOG_LOADING", FE_LOG_ERROR); - continue; - } - - for (size_t j = 0; j < OldSourceFilesList.size(); j++) - { - if (OldSourceFilesList[j].Name == SourceFileList[i]) - { - if (!PackageData->UpdateAssetFromFile(OldSourceFilesList[j].ID, FullFilePath)) - { - LOG.Add("FENativeScriptProject::Save: Failed to update asset!", "FE_LOG_LOADING", FE_LOG_ERROR); - } - break; - } - } - } - } - - PackageData->SaveToFile(FolderPath + "NativeScriptProjectData.feassetpackage"); -} - -bool FENativeScriptProject::GenerateScriptModule() -{ - std::string DebugDllPath = DebugDllFileData.Path; - std::string DebugPdbPath = DebugPdbFileData.Path; - std::string ReleaseDllPath = ReleaseDllFileData.Path; - - FENativeScriptModule* NewNativeScriptModule = RESOURCE_MANAGER.CreateNativeScriptModule(DebugDllPath, DebugPdbPath, ReleaseDllPath); - if (NewNativeScriptModule == nullptr) - { - LOG.Add("FENativeScriptProject::GenerateScriptModule: Error creating native script module after external project files update.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - if (LastGeneratedScriptModule != nullptr) - { - NATIVE_SCRIPT_SYSTEM.UpdateNativeScriptModule(LastGeneratedScriptModule->GetObjectID(), NewNativeScriptModule->GetObjectID()); - } - else - { - NATIVE_SCRIPT_SYSTEM.ActivateNativeScriptModule(NewNativeScriptModule); - } - - LastGeneratedScriptModule = NewNativeScriptModule; - return true; -} - -bool FENativeScriptProject::IsVSProjectValid() -{ - if (Parent == nullptr) - { - LOG.Add("FENativeScriptProject::IsVSProjectValid: Parent is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (ProjectPath.empty()) - { - LOG.Add("FENativeScriptProject::IsVSProjectValid: Path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (!FILE_SYSTEM.DoesDirectoryExist(ProjectPath)) - { - LOG.Add("FENativeScriptProject::IsVSProjectValid: Path does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - std::vector InitialFilesToCheck = { - "CMakeLists.txt", - "SubSystems/FocalEngine/FENativeScriptConnector.h", "SubSystems/FocalEngine/FENativeScriptConnector.cpp", - "FocalEngine.lib", "FEBasicApplication.lib", - "BuildManagement/EnsureBuildCompletion.cmake", - "BuildManagement/DebugBuildActions.cmake", "BuildManagement/ReleaseBuildActions.cmake" - }; - - for (size_t i = 0; i < InitialFilesToCheck.size(); i++) - { - if (!FILE_SYSTEM.DoesFileExist(ProjectPath + InitialFilesToCheck[i])) - { - LOG.Add("FENativeScriptProject::IsVSProjectValid: File " + InitialFilesToCheck[i] + " does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - } - - std::string AppropriateProjectName = GetCorrectProjectName(); - std::vector VSProjectFilesToCheck = { - AppropriateProjectName + ".sln", AppropriateProjectName + ".vcxproj", AppropriateProjectName + ".vcxproj.filters" - }; - - for (size_t i = 0; i < VSProjectFilesToCheck.size(); i++) - { - if (!FILE_SYSTEM.DoesFileExist(ProjectPath + VSProjectFilesToCheck[i])) - { - LOG.Add("FENativeScriptProject::IsVSProjectValid: File " + VSProjectFilesToCheck[i] + " does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - } - - if (SourceFileList.empty()) - return false; - - for (size_t i = 0; i < SourceFileList.size(); i++) - { - if (!FILE_SYSTEM.DoesFileExist(ProjectPath + SourceFileList[i])) - { - LOG.Add("FENativeScriptProject::IsVSProjectValid: File " + SourceFileList[i] + " does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - } - - return true; -} - -bool FENativeScriptProject::RegenerateVSProject() -{ - if (PackageData == nullptr) - { - LOG.Add("FENativeScriptProject::RegenerateVSProject: PackageData is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - std::vector AssetPackageContent = PackageData->GetEntryList(); - if (AssetPackageContent.empty()) - { - LOG.Add("FENativeScriptProject::RegenerateVSProject: Asset package is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (Parent == nullptr) - { - LOG.Add("FENativeScriptProject::RegenerateVSProject: Parent is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (ProjectPath.empty()) - { - LOG.Add("FENativeScriptProject::RegenerateVSProject: Project path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (!FILE_SYSTEM.CreateDirectory(ProjectPath)) - { - LOG.Add("FENativeScriptProject::RegenerateVSProject: Error creating directory", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - std::vector SourceFileFullPathList; - for (size_t i = 0; i < AssetPackageContent.size(); i++) - { - PackageData->ExportAssetToFile(AssetPackageContent[i].ID, ProjectPath + AssetPackageContent[i].Name); - SourceFileFullPathList.push_back(ProjectPath + AssetPackageContent[i].Name); - } - - if (!InitializeProject(SourceFileFullPathList)) - return false; - - if (!ConfigureAndBuildCMake()) - return false; - - // FIX ME! that should not be part of this function. - return RunProjectVSSolution(); -} - -bool FENativeScriptProject::InitializeProject(std::vector SourceFileFullPathList) -{ - if (Parent == nullptr) - { - LOG.Add("FENativeScriptProject::InitializeProject: Parent is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (ProjectPath.empty()) - { - LOG.Add("FENativeScriptProject::InitializeProject: Project path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (SourceFileFullPathList.empty()) - { - LOG.Add("FENativeScriptProject::InitializeProject: source file list are empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (!SourceFileFullPathList.empty()) - { - for (size_t i = 0; i < SourceFileFullPathList.size(); i++) - { - if (!FILE_SYSTEM.DoesFileExist(SourceFileFullPathList[i])) - { - LOG.Add("FENativeScriptProject::InitializeProject: Source file " + SourceFileFullPathList[i] + " does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - } - } - - // Create all needed folders. - std::vector FoldersToCreate = { "SubSystems/", "SubSystems/FocalEngine", "BuildManagement/" }; - for (size_t i = 0; i < FoldersToCreate.size(); i++) - { - if (!FILE_SYSTEM.CreateDirectory(ProjectPath + FoldersToCreate[i])) - { - LOG.Add("FENativeScriptProject::InitializeProject: Error creating " + FoldersToCreate[i] + " directory", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - } - - // Place required files in the destination directory. - std::string EditorFolder = FILE_SYSTEM.GetCurrentWorkingPath(); - std::vector> FilesToCopy; - FilesToCopy.push_back({ EditorFolder + "/UserScripts/NativeScriptProjectData/BuildManagement/EnsureBuildCompletion.cmake", ProjectPath + "BuildManagement/EnsureBuildCompletion.cmake" }); - FilesToCopy.push_back({ EditorFolder + "/UserScripts/NativeScriptProjectData/BuildManagement/DebugBuildActions.cmake", ProjectPath + "BuildManagement/DebugBuildActions.cmake" }); - FilesToCopy.push_back({ EditorFolder + "/UserScripts/NativeScriptProjectData/BuildManagement/ReleaseBuildActions.cmake", ProjectPath + "BuildManagement/ReleaseBuildActions.cmake" }); - FilesToCopy.push_back({ EditorFolder + "/UserScripts/NativeScriptProjectData/CMakeLists.txt", ProjectPath + "CMakeLists.txt" }); - std::string EnginePath = FILE_SYSTEM.GetCurrentWorkingPath() + "/" + std::string(ENGINE_FOLDER); - FilesToCopy.push_back({ EnginePath + "/Resources/UserScriptsData/FENativeScriptConnector.h", ProjectPath + "SubSystems/FocalEngine/FENativeScriptConnector.h" }); - FilesToCopy.push_back({ EnginePath + "/Resources/UserScriptsData/FENativeScriptConnector.cpp", ProjectPath + "SubSystems/FocalEngine/FENativeScriptConnector.cpp" }); - - for (size_t i = 0; i < SourceFileFullPathList.size(); i++) - { - FilesToCopy.push_back({ SourceFileFullPathList[i], ProjectPath + FILE_SYSTEM.GetFileName(SourceFileFullPathList[i]) }); - if (FilesToCopy.back().first == FilesToCopy.back().second) - FilesToCopy.pop_back(); - } - - for (size_t i = 0; i < FilesToCopy.size(); i++) - { - if (!FILE_SYSTEM.CopyFile(FilesToCopy[i].first, FilesToCopy[i].second)) - { - LOG.Add("FENativeScriptProject::InitializeProject: Error copying file " + FilesToCopy[i].first + " to " + FilesToCopy[i].second, "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - } - - SourceFileList.clear(); - for (size_t i = 0; i < SourceFileFullPathList.size(); i++) - { - SourceFileList.push_back(FILE_SYSTEM.GetFileName(SourceFileFullPathList[i])); - } - - if (!InitializeCMakeFileAndScriptFiles(SourceFileFullPathList)) - { - LOG.Add("FENativeScriptProject::InitializeProject: Error initializing CMakeLists.txt", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - if (!UpdateEngineFiles()) - { - LOG.Add("FENativeScriptProject::InitializeProject: Error updating engine files in user native script project", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - SetFileTracking(); - return true; -} - -bool FENativeScriptProject::InitializeCMakeFileAndScriptFiles(std::vector SourceFileFullPathList) -{ - if (ProjectPath.empty()) - { - LOG.Add("FENativeScriptProject::InitializeCMakeFileAndScriptFiles: path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (ModuleID.empty()) - { - LOG.Add("FENativeScriptProject::InitializeCMakeFileAndScriptFiles: DLL module ID is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - std::string ProjectName = GetCorrectProjectName(); - - std::string CMakeFilePath = ProjectPath + "CMakeLists.txt"; - - std::vector Instructions; - InstructionWhatToReplaceInFile CurrentInstruction; - CurrentInstruction.SubStringInLineToTrigger = "set(PROJECT_NAME PLACE_HOLDER)"; - CurrentInstruction.What = "PLACE_HOLDER"; - CurrentInstruction.ReplaceWith = ProjectName; - Instructions.push_back(CurrentInstruction); - - std::string SourceFilesList = "file(GLOB Main_SRC\n"; - for (size_t i = 0; i < SourceFileFullPathList.size(); i++) - { - SourceFilesList += "\t\"" + FILE_SYSTEM.GetFileName(SourceFileFullPathList[i]) + "\"\n"; - } - SourceFilesList += ")"; - - CurrentInstruction.SubStringInLineToTrigger = "file(GLOB Main_SRC PLACE_HOLDER)"; - CurrentInstruction.What = "file(GLOB Main_SRC PLACE_HOLDER)"; - CurrentInstruction.ReplaceWith = SourceFilesList; - Instructions.push_back(CurrentInstruction); - - if (!ReplaceInFile(CMakeFilePath, Instructions)) - { - LOG.Add("FENativeScriptProject::InitializeCMakeFileAndScriptFiles: Error initializing CMakeLists.txt", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - Instructions.clear(); - - CurrentInstruction.SubStringInLineToTrigger = "--target PLACE_HOLDER --config Release"; - CurrentInstruction.What = "PLACE_HOLDER"; - CurrentInstruction.ReplaceWith = ProjectName; - Instructions.push_back(CurrentInstruction); - - std::string DebugBuildActionsCMake = ProjectPath + "BuildManagement/DebugBuildActions.cmake"; - if (!ReplaceInFile(DebugBuildActionsCMake, Instructions)) - { - LOG.Add("FENativeScriptProject::InitializeCMakeFileAndScriptFiles: Error initializing BuildManagement/DebugBuildActions.cmake", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - Instructions.clear(); - - CurrentInstruction.SubStringInLineToTrigger = "--target PLACE_HOLDER --config Debug"; - CurrentInstruction.What = "PLACE_HOLDER"; - CurrentInstruction.ReplaceWith = ProjectName; - Instructions.push_back(CurrentInstruction); - - std::string ReleaseBuildActionsCMake = ProjectPath + "BuildManagement/ReleaseBuildActions.cmake"; - if (!ReplaceInFile(ReleaseBuildActionsCMake, Instructions)) - { - LOG.Add("FENativeScriptProject::InitializeCMakeFileAndScriptFiles: Error initializing BuildManagement/ReleaseBuildActions.cmake", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - Instructions.clear(); - - CurrentInstruction.SubStringInLineToTrigger = "SET_MODULE_ID(\"PLACE_HOLDER\");"; - CurrentInstruction.What = "PLACE_HOLDER"; - CurrentInstruction.ReplaceWith = ModuleID; - Instructions.push_back(CurrentInstruction); - - std::string FENativeScriptConnectorHeaderFilePath = ProjectPath + "SubSystems/FocalEngine/FENativeScriptConnector.h"; - if (!ReplaceInFile(FENativeScriptConnectorHeaderFilePath, Instructions)) - { - LOG.Add("FENativeScriptProject::InitializeCMakeFileAndScriptFiles: Error initializing FENativeScriptConnector.h", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - Instructions.clear(); - - return true; -} - -bool FENativeScriptProject::ReplaceInFile(std::string Path, std::vector Instructions) -{ - if (Path.empty()) - { - LOG.Add("FENativeScriptProject::ReplaceInFile: File path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - std::fstream File(Path, std::ios::in); - if (!File.is_open()) - { - LOG.Add("FENativeScriptProject::ReplaceInFile: Error opening file " + Path, "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - std::vector FileContent; - std::string Line; - while (std::getline(File, Line)) - FileContent.push_back(Line); - - File.close(); - - for (size_t i = 0; i < FileContent.size(); i++) - { - for (size_t j = 0; j < Instructions.size(); j++) - { - if (FileContent[i].find(Instructions[j].SubStringInLineToTrigger) != std::string::npos) - { - FileContent[i].replace(FileContent[i].find(Instructions[j].What), Instructions[j].What.size(), Instructions[j].ReplaceWith); - } - } - } - - File.open(Path, std::ios::out | std::ios::trunc); - if (!File.is_open()) - { - LOG.Add("FENativeScriptProject::ReplaceInFile: Error opening file " + Path, "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - // Write the modified content back to the file - for (size_t i = 0; i < FileContent.size(); i++) - File << FileContent[i] + "\n"; - - File.close(); - return true; -} - -bool FENativeScriptProject::UpdateEngineFiles() -{ - if (ProjectPath.empty()) - { - LOG.Add("FENativeScriptProject::UpdateEngineFiles: ProjectPath is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (!FILE_SYSTEM.DoesDirectoryExist(ProjectPath)) - { - LOG.Add("FENativeScriptProject::UpdateEngineFiles: ProjectPath does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - FEAssetPackage* EngineHeadersPackage = CreateEngineHeadersAssetPackage(); - if (EngineHeadersPackage == nullptr) - { - LOG.Add("FENativeScriptProject::UpdateEngineFiles: Error creating engine headers asset package.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - if (!UnPackEngineHeadersAssetPackage(EngineHeadersPackage, ProjectPath + "SubSystems/FocalEngine/")) - { - LOG.Add("FENativeScriptProject::UpdateEngineFiles: Error unpacking engine headers asset package.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - FEAssetPackage* EngineLIBPackage = CreateEngineLIBAssetPackage(); - if (EngineLIBPackage == nullptr) - { - LOG.Add("FENativeScriptProject::UpdateEngineFiles: Error creating engine lib asset package.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - if (!UnPackEngineLIBAssetPackage(EngineLIBPackage, ProjectPath)) - { - LOG.Add("FENativeScriptProject::UpdateEngineFiles: Error unpacking engine lib asset package.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - return true; -} - -FEAssetPackage* FENativeScriptProject::CreateEngineHeadersAssetPackage() -{ - FEAssetPackage* EngineHeadersAssetPackage = new FEAssetPackage(); - EngineHeadersAssetPackage->SetName("EngineHeaders"); - if (EngineHeadersAssetPackage == nullptr) - { - LOG.Add("FENativeScriptProject::CreateEngineHeadersAssetPackage: Error creating asset package", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return nullptr; - } - - std::string EnginePath = FILE_SYSTEM.GetCurrentWorkingPath() + "/" + std::string(ENGINE_FOLDER) + "/"; - if (!FILE_SYSTEM.DoesDirectoryExist(EnginePath)) - { - LOG.Add("FENativeScriptProject::CreateEngineHeadersAssetPackage: Engine folder does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return nullptr; - } - - std::vector AllFiles = FILE_SYSTEM.GetFilesInDirectory(EnginePath, true); - // After having all files in the engine folder, we need to filter out only the header files. - for (size_t i = 0; i < AllFiles.size(); i++) - { - if (AllFiles[i].find(".h") != std::string::npos || AllFiles[i].find(".inl") != std::string::npos) - { - FEAssetPackageEntryIntializeData EntryData; - // Also since FEAssetPackage does not support folders, we need to save folder structure in the file name. - // But we will erase the engine folder path from the file name. - EntryData.Name = AllFiles[i].substr(EnginePath.size()); - EntryData.Type = "Text"; - EntryData.Tag = EDITOR_RESOURCE_TAG; - EntryData.Comment = "Engine header file"; - - EngineHeadersAssetPackage->ImportAssetFromFile(AllFiles[i], EntryData); - } - } - - return EngineHeadersAssetPackage; -} - -bool FENativeScriptProject::UnPackEngineHeadersAssetPackage(FEAssetPackage* AssetPackage, std::string Path) -{ - if (AssetPackage == nullptr) - { - LOG.Add("FENativeScriptProject::UnPackEngineHeadersAssetPackage: Asset package is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (Path.empty()) - { - LOG.Add("FENativeScriptProject::UnPackEngineHeadersAssetPackage: Destination path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (!FILE_SYSTEM.DoesDirectoryExist(Path)) - { - LOG.Add("FENativeScriptProject::UnPackEngineHeadersAssetPackage: Destination path does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - std::vector AssetPackageContent = AssetPackage->GetEntryList(); - if (AssetPackageContent.empty()) - { - LOG.Add("FENativeScriptProject::UnPackEngineHeadersAssetPackage: Asset package is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - for (size_t i = 0; i < AssetPackageContent.size(); i++) - { - std::string LocalPath = std::filesystem::path(AssetPackageContent[i].Name).parent_path().string(); - // Since we are not using folders in FEAssetPackage, we need to create all folders in the file path. - // First we need to get chain of folders. - std::vector FolderChain; - try - { - std::filesystem::path Directory(LocalPath); - while (!Directory.string().empty()) - { - if (!FolderChain.empty()) - { - if (FolderChain.back() == Directory.string()) - break; - } - FolderChain.push_back(Directory.string()); - Directory = Directory.parent_path(); - } - - std::reverse(FolderChain.begin(), FolderChain.end()); - } - catch (const std::exception& Exception) - { - LOG.Add("Error in FENativeScriptProject::UnPackEngineHeadersAssetPackage: " + std::string(Exception.what()), "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - // Then we will go from the root folder to the last folder and create them if they do not exist. - for (size_t i = 0; i < FolderChain.size(); i++) - { - std::string FinalPath = Path + FolderChain[i]; - if (!FILE_SYSTEM.DoesDirectoryExist(FinalPath)) - { - if (!FILE_SYSTEM.CreateDirectory(FinalPath)) - { - LOG.Add("FENativeScriptProject::UnPackEngineHeadersAssetPackage: Error creating directory " + FinalPath, "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - } - } - - // Now we are ready to write the file. - if (!AssetPackage->ExportAssetToFile(AssetPackageContent[i].ID, Path + AssetPackageContent[i].Name)) - { - LOG.Add("FENativeScriptProject::UnPackEngineHeadersAssetPackage: Error exporting asset " + AssetPackageContent[i].ID + " to " + Path + AssetPackageContent[i].Name, "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - } - - return true; -} - -FEAssetPackage* FENativeScriptProject::CreateEngineLIBAssetPackage() -{ - FEAssetPackage* EngineLIBAssetPackage = new FEAssetPackage(); - EngineLIBAssetPackage->SetName("EngineHeaders"); - if (EngineLIBAssetPackage == nullptr) - { - LOG.Add("FENativeScriptProject::CreateEngineLIBAssetPackage: Error creating asset package", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return nullptr; - } - - std::string EnginePath = FILE_SYSTEM.GetCurrentWorkingPath() + "/" + std::string(ENGINE_FOLDER) + "/"; - if (!FILE_SYSTEM.DoesDirectoryExist(EnginePath)) - { - LOG.Add("FENativeScriptProject::CreateEngineLIBAssetPackage: Engine folder does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return nullptr; - } - - std::vector AllFiles = FILE_SYSTEM.GetFilesInDirectory(EnginePath, true); - - std::vector DebugStrings; - // After having all files in the engine folder, we need to filter out only the lib files. - for (size_t i = 0; i < AllFiles.size(); i++) - { - if (AllFiles[i].find(".lib") != std::string::npos) - { - // FIX ME! Currently projects would need only debug lib files. Is it correct? - // And only FocalEngine.lib and FEBasicApplication.lib are needed. - if (AllFiles[i].find("FocalEngine.lib") == std::string::npos && AllFiles[i].find("FEBasicApplication.lib") == std::string::npos) - continue; - - FEAssetPackageEntryIntializeData EntryData; - EntryData.Name = FILE_SYSTEM.GetFileName(AllFiles[i]); - DebugStrings.push_back(EntryData.Name); - EntryData.Type = "BINARY"; - EntryData.Tag = EDITOR_RESOURCE_TAG; - EntryData.Comment = "Engine lib file"; - - EngineLIBAssetPackage->ImportAssetFromFile(AllFiles[i], EntryData); - } - } - - return EngineLIBAssetPackage; -} - -bool FENativeScriptProject::UnPackEngineLIBAssetPackage(FEAssetPackage* AssetPackage, std::string Path) -{ - if (AssetPackage == nullptr) - { - LOG.Add("FENativeScriptProject::UnPackEngineLIBAssetPackage: Asset package is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (Path.empty()) - { - LOG.Add("FENativeScriptProject::UnPackEngineLIBAssetPackage: Destination path is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (!FILE_SYSTEM.DoesDirectoryExist(Path)) - { - LOG.Add("FENativeScriptProject::UnPackEngineLIBAssetPackage: Destination path does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - std::vector AssetPackageContent = AssetPackage->GetEntryList(); - if (AssetPackageContent.empty()) - { - LOG.Add("FENativeScriptProject::UnPackEngineLIBAssetPackage: Asset package is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - for (size_t i = 0; i < AssetPackageContent.size(); i++) - { - // Now we are ready to write the file. - if (!AssetPackage->ExportAssetToFile(AssetPackageContent[i].ID, Path + AssetPackageContent[i].Name)) - { - LOG.Add("FENativeScriptProject::UnPackEngineHeadersAssetPackage: Error exporting asset " + AssetPackageContent[i].ID + " to " + Path + AssetPackageContent[i].Name, "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - } - - return true; -} - -bool FENativeScriptProject::ConfigureAndBuildCMake() -{ - if (ProjectPath.empty()) - { - LOG.Add("FENativeScriptProject::RunCMake: ProjectPath is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - std::string Generator = "Visual Studio 17 2022"; - - // CMake configure command. - std::string ConfigureCommand = "cmake -S \"" + ProjectPath + "\" -B \"" + ProjectPath + "\" -G \"" + Generator + "\""; - - // Execute CMake configure command. - int ConfigureResult = std::system(ConfigureCommand.c_str()); - if (ConfigureResult != 0) - { - LOG.Add("FENativeScriptProject::RunCMake: Error running CMake configure command", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - // Construct the CMake build command - std::string BuildCommand = "cmake --build \"" + ProjectPath + "\" --config Debug"; - - // Execute CMake build command - int BuildResult = std::system(BuildCommand.c_str()); - if (BuildResult != 0) - { - LOG.Add("FENativeScriptProject::RunCMake: Error running CMake build command", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - return true; -} - -bool FENativeScriptProject::RunProjectVSSolution() -{ - if (ProjectPath.empty()) - { - LOG.Add("FENativeScriptProject::RunProjectVSSolution: ProjectPath is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - std::string ProjectName = GetCorrectProjectName(); - if (ProjectName.empty()) - { - LOG.Add("FENativeScriptProject::RunProjectVSSolution: Project name is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - std::string SolutionPath = ProjectPath + ProjectName + ".sln"; - - // Use ShellExecute to open the solution file - HINSTANCE Result = ShellExecuteA( - NULL, - "open", - SolutionPath.c_str(), - NULL, - NULL, - SW_SHOWNORMAL - ); - - // Check if ShellExecute was successful - if ((INT_PTR)Result <= 32) - { - LOG.Add("FENativeScriptProject::RunProjectVSSolution: Error running solution", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - return true; -} - -void FENativeScriptProject::SetFileTracking() -{ - std::string AppropriateProjectName = GetCorrectProjectName(); - - DebugDllFileData.Path = ProjectPath + "Debug/" + AppropriateProjectName + ".dll"; - DebugDllFileData.WriteTime = FILE_SYSTEM.GetFileLastWriteTime(DebugDllFileData.Path); - - DebugPdbFileData.Path = ProjectPath + "Debug/" + AppropriateProjectName + ".pdb"; - DebugPdbFileData.WriteTime = FILE_SYSTEM.GetFileLastWriteTime(DebugPdbFileData.Path); - - ReleaseDllFileData.Path = ProjectPath + "Release/" + AppropriateProjectName + ".dll"; - ReleaseDllFileData.WriteTime = FILE_SYSTEM.GetFileLastWriteTime(ReleaseDllFileData.Path); -} - -bool FENativeScriptProject::GenerateScriptFilesFromTemplate(std::string ScriptName) -{ - if (!FILE_SYSTEM.DoesDirectoryExist(ProjectPath)) - { - LOG.Add("FENativeScriptProject::GenerateScriptFilesFromTemplate: ProjectPath does not exist", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (ScriptName.empty()) - { - LOG.Add("FENativeScriptProject::GenerateScriptFilesFromTemplate: Script name is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - std::string EnginePath = FILE_SYSTEM.GetCurrentWorkingPath() + "/" + std::string(ENGINE_FOLDER); - std::string TemplateHeaderFilePath = EnginePath + "/Resources/UserScriptsData/NativeScriptTemplate.h"; - std::string TemplateCPPFilePath = EnginePath + "/Resources/UserScriptsData/NativeScriptTemplate.cpp"; - - if (!FILE_SYSTEM.CopyFile(TemplateHeaderFilePath, ProjectPath + ScriptName + ".h")) - { - LOG.Add("FENativeScriptProject::GenerateScriptFilesFromTemplate: Error copying file " + TemplateHeaderFilePath + " to " + ProjectPath + ScriptName + ".h", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - if (!FILE_SYSTEM.CopyFile(TemplateCPPFilePath, ProjectPath + ScriptName + ".cpp")) - { - LOG.Add("FENativeScriptProject::GenerateScriptFilesFromTemplate: Error copying file " + TemplateCPPFilePath + " to " + ProjectPath + ScriptName + ".cpp", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - std::vector Instructions; - InstructionWhatToReplaceInFile CurrentInstruction; - CurrentInstruction.SubStringInLineToTrigger = "SET_MODULE_ID(\"PLACE_HOLDER\")"; - CurrentInstruction.What = "PLACE_HOLDER"; - CurrentInstruction.ReplaceWith = "2342HA"; - Instructions.push_back(CurrentInstruction); - - CurrentInstruction.SubStringInLineToTrigger = "class PLACE_HOLDER : public FENativeScriptCore"; - CurrentInstruction.What = "PLACE_HOLDER"; - CurrentInstruction.ReplaceWith = ScriptName; - Instructions.push_back(CurrentInstruction); - - CurrentInstruction.SubStringInLineToTrigger = "REGISTER_SCRIPT(PLACE_HOLDER)"; - CurrentInstruction.What = "PLACE_HOLDER"; - CurrentInstruction.ReplaceWith = ScriptName; - Instructions.push_back(CurrentInstruction); - - CurrentInstruction.SubStringInLineToTrigger = "REGISTER_SCRIPT_FIELD(PLACE_HOLDER, int, ExampleVariable)"; - CurrentInstruction.What = "PLACE_HOLDER"; - CurrentInstruction.ReplaceWith = ScriptName; - Instructions.push_back(CurrentInstruction); - - std::string ScriptHeaderFilePath = ProjectPath + ScriptName + ".h"; - if (!ReplaceInFile(ScriptHeaderFilePath, Instructions)) - { - LOG.Add("FENativeScriptProject::GenerateScriptFilesFromTemplate: Error initializing " + ScriptName + ".h", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - Instructions.clear(); - - CurrentInstruction.SubStringInLineToTrigger = "#include \"NativeScriptTemplate.h\""; - CurrentInstruction.What = "NativeScriptTemplate"; - CurrentInstruction.ReplaceWith = ScriptName; - Instructions.push_back(CurrentInstruction); - - CurrentInstruction.SubStringInLineToTrigger = "void PLACE_HOLDER::Awake()"; - CurrentInstruction.What = "PLACE_HOLDER"; - CurrentInstruction.ReplaceWith = ScriptName; - Instructions.push_back(CurrentInstruction); - - CurrentInstruction.SubStringInLineToTrigger = "void PLACE_HOLDER::OnDestroy()"; - CurrentInstruction.What = "PLACE_HOLDER"; - CurrentInstruction.ReplaceWith = ScriptName; - Instructions.push_back(CurrentInstruction); - - CurrentInstruction.SubStringInLineToTrigger = "void PLACE_HOLDER::OnUpdate(double DeltaTime)"; - CurrentInstruction.What = "PLACE_HOLDER"; - CurrentInstruction.ReplaceWith = ScriptName; - Instructions.push_back(CurrentInstruction); - - std::string ScriptSourceFilePath = ProjectPath + ScriptName + ".cpp"; - if (!ReplaceInFile(ScriptSourceFilePath, Instructions)) - { - LOG.Add("FENativeScriptProject::GenerateScriptFilesFromTemplate: Error initializing " + ScriptName + ".cpp", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - Instructions.clear(); - - return true; -} - -bool FENativeScriptProject::GenerateNewVSProject(std::string FirstScriptName) -{ - if (FirstScriptName.empty()) - { - LOG.Add("FENativeScriptProject::GenerateNewVSProject: First script name is empty", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (Parent == nullptr) - { - LOG.Add("FENativeScriptProject::GenerateNewVSProject: Parent is nullptr", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - // Replace all spaces with underscores. - for (size_t i = 0; i < FirstScriptName.size(); i++) - { - if (FirstScriptName[i] == ' ') - FirstScriptName[i] = '_'; - } - - if (FILE_SYSTEM.DoesDirectoryExist(ProjectPath)) - { - LOG.Add("FENativeScriptProject::GenerateNewVSProject: VS project already exists", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - return false; - } - - if (!FILE_SYSTEM.CreateDirectory(ProjectPath)) - { - LOG.Add("FENativeScriptProject::GenerateNewVSProject: Error creating directory", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - ModuleID = APPLICATION.GetUniqueHexID(); - - if (!GenerateScriptFilesFromTemplate(FirstScriptName)) - { - LOG.Add("FENativeScriptProject::GenerateNewVSProject: Error generating script files from template", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_ERROR); - return false; - } - - if (!InitializeProject({ ProjectPath + FirstScriptName + ".h", ProjectPath + FirstScriptName + ".cpp" })) - return false; - - if (!ConfigureAndBuildCMake()) - return false; - - // FIX ME! that should not be part of this function. - return RunProjectVSSolution(); -} - -bool FENativeScriptProject::IsFileChanged(const TrackedFileData& FileData) -{ - uint64_t NewWriteTime = FILE_SYSTEM.GetFileLastWriteTime(FileData.Path); - if (NewWriteTime != FileData.WriteTime && NewWriteTime != 0) - { - uint64_t Differece = NewWriteTime >= FileData.WriteTime ? NewWriteTime - FileData.WriteTime : FileData.WriteTime - NewWriteTime; - if (Differece > DifferenceThreshold) - return true; - } - - return false; -} - -void FENativeScriptProject::UpdateTrackedFileWriteTime(TrackedFileData& FileData) -{ - uint64_t NewTimeStamp = FILE_SYSTEM.GetFileLastWriteTime(FileData.Path); - - if (NewTimeStamp > FileData.WriteTime) - FileData.WriteTime = NewTimeStamp; -} - -bool FENativeScriptProject::Update() -{ - if (!IsVSProjectValid()) - return false; - - bool CheckForReload = false; - if (IsFileChanged(DebugDllFileData) && IsFileChanged(DebugPdbFileData) || IsFileChanged(ReleaseDllFileData)) - CheckForReload = true; - - if (!CheckForReload) - return false; - - // Waiting for external build system to finish. - FILE_SYSTEM.WaitForFileAccess(ProjectPath + "BuildManagement/Force_Build_Finished.txt", 1000); - - if (FILE_SYSTEM.DoesFileExist(ProjectPath + "BuildManagement/Force_Build_Finished.txt")) - { - FILE_SYSTEM.DeleteFile(ProjectPath + "BuildManagement/Force_Build_Finished.txt"); - } - else - { - LOG.Add("FENativeScriptProject::Update: Force_Build_Finished.txt does not exist, script reload aborted.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - - UpdateTrackedFileWriteTime(DebugDllFileData); - UpdateTrackedFileWriteTime(DebugPdbFileData); - UpdateTrackedFileWriteTime(ReleaseDllFileData); - - return false; - } - - // Waiting for all files to be accessible. - if (!FILE_SYSTEM.WaitForFileAccess(DebugDllFileData.Path, 2000)) - { - LOG.Add("FENativeScriptProject::Update: File " + DebugDllFileData.Path + "does not exist, script reload aborted.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - - UpdateTrackedFileWriteTime(DebugDllFileData); - UpdateTrackedFileWriteTime(DebugPdbFileData); - UpdateTrackedFileWriteTime(ReleaseDllFileData); - - return false; - } - - if (!FILE_SYSTEM.WaitForFileAccess(DebugPdbFileData.Path, 2000)) - { - LOG.Add("FENativeScriptProject::Update: File " + DebugPdbFileData.Path + "does not exist, script reload aborted.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - - UpdateTrackedFileWriteTime(DebugDllFileData); - UpdateTrackedFileWriteTime(DebugPdbFileData); - UpdateTrackedFileWriteTime(ReleaseDllFileData); - - return false; - } - - if (!FILE_SYSTEM.WaitForFileAccess(ReleaseDllFileData.Path, 2000)) - { - LOG.Add("FENativeScriptProject::Update: File " + ReleaseDllFileData.Path + "does not exist, script reload aborted.", "FE_EDITOR_SCRIPT_SYSTEM", FE_LOG_WARNING); - - UpdateTrackedFileWriteTime(DebugDllFileData); - UpdateTrackedFileWriteTime(DebugPdbFileData); - UpdateTrackedFileWriteTime(ReleaseDllFileData); - - return false; - } - - bool bResult = GenerateScriptModule(); - - UpdateTrackedFileWriteTime(DebugDllFileData); - UpdateTrackedFileWriteTime(DebugPdbFileData); - UpdateTrackedFileWriteTime(ReleaseDllFileData); - - return bResult; -} \ No newline at end of file diff --git a/SubSystems/ProjectManagment/FENativeScriptProject.h b/SubSystems/ProjectManagment/FENativeScriptProject.h deleted file mode 100644 index 5c7b748..0000000 --- a/SubSystems/ProjectManagment/FENativeScriptProject.h +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once -#include "../FEngine.h" -using namespace FocalEngine; - -struct TrackedFileData -{ - std::string Path; - uint64_t WriteTime; -}; - -class FENativeScriptProject -{ - friend class FEProject; - - FEProject* Parent = nullptr; - std::string ProjectPath = ""; - std::vector SourceFileList; - FEAssetPackage* PackageData = nullptr; - - TrackedFileData DebugDllFileData; - TrackedFileData DebugPdbFileData; - TrackedFileData ReleaseDllFileData; - - const uint64_t DifferenceThreshold = 1'000'000; - - FENativeScriptModule* LastGeneratedScriptModule = nullptr; - - bool InitializeProject(std::vector SourceFileFullPathList); - bool ConfigureAndBuildCMake(); - bool RunProjectVSSolution(); - - bool InitializeCMakeFileAndScriptFiles(std::vector SourceFileFullPathList); - - struct InstructionWhatToReplaceInFile - { - std::string SubStringInLineToTrigger; - std::string What; - std::string ReplaceWith; - }; - - bool ReplaceInFile(std::string FilePath, std::vector Instructions); - bool UpdateEngineFiles(); - - FEAssetPackage* CreateEngineHeadersAssetPackage(); - bool UnPackEngineHeadersAssetPackage(FEAssetPackage* AssetPackage, std::string Path); - - FEAssetPackage* CreateEngineLIBAssetPackage(); - bool UnPackEngineLIBAssetPackage(FEAssetPackage* AssetPackage, std::string Path); - - void SetFileTracking(); - bool GenerateScriptFilesFromTemplate(std::string ScriptName); - - bool IsFileChanged(const TrackedFileData& FileData); - void UpdateTrackedFileWriteTime(TrackedFileData& FileData); -public: - FENativeScriptProject(FEProject* Parent); - ~FENativeScriptProject(); - - bool GenerateNewVSProject(std::string FirstScriptName); - bool IsVSProjectValid(); - bool RegenerateVSProject(); - - bool Load(Json::Value Root, std::string FolderPath); - void Save(Json::Value& Root, std::string FolderPath); - - bool GenerateScriptModule(); - - std::string GetCorrectProjectName(); - std::string ModuleID = ""; - - bool Update(); -}; \ No newline at end of file diff --git a/SubSystems/ProjectManagment/FEProject.cpp b/SubSystems/ProjectManagment/FEProject.cpp index bac9b02..51aa5c1 100644 --- a/SubSystems/ProjectManagment/FEProject.cpp +++ b/SubSystems/ProjectManagment/FEProject.cpp @@ -213,7 +213,24 @@ void FEProject::SaveResourcesTo(std::string FilePath, bool bFullSave) } Root["Prefabs"] = PrefabData; - // Saving scenes. + // Saving NativeScriptModules. + Json::Value NativeScriptModulesData; + std::vector NativeScriptModulesList = RESOURCE_MANAGER.GetNativeScriptModuleIDList(); + for (size_t i = 0; i < NativeScriptModulesList.size(); i++) + { + FENativeScriptModule* NativeScriptModule = RESOURCE_MANAGER.GetNativeScriptModule(NativeScriptModulesList[i]); + if (NativeScriptModule->GetTag() == ENGINE_RESOURCE_TAG || + NativeScriptModule->GetTag() == EDITOR_RESOURCE_TAG) + continue; + + NativeScriptModulesData[NativeScriptModule->GetObjectID()]["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(NativeScriptModule); + NativeScriptModulesData[NativeScriptModule->GetObjectID()]["FileName"] = NativeScriptModule->GetObjectID() + ".nativescriptmodule"; + + RESOURCE_MANAGER.SaveFENativeScriptModule(NativeScriptModule, GetProjectFolder() + NativeScriptModule->GetObjectID() + ".nativescriptmodule"); + } + Root["NativeScriptModules"] = NativeScriptModulesData; + + // Saving Scenes. std::vector SceneList = SCENE_MANAGER.GetAllScenes(); Json::Value SceneData; for (size_t i = 0; i < SceneList.size(); i++) @@ -287,9 +304,6 @@ void FEProject::SaveProject(bool bFullSave) Root["ID"] = ID; Root["Name"] = Name; - if (NativeScriptProject != nullptr) - NativeScriptProject->Save(Root["NativeScriptProject"], ProjectFolder); - FEScene* SceneForScreenshot = EDITOR.GetFocusedScene(); if (SceneForScreenshot != nullptr) { @@ -539,6 +553,17 @@ void FEProject::LoadResources(std::string FilePath) } } + // Loading NativeScriptModules. + std::vector NativeScriptModulesList = Root["NativeScriptModules"].getMemberNames(); + for (size_t i = 0; i < NativeScriptModulesList.size(); i++) + { + FENativeScriptModule* LoadedNativeScriptModule = RESOURCE_MANAGER.LoadFENativeScriptModule((ProjectFolder + Root["NativeScriptModules"][NativeScriptModulesList[i]]["FileName"].asCString()).c_str()); + if (LoadedNativeScriptModule == nullptr) + continue; + + NATIVE_SCRIPT_SYSTEM.ActivateNativeScriptModule(LoadedNativeScriptModule); + } + // Prefabs and Scenes are interconnected so we need to load them in two steps. // Currently Prefabs can not contain other Prefabs or Scenes, if it will change we need to change this code. // First load all prefab scenes. @@ -595,44 +620,6 @@ void FEProject::LoadResources(std::string FilePath) } } -void FEProject::LoadNativeScriptProjectData(Json::Value Root) -{ - if (Root.isMember("NativeScriptProject")) - { - NativeScriptProject = new FENativeScriptProject(this); - if (NativeScriptProject->Load(Root["NativeScriptProject"], ProjectFolder)) - { - // Check if VS Project is valid. - if (NativeScriptProject->IsVSProjectValid()) - { - NativeScriptProject->GenerateScriptModule(); - } - else - { - std::string VSProjectPath = ProjectFolder + "NativeScriptProject/"; - if (FILE_SYSTEM.DoesDirectoryExist(VSProjectPath)) - { - if (!FILE_SYSTEM.DeleteDirectory(VSProjectPath)) - { - LOG.Add("FEProject::LoadNativeScriptProjectData: Failed to delete old Visual Studio project!", "FE_LOG_LOADING", FE_LOG_ERROR); - return; - } - } - - if (NativeScriptProject->RegenerateVSProject()) - { - NativeScriptProject->GenerateScriptModule(); - } - else - { - LOG.Add("FEProject::LoadNativeScriptProjectData: Failed to regenerate Visual Studio project!", "FE_LOG_LOADING", FE_LOG_ERROR); - return; - } - } - } - } -} - void FEProject::LoadProject() { std::ifstream ProjectFile; @@ -660,7 +647,6 @@ void FEProject::LoadProject() ID = Root["ID"].asCString(); Name = Root["Name"].asCString(); - LoadNativeScriptProjectData(Root); LoadResources(ProjectFolder + "Resources.txt"); // After we loaded all resources we can load editor cameras. @@ -721,10 +707,9 @@ void FEProject::LoadProject() } if (!LoadVFSData(ProjectFolder + "VFS.txt")) - { - LOG.Add("Can't find VIRTUAL_FILE_SYSTEM file in project folder. Creating basic VIRTUAL_FILE_SYSTEM layout.", "FE_LOG_LOADING", FE_LOG_WARNING); - GenerateVFSData(); - } + LOG.Add("Can't find VIRTUAL_FILE_SYSTEM file in project folder.", "FE_LOG_LOADING", FE_LOG_WARNING); + + AddMissingVFSData(); } bool FEProject::LoadVFSData(std::string FilePath) @@ -765,24 +750,25 @@ bool FEProject::LoadVFSData(std::string FilePath) return true; } -void FEProject::GenerateVFSData() +void FEProject::AddMissingVFSData() { - VIRTUAL_FILE_SYSTEM.CreateDirectory("Shaders", "/"); - std::vector ShaderList = RESOURCE_MANAGER.GetShadersList(); for (size_t i = 0; i < ShaderList.size(); i++) { - if (OBJECT_MANAGER.GetFEObject(ShaderList[i]) == nullptr) + if (VIRTUAL_FILE_SYSTEM.DoesFileExistAnywhere(OBJECT_MANAGER.GetFEObject(ShaderList[i]))) continue; + VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(ShaderList[i]), "/Shaders"); } std::vector StandardShaderList = RESOURCE_MANAGER.GetEnginePrivateShadersList(); for (size_t i = 0; i < StandardShaderList.size(); i++) { - if (OBJECT_MANAGER.GetFEObject(StandardShaderList[i]) == nullptr) + if (VIRTUAL_FILE_SYSTEM.DoesFileExistAnywhere(OBJECT_MANAGER.GetFEObject(StandardShaderList[i]))) continue; + VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(StandardShaderList[i]), "/Shaders"); + VIRTUAL_FILE_SYSTEM.SetFileReadOnly(true, OBJECT_MANAGER.GetFEObject(StandardShaderList[i]), "/Shaders"); } std::vector OtherResourceList = RESOURCE_MANAGER.GetMeshList(); @@ -792,14 +778,33 @@ void FEProject::GenerateVFSData() OtherResourceList.insert(OtherResourceList.end(), MaterialList.begin(), MaterialList.end()); std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); OtherResourceList.insert(OtherResourceList.end(), GameModelList.begin(), GameModelList.end()); + std::vector PrefabList = RESOURCE_MANAGER.GetPrefabIDList(); + OtherResourceList.insert(OtherResourceList.end(), PrefabList.begin(), PrefabList.end()); + std::vector NativeScriptModuleList = RESOURCE_MANAGER.GetNativeScriptModuleIDList(); + OtherResourceList.insert(OtherResourceList.end(), NativeScriptModuleList.begin(), NativeScriptModuleList.end()); + std::vector SceneList = SCENE_MANAGER.GetSceneIDList(); + // Filter prefab scenes. + for (size_t i = 0; i < SceneList.size(); i++) + { + FEScene* Scene = SCENE_MANAGER.GetScene(SceneList[i]); + if (Scene->GetTag() == PREFAB_SCENE_DESCRIPTION_TAG) + continue; + + OtherResourceList.push_back(SceneList[i]); + } for (size_t i = 0; i < OtherResourceList.size(); i++) { - if (OBJECT_MANAGER.GetFEObject(OtherResourceList[i])->GetTag() == ENGINE_RESOURCE_TAG || - OBJECT_MANAGER.GetFEObject(OtherResourceList[i])->GetTag() == EDITOR_RESOURCE_TAG) + if (VIRTUAL_FILE_SYSTEM.DoesFileExistAnywhere(OBJECT_MANAGER.GetFEObject(OtherResourceList[i]))) continue; VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(OtherResourceList[i]), "/"); + + if (OBJECT_MANAGER.GetFEObject(OtherResourceList[i])->GetTag() == ENGINE_RESOURCE_TAG || + OBJECT_MANAGER.GetFEObject(OtherResourceList[i])->GetTag() == EDITOR_RESOURCE_TAG) + { + VIRTUAL_FILE_SYSTEM.SetFileReadOnly(true, OBJECT_MANAGER.GetFEObject(OtherResourceList[i]), "/"); + } } } diff --git a/SubSystems/ProjectManagment/FEProject.h b/SubSystems/ProjectManagment/FEProject.h index 416e244..edda89c 100644 --- a/SubSystems/ProjectManagment/FEProject.h +++ b/SubSystems/ProjectManagment/FEProject.h @@ -3,8 +3,6 @@ #include "../../FEEditorDragAndDropManager.h" #include "../../FEEditorVirtualFileSystem.h" -#include "FENativeScriptProject.h" - class FEProject { friend class FEProjectManager; @@ -50,12 +48,8 @@ class FEProject void LoadResources(std::string FilePath); void SaveResourcesTo(std::string FilePath, bool bFullSave = false); - void LoadNativeScriptProjectData(Json::Value Root); - - FENativeScriptProject* NativeScriptProject = nullptr; - bool LoadVFSData(std::string FilePath); - void GenerateVFSData(); + void AddMissingVFSData(); }; #define PROJECTS_FILE_VER 0.05f diff --git a/SubSystems/ProjectManagment/FEProjectManager.cpp b/SubSystems/ProjectManagment/FEProjectManager.cpp index 9d471d3..a0c8d6b 100644 --- a/SubSystems/ProjectManagment/FEProjectManager.cpp +++ b/SubSystems/ProjectManagment/FEProjectManager.cpp @@ -292,7 +292,7 @@ void FEProjectManager::CreateNewProject(std::string ProjectName, std::string Pro EDITOR.AddEditorScene(NewScene); NewProject->InjectEditorCamera(NewScene); - NewProject->GenerateVFSData(); + NewProject->AddMissingVFSData(); NewProject->SaveProject(true); CloseCurrentProject(); diff --git a/main.cpp b/main.cpp index 7d48a72..a207b58 100644 --- a/main.cpp +++ b/main.cpp @@ -57,23 +57,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine bPutThisFrameToTimeline = true; } - if (PROJECT_MANAGER.GetCurrent() != nullptr) - { - bool bIsVSProjectPresent = EDITOR_SCRIPTING_SYSTEM.IsCurrentProjectHaveVSProjectInitialized(); - std::string Text = "Is VS project present: "; - Text += bIsVSProjectPresent ? "true" : "false"; - ImGui::Text(Text.c_str()); - - if (!bIsVSProjectPresent) - { - if (ImGui::Button("Initialize VS Project")) - { - EDITOR_SCRIPTING_SYSTEM.GenerateNewNativeScriptProject("FirstScript"); - } - } - } - - //ImGui::ShowDemoWindow(); EDITOR.Render(); ENGINE.EndFrame(); From 3058cd22b21e31674c5a7b25590cb559325cd658 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Sun, 20 Oct 2024 21:42:01 -0400 Subject: [PATCH 36/46] Engine update and changes to accommodate these updates; Users can now set a scene as the starting scene directly in the content browser; Added TERRAIN_SYSTEM_RESOURCE_TAG to hidden tags in the content browser; Updated system to handle increased complexity due to the interaction between editor cameras and the usual main cameras; Introduced FEProjectBuildSystem, which specializes in building the project as a final executable along with resources; Moved much of the project saving/loading functionality from FEProject to RESOURCE_MANAGER to ensure unified code in the built game; The StartingScene will now be saved within the project; Some native script project template files have been moved to the engine. --- .gitignore | 3 +- CMakeLists.txt | 2 + EditorWindows/ContentBrowserWindow.cpp | 21 + EditorWindows/DeletePopups.cpp | 12 +- EditorWindows/EditPopups.cpp | 2 +- .../FEEditorSceneWindow.cpp | 29 +- EditorWindows/InspectorWindow.cpp | 21 +- EditorWindows/InspectorWindow.h | 1 + EditorWindows/PrefabEditorManager.cpp | 23 +- EditorWindows/SceneGraphWindow.cpp | 8 +- EditorWindows/SelectPopups.cpp | 8 +- EditorWindows/ShaderEditorWindow.cpp | 4 +- FEEditor.cpp | 42 +- FEEditor.h | 4 + FEEditorGizmoManager.cpp | 20 +- FEEditorHaloSelectionEffect.cpp | 4 +- FEEditorPreviewManager.cpp | 14 +- FEEditorScriptingSystem.cpp | 4 + FEEditorSelectedObject.cpp | 10 +- FEProjectBuildSystem.cpp | 538 ++++++++++++++++++ FEProjectBuildSystem.h | 36 ++ .../BuildScripts/CMakeLists_Template.txt | 100 ++++ Resources/BuildScripts/Main_Template.cpp | 208 +++++++ Resources/BuildScripts/Main_Template.h | 9 + SubSystems/FocalEngine | 2 +- SubSystems/ProjectManagment/FEProject.cpp | 466 ++++++++------- SubSystems/ProjectManagment/FEProject.h | 26 +- .../BuildManagement/DebugBuildActions.cmake | 22 - .../EnsureBuildCompletion.cmake | 9 - .../BuildManagement/ReleaseBuildActions.cmake | 22 - .../NativeScriptProjectData/CMakeLists.txt | 83 --- main.cpp | 9 + 32 files changed, 1361 insertions(+), 401 deletions(-) create mode 100644 FEProjectBuildSystem.cpp create mode 100644 FEProjectBuildSystem.h create mode 100644 Resources/BuildScripts/CMakeLists_Template.txt create mode 100644 Resources/BuildScripts/Main_Template.cpp create mode 100644 Resources/BuildScripts/Main_Template.h delete mode 100644 UserScripts/NativeScriptProjectData/BuildManagement/DebugBuildActions.cmake delete mode 100644 UserScripts/NativeScriptProjectData/BuildManagement/EnsureBuildCompletion.cmake delete mode 100644 UserScripts/NativeScriptProjectData/BuildManagement/ReleaseBuildActions.cmake delete mode 100644 UserScripts/NativeScriptProjectData/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 06eba80..aaaaa4d 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ cmake_install.cmake Debug/ Release/ .vs/ -CMakeFiles/ \ No newline at end of file +CMakeFiles/ +BuildProjects_Temporary/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c8a5d9..f125ebd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,8 @@ file(GLOB Editor_SRC "FEEditorVirtualFileSystem.h" "FEEditorScriptingSystem.cpp" "FEEditorScriptingSystem.h" + "FEProjectBuildSystem.cpp" + "FEProjectBuildSystem.h" ) file(GLOB ProjectManagment_SRC diff --git a/EditorWindows/ContentBrowserWindow.cpp b/EditorWindows/ContentBrowserWindow.cpp index 39c6292..4903147 100644 --- a/EditorWindows/ContentBrowserWindow.cpp +++ b/EditorWindows/ContentBrowserWindow.cpp @@ -457,6 +457,25 @@ void FEEditorContentBrowserWindow::Render() ImGui::EndMenu(); } } + + if (FilteredResources[ItemUnderMouse]->GetType() == FE_SCENE) + { + if (ImGui::MenuItem("Open")) + { + //EDITOR.LoadScene(RESOURCE_MANAGER.GetScene(FilteredResources[ItemUnderMouse]->GetObjectID())); + } + + FEScene* StartingScene = SCENE_MANAGER.GetStartingScene(); + bool bIsSceneStarting = false; + if (StartingScene != nullptr) + bIsSceneStarting = StartingScene->GetObjectID() == FilteredResources[ItemUnderMouse]->GetObjectID(); + + if (ImGui::MenuItem("Starting scene", NULL, &bIsSceneStarting)) + { + if (bIsSceneStarting) + SCENE_MANAGER.SetStartingScene(FilteredResources[ItemUnderMouse]->GetObjectID()); + } + } } ImGui::EndPopup(); @@ -942,6 +961,7 @@ void FEEditorContentBrowserWindow::RenderFilterMenu() ObjectTagNegativeFilters.push_back(ENGINE_RESOURCE_TAG); ObjectTagNegativeFilters.push_back(EDITOR_RESOURCE_TAG); ObjectTagNegativeFilters.push_back(PREFAB_SCENE_DESCRIPTION_TAG); + ObjectTagNegativeFilters.push_back(TERRAIN_SYSTEM_RESOURCE_TAG); } if (ImGui::Checkbox("Hide private tags", &bIsPrivateTagsInFilters)) @@ -952,6 +972,7 @@ void FEEditorContentBrowserWindow::RenderFilterMenu() ObjectTagNegativeFilters.push_back(ENGINE_RESOURCE_TAG); ObjectTagNegativeFilters.push_back(EDITOR_RESOURCE_TAG); ObjectTagNegativeFilters.push_back(PREFAB_SCENE_DESCRIPTION_TAG); + ObjectTagNegativeFilters.push_back(TERRAIN_SYSTEM_RESOURCE_TAG); } } diff --git a/EditorWindows/DeletePopups.cpp b/EditorWindows/DeletePopups.cpp index 3a1431a..8d11d60 100644 --- a/EditorWindows/DeletePopups.cpp +++ b/EditorWindows/DeletePopups.cpp @@ -64,7 +64,7 @@ void DeleteTexturePopup::Render() std::vector DeleteTexturePopup::MaterialsThatUsesTexture(const FETexture* Texture) { std::vector Result; - const std::vector MateriasList = RESOURCE_MANAGER.GetMaterialList(); + const std::vector MateriasList = RESOURCE_MANAGER.GetMaterialIDList(); for (size_t i = 0; i < MateriasList.size(); i++) { @@ -110,7 +110,7 @@ void DeleteTexturePopup::DeleteTexture(FETexture* Texture) // re-create game model preview that was using material that uses this texture if (!MaterialsThatUseTexture.empty()) { - const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); + const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelIDList(); for (size_t i = 0; i < GameModelList.size(); i++) { const FEGameModel* CurrentGameModel = RESOURCE_MANAGER.GetGameModel(GameModelList[i]); @@ -195,7 +195,7 @@ void DeleteMeshPopup::Render() int DeleteMeshPopup::TimesMeshUsed(const FEMesh* Mesh) { int Result = 0; - const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); + const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelIDList(); for (size_t i = 0; i < GameModelList.size(); i++) { @@ -215,7 +215,7 @@ void DeleteMeshPopup::DeleteMesh(FEMesh* Mesh) // re-create game model preview std::vector GameModelListToUpdate; - const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); + const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelIDList(); for (size_t i = 0; i < GameModelList.size(); i++) { const FEGameModel* CurrentGameModel = RESOURCE_MANAGER.GetGameModel(GameModelList[i]); @@ -487,7 +487,7 @@ void DeleteMaterialPopup::Render() int DeleteMaterialPopup::TimesMaterialUsed(const FEMaterial* Material) { int Result = 0; - const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); + const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelIDList(); for (size_t i = 0; i < GameModelList.size(); i++) { @@ -506,7 +506,7 @@ void DeleteMaterialPopup::DeleteMaterial(FEMaterial* Material) const std::string name = Material->GetName(); // re-create game model preview std::vector GameModelListToUpdate; - const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); + const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelIDList(); for (size_t i = 0; i < GameModelList.size(); i++) { const FEGameModel* CurrentGameModel = RESOURCE_MANAGER.GetGameModel(GameModelList[i]); diff --git a/EditorWindows/EditPopups.cpp b/EditorWindows/EditPopups.cpp index d4a9513..1171e60 100644 --- a/EditorWindows/EditPopups.cpp +++ b/EditorWindows/EditPopups.cpp @@ -545,7 +545,7 @@ void EditGameModelPopup::Render() { UpdatedBillboardMaterial = TempModel->GetBillboardMaterial(); - const std::vector TempMaterialList = RESOURCE_MANAGER.GetMaterialList(); + const std::vector TempMaterialList = RESOURCE_MANAGER.GetMaterialIDList(); std::vector FinalMaterialList; for (size_t j = 0; j < TempMaterialList.size(); j++) { diff --git a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp index 7cba5b5..ac25b17 100644 --- a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp +++ b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp @@ -30,7 +30,7 @@ bool FEEditorSceneWindow::DragAndDropCallBack(FEObject* Object, void** UserData) if (EDITOR.GetFocusedScene() == nullptr) return false; - if (CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene()) == nullptr) + if (CAMERA_SYSTEM.GetMainCamera(EDITOR.GetFocusedScene()) == nullptr) return false; if (UserData == nullptr) @@ -44,8 +44,8 @@ bool FEEditorSceneWindow::DragAndDropCallBack(FEObject* Object, void** UserData) { FEGameModel* GameModel = RESOURCE_MANAGER.GetGameModel(Object->GetObjectID()); - FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); - FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCamera(EDITOR.GetFocusedScene())->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCamera(EDITOR.GetFocusedScene())->GetComponent(); FEEntity* Entity = EditorSceneWindow->GetScene()->CreateEntity(Object->GetName()); Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); @@ -59,8 +59,8 @@ bool FEEditorSceneWindow::DragAndDropCallBack(FEObject* Object, void** UserData) } else if (Object->GetType() == FE_PREFAB) { - FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); - FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCamera(EDITOR.GetFocusedScene())->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCamera(EDITOR.GetFocusedScene())->GetComponent(); FEPrefab* Prefab = RESOURCE_MANAGER.GetPrefab(Object->GetObjectID()); FEScene* PrefabScene = Prefab->GetScene(); @@ -109,7 +109,22 @@ void FEEditorSceneWindow::Render() if (ImGui::IsWindowFocused()) EDITOR.SetFocusedScene(Scene); - FEEntity* CameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(Scene); + + FEProject* CurrentProject = PROJECT_MANAGER.GetCurrent(); + if (CurrentProject == nullptr) + return; + + FEEntity* CameraEntity = nullptr; + if (Scene->HasFlag(FESceneFlag::EditorMode)) + { + std::string EditorCameraID = CurrentProject->GetEditorCameraIDBySceneID(Scene->GetObjectID()); + CameraEntity = Scene->GetEntity(EditorCameraID); + } + else if (Scene->HasFlag(FESceneFlag::GameMode)) + { + CameraEntity = CAMERA_SYSTEM.GetMainCamera(Scene); + } + if (CameraEntity != nullptr) { FECameraComponent& CameraComponent = CameraEntity->GetComponent(); @@ -130,7 +145,7 @@ void FEEditorSceneWindow::Render() Style.WindowBorderSize = 0.0f; Style.WindowPadding = ImVec2(0.0f, 0.0f); - FETexture* CameraResult = RENDERER.GetCameraResult(CAMERA_SYSTEM.GetMainCameraEntity(Scene)); + FETexture* CameraResult = RENDERER.GetCameraResult(CAMERA_SYSTEM.GetMainCamera(Scene)); if (CameraResult != nullptr) { ImGui::Image((void*)(intptr_t)CameraResult->GetTextureID(), ImVec2(GetWindow()->ContentRegionRect.GetWidth(), GetWindow()->ContentRegionRect.GetHeight()), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index 804dd4c..0b91add 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -454,9 +454,20 @@ void FEEditorInspectorWindow::DisplayCameraProperties(FEEntity* CameraEntity) co { FECameraComponent& CameraComponent = CameraEntity->GetComponent(); - bool bIsMainCamera = CameraComponent.IsMainCamera(); + // Because of editor camera system, we need to check if it is main camera in a different way. + std::string MainCameraID = PROJECT_MANAGER.GetCurrent()->GetProperMainCameraIDBySceneID(EDITOR.GetFocusedScene()->GetObjectID()); + bool bIsMainCamera = MainCameraID == CameraEntity->GetObjectID(); if (ImGui::Checkbox("Main camera", &bIsMainCamera)) - CAMERA_SYSTEM.SetMainCamera(CameraEntity); + { + if (bIsMainCamera) + { + PROJECT_MANAGER.GetCurrent()->SetProperMainCameraIDBySceneID(EDITOR.GetFocusedScene()->GetObjectID(), CameraEntity->GetObjectID()); + } + else + { + PROJECT_MANAGER.GetCurrent()->SetProperMainCameraIDBySceneID(EDITOR.GetFocusedScene()->GetObjectID(), ""); + } + } float FOV = CameraComponent.GetFOV(); ImGui::Text("Field of view : "); @@ -1009,7 +1020,7 @@ void FEEditorInspectorWindow::Render() return; FEScene* CurrentScene = EDITOR.GetFocusedScene(); - FEEntity* MainCameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(CurrentScene); + FEEntity* MainCameraEntity = CAMERA_SYSTEM.GetMainCamera(CurrentScene); if (MainCameraEntity == nullptr) return; @@ -1889,7 +1900,7 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) if (ImGui::MenuItem("Add layer...")) { - std::vector TempMaterialList = RESOURCE_MANAGER.GetMaterialList(); + std::vector TempMaterialList = RESOURCE_MANAGER.GetMaterialIDList(); std::vector FinalMaterialList; for (size_t i = 0; i < TempMaterialList.size(); i++) { @@ -1950,7 +1961,7 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) if (ImGui::MenuItem("Change material...")) { - std::vector TempMaterialList = RESOURCE_MANAGER.GetMaterialList(); + std::vector TempMaterialList = RESOURCE_MANAGER.GetMaterialIDList(); std::vector FinalMaterialList; for (size_t i = 0; i < TempMaterialList.size(); i++) { diff --git a/EditorWindows/InspectorWindow.h b/EditorWindows/InspectorWindow.h index 7fc9309..69adf11 100644 --- a/EditorWindows/InspectorWindow.h +++ b/EditorWindows/InspectorWindow.h @@ -2,6 +2,7 @@ #include "ContentBrowserWindow.h" #include "../FEEditorScriptingSystem.h" +#include "../FEProjectBuildSystem.h" class FEEditorInspectorWindow { diff --git a/EditorWindows/PrefabEditorManager.cpp b/EditorWindows/PrefabEditorManager.cpp index c003fe4..a55058e 100644 --- a/EditorWindows/PrefabEditorManager.cpp +++ b/EditorWindows/PrefabEditorManager.cpp @@ -76,7 +76,7 @@ bool FEPrefabSceneEditorWindow::DragAndDropCallBack(FEObject* Object, void** Use if (EDITOR.GetFocusedScene() == nullptr) return false; - if (CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene()) == nullptr) + if (CAMERA_SYSTEM.GetMainCamera(EDITOR.GetFocusedScene()) == nullptr) return false; if (UserData == nullptr) @@ -90,8 +90,8 @@ bool FEPrefabSceneEditorWindow::DragAndDropCallBack(FEObject* Object, void** Use { FEGameModel* GameModel = RESOURCE_MANAGER.GetGameModel(Object->GetObjectID()); - FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); - FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCamera(EDITOR.GetFocusedScene())->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCamera(EDITOR.GetFocusedScene())->GetComponent(); FEEntity* Entity = EditorSceneWindow->GetScene()->CreateEntity(Object->GetName()); Entity->AddComponent(GameModel); @@ -133,6 +133,21 @@ void FEPrefabEditorManager::Clear() FEEntity* FEPrefabEditorManager::InjectModelViewCamera(FEScene* Scene) { + FEProject* CurrentProject = PROJECT_MANAGER.GetCurrent(); + if (CurrentProject->SceneIDToEditorCameraID.find(Scene->GetObjectID()) != CurrentProject->SceneIDToEditorCameraID.end()) + { + FEEntity* CameraEntity = Scene->GetEntity(CurrentProject->SceneIDToEditorCameraID[Scene->GetObjectID()]); + if (CameraEntity != nullptr) + { + LOG.Add("FEPrefabEditorManager::InjectModelViewCamera: Editor camera already exists in scene " + Scene->GetName(), "FE_LOG_LOADING", FE_LOG_WARNING); + return nullptr; + } + else + { + CurrentProject->SceneIDToEditorCameraID.erase(Scene->GetObjectID()); + } + } + FEEntity* CameraEntity = nullptr; std::vector CameraPrefab = RESOURCE_MANAGER.GetPrefabByName("Model view camera prefab"); if (CameraPrefab.size() == 0) @@ -170,6 +185,8 @@ FEEntity* FEPrefabEditorManager::InjectModelViewCamera(FEScene* Scene) RESOURCE_MANAGER.SetTag(CameraEntity, EDITOR_RESOURCE_TAG); CAMERA_SYSTEM.SetMainCamera(CameraEntity); + CurrentProject->SceneIDToEditorCameraID[Scene->GetObjectID()] = CameraEntity->GetObjectID(); + return CameraEntity; } diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 77a398a..2750487 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -88,8 +88,8 @@ static void CreateInstancedEntityCallBack(const std::vector Selection if (SelectedGameModel == nullptr) return; - FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); - FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCamera(EDITOR.GetFocusedScene())->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCamera(EDITOR.GetFocusedScene())->GetComponent(); FEEntity* Entity = EDITOR.GetFocusedScene()->CreateEntity(); Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); Entity->AddComponent(SelectedGameModel); @@ -111,8 +111,8 @@ static void CreateEntityCallBack(const std::vector SelectionsResult) if (SelectedPrefab == nullptr) return; - FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); - FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.GetFocusedScene())->GetComponent(); + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCamera(EDITOR.GetFocusedScene())->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCamera(EDITOR.GetFocusedScene())->GetComponent(); FEEntity* Entity = EDITOR.GetFocusedScene()->CreateEntity(); Entity->GetComponent().SetPosition(CameraTransformComponent.GetPosition(FE_WORLD_SPACE) + CameraComponent.GetForward() * 10.0f); SELECTED.SetSelected(Entity); diff --git a/EditorWindows/SelectPopups.cpp b/EditorWindows/SelectPopups.cpp index e1ba848..ccb9b03 100644 --- a/EditorWindows/SelectPopups.cpp +++ b/EditorWindows/SelectPopups.cpp @@ -67,25 +67,25 @@ void SelectFEObjectPopUp::Show(const FE_OBJECT_TYPE Type, void(*CallBack)(std::v { case FE_TEXTURE: { - TempList = RESOURCE_MANAGER.GetTextureList(); + TempList = RESOURCE_MANAGER.GetTextureIDList(); break; } case FE_MESH: { - TempList = RESOURCE_MANAGER.GetMeshList(); + TempList = RESOURCE_MANAGER.GetMeshIDList(); break; } case FE_MATERIAL: { - TempList = RESOURCE_MANAGER.GetMaterialList(); + TempList = RESOURCE_MANAGER.GetMaterialIDList(); break; } case FE_GAMEMODEL: { - TempList = RESOURCE_MANAGER.GetGameModelList(); + TempList = RESOURCE_MANAGER.GetGameModelIDList(); break; } diff --git a/EditorWindows/ShaderEditorWindow.cpp b/EditorWindows/ShaderEditorWindow.cpp index d21496f..7819e60 100644 --- a/EditorWindows/ShaderEditorWindow.cpp +++ b/EditorWindows/ShaderEditorWindow.cpp @@ -442,7 +442,7 @@ void ShaderEditorWindow::Render() void ShaderEditorWindow::ReplaceShader(FEShader* OldShader, FEShader* NewShader) { - std::vector MaterialList = RESOURCE_MANAGER.GetMaterialList(); + std::vector MaterialList = RESOURCE_MANAGER.GetMaterialIDList(); for (size_t i = 0; i < MaterialList.size(); i++) { FEMaterial* TempMaterial = RESOURCE_MANAGER.GetMaterial(MaterialList[i]); @@ -452,7 +452,7 @@ void ShaderEditorWindow::ReplaceShader(FEShader* OldShader, FEShader* NewShader) } } - MaterialList = RESOURCE_MANAGER.GetEnginePrivateMaterialList(); + MaterialList = RESOURCE_MANAGER.GetEnginePrivateMaterialIDList(); for (size_t i = 0; i < MaterialList.size(); i++) { FEMaterial* TempMaterial = RESOURCE_MANAGER.GetMaterial(MaterialList[i]); diff --git a/FEEditor.cpp b/FEEditor.cpp index cff12bd..e8c8ec8 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -75,7 +75,7 @@ void FEEditor::MouseButtonCallback(const int Button, const int Action, int Mods) if (ImGui::GetCurrentContext()->HoveredWindow != nullptr && EDITOR.EditorSceneWindows[i]->GetWindow() != nullptr) EDITOR.EditorSceneWindows[i]->bWindowHovered = ImGui::GetCurrentContext()->HoveredWindow->Name == EDITOR.EditorSceneWindows[i]->GetWindow()->Name; - FEEntity* CurrentMainCamera = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.EditorSceneWindows[i]->Scene); + FEEntity* CurrentMainCamera = CAMERA_SYSTEM.GetMainCamera(EDITOR.EditorSceneWindows[i]->Scene); if (ImGui::GetIO().WantCaptureMouse && !EDITOR.EditorSceneWindows[i]->bWindowHovered) { @@ -548,7 +548,21 @@ void FEEditor::OnViewportResize(std::string ViewportID) for (size_t i = 0; i < EDITOR.EditorSceneWindows.size(); i++) { - FEEntity* CameraEntity = CAMERA_SYSTEM.GetMainCameraEntity(EDITOR.EditorSceneWindows[i]->Scene); + FEProject* CurrentProject = PROJECT_MANAGER.GetCurrent(); + if (CurrentProject == nullptr) + return; + + FEEntity* CameraEntity = nullptr; + if (EDITOR.EditorSceneWindows[i]->Scene->HasFlag(FESceneFlag::EditorMode)) + { + std::string EditorCameraID = CurrentProject->GetEditorCameraIDBySceneID(EDITOR.EditorSceneWindows[i]->Scene->GetObjectID()); + CameraEntity = EDITOR.EditorSceneWindows[i]->Scene->GetEntity(EditorCameraID); + } + else if (EDITOR.EditorSceneWindows[i]->Scene->HasFlag(FESceneFlag::GameMode)) + { + CameraEntity = CAMERA_SYSTEM.GetMainCamera(EDITOR.EditorSceneWindows[i]->Scene); + } + if (CameraEntity == nullptr) continue; @@ -958,4 +972,28 @@ bool FEEditor::SetFocusedScene(std::string NewSceneInFocusID) FocusedEditorSceneID = NewSceneInFocusID; return true; +} + +void FEEditor::UpdateBeforeRender() +{ + // Before rendering, we need to ensure that if scene is in editor mode, it's main camera would be editor camera. + FEProject* CurrentProject = PROJECT_MANAGER.GetCurrent(); + if (CurrentProject != nullptr) + { + std::vector Scenes = SCENE_MANAGER.GetScenesByFlagMask(FESceneFlag::Active | FESceneFlag::Renderable | FESceneFlag::EditorMode); + for (size_t i = 0; i < Scenes.size(); i++) + { + FEEntity* CurrentMainCameraEntity = CAMERA_SYSTEM.GetMainCamera(Scenes[i]); + std::string EditorCameraID = CurrentProject->GetEditorCameraIDBySceneID(Scenes[i]->GetObjectID()); + if (!EditorCameraID.empty()) + { + if (CurrentMainCameraEntity != nullptr && CurrentMainCameraEntity->GetObjectID() != EditorCameraID) + { + //SceneIDToOldMainCameraID[Scenes[i]->GetObjectID()] = CurrentMainCameraEntity->GetObjectID(); + //CurrentProject->SceneIDToProperMainCameraID[Scenes[i]->GetObjectID()] = EditorCameraID; + CAMERA_SYSTEM.SetMainCamera(Scenes[i]->GetEntity(EditorCameraID)); + } + } + } + } } \ No newline at end of file diff --git a/FEEditor.h b/FEEditor.h index 4dcedac..dad4539 100644 --- a/FEEditor.h +++ b/FEEditor.h @@ -42,6 +42,8 @@ class FEEditor bool IsInGameMode() const; void SetGameMode(bool GameMode); + + void UpdateBeforeRender(); private: SINGLETON_PRIVATE_PART(FEEditor) @@ -100,6 +102,8 @@ class FEEditor void OnProjectClose(); void BeforeChangeOfFocusedScene(FEScene* NewSceneInFocus); + + std::unordered_map SceneIDToOldMainCameraID; }; #define EDITOR FEEditor::GetInstance() \ No newline at end of file diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index ee503e5..0e087e3 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -291,14 +291,14 @@ void GizmoManager::Update() } FEScene* Scene = SCENE_MANAGER.GetScene(GizmoSceneData->SceneID); - if (SELECTED.GetSelected(Scene) == nullptr || CAMERA_SYSTEM.GetMainCameraEntity(Scene) == nullptr) + if (SELECTED.GetSelected(Scene) == nullptr || CAMERA_SYSTEM.GetMainCamera(Scene) == nullptr) { HideAllGizmo(Scene); PerSceneIterator++; continue; } - FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCamera(Scene)->GetComponent(); FETransformComponent& ObjTransform = GetTransformComponentOfSelectedObject(Scene); const glm::vec3 ObjectSpaceOriginInWorldSpace = glm::vec3(ObjTransform.GetWorldMatrix() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); glm::vec3 ToObject = ObjectSpaceOriginInWorldSpace - CameraTransformComponent.GetPosition(FE_WORLD_SPACE); @@ -499,8 +499,8 @@ glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, if (GizmoSceneData == nullptr) return glm::vec3(); - FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); - FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCamera(Scene)->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCamera(Scene)->GetComponent(); FEViewport* CurrentViewport = CAMERA_SYSTEM.GetMainCameraViewport(Scene); glm::ivec2 ViewportPosition = glm::ivec2(CurrentViewport->GetX(), CurrentViewport->GetY()); glm::ivec2 ViewportSize = glm::ivec2(CurrentViewport->GetWidth(), CurrentViewport->GetHeight()); @@ -544,8 +544,8 @@ glm::vec3 GizmoManager::GetMousePositionDifferenceOnPlane(glm::vec3 PlaneNormal, if (GizmoSceneData == nullptr) return glm::vec3(); - FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); - FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCamera(Scene)->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCamera(Scene)->GetComponent(); FEViewport* CurrentViewport = CAMERA_SYSTEM.GetMainCameraViewport(Scene); glm::ivec2 ViewportPosition = glm::ivec2(CurrentViewport->GetX(), CurrentViewport->GetY()); glm::ivec2 ViewportSize = glm::ivec2(CurrentViewport->GetWidth(), CurrentViewport->GetHeight()); @@ -590,11 +590,11 @@ void GizmoManager::MouseMoveTransformationGizmos(FEScene* Scene) if (GizmoSceneData == nullptr) return; - if (CAMERA_SYSTEM.GetMainCameraEntity(Scene) == nullptr) + if (CAMERA_SYSTEM.GetMainCamera(Scene) == nullptr) return; - FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); - FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); + FETransformComponent& CameraTransformComponent = CAMERA_SYSTEM.GetMainCamera(Scene)->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCamera(Scene)->GetComponent(); FEViewport* CurrentViewport = CAMERA_SYSTEM.GetMainCameraViewport(Scene); glm::ivec2 ViewportPosition = glm::ivec2(CurrentViewport->GetX(), CurrentViewport->GetY()); glm::ivec2 ViewportSize = glm::ivec2(CurrentViewport->GetWidth(), CurrentViewport->GetHeight()); @@ -713,7 +713,7 @@ void GizmoManager::MouseMoveScaleGizmos(FEScene* Scene) if (GizmoSceneData == nullptr) return; - FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCameraEntity(Scene)->GetComponent(); + FECameraComponent& CameraComponent = CAMERA_SYSTEM.GetMainCamera(Scene)->GetComponent(); FETransformComponent& ObjTransform = GetTransformComponentOfSelectedObject(Scene); if (GizmoSceneData->bScaleXGizmoActive && GizmoSceneData->bScaleYGizmoActive && GizmoSceneData->bScaleZGizmoActive) diff --git a/FEEditorHaloSelectionEffect.cpp b/FEEditorHaloSelectionEffect.cpp index e330112..20331b8 100644 --- a/FEEditorHaloSelectionEffect.cpp +++ b/FEEditorHaloSelectionEffect.cpp @@ -50,7 +50,7 @@ void FEEditorHaloSelectionEffect::UpdateResources(FEScene* Scene) if (CurrentHaloSelectionData == nullptr) return; - FECameraRenderingData* CameraData = RENDERER.GetCameraRenderingData(CAMERA_SYSTEM.GetMainCameraEntity(Scene)); + FECameraRenderingData* CameraData = RENDERER.GetCameraRenderingData(CAMERA_SYSTEM.GetMainCamera(Scene)); if (CameraData == nullptr) return; @@ -132,7 +132,7 @@ void FEEditorHaloSelectionEffect::AddSceneData(const std::string& SceneID) PerSceneData[SceneID] = new FEHaloSelectionData(); PerSceneData[SceneID]->SceneID = SceneID; - FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(CurrentScene); + FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCamera(CurrentScene); FECameraRenderingData* CameraData = RENDERER.GetCameraRenderingData(MainCamera); if (CameraData == nullptr) return; diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index 6ff02ae..fdbac6d 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -57,13 +57,13 @@ void FEEditorPreviewManager::UpdateAll() { Clear(); - const std::vector MeshList = RESOURCE_MANAGER.GetMeshList(); + const std::vector MeshList = RESOURCE_MANAGER.GetMeshIDList(); for (size_t i = 0; i < MeshList.size(); i++) { CreateMeshPreview(MeshList[i]); } - const std::vector MaterialList = RESOURCE_MANAGER.GetMaterialList(); + const std::vector MaterialList = RESOURCE_MANAGER.GetMaterialIDList(); for (size_t i = 0; i < MaterialList.size(); i++) { FEObject* CurrentMaterial = OBJECT_MANAGER.GetFEObject(MaterialList[i]); @@ -71,7 +71,7 @@ void FEEditorPreviewManager::UpdateAll() CreateMaterialPreview(MaterialList[i]); } - const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); + const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelIDList(); for (size_t i = 0; i < GameModelList.size(); i++) { FEObject* CurrentGameModel = OBJECT_MANAGER.GetFEObject(GameModelList[i]); @@ -143,7 +143,7 @@ FETexture* FEEditorPreviewManager::GetMeshPreview(const std::string MeshID) { CreateMeshPreview(MeshID); // if some game model uses this mesh we should also update it's preview - const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); + const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelIDList(); for (size_t i = 0; i < GameModelList.size(); i++) { @@ -196,7 +196,7 @@ void FEEditorPreviewManager::CreateMaterialPreview(const std::string MaterialID) } // Looking for all gameModels that uses this material to also update them. - const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); + const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelIDList(); for (size_t i = 0; i < GameModelList.size(); i++) { const FEGameModel* CurrentGameModel = RESOURCE_MANAGER.GetGameModel(GameModelList[i]); @@ -221,7 +221,7 @@ FETexture* FEEditorPreviewManager::GetMaterialPreview(const std::string Material { CreateMaterialPreview(MaterialID); // if some game model uses this material we should also update it's preview - const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); + const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelIDList(); for (size_t i = 0; i < GameModelList.size(); i++) { const FEGameModel* CurrentGameModel = RESOURCE_MANAGER.GetGameModel(GameModelList[i]); @@ -367,7 +367,7 @@ FETexture* FEEditorPreviewManager::GetGameModelPreview(const std::string GameMod void FEEditorPreviewManager::UpdateAllGameModelPreviews() { // Getting list of all game models. - const auto GameModelsList = RESOURCE_MANAGER.GetGameModelList(); + const auto GameModelsList = RESOURCE_MANAGER.GetGameModelIDList(); for (size_t i = 0; i < GameModelsList.size(); i++) { CreateGameModelPreview(GameModelsList[i]); diff --git a/FEEditorScriptingSystem.cpp b/FEEditorScriptingSystem.cpp index 7391d0d..5d56f2e 100644 --- a/FEEditorScriptingSystem.cpp +++ b/FEEditorScriptingSystem.cpp @@ -23,6 +23,10 @@ void FEEditorScriptingSystem::Update() if (CurrentModule == nullptr) continue; + if (CurrentModule->GetTag() == ENGINE_RESOURCE_TAG || + CurrentModule->GetTag() == EDITOR_RESOURCE_TAG) + continue; + if (CurrentModule->GetProject() != nullptr) CurrentModule->GetProject()->Update(); } diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index a07f273..d7a2b54 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -48,7 +48,7 @@ void FEEditorSelectedObject::UpdateResources(FEScene* Scene) if (CurrentSelectionData == nullptr) return; - FEEntity* CurrentCamera = CAMERA_SYSTEM.GetMainCameraEntity(Scene); + FEEntity* CurrentCamera = CAMERA_SYSTEM.GetMainCamera(Scene); FECameraComponent& CameraComponent = CurrentCamera->GetComponent(); delete CurrentSelectionData->PixelAccurateSelectionFB; @@ -139,7 +139,7 @@ void FEEditorSelectedObject::DetermineEntityUnderMouse(const double MouseX, cons CurrentSelectionData->SceneEntitiesUnderMouse.clear(); CurrentSelectionData->InstancedSubObjectsInfo.clear(); - FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(Scene); + FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCamera(Scene); FETransformComponent& CameraTransformComponent = MainCamera->GetComponent(); FECameraComponent& CameraComponent = MainCamera->GetComponent(); @@ -323,7 +323,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons glClearColor(0.0f, 0.0f, 0.0f, 0.0f); FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); - FEEntity* CurrentCamera = CAMERA_SYSTEM.GetMainCameraEntity(Scene); + FEEntity* CurrentCamera = CAMERA_SYSTEM.GetMainCamera(Scene); for (size_t i = 0; i < CurrentSelectionData->SceneEntitiesUnderMouse.size(); i++) { @@ -562,7 +562,7 @@ void FEEditorSelectedObject::OnCameraUpdate() const } FEHaloSelectionData* HaloSelectionData = HALO_SELECTION_EFFECT.GetSceneData(CurrentScene->GetObjectID()); - FEEntity* CurrentCamera = CAMERA_SYSTEM.GetMainCameraEntity(CurrentScene); + FEEntity* CurrentCamera = CAMERA_SYSTEM.GetMainCamera(CurrentScene); if (CurrentCamera == nullptr || HaloSelectionData->PostProcess == nullptr) { SceneIterator++; @@ -702,7 +702,7 @@ void FEEditorSelectedObject::AddSceneData(const std::string& SceneID) if (PerSceneData.find(SceneID) != PerSceneData.end()) return; - FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCameraEntity(CurrentScene); + FEEntity* MainCamera = CAMERA_SYSTEM.GetMainCamera(CurrentScene); if (MainCamera == nullptr) return; diff --git a/FEProjectBuildSystem.cpp b/FEProjectBuildSystem.cpp new file mode 100644 index 0000000..0161c8e --- /dev/null +++ b/FEProjectBuildSystem.cpp @@ -0,0 +1,538 @@ +#include "FEProjectBuildSystem.h" +using namespace FocalEngine; + +FEProjectBuildSystem::FEProjectBuildSystem() +{ + +} + +FEProjectBuildSystem::~FEProjectBuildSystem() +{ +} + +std::string FEProjectBuildSystem::GetVSProjectName(FEProject* ProjectToBuild) +{ + if (ProjectToBuild == nullptr) + { + LOG.Add("FEProjectBuildSystem::GetVSProjectName: ProjectToBuild is nullptr!", "FE_LOG_LOADING", FE_LOG_ERROR); + return ""; + } + + std::string AppropriateProjectName = ProjectToBuild->GetName(); + for (size_t i = 0; i < AppropriateProjectName.size(); i++) + { + if (AppropriateProjectName[i] == ' ') + AppropriateProjectName[i] = '_'; + } + + if (AppropriateProjectName.empty()) + AppropriateProjectName = "UntitledProject"; + + return AppropriateProjectName; +} + +bool FEProjectBuildSystem::ReplaceInFile(std::string Path, std::vector Instructions) +{ + if (Path.empty()) + { + LOG.Add("FEProjectBuildSystem::ReplaceInFile: File path is empty", "FE_BUILD_EXECUTABLE", FE_LOG_WARNING); + return false; + } + + std::fstream File(Path, std::ios::in); + if (!File.is_open()) + { + LOG.Add("FEProjectBuildSystem::ReplaceInFile: Error opening file " + Path, "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + std::vector FileContent; + std::string Line; + while (std::getline(File, Line)) + FileContent.push_back(Line); + + File.close(); + + for (size_t i = 0; i < FileContent.size(); i++) + { + for (size_t j = 0; j < Instructions.size(); j++) + { + if (FileContent[i].find(Instructions[j].SubStringInLineToTrigger) != std::string::npos) + { + FileContent[i].replace(FileContent[i].find(Instructions[j].What), Instructions[j].What.size(), Instructions[j].ReplaceWith); + } + } + } + + File.open(Path, std::ios::out | std::ios::trunc); + if (!File.is_open()) + { + LOG.Add("FEProjectBuildSystem::ReplaceInFile: Error opening file " + Path, "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + // Write the modified content back to the file + for (size_t i = 0; i < FileContent.size(); i++) + File << FileContent[i] + "\n"; + + File.close(); + return true; +} + +bool FEProjectBuildSystem::CopyVisualNodeSystemSubProjectFiles(const std::string& OutputPath) +{ + if (!FILE_SYSTEM.DoesDirectoryExist(OutputPath)) + { + LOG.Add("FEProjectBuildSystem::CopyVisualNodeSystemSubProjectFiles: OutputPath does not exist!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + // Create all needed folders. + std::vector FoldersToCreate = { "VisualNodeSystem/"}; + for (size_t i = 0; i < FoldersToCreate.size(); i++) + { + if (!FILE_SYSTEM.CreateDirectory(OutputPath + FoldersToCreate[i])) + { + LOG.Add("FEProjectBuildSystem::CopyVisualNodeSystemSubProjectFiles: Error creating " + FoldersToCreate[i] + " directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + } + + // Place required files in the destination directory. + std::string EditorPath = FILE_SYSTEM.GetCurrentWorkingPath() + "/"; + std::string VisualNodeSystemPath = EditorPath + "SubSystems/NodeSystem/VisualNodeSystem/"; + std::vector> FilesToCopy; + FilesToCopy.push_back({ VisualNodeSystemPath + "CMakeLists.txt", OutputPath + "VisualNodeSystem/CMakeLists.txt" }); + + // Add all source files to the list. + std::vector FilesInMainFolder = FILE_SYSTEM.GetFileList(VisualNodeSystemPath); + for (size_t i = 0; i < FilesInMainFolder.size(); i++) + { + if (FilesInMainFolder[i].substr(FilesInMainFolder[i].size() - 2) == ".h" || + FilesInMainFolder[i].substr(FilesInMainFolder[i].size() - 4) == ".hpp" || + FilesInMainFolder[i].substr(FilesInMainFolder[i].size() - 4) == ".inl" || + FilesInMainFolder[i].substr(FilesInMainFolder[i].size() - 4) == ".cpp" || + FilesInMainFolder[i].substr(FilesInMainFolder[i].size() - 2) == ".c") + { + FilesToCopy.push_back({ VisualNodeSystemPath + FilesInMainFolder[i], OutputPath + "VisualNodeSystem/" + FilesInMainFolder[i] }); + } + } + + for (size_t i = 0; i < FilesToCopy.size(); i++) + { + if (!FILE_SYSTEM.CopyFile(FilesToCopy[i].first, FilesToCopy[i].second)) + { + LOG.Add("FEProjectBuildSystem::CopyVisualNodeSystemSubProjectFiles: Error copying file " + FilesToCopy[i].first + " to " + FilesToCopy[i].second, "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + } + + if (!FILE_SYSTEM.CopyDirectory(VisualNodeSystemPath + "SubSystems/", + OutputPath + "VisualNodeSystem/SubSystems/")) + { + LOG.Add("FEProjectBuildSystem::CopyVisualNodeSystemSubProjectFiles: Error copying directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + if (!FILE_SYSTEM.CopyDirectory(VisualNodeSystemPath + "ThirdParty/", + OutputPath + "VisualNodeSystem/ThirdParty/")) + { + LOG.Add("FEProjectBuildSystem::CopyVisualNodeSystemSubProjectFiles: Error copying directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + return true; +} + +bool FEProjectBuildSystem::BuildExecutable(FEProject* ProjectToBuild) +{ + if (ProjectToBuild == nullptr) + { + LOG.Add("FEProjectBuildSystem::BuildExecutable: ProjectToBuild is nullptr!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + std::string VSProjectDirectory = FILE_SYSTEM.GetCurrentWorkingPath() + "/BuildProjects_Temporary/"; + if (FILE_SYSTEM.DoesDirectoryExist(VSProjectDirectory)) + { + if (!FILE_SYSTEM.DeleteDirectory(VSProjectDirectory)) + { + LOG.Add("FEProjectBuildSystem::BuildExecutable: Error deleting BuildProjects_Temporary directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + } + + if (!FILE_SYSTEM.CreateDirectory(VSProjectDirectory)) + { + LOG.Add("FEProjectBuildSystem::BuildExecutable: Error creating BuildProjects_Temporary directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + VSProjectDirectory += ProjectToBuild->GetID() + "/"; + if (!FILE_SYSTEM.CreateDirectory(VSProjectDirectory)) + { + LOG.Add("FEProjectBuildSystem::BuildExecutable: Error creating project directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + if (!FILE_SYSTEM.DoesDirectoryExist(VSProjectDirectory)) + { + LOG.Add("FEProjectBuildSystem::BuildExecutable: VSProjectDirectory does not exist!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + FEAssetPackage* Resources = ProjectToBuild->SaveResourcesToAssetPackage(); + Resources->SaveToFile(VSProjectDirectory + "/Resources.fepackage"); + + // Create all needed folders. + std::vector FoldersToCreate = { "SubSystems/", + "SubSystems/FocalEngine", + "ScriptModules/", + "SubSystems/FocalEngine/ResourceManager", + "SubSystems/FocalEngine/SubSystems", + "SubSystems/FocalEngine/ThirdParty", + "SubSystems/FocalEngine/ThirdParty/openxr", + "SubSystems/FocalEngine/SubSystems/FEBasicApplication", + "SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty", + "SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/GLFW", + "SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/glew2" }; + + for (size_t i = 0; i < FoldersToCreate.size(); i++) + { + if (!FILE_SYSTEM.CreateDirectory(VSProjectDirectory + FoldersToCreate[i])) + { + LOG.Add("FEProjectBuildSystem::InitializeProject: Error creating " + FoldersToCreate[i] + " directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + } + + // Place required files in the destination directory. + std::string EditorPath = FILE_SYSTEM.GetCurrentWorkingPath() + "/"; + std::vector> FilesToCopy; + FilesToCopy.push_back({ EditorPath + "/Resources/BuildScripts/Main_Template.cpp", VSProjectDirectory + "Main.cpp" }); + FilesToCopy.push_back({ EditorPath + "/Resources/BuildScripts/Main_Template.h", VSProjectDirectory + "Main.h" }); + FilesToCopy.push_back({ EditorPath + "/Resources/BuildScripts/CMakeLists_Template.txt", VSProjectDirectory + "CMakeLists.txt" }); + std::string EnginePath = FILE_SYSTEM.GetCurrentWorkingPath() + "/" + std::string(ENGINE_FOLDER) + "/"; + FilesToCopy.push_back({ EnginePath + "CMakeLists.txt", VSProjectDirectory + "SubSystems/FocalEngine/CMakeLists.txt" }); + FilesToCopy.push_back({ EnginePath + "UpdateTimestamp.cmake", VSProjectDirectory + "SubSystems/FocalEngine/UpdateTimestamp.cmake" }); + FilesToCopy.push_back({ EnginePath + "ResourceManager/Config.h.in", VSProjectDirectory + "SubSystems/FocalEngine/ResourceManager/Config.h.in" }); + FilesToCopy.push_back({ EnginePath + "ResourceManager/Timestamp.h.in", VSProjectDirectory + "SubSystems/FocalEngine/ResourceManager/Timestamp.h.in" }); + FilesToCopy.push_back({ EnginePath + "SubSystems/FEBasicApplication/CMakeLists.txt", VSProjectDirectory + "SubSystems/FocalEngine/SubSystems/FEBasicApplication/CMakeLists.txt" }); + + for (size_t i = 0; i < FilesToCopy.size(); i++) + { + if (!FILE_SYSTEM.CopyFile(FilesToCopy[i].first, FilesToCopy[i].second)) + { + LOG.Add("FEProjectBuildSystem::BuildExecutable: Error copying file " + FilesToCopy[i].first + " to " + FilesToCopy[i].second, "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + } + + if (!FILE_SYSTEM.CopyDirectory(EnginePath + "/SubSystems/FEBasicApplication/ThirdParty/GLFW/lib", + VSProjectDirectory + "SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/GLFW/lib")) + { + LOG.Add("FEProjectBuildSystem::InitializeProject: Error copying directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + if (!FILE_SYSTEM.CopyDirectory(EnginePath + "/SubSystems/FEBasicApplication/ThirdParty/glew2/lib", + VSProjectDirectory + "SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/glew2/lib")) + { + LOG.Add("FEProjectBuildSystem::InitializeProject: Error copying directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + if (!FILE_SYSTEM.CopyDirectory(EnginePath + "/ThirdParty/openxr/Lib", + VSProjectDirectory + "SubSystems/FocalEngine/ThirdParty/openxr/Lib")) + { + LOG.Add("FEProjectBuildSystem::InitializeProject: Error copying directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + if (!CopyVisualNodeSystemSubProjectFiles(VSProjectDirectory + "/SubSystems/")) + { + LOG.Add("FEProjectBuildSystem::BuildExecutable: Error copying VisualNodeSystem sub project files", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + FEAssetPackage* EngineResources = RESOURCE_MANAGER.CreatePrivateEngineAssetPackage(); + if (EngineResources == nullptr) + { + LOG.Add("FEProjectBuildSystem::BuildExecutable: Error creating private engine asset package", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + EngineResources->SaveToFile(VSProjectDirectory + "/EngineResources.fepackage"); + + if (!InitializeCMakeFileAndScriptFiles(ProjectToBuild, VSProjectDirectory)) + { + LOG.Add("FEProjectBuildSystem::InitializeProject: Error initializing CMakeLists.txt", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + // Copy the engine files to the temporary directory + if (!RESOURCE_MANAGER.CopyEngineFiles(true, true, false, VSProjectDirectory)) + { + LOG.Add("FEProjectBuildSystem::BuildExecutable: Error copying engine files", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + // Build the executable + if (!ConfigureAndBuildCMake(VSProjectDirectory)) + { + LOG.Add("FEProjectBuildSystem::BuildExecutable: Error configuring and building VS Project", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + if (!CreateFinalExecutableDirectory(ProjectToBuild/*, VSProjectDirectory*/)) + { + LOG.Add("FEProjectBuildSystem::BuildExecutable: Error creating final executable directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + // Delete the temporary directory + if (!FILE_SYSTEM.DeleteDirectory(VSProjectDirectory)) + { + LOG.Add("FEProjectBuildSystem::BuildExecutable: Error deleting temporary directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + return true; +} + +bool FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles(FEProject* ProjectToBuild, const std::string& VSProjectDirectory) +{ + if (ProjectToBuild == nullptr) + { + LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: ProjectToBuild is nullptr!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + if (VSProjectDirectory.empty()) + { + LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: path is empty", "FE_BUILD_EXECUTABLE", FE_LOG_WARNING); + return false; + } + + std::vector NativeScriptModuleIDList = RESOURCE_MANAGER.GetNativeScriptModuleIDList(); + + std::string CMakeFilePath = VSProjectDirectory + "CMakeLists.txt"; + + std::vector Instructions; + InstructionWhatToReplaceInFile CurrentInstruction; + CurrentInstruction.SubStringInLineToTrigger = "set(PROJECT_NAME PLACE_HOLDER)"; + CurrentInstruction.What = "PLACE_HOLDER"; + CurrentInstruction.ReplaceWith = GetVSProjectName(ProjectToBuild); + Instructions.push_back(CurrentInstruction); + + std::string SourceFileListString = ""; + std::string ExecutableListString = ""; + std::string FolderListInVSProjectString = ""; + + for (size_t i = 0; i < NativeScriptModuleIDList.size(); i++) + { + FENativeScriptModule* CurrentModule = RESOURCE_MANAGER.GetNativeScriptModule(NativeScriptModuleIDList[i]); + if (CurrentModule == nullptr) + { + LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: Error getting native script module with ID: " + NativeScriptModuleIDList[i], "FE_BUILD_EXECUTABLE", FE_LOG_WARNING); + continue; + } + + if (CurrentModule->GetProject() == nullptr) + { + LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: Error getting project of native script module with ID: " + NativeScriptModuleIDList[i], "FE_BUILD_EXECUTABLE", FE_LOG_WARNING); + continue; + } + + if (!CurrentModule->GetProject()->HasRecoverableVSProjectData()) + { + LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: Project of native script module with ID: " + NativeScriptModuleIDList[i] + " does not have recoverable VS project data", "FE_BUILD_EXECUTABLE", FE_LOG_WARNING); + continue; + } + + std::vector SourceFileList = CurrentModule->GetProject()->GetSourceFileList(); + if (SourceFileList.empty()) + { + LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: SourceFileList is empty for native script module with ID: " + NativeScriptModuleIDList[i], "FE_BUILD_EXECUTABLE", FE_LOG_WARNING); + continue; + } + + std::string CurrentString = "file(GLOB Script_Module_" + CurrentModule->GetObjectID() + "_SRC\n"; + for (size_t i = 0; i < SourceFileList.size(); i++) + { + CurrentString += std::string("\t\"") + "ScriptModules/" + CurrentModule->GetObjectID() + "/" + SourceFileList[i] + "\"\n"; + } + + CurrentString += ")\n"; + CurrentString += "\n"; + + SourceFileListString += CurrentString; + + // Replace the placeholder in add_executable list. + CurrentString = std::string("\t\t") + "${Script_Module_" + CurrentModule->GetObjectID() + "_SRC}\n"; + ExecutableListString += CurrentString; + + // Add the folder to the list of folders in VS project. + FolderListInVSProjectString += "source_group(\"Source Files/ScriptModules/" + CurrentModule->GetObjectID() + "/\" FILES ${Script_Module_" + CurrentModule->GetObjectID() + "_SRC})\n"; + + // Now we will create the directories and copy the files to the destination directory. + std::string ScriptModuleDirectory = VSProjectDirectory + "ScriptModules/" + CurrentModule->GetObjectID() + "/"; + if (!FILE_SYSTEM.CreateDirectory(ScriptModuleDirectory)) + { + LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: Error creating directory " + ScriptModuleDirectory, "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + if (!CurrentModule->GetProject()->ExtractSourceFilesTo(ScriptModuleDirectory)) + { + LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: Error extracting source files to " + ScriptModuleDirectory, "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + } + + CurrentInstruction.SubStringInLineToTrigger = "#(PLACE_HOLDER) Here should be list of all script modules sources."; + CurrentInstruction.What = "#(PLACE_HOLDER) Here should be list of all script modules sources."; + CurrentInstruction.ReplaceWith = SourceFileListString; + Instructions.push_back(CurrentInstruction); + + + CurrentInstruction.SubStringInLineToTrigger = " #(PLACE_HOLDER) Here should be list of all script modules."; + CurrentInstruction.What = " #(PLACE_HOLDER) Here should be list of all script modules."; + CurrentInstruction.ReplaceWith = ExecutableListString; + Instructions.push_back(CurrentInstruction); + + CurrentInstruction.SubStringInLineToTrigger = "#(PLACE_HOLDER) Here should be list of all script modules and where to place them in VS project."; + CurrentInstruction.What = "#(PLACE_HOLDER) Here should be list of all script modules and where to place them in VS project."; + CurrentInstruction.ReplaceWith = FolderListInVSProjectString; + Instructions.push_back(CurrentInstruction); + + if (!ReplaceInFile(CMakeFilePath, Instructions)) + { + LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: Error initializing CMakeLists.txt", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + Instructions.clear(); + + return true; +} + +bool FEProjectBuildSystem::ConfigureAndBuildCMake(const std::string& VSProjectDirectory) +{ + if (VSProjectDirectory.empty()) + { + LOG.Add("FEProjectBuildSystem::ConfigureAndBuildCMake: VSProjectDirectory is empty", "FE_BUILD_EXECUTABLE", FE_LOG_WARNING); + return false; + } + + std::string Generator = "Visual Studio 17 2022"; + + // CMake configure command. + std::string ConfigureCommand = "cmake -S \"" + VSProjectDirectory + "\" -B \"" + VSProjectDirectory + "\" -G \"" + Generator + "\""; + + // Execute CMake configure command. + int ConfigureResult = std::system(ConfigureCommand.c_str()); + if (ConfigureResult != 0) + { + LOG.Add("FEProjectBuildSystem::ConfigureAndBuildCMake: Error running CMake configure command", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + // Construct the CMake build command + std::string BuildCommand = "cmake --build \"" + VSProjectDirectory + "\" --config Release"; + + // Execute CMake build command + int BuildResult = std::system(BuildCommand.c_str()); + if (BuildResult != 0) + { + LOG.Add("FEProjectBuildSystem::ConfigureAndBuildCMake: Error running CMake build command", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + return true; +} + +std::string NormalizePathToWindows(const std::string& Path) +{ + std::filesystem::path FSPath(Path); + std::string Normalized = FSPath.make_preferred().string(); + + // Replace remaining forward slashes with backslashes + std::replace(Normalized.begin(), Normalized.end(), '/', '\\'); + + // Remove trailing backslash if present + if (!Normalized.empty() && Normalized.back() == '\\') + Normalized.pop_back(); + + return Normalized; +} + +bool FEProjectBuildSystem::CreateFinalExecutableDirectory(FEProject* ProjectToBuild) +{ + std::string ProjectFolder = ProjectToBuild->GetProjectFolder(); + if (!FILE_SYSTEM.DoesDirectoryExist(ProjectFolder)) + { + LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: ProjectFolder does not exist!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + std::string ExecutablePath = FILE_SYSTEM.GetCurrentWorkingPath() + "/BuildProjects_Temporary/" + ProjectToBuild->GetID() + "/Release/" + GetVSProjectName(ProjectToBuild) + ".exe"; + if (!FILE_SYSTEM.DoesFileExist(ExecutablePath)) + { + LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: Executable does not exist!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + std::string EngineResourcesPath = FILE_SYSTEM.GetCurrentWorkingPath() + "/BuildProjects_Temporary/" + ProjectToBuild->GetID() + "/EngineResources.fepackage"; + if (!FILE_SYSTEM.DoesFileExist(EngineResourcesPath)) + { + LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: EngineResources.fepackage does not exist!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + std::string ProjectResourcesPath = FILE_SYSTEM.GetCurrentWorkingPath() + "/BuildProjects_Temporary/" + ProjectToBuild->GetID() + "/Resources.fepackage"; + if (!FILE_SYSTEM.DoesFileExist(ProjectResourcesPath)) + { + LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: ProjectResources.fepackage does not exist!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + std::string FinalDirectory = ProjectFolder + "Build/"; + if (FILE_SYSTEM.DoesDirectoryExist(FinalDirectory)) + { + if (!FILE_SYSTEM.DeleteDirectory(FinalDirectory)) + { + LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: Error deleting Build directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + } + + if (!FILE_SYSTEM.CreateDirectory(FinalDirectory)) + { + LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: Error creating Build directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + // Copy all files to the final directory. + if (!FILE_SYSTEM.CopyFile(ExecutablePath, FinalDirectory + GetVSProjectName(ProjectToBuild) + ".exe")) + { + LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: Error copying executable", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + if (!FILE_SYSTEM.CopyFile(EngineResourcesPath, FinalDirectory + "EngineResources.fepackage")) + { + LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: Error copying EngineResources.fepackage", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + if (!FILE_SYSTEM.CopyFile(ProjectResourcesPath, FinalDirectory + "Resources.fepackage")) + { + LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: Error copying ProjectResources.fepackage", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); + return false; + } + + // Open the directory in file explorer. + std::string OpenCommand = "explorer \"" + NormalizePathToWindows(FinalDirectory) + "\""; + std::system(OpenCommand.c_str()); + + return true; +} \ No newline at end of file diff --git a/FEProjectBuildSystem.h b/FEProjectBuildSystem.h new file mode 100644 index 0000000..0cbd6cc --- /dev/null +++ b/FEProjectBuildSystem.h @@ -0,0 +1,36 @@ +#pragma once + +#include "FEEditor.h" +using namespace FocalEngine; + +class FEProjectBuildSystem +{ +public: + SINGLETON_PUBLIC_PART(FEProjectBuildSystem) + + // Redundant functions(FENativeScriptProject). It should be unified ? + struct InstructionWhatToReplaceInFile + { + std::string SubStringInLineToTrigger; + std::string What; + std::string ReplaceWith; + }; + + bool ReplaceInFile(std::string FilePath, std::vector Instructions); + + bool BuildExecutable(FEProject* ProjectToBuild); + bool CopyVisualNodeSystemSubProjectFiles(const std::string& OutputPath); + bool InitializeCMakeFileAndScriptFiles(FEProject* ProjectToBuild, const std::string& VSProjectDirectory); + + bool ConfigureAndBuildCMake(const std::string& VSProjectDirectory); + bool CreateFinalExecutableDirectory(FEProject* ProjectToBuild); + + // Space in project name is not allowed + std::string GetVSProjectName(FEProject* ProjectToBuild); + + //bool PackProjectResources(FEProject* ProjectToPack, const std::string& OutputPath); +private: + SINGLETON_PRIVATE_PART(FEProjectBuildSystem) +}; + +#define EDITOR_PROJECT_BUILD_SYSTEM FEProjectBuildSystem::GetInstance() diff --git a/Resources/BuildScripts/CMakeLists_Template.txt b/Resources/BuildScripts/CMakeLists_Template.txt new file mode 100644 index 0000000..5def3ba --- /dev/null +++ b/Resources/BuildScripts/CMakeLists_Template.txt @@ -0,0 +1,100 @@ +cmake_minimum_required(VERSION 3.10) + +add_definitions(-DUNICODE) +add_definitions(-D_UNICODE) + +set(PROJECT_NAME PLACE_HOLDER) + +project(${PROJECT_NAME}) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Set compiler flags based on USE_STATIC_RUNTIME +if(MSVC) + # Disable C4251 warning + add_compile_options(/wd4251) + + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") + set(VISUAL_NODE_SYSTEM_USE_STATIC_RUNTIME ON CACHE BOOL "Use static runtime (/MT) instead of dynamic (/MD) for VisualNodeSystem" FORCE) + + # Always add /MP for multi-processor compilation + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") +endif() + +# Turn on the ability to create folders to organize projects (.vcproj) +# It creates "CMakePredefinedTargets" folder by default and adds CMake +# defined projects like INSTALL.vcproj and ZERO_CHECK.vcproj +set_property(GLOBAL PROPERTY USE_FOLDERS ON) + +set(DEAR_IMGUI_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/imgui CACHE PATH "Path to Dear ImGui directory." FORCE) +set(VISUAL_NODE_SYSTEM_BUILD_SHARED_LIBS OFF CACHE BOOL "Build VisualNodeSystem as a shared library" FORCE) +set(VISUAL_NODE_SYSTEM_GLFW_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/GLFW/lib/x64/glfw3_mt.lib CACHE PATH "Path to GLFW library." FORCE) + +if(NOT TARGET VisualNodeSystem) + add_subdirectory(SubSystems/VisualNodeSystem) +endif() + +if(NOT TARGET FocalEngine) + add_subdirectory(SubSystems/FocalEngine) +endif() + +# Extract the relative path of the engine folder +file(RELATIVE_PATH RELATIVE_PATH_TO_ENGINE_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}" "${ENGINE_FOLDER}") +# We need to re-configure the Config.h file for the engine +# This is necessary for any project that will include FocalEngine +# to make sure that the engine can find its dependencies +set(ENGINE_FOLDER "${RELATIVE_PATH_TO_ENGINE_FOLDER}") +configure_file(${ENGINE_FOLDER}/ResourceManager/Config.h.in ${ENGINE_FOLDER}/ResourceManager/Config.h @ONLY) + +file(GLOB Main_SRC + "Main.h" + "Main.cpp" +) + +file(GLOB Connection_To_Engine_SRC + "SubSystems/FocalEngine/Resources/UserScriptsData/FENativeScriptConnector.cpp" + "SubSystems/FocalEngine/Resources/UserScriptsData/FENativeScriptConnector.h" +) + +#(PLACE_HOLDER) Here should be list of all script modules sources. +link_directories(${GLEW_LIB_DIR}) +link_directories(${GLFW_LIB_DIR}) + +add_executable(${PROJECT_NAME} + WIN32 + ${Main_SRC} + ${Connection_To_Engine_SRC} + #(PLACE_HOLDER) Here should be list of all script modules. +) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + FEBasicApplication + VisualNodeSystem + FocalEngine + ${GLFW_LIBRARY} + ${GLEW_LIBRARY} + opengl32.lib +) + +# FocalEngine is headers-only, we need to add its include directories +target_include_directories(${PROJECT_NAME} PRIVATE ${FOCAL_ENGINE_INCLUDES}) +target_compile_definitions(${PROJECT_NAME} PRIVATE FOCAL_ENGINE_HEADERS_ONLY) + +source_group("Source Files/" FILES ${Main_SRC}) +source_group("Source Files/Engine/" FILES ${Connection_To_Engine_SRC}) +#(PLACE_HOLDER) Here should be list of all script modules and where to place them in VS project. + +# set the startup project +set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME}) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${GLEW_INCLUDE_DIR} + ${BASICAPP_THIRDPARTY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/imgui + ${BASICAPP_DIR} + ${FOCAL_ENGINE_INCLUDES} + ${VISUAL_NODE_SYSTEM_DIR} +) \ No newline at end of file diff --git a/Resources/BuildScripts/Main_Template.cpp b/Resources/BuildScripts/Main_Template.cpp new file mode 100644 index 0000000..a74e67b --- /dev/null +++ b/Resources/BuildScripts/Main_Template.cpp @@ -0,0 +1,208 @@ +#include "Main.h" +using namespace FocalEngine; + +void LoadResources(std::string DirectoryPath) +{ + std::ifstream ResourcesFile; + ResourcesFile.open(DirectoryPath + "Resources.txt"); + + std::string FileData((std::istreambuf_iterator(ResourcesFile)), std::istreambuf_iterator()); + ResourcesFile.close(); + + Json::Value Root; + JSONCPP_STRING Error; + Json::CharReaderBuilder Builder; + + const std::unique_ptr Reader(Builder.newCharReader()); + if (!Reader->parse(FileData.c_str(), FileData.c_str() + FileData.size(), &Root, &Error)) + return; + + // Loading meshes. + std::vector MeshList = Root["Meshes"].getMemberNames(); + for (size_t i = 0; i < MeshList.size(); i++) + { + FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Meshes"][MeshList[i]]["FEObjectData"]); + RESOURCE_MANAGER.LoadFEMesh((DirectoryPath + Root["Meshes"][MeshList[i]]["FileName"].asCString()).c_str(), LoadedObjectData.Name); + } + + // Loading textures. + std::vector TexturesList = Root["Textures"].getMemberNames(); + for (size_t i = 0; i < TexturesList.size(); i++) + { + FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Textures"][TexturesList[i]]["FEObjectData"]); + // Terrain textures should be loaded right away, not async. + if (LoadedObjectData.Tag == TERRAIN_SYSTEM_RESOURCE_TAG) + { + RESOURCE_MANAGER.LoadFETexture((DirectoryPath + Root["Textures"][TexturesList[i]]["FileName"].asCString()).c_str()); + } + else + { + RESOURCE_MANAGER.LoadFETextureAsync((DirectoryPath + Root["Textures"][TexturesList[i]]["FileName"].asCString()).c_str(), LoadedObjectData.Name, nullptr, LoadedObjectData.ID); + } + } + + // Loading materials. + std::vector MaterialsList = Root["Materials"].getMemberNames(); + for (size_t i = 0; i < MaterialsList.size(); i++) + { + if (RESOURCE_MANAGER.LoadMaterialFromJSON(Root["Materials"][MaterialsList[i]]) == nullptr) + LOG.Add("FEProject::LoadResources: Error loading material " + MaterialsList[i], "FE_LOG_LOADING", FE_LOG_ERROR); + } + + // Loading game models. + std::vector GameModelList = Root["GameModels"].getMemberNames(); + for (size_t i = 0; i < GameModelList.size(); i++) + { + if (RESOURCE_MANAGER.LoadGameModelFromJSON(Root["GameModels"][GameModelList[i]]) == nullptr) + LOG.Add("FEProject::LoadResources: Error loading game model " + GameModelList[i], "FE_LOG_LOADING", FE_LOG_ERROR); + } + + // Loading NativeScriptModules. + std::vector NativeScriptModulesList = Root["NativeScriptModules"].getMemberNames(); + for (size_t i = 0; i < NativeScriptModulesList.size(); i++) + { + FENativeScriptModule* LoadedNativeScriptModule = RESOURCE_MANAGER.LoadFENativeScriptModule((DirectoryPath + Root["NativeScriptModules"][NativeScriptModulesList[i]]["FileName"].asCString()).c_str()); + if (LoadedNativeScriptModule == nullptr) + continue; + + NATIVE_SCRIPT_SYSTEM.ActivateNativeScriptModule(LoadedNativeScriptModule); + } + + // Prefabs and Scenes are interconnected so we need to load them in two steps. + // Currently Prefabs can not contain other Prefabs or Scenes, if it will change we need to change this code. + // First load all prefab scenes. + std::vector SceneList = Root["Scenes"].getMemberNames(); + for (size_t i = 0; i < SceneList.size(); i++) + { + FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Scenes"][SceneList[i]]["FEObjectData"]); + if (LoadedObjectData.Tag != PREFAB_SCENE_DESCRIPTION_TAG) + continue; + + if (SCENE_MANAGER.LoadSceneFromJSON(Root["Scenes"][SceneList[i]], FESceneFlag::PrefabDescription) == nullptr) + LOG.Add("FEProject::LoadResources: Error loading scene " + SceneList[i], "FE_LOG_LOADING", FE_LOG_ERROR); + } + + // Then load Prefabs and initialize them with corresponding scenes. + std::vector PrefabList = Root["Prefabs"].getMemberNames(); + for (size_t i = 0; i < PrefabList.size(); i++) + { + if (RESOURCE_MANAGER.LoadPrefabFromJSON(Root["Prefabs"][PrefabList[i]]) == nullptr) + LOG.Add("FEProject::LoadResources: Error loading prefab " + PrefabList[i], "FE_LOG_LOADING", FE_LOG_ERROR); + } + + for (size_t i = 0; i < SceneList.size(); i++) + { + FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Scenes"][SceneList[i]]["FEObjectData"]); + if (LoadedObjectData.Tag == PREFAB_SCENE_DESCRIPTION_TAG) + continue; + + if (SCENE_MANAGER.LoadSceneFromJSON(Root["Scenes"][SceneList[i]], FESceneFlag::Active) == nullptr) + LOG.Add("FEProject::LoadResources: Error loading scene " + SceneList[i], "FE_LOG_LOADING", FE_LOG_ERROR); + } +} + +void LoadResourcesFromAssetPackage(FEAssetPackage* AssetPackage) +{ + if (AssetPackage == nullptr) + { + LOG.Add("FEProject::LoadResourcesFromAssetPackage: AssetPackage is nullptr!", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + + std::string TemporaryFolder = FILE_SYSTEM.GetCurrentWorkingPath() + "/Temporary_Project_Resources/"; + if (FILE_SYSTEM.DoesDirectoryExist(TemporaryFolder)) + { + LOG.Add("FEProject::LoadResourcesFromAssetPackage: Temporary_Project_Resources directory already exist, trying to delete it.", "FE_LOG_LOADING", FE_LOG_WARNING); + + if (!FILE_SYSTEM.DeleteDirectory(TemporaryFolder)) + { + LOG.Add("FEProject::LoadResourcesFromAssetPackage: Error deleting Temporary_Project_Resources directory", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + } + + if (!FILE_SYSTEM.CreateDirectory(TemporaryFolder)) + { + LOG.Add("FEProject::LoadResourcesFromAssetPackage: Error creating Temporary_Project_Resources directory", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + + // Exporting all assets to files. + std::vector AssetList = AssetPackage->GetEntryList(); + for (size_t i = 0; i < AssetList.size(); i++) + { + if (!AssetPackage->ExportAssetToFile(AssetList[i].ID, TemporaryFolder + AssetList[i].Name)) + { + LOG.Add("FEProject::LoadResourcesFromAssetPackage: Error exporting asset " + AssetList[i].Name + " to file", "FE_LOG_LOADING", FE_LOG_WARNING); + continue; + } + } + + LoadResources(TemporaryFolder); + + if (!FILE_SYSTEM.DeleteDirectory(TemporaryFolder)) + LOG.Add("FEProject::LoadResourcesFromAssetPackage: Error deleting Temporary_Project_Resources directory", "FE_LOG_LOADING", FE_LOG_WARNING); +} + +FEEntity* CameraEntity = nullptr; +void mouseButtonCallback(int Button, int Action, int Mods) +{ + if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_PRESS) + { + if (CameraEntity != nullptr) + CameraEntity->GetComponent().SetActive(true); + } + else if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_RELEASE) + { + if (CameraEntity != nullptr) + CameraEntity->GetComponent().SetActive(false); + } +} + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +{ + ENGINE.InitWindow(); + THREAD_POOL.SetConcurrentThreadCount(10); + + // Here we need to load all resources + // And then load main scene? + FEAssetPackage* AssetPackage = new FEAssetPackage(); + if (!AssetPackage->LoadFromFile("Resources.fepackage")) + { + LOG.Add("Error: loading asset package", "FE_STARTING_APPLICATION", FE_LOG_ERROR); + return 1; + } + + LoadResourcesFromAssetPackage(AssetPackage); + + FEScene* StartingScene = SCENE_MANAGER.GetStartingScene(); + if (StartingScene == nullptr) + { + LOG.Add("Error: no starting scene", "FE_STARTING_APPLICATION", FE_LOG_ERROR); + return 1; + } + + StartingScene->SetFlag(FESceneFlag::Active | FESceneFlag::Renderable | FESceneFlag::GameMode, true); + + CameraEntity = CAMERA_SYSTEM.GetMainCamera(StartingScene); + if (CameraEntity != nullptr) + { + FECameraComponent& CameraComponent = CameraEntity->GetComponent(); + CAMERA_SYSTEM.SetCameraViewport(CameraEntity, ENGINE.GetDefaultViewport()->GetID()); + } + else + { + LOG.Add("Error: no camera in starting scene", "FE_STARTING_APPLICATION", FE_LOG_ERROR); + } + + INPUT.AddMouseButtonCallback(mouseButtonCallback); + + while (ENGINE.IsNotTerminated()) + { + ENGINE.BeginFrame(); + ENGINE.Render(); + ENGINE.EndFrame(); + } + + return 0; +} \ No newline at end of file diff --git a/Resources/BuildScripts/Main_Template.h b/Resources/BuildScripts/Main_Template.h new file mode 100644 index 0000000..959b1f8 --- /dev/null +++ b/Resources/BuildScripts/Main_Template.h @@ -0,0 +1,9 @@ +#include "SubSystems/FocalEngine/FEngine.h" +using namespace FocalEngine; + +// FIX ME! Move that to a RESOURCE_MANAGER +void LoadResources(std::string DirectoryPath); + +// TO-DO: Make that process in memory, not involving creating temporary files. +//FEAssetPackage* SaveResourcesToAssetPackage(); +void LoadResourcesFromAssetPackage(FEAssetPackage* AssetPackage); \ No newline at end of file diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index f213604..17d3d39 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit f213604613696183af5e1b56457e6de27192c535 +Subproject commit 17d3d394379f0ad0a3e1a0a7608084ed51543f05 diff --git a/SubSystems/ProjectManagment/FEProject.cpp b/SubSystems/ProjectManagment/FEProject.cpp index 51aa5c1..03f33b5 100644 --- a/SubSystems/ProjectManagment/FEProject.cpp +++ b/SubSystems/ProjectManagment/FEProject.cpp @@ -45,7 +45,7 @@ std::string FEProject::GetProjectFolder() return ProjectFolder; } -void FEProject::SaveResourcesTo(std::string FilePath, bool bFullSave) +void FEProject::SaveResources(std::string DirectoryPath, bool bFullSave) { Json::Value Root; std::ofstream ResourcesFile; @@ -64,7 +64,7 @@ void FEProject::SaveResourcesTo(std::string FilePath, bool bFullSave) { FEMesh* MeshToSave = RESOURCE_MANAGER.GetMesh(UnSavedObjects[i]->GetObjectID()); if (MeshToSave != nullptr) - RESOURCE_MANAGER.SaveFEMesh(MeshToSave, (GetProjectFolder() + MeshToSave->GetObjectID() + std::string(".model")).c_str()); + RESOURCE_MANAGER.SaveFEMesh(MeshToSave, (DirectoryPath + MeshToSave->GetObjectID() + std::string(".model")).c_str()); break; } @@ -72,7 +72,7 @@ void FEProject::SaveResourcesTo(std::string FilePath, bool bFullSave) { FETexture* TextureToSave = RESOURCE_MANAGER.GetTexture(UnSavedObjects[i]->GetObjectID()); if (TextureToSave != nullptr) - RESOURCE_MANAGER.SaveFETexture(TextureToSave, (GetProjectFolder() + TextureToSave->GetObjectID() + std::string(".texture")).c_str()); + RESOURCE_MANAGER.SaveFETexture(TextureToSave, (DirectoryPath + TextureToSave->GetObjectID() + std::string(".texture")).c_str()); break; } } @@ -80,7 +80,7 @@ void FEProject::SaveResourcesTo(std::string FilePath, bool bFullSave) } // Saving Meshes. - std::vector MeshList = RESOURCE_MANAGER.GetMeshList(); + std::vector MeshList = RESOURCE_MANAGER.GetMeshIDList(); Json::Value MeshData; for (size_t i = 0; i < MeshList.size(); i++) { @@ -93,14 +93,14 @@ void FEProject::SaveResourcesTo(std::string FilePath, bool bFullSave) MeshData[Mesh->GetObjectID()]["FileName"] = Mesh->GetObjectID() + ".model"; if (bFullSave) - RESOURCE_MANAGER.SaveFEMesh(Mesh, (GetProjectFolder() + Mesh->GetObjectID() + std::string(".model")).c_str()); + RESOURCE_MANAGER.SaveFEMesh(Mesh, (DirectoryPath + Mesh->GetObjectID() + std::string(".model")).c_str()); Mesh->SetDirtyFlag(false); } Root["Meshes"] = MeshData; // Saving Textures. - std::vector TexturesList = RESOURCE_MANAGER.GetTextureList(); + std::vector TexturesList = RESOURCE_MANAGER.GetTextureIDList(); Json::Value TexturesData; for (size_t i = 0; i < TexturesList.size(); i++) { @@ -113,14 +113,14 @@ void FEProject::SaveResourcesTo(std::string FilePath, bool bFullSave) TexturesData[Texture->GetObjectID()]["FileName"] = Texture->GetObjectID() + ".texture"; if (bFullSave) - RESOURCE_MANAGER.SaveFETexture(Texture, (GetProjectFolder() + Texture->GetObjectID() + std::string(".texture")).c_str()); + RESOURCE_MANAGER.SaveFETexture(Texture, (DirectoryPath + Texture->GetObjectID() + std::string(".texture")).c_str()); Texture->SetDirtyFlag(false); } Root["Textures"] = TexturesData; // Saving Materials. - std::vector MaterialList = RESOURCE_MANAGER.GetMaterialList(); + std::vector MaterialList = RESOURCE_MANAGER.GetMaterialIDList(); Json::Value MaterialData; for (size_t i = 0; i < MaterialList.size(); i++) { @@ -129,35 +129,13 @@ void FEProject::SaveResourcesTo(std::string FilePath, bool bFullSave) Material->GetTag() == EDITOR_RESOURCE_TAG) continue; - for (size_t j = 0; j < FE_MAX_TEXTURES_PER_MATERIAL; j++) - { - if (Material->Textures[j] != nullptr) - MaterialData[Material->GetObjectID()]["Textures"][std::to_string(j).c_str()] = Material->Textures[j]->GetObjectID(); - - if (Material->TextureBindings[j] != -1) - MaterialData[Material->GetObjectID()]["Texture bindings"][std::to_string(j).c_str()] = Material->TextureBindings[j]; - - if (Material->TextureChannels[j] != -1) - MaterialData[Material->GetObjectID()]["Texture channels"][std::to_string(j).c_str()] = Material->TextureChannels[j]; - } - - MaterialData[Material->GetObjectID()]["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(Material); - MaterialData[Material->GetObjectID()]["Metalness"] = Material->GetMetalness(); - MaterialData[Material->GetObjectID()]["Roughness"] = Material->GetRoughness(); - MaterialData[Material->GetObjectID()]["NormalMap intensity"] = Material->GetNormalMapIntensity(); - MaterialData[Material->GetObjectID()]["AmbientOcclusion intensity"] = Material->GetAmbientOcclusionIntensity(); - MaterialData[Material->GetObjectID()]["AmbientOcclusionMap intensity"] = Material->GetAmbientOcclusionMapIntensity(); - MaterialData[Material->GetObjectID()]["RoughnessMap intensity"] = Material->GetRoughnessMapIntensity(); - MaterialData[Material->GetObjectID()]["MetalnessMap intensity"] = Material->GetMetalnessMapIntensity(); - MaterialData[Material->GetObjectID()]["Tiling"] = Material->GetTiling(); - MaterialData[Material->GetObjectID()]["Compack packing"] = Material->IsCompackPacking(); - + MaterialData[Material->GetObjectID()] = RESOURCE_MANAGER.SaveMaterialToJSON(Material); Material->SetDirtyFlag(false); } Root["Materials"] = MaterialData; // Saving GameModels. - std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); + std::vector GameModelList = RESOURCE_MANAGER.GetGameModelIDList(); Json::Value GameModelData; for (size_t i = 0; i < GameModelList.size(); i++) { @@ -166,27 +144,7 @@ void FEProject::SaveResourcesTo(std::string FilePath, bool bFullSave) GameModel->GetTag() == EDITOR_RESOURCE_TAG) continue; - GameModelData[GameModel->GetObjectID()]["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(GameModel); - GameModelData[GameModel->GetObjectID()]["Mesh"] = GameModel->Mesh->GetObjectID(); - GameModelData[GameModel->GetObjectID()]["Material"] = GameModel->Material->GetObjectID(); - GameModelData[GameModel->GetObjectID()]["ScaleFactor"] = GameModel->GetScaleFactor(); - - GameModelData[GameModel->GetObjectID()]["LODs"]["HaveLODlevels"] = GameModel->IsUsingLOD(); - if (GameModel->IsUsingLOD()) - { - GameModelData[GameModel->GetObjectID()]["LODs"]["CullDistance"] = GameModel->GetCullDistance(); - GameModelData[GameModel->GetObjectID()]["LODs"]["Billboard zero rotaion"] = GameModel->GetBillboardZeroRotaion(); - GameModelData[GameModel->GetObjectID()]["LODs"]["LODCount"] = GameModel->GetLODCount(); - for (size_t j = 0; j < GameModel->GetLODCount(); j++) - { - GameModelData[GameModel->GetObjectID()]["LODs"][std::to_string(j)]["Mesh"] = GameModel->GetLODMesh(j)->GetObjectID(); - GameModelData[GameModel->GetObjectID()]["LODs"][std::to_string(j)]["Max draw distance"] = GameModel->GetLODMaxDrawDistance(j); - GameModelData[GameModel->GetObjectID()]["LODs"][std::to_string(j)]["IsBillboard"] = GameModel->IsLODBillboard(j); - if (GameModel->IsLODBillboard(j)) - GameModelData[GameModel->GetObjectID()]["LODs"][std::to_string(j)]["Billboard material"] = GameModel->GetBillboardMaterial()->GetObjectID(); - } - } - + GameModelData[GameModel->GetObjectID()] = RESOURCE_MANAGER.SaveGameModelToJSON(GameModel); GameModel->SetDirtyFlag(false); } Root["GameModels"] = GameModelData; @@ -201,15 +159,7 @@ void FEProject::SaveResourcesTo(std::string FilePath, bool bFullSave) Prefab->GetTag() == EDITOR_RESOURCE_TAG) continue; - PrefabData[Prefab->GetObjectID()]["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(Prefab); - if (Prefab->GetScene() == nullptr) - { - LOG.Add("FEProject::SaveResourcesTo: Prefab scene is nullptr!", "FE_LOG_LOADING", FE_LOG_ERROR); - PrefabData[Prefab->GetObjectID()]["SceneID"] = ""; - continue; - } - - PrefabData[Prefab->GetObjectID()]["SceneID"] = Prefab->GetScene()->GetObjectID(); + PrefabData[Prefab->GetObjectID()] = RESOURCE_MANAGER.SavePrefabToJSON(Prefab); } Root["Prefabs"] = PrefabData; @@ -226,7 +176,7 @@ void FEProject::SaveResourcesTo(std::string FilePath, bool bFullSave) NativeScriptModulesData[NativeScriptModule->GetObjectID()]["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(NativeScriptModule); NativeScriptModulesData[NativeScriptModule->GetObjectID()]["FileName"] = NativeScriptModule->GetObjectID() + ".nativescriptmodule"; - RESOURCE_MANAGER.SaveFENativeScriptModule(NativeScriptModule, GetProjectFolder() + NativeScriptModule->GetObjectID() + ".nativescriptmodule"); + RESOURCE_MANAGER.SaveFENativeScriptModule(NativeScriptModule, DirectoryPath + NativeScriptModule->GetObjectID() + ".nativescriptmodule"); } Root["NativeScriptModules"] = NativeScriptModulesData; @@ -272,17 +222,12 @@ void FEProject::SaveResourcesTo(std::string FilePath, bool bFullSave) if (!bShouldProceed) continue; - Json::Value SceneDataNode; - SceneDataNode["FEObjectData"] = RESOURCE_MANAGER.SaveFEObjectPart(SceneList[i]); - Json::Value SceneHierarchy = SceneList[i]->SceneGraph.ToJson([](FEEntity* Entity) -> bool { + SceneData[SceneList[i]->GetObjectID()] = SCENE_MANAGER.SaveSceneToJSON(SceneList[i], [](FEEntity* Entity) -> bool { if (Entity->GetTag() == EDITOR_RESOURCE_TAG) return false; return true; }); - SceneDataNode["Scene hierarchy"] = SceneHierarchy; - - SceneData[SceneList[i]->GetObjectID()] = SceneDataNode; } Root["Scenes"] = SceneData; @@ -290,11 +235,106 @@ void FEProject::SaveResourcesTo(std::string FilePath, bool bFullSave) Json::StreamWriterBuilder Builder; const std::string JsonFile = Json::writeString(Builder, Root); - ResourcesFile.open(FilePath); + ResourcesFile.open(DirectoryPath + "Resources.txt"); ResourcesFile << JsonFile; ResourcesFile.close(); } +// TO-DO: Make that process in memory, not involving creating temporary files. +FEAssetPackage* FEProject::SaveResourcesToAssetPackage() +{ + FEAssetPackage* Result = new FEAssetPackage(); + + std::string TemporaryFolder = FILE_SYSTEM.GetCurrentWorkingPath() + "/Temporary_Project_Resources/"; + if (FILE_SYSTEM.DoesDirectoryExist(TemporaryFolder)) + { + LOG.Add("FEProject::SaveResourcesToAssetPackage: Temporary_Project_Resources directory already exist, trying to delete it.", "FE_LOG_LOADING", FE_LOG_WARNING); + + if (!FILE_SYSTEM.DeleteDirectory(TemporaryFolder)) + { + LOG.Add("FEProject::SaveResourcesToAssetPackage: Error deleting Temporary_Project_Resources directory", "FE_LOG_LOADING", FE_LOG_ERROR); + return nullptr; + } + } + + if (!FILE_SYSTEM.CreateDirectory(TemporaryFolder)) + { + LOG.Add("FEProject::SaveResourcesToAssetPackage: Error creating Temporary_Project_Resources directory", "FE_LOG_LOADING", FE_LOG_ERROR); + return nullptr; + } + + // Because of editor camera system, we need to adjust main camera for each scene before saving. + SetProperMainCamerasInsteadOfEditorCameras(); + + // Saving resources. + SaveResources(TemporaryFolder, true); + + // After saving resources we restore editor cameras as main cameras. + SetEditorCamerasInsteadOfProperMainCameras(); + + // Saving all files to package. + std::vector Files = FILE_SYSTEM.GetFileNamesInDirectory(TemporaryFolder); + for (size_t i = 0; i < Files.size(); i++) + { + if (Result->ImportAssetFromFile(TemporaryFolder + Files[i]).empty()) + { + LOG.Add("FEProject::SaveResourcesToAssetPackage: Error importing asset " + Files[i] + " to package", "FE_LOG_LOADING", FE_LOG_WARNING); + //return nullptr; + } + } + + if (!FILE_SYSTEM.DeleteDirectory(TemporaryFolder)) + LOG.Add("FEProject::SaveResourcesToAssetPackage: Error deleting Temporary_Project_Resources directory", "FE_LOG_LOADING", FE_LOG_WARNING); + + return Result; +} + +void FEProject::LoadResourcesFromAssetPackage(FEAssetPackage* AssetPackage) +{ + if (AssetPackage == nullptr) + { + LOG.Add("FEProject::LoadResourcesFromAssetPackage: AssetPackage is nullptr!", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + + std::string TemporaryFolder = FILE_SYSTEM.GetCurrentWorkingPath() + "/Temporary_Project_Resources/"; + if (FILE_SYSTEM.DoesDirectoryExist(TemporaryFolder)) + { + LOG.Add("FEProject::LoadResourcesFromAssetPackage: Temporary_Project_Resources directory already exist, trying to delete it.", "FE_LOG_LOADING", FE_LOG_WARNING); + + if (!FILE_SYSTEM.DeleteDirectory(TemporaryFolder)) + { + LOG.Add("FEProject::LoadResourcesFromAssetPackage: Error deleting Temporary_Project_Resources directory", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + } + + if (!FILE_SYSTEM.CreateDirectory(TemporaryFolder)) + { + LOG.Add("FEProject::LoadResourcesFromAssetPackage: Error creating Temporary_Project_Resources directory", "FE_LOG_LOADING", FE_LOG_ERROR); + return; + } + + // Exporting all assets to files. + std::vector AssetList = AssetPackage->GetEntryList(); + for (size_t i = 0; i < AssetList.size(); i++) + { + if (!AssetPackage->ExportAssetToFile(AssetList[i].ID, TemporaryFolder + AssetList[i].Name)) + { + LOG.Add("FEProject::LoadResourcesFromAssetPackage: Error exporting asset " + AssetList[i].Name + " to file", "FE_LOG_LOADING", FE_LOG_WARNING); + continue; + } + } + + LoadResources(TemporaryFolder); + + // Because of editor camera system, we need to save proper main camera for each scene. + SaveProperMainCameras(); + + if (!FILE_SYSTEM.DeleteDirectory(TemporaryFolder)) + LOG.Add("FEProject::LoadResourcesFromAssetPackage: Error deleting Temporary_Project_Resources directory", "FE_LOG_LOADING", FE_LOG_WARNING); +} + void FEProject::SaveProject(bool bFullSave) { Json::Value Root; @@ -313,6 +353,11 @@ void FEProject::SaveProject(bool bFullSave) { CreateDummyScreenshot(); } + + // Save starting scene. + FEScene* StartingScene = SCENE_MANAGER.GetStartingScene(); + if (StartingScene != nullptr) + Root["StartingScene"] = StartingScene->GetObjectID(); // Saving editor scenes information. std::vector EditorSceneIDs = EDITOR.GetEditorOpenedScenesIDs(); @@ -351,8 +396,14 @@ void FEProject::SaveProject(bool bFullSave) Root["EditorScenes"]["FocusedSceneID"] = FocusedSceneID; + // Because of editor camera system, we need to adjust main camera for each scene before saving. + SetProperMainCamerasInsteadOfEditorCameras(); + // Saving resources. - SaveResourcesTo(ProjectFolder + "Resources.txt", bFullSave); + SaveResources(ProjectFolder, bFullSave); + + // After saving resources we restore editor cameras as main cameras. + SetEditorCamerasInsteadOfProperMainCameras(); // All of editor cameras would not be saved because of editor only tag. // But we need to save their state. @@ -406,10 +457,10 @@ void FEProject::SaveProject(bool bFullSave) bModified = false; } -void FEProject::LoadResources(std::string FilePath) +void FEProject::LoadResources(std::string DirectoryPath) { std::ifstream ResourcesFile; - ResourcesFile.open(FilePath); + ResourcesFile.open(DirectoryPath + "Resources.txt"); std::string FileData((std::istreambuf_iterator(ResourcesFile)), std::istreambuf_iterator()); ResourcesFile.close(); @@ -435,7 +486,7 @@ void FEProject::LoadResources(std::string FilePath) for (size_t i = 0; i < MeshList.size(); i++) { FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Meshes"][MeshList[i]]["FEObjectData"]); - RESOURCE_MANAGER.LoadFEMesh((ProjectFolder + Root["Meshes"][MeshList[i]]["FileName"].asCString()).c_str(), LoadedObjectData.Name); + RESOURCE_MANAGER.LoadFEMesh((DirectoryPath + Root["Meshes"][MeshList[i]]["FileName"].asCString()).c_str(), LoadedObjectData.Name); } // Loading textures. @@ -446,11 +497,11 @@ void FEProject::LoadResources(std::string FilePath) // Terrain textures should be loaded right away, not async. if (LoadedObjectData.Tag == TERRAIN_SYSTEM_RESOURCE_TAG) { - RESOURCE_MANAGER.LoadFETexture((ProjectFolder + Root["Textures"][TexturesList[i]]["FileName"].asCString()).c_str()); + RESOURCE_MANAGER.LoadFETexture((DirectoryPath + Root["Textures"][TexturesList[i]]["FileName"].asCString()).c_str()); } else { - RESOURCE_MANAGER.LoadFETextureAsync((ProjectFolder + Root["Textures"][TexturesList[i]]["FileName"].asCString()).c_str(), LoadedObjectData.Name, nullptr, LoadedObjectData.ID); + RESOURCE_MANAGER.LoadFETextureAsync((DirectoryPath + Root["Textures"][TexturesList[i]]["FileName"].asCString()).c_str(), LoadedObjectData.Name, nullptr, LoadedObjectData.ID); } } @@ -458,106 +509,23 @@ void FEProject::LoadResources(std::string FilePath) std::vector MaterialsList = Root["Materials"].getMemberNames(); for (size_t i = 0; i < MaterialsList.size(); i++) { - FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Materials"][MaterialsList[i]]["FEObjectData"]); - - FEMaterial* NewMaterial = RESOURCE_MANAGER.CreateMaterial(LoadedObjectData.Name, LoadedObjectData.ID); - RESOURCE_MANAGER.SetTag(NewMaterial, LoadedObjectData.Tag); - NewMaterial->Shader = RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/); - - std::vector MembersList = Root["Materials"][MaterialsList[i]].getMemberNames(); - for (size_t j = 0; j < MembersList.size(); j++) - { - if (MembersList[j] == "Textures") - { - for (size_t k = 0; k < FE_MAX_TEXTURES_PER_MATERIAL; k++) - { - if (Root["Materials"][MaterialsList[i]]["Textures"].isMember(std::to_string(k).c_str())) - { - std::string TextureID = Root["Materials"][MaterialsList[i]]["Textures"][std::to_string(k).c_str()].asCString(); - NewMaterial->Textures[k] = RESOURCE_MANAGER.GetTexture(TextureID); - if (NewMaterial->Textures[k] == nullptr) - NewMaterial->Textures[k] = RESOURCE_MANAGER.NoTexture; - } - } - } - - if (MembersList[j] == "Texture bindings") - { - for (size_t k = 0; k < FE_MAX_TEXTURES_PER_MATERIAL; k++) - { - if (Root["Materials"][MaterialsList[i]]["Texture bindings"].isMember(std::to_string(k).c_str())) - { - int Binding = Root["Materials"][MaterialsList[i]]["Texture bindings"][std::to_string(k).c_str()].asInt(); - NewMaterial->TextureBindings[k] = Binding; - } - } - } - - if (MembersList[j] == "Texture channels") - { - for (size_t k = 0; k < FE_MAX_TEXTURES_PER_MATERIAL; k++) - { - if (Root["Materials"][MaterialsList[i]]["Texture channels"].isMember(std::to_string(k).c_str())) - { - int binding = Root["Materials"][MaterialsList[i]]["Texture channels"][std::to_string(k).c_str()].asInt(); - NewMaterial->TextureChannels[k] = binding; - } - } - } - } - - NewMaterial->SetMetalness(Root["Materials"][MaterialsList[i]]["Metalness"].asFloat()); - NewMaterial->SetRoughness(Root["Materials"][MaterialsList[i]]["Roughness"].asFloat()); - NewMaterial->SetNormalMapIntensity(Root["Materials"][MaterialsList[i]]["NormalMap intensity"].asFloat()); - NewMaterial->SetAmbientOcclusionIntensity(Root["Materials"][MaterialsList[i]]["AmbientOcclusion intensity"].asFloat()); - NewMaterial->SetAmbientOcclusionMapIntensity(Root["Materials"][MaterialsList[i]]["AmbientOcclusionMap intensity"].asFloat()); - NewMaterial->SetRoughnessMapIntensity(Root["Materials"][MaterialsList[i]]["RoughnessMap intensity"].asFloat()); - NewMaterial->SetMetalnessMapIntensity(Root["Materials"][MaterialsList[i]]["MetalnessMap intensity"].asFloat()); - - if (Root["Materials"][MaterialsList[i]].isMember("Tiling")) - NewMaterial->SetTiling(Root["Materials"][MaterialsList[i]]["Tiling"].asFloat()); - NewMaterial->SetCompackPacking(Root["Materials"][MaterialsList[i]]["Compack packing"].asBool()); + if (RESOURCE_MANAGER.LoadMaterialFromJSON(Root["Materials"][MaterialsList[i]]) == nullptr) + LOG.Add("FEProject::LoadResources: Error loading material " + MaterialsList[i], "FE_LOG_LOADING", FE_LOG_ERROR); } // Loading game models. std::vector GameModelList = Root["GameModels"].getMemberNames(); for (size_t i = 0; i < GameModelList.size(); i++) { - FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["GameModels"][GameModelList[i]]["FEObjectData"]); - - FEGameModel* NewGameModel = RESOURCE_MANAGER.CreateGameModel(RESOURCE_MANAGER.GetMesh(Root["GameModels"][GameModelList[i]]["Mesh"].asCString()), - RESOURCE_MANAGER.GetMaterial(Root["GameModels"][GameModelList[i]]["Material"].asCString()), - LoadedObjectData.Name, LoadedObjectData.ID); - RESOURCE_MANAGER.SetTag(NewGameModel, LoadedObjectData.Tag); - - NewGameModel->SetScaleFactor(Root["GameModels"][GameModelList[i]]["ScaleFactor"].asFloat()); - - bool bHaveLODLevels = Root["GameModels"][GameModelList[i]]["LODs"]["HaveLODlevels"].asBool(); - NewGameModel->SetUsingLOD(bHaveLODLevels); - if (bHaveLODLevels) - { - NewGameModel->SetCullDistance(Root["GameModels"][GameModelList[i]]["LODs"]["CullDistance"].asFloat()); - NewGameModel->SetBillboardZeroRotaion(Root["GameModels"][GameModelList[i]]["LODs"]["Billboard zero rotaion"].asFloat()); - - size_t LODCount = Root["GameModels"][GameModelList[i]]["LODs"]["LODCount"].asInt(); - for (size_t j = 0; j < LODCount; j++) - { - NewGameModel->SetLODMesh(j, RESOURCE_MANAGER.GetMesh(Root["GameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["Mesh"].asString())); - NewGameModel->SetLODMaxDrawDistance(j, Root["GameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["Max draw distance"].asFloat()); - - bool bLODBillboard = Root["GameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["IsBillboard"].asBool(); - NewGameModel->SetIsLODBillboard(j, bLODBillboard); - if (bLODBillboard) - NewGameModel->SetBillboardMaterial(RESOURCE_MANAGER.GetMaterial(Root["GameModels"][GameModelList[i]]["LODs"][std::to_string(j)]["Billboard material"].asString())); - } - } + if (RESOURCE_MANAGER.LoadGameModelFromJSON(Root["GameModels"][GameModelList[i]]) == nullptr) + LOG.Add("FEProject::LoadResources: Error loading game model " + GameModelList[i], "FE_LOG_LOADING", FE_LOG_ERROR); } // Loading NativeScriptModules. std::vector NativeScriptModulesList = Root["NativeScriptModules"].getMemberNames(); for (size_t i = 0; i < NativeScriptModulesList.size(); i++) { - FENativeScriptModule* LoadedNativeScriptModule = RESOURCE_MANAGER.LoadFENativeScriptModule((ProjectFolder + Root["NativeScriptModules"][NativeScriptModulesList[i]]["FileName"].asCString()).c_str()); + FENativeScriptModule* LoadedNativeScriptModule = RESOURCE_MANAGER.LoadFENativeScriptModule((DirectoryPath + Root["NativeScriptModules"][NativeScriptModulesList[i]]["FileName"].asCString()).c_str()); if (LoadedNativeScriptModule == nullptr) continue; @@ -574,37 +542,16 @@ void FEProject::LoadResources(std::string FilePath) if (LoadedObjectData.Tag != PREFAB_SCENE_DESCRIPTION_TAG) continue; - FEScene* NewScene = SCENE_MANAGER.CreateScene(LoadedObjectData.Name, LoadedObjectData.ID, FESceneFlag::PrefabDescription); - RESOURCE_MANAGER.SetTag(NewScene, LoadedObjectData.Tag); - - NewScene->SceneGraph.FromJson(Root["Scenes"][SceneList[i]]["Scene hierarchy"]); + if (SCENE_MANAGER.LoadSceneFromJSON(Root["Scenes"][SceneList[i]], FESceneFlag::PrefabDescription) == nullptr) + LOG.Add("FEProject::LoadResources: Error loading scene " + SceneList[i], "FE_LOG_LOADING", FE_LOG_ERROR); } // Then load Prefabs and initialize them with corresponding scenes. std::vector PrefabList = Root["Prefabs"].getMemberNames(); for (size_t i = 0; i < PrefabList.size(); i++) { - FEObjectLoadedData LoadedObjectData = RESOURCE_MANAGER.LoadFEObjectPart(Root["Prefabs"][PrefabList[i]]["FEObjectData"]); - - std::string SceneID; - if (Root["Prefabs"][PrefabList[i]].isMember("Scene")) - { - SceneID = Root["Prefabs"][PrefabList[i]]["Scene"]["ID"].asCString(); - } - else - { - SceneID = Root["Prefabs"][PrefabList[i]]["SceneID"].asCString(); - } - - FEScene* Scene = SCENE_MANAGER.GetScene(SceneID); - if (Scene == nullptr) - { - LOG.Add("FEProject::LoadResources: Prefab scene is missing!", "FE_LOG_LOADING", FE_LOG_ERROR); - continue; - } - - FEPrefab* NewPrefab = RESOURCE_MANAGER.CreatePrefab(LoadedObjectData.Name, LoadedObjectData.ID, Scene); - RESOURCE_MANAGER.SetTag(NewPrefab, LoadedObjectData.Tag); + if (RESOURCE_MANAGER.LoadPrefabFromJSON(Root["Prefabs"][PrefabList[i]]) == nullptr) + LOG.Add("FEProject::LoadResources: Error loading prefab " + PrefabList[i], "FE_LOG_LOADING", FE_LOG_ERROR); } for (size_t i = 0; i < SceneList.size(); i++) @@ -613,10 +560,8 @@ void FEProject::LoadResources(std::string FilePath) if (LoadedObjectData.Tag == PREFAB_SCENE_DESCRIPTION_TAG) continue; - FEScene* NewScene = SCENE_MANAGER.CreateScene(LoadedObjectData.Name, LoadedObjectData.ID, FESceneFlag::Active); - RESOURCE_MANAGER.SetTag(NewScene, LoadedObjectData.Tag); - - NewScene->SceneGraph.FromJson(Root["Scenes"][SceneList[i]]["Scene hierarchy"]); + if (SCENE_MANAGER.LoadSceneFromJSON(Root["Scenes"][SceneList[i]], FESceneFlag::Active) == nullptr) + LOG.Add("FEProject::LoadResources: Error loading scene " + SceneList[i], "FE_LOG_LOADING", FE_LOG_ERROR); } } @@ -647,7 +592,10 @@ void FEProject::LoadProject() ID = Root["ID"].asCString(); Name = Root["Name"].asCString(); - LoadResources(ProjectFolder + "Resources.txt"); + LoadResources(ProjectFolder); + + // Because of editor camera system, we need to save proper main camera for each scene. + SaveProperMainCameras(); // After we loaded all resources we can load editor cameras. Json::Value EditorCamerasData = Root["EditorCameras"]; @@ -663,6 +611,13 @@ void FEProject::LoadProject() CAMERA_SYSTEM.SetMainCamera(EditorCameraEntity); } + // Set starting scene. + if (Root.isMember("StartingScene")) + { + std::string StartingSceneID = Root["StartingScene"].asCString(); + SCENE_MANAGER.SetStartingScene(StartingSceneID); + } + // Now we can restore editor scenes. if (Root.isMember("EditorScenes")) { @@ -729,7 +684,7 @@ bool FEProject::LoadVFSData(std::string FilePath) VIRTUAL_FILE_SYSTEM.DeleteFile(Files[i], "/Shaders"); } - std::vector ShaderList = RESOURCE_MANAGER.GetShadersList(); + std::vector ShaderList = RESOURCE_MANAGER.GetShaderIDList(); for (size_t i = 0; i < ShaderList.size(); i++) { if (OBJECT_MANAGER.GetFEObject(ShaderList[i]) == nullptr) @@ -737,7 +692,7 @@ bool FEProject::LoadVFSData(std::string FilePath) VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(ShaderList[i]), "/Shaders"); } - std::vector StandardShaderList = RESOURCE_MANAGER.GetEnginePrivateShadersList(); + std::vector StandardShaderList = RESOURCE_MANAGER.GetEnginePrivateShaderIDList(); for (size_t i = 0; i < StandardShaderList.size(); i++) { if (OBJECT_MANAGER.GetFEObject(StandardShaderList[i]) == nullptr) @@ -752,7 +707,7 @@ bool FEProject::LoadVFSData(std::string FilePath) void FEProject::AddMissingVFSData() { - std::vector ShaderList = RESOURCE_MANAGER.GetShadersList(); + std::vector ShaderList = RESOURCE_MANAGER.GetShaderIDList(); for (size_t i = 0; i < ShaderList.size(); i++) { if (VIRTUAL_FILE_SYSTEM.DoesFileExistAnywhere(OBJECT_MANAGER.GetFEObject(ShaderList[i]))) @@ -761,7 +716,7 @@ void FEProject::AddMissingVFSData() VIRTUAL_FILE_SYSTEM.CreateFile(OBJECT_MANAGER.GetFEObject(ShaderList[i]), "/Shaders"); } - std::vector StandardShaderList = RESOURCE_MANAGER.GetEnginePrivateShadersList(); + std::vector StandardShaderList = RESOURCE_MANAGER.GetEnginePrivateShaderIDList(); for (size_t i = 0; i < StandardShaderList.size(); i++) { if (VIRTUAL_FILE_SYSTEM.DoesFileExistAnywhere(OBJECT_MANAGER.GetFEObject(StandardShaderList[i]))) @@ -771,12 +726,12 @@ void FEProject::AddMissingVFSData() VIRTUAL_FILE_SYSTEM.SetFileReadOnly(true, OBJECT_MANAGER.GetFEObject(StandardShaderList[i]), "/Shaders"); } - std::vector OtherResourceList = RESOURCE_MANAGER.GetMeshList(); - std::vector TextureList = RESOURCE_MANAGER.GetTextureList(); + std::vector OtherResourceList = RESOURCE_MANAGER.GetMeshIDList(); + std::vector TextureList = RESOURCE_MANAGER.GetTextureIDList(); OtherResourceList.insert(OtherResourceList.end(), TextureList.begin(), TextureList.end()); - std::vector MaterialList = RESOURCE_MANAGER.GetMaterialList(); + std::vector MaterialList = RESOURCE_MANAGER.GetMaterialIDList(); OtherResourceList.insert(OtherResourceList.end(), MaterialList.begin(), MaterialList.end()); - std::vector GameModelList = RESOURCE_MANAGER.GetGameModelList(); + std::vector GameModelList = RESOURCE_MANAGER.GetGameModelIDList(); OtherResourceList.insert(OtherResourceList.end(), GameModelList.begin(), GameModelList.end()); std::vector PrefabList = RESOURCE_MANAGER.GetPrefabIDList(); OtherResourceList.insert(OtherResourceList.end(), PrefabList.begin(), PrefabList.end()); @@ -939,4 +894,111 @@ void FEProject::InjectEditorCamera(FEScene* Scene) CameraTransform.SetPosition(glm::vec3(-4.2269f, 15.7178f, 19.6429f)); SceneIDToEditorCameraID[Scene->GetObjectID()] = CameraEntity->GetObjectID(); +} + +std::string FEProject::GetEditorCameraIDBySceneID(std::string SceneID) +{ + if (SceneIDToEditorCameraID.find(SceneID) == SceneIDToEditorCameraID.end()) + { + LOG.Add("FEProject::GetEditorCameraIDBySceneID: Editor camera not found for scene " + SceneID, "FE_LOG_LOADING", FE_LOG_WARNING); + return ""; + } + + return SceneIDToEditorCameraID[SceneID]; +} + +std::string FEProject::GetProperMainCameraIDBySceneID(std::string SceneID) +{ + if (SceneIDToProperMainCameraID.find(SceneID) == SceneIDToProperMainCameraID.end()) + { + LOG.Add("FEProject::GetProperMainCameraIDBySceneID: Editor camera not found for scene " + SceneID, "FE_LOG_LOADING", FE_LOG_WARNING); + return ""; + } + + return SceneIDToProperMainCameraID[SceneID]; +} + +bool FEProject::SetProperMainCameraIDBySceneID(std::string SceneID, std::string CameraID) +{ + FEScene* Scene = SCENE_MANAGER.GetScene(SceneID); + if (Scene == nullptr) + { + LOG.Add("FEProject::SetProperMainCameraIDBySceneID: Scene " + SceneID + " not found!", "FE_LOG_LOADING", FE_LOG_WARNING); + return false; + } + + if (!CameraID.empty()) + { + FEEntity* CameraEntity = Scene->GetEntity(CameraID); + if (CameraEntity == nullptr) + { + LOG.Add("FEProject::SetProperMainCameraIDBySceneID: Camera " + CameraID + " not found in scene " + SceneID, "FE_LOG_LOADING", FE_LOG_WARNING); + return false; + } + + if (!CameraEntity->HasComponent()) + { + LOG.Add("FEProject::SetProperMainCameraIDBySceneID: Entity " + CameraID + " in scene " + SceneID + " does not have camera component!", "FE_LOG_LOADING", FE_LOG_WARNING); + return false; + } + } + + SceneIDToProperMainCameraID[SceneID] = CameraID; + return true; +} + +void FEProject::SetProperMainCamerasInsteadOfEditorCameras() +{ + auto Iterator = SceneIDToProperMainCameraID.begin(); + while (Iterator != SceneIDToProperMainCameraID.end()) + { + FEScene* Scene = SCENE_MANAGER.GetScene(Iterator->first); + if (Scene != nullptr) + { + FEEntity* CurrentMainCameraEntity = CAMERA_SYSTEM.GetMainCamera(Scene); + if (CurrentMainCameraEntity != nullptr && CurrentMainCameraEntity->GetObjectID() != SceneIDToProperMainCameraID[Scene->GetObjectID()]) + { + CAMERA_SYSTEM.SetMainCamera(Scene->GetEntity(Iterator->second)); + } + } + Iterator++; + } +} + +void FEProject::SetEditorCamerasInsteadOfProperMainCameras() +{ + auto Iterator = SceneIDToEditorCameraID.begin(); + while (Iterator != SceneIDToEditorCameraID.end()) + { + FEScene* Scene = SCENE_MANAGER.GetScene(Iterator->first); + if (Scene != nullptr) + { + FEEntity* CurrentMainCameraEntity = CAMERA_SYSTEM.GetMainCamera(Scene); + if (CurrentMainCameraEntity != nullptr && CurrentMainCameraEntity->GetObjectID() != SceneIDToEditorCameraID[Scene->GetObjectID()]) + { + CAMERA_SYSTEM.SetMainCamera(Scene->GetEntity(Iterator->second)); + } + } + Iterator++; + } +} + +void FEProject::SaveProperMainCameras() +{ + std::vector SceneList = SCENE_MANAGER.GetSceneIDList(); + for (size_t i = 0; i < SceneList.size(); i++) + { + FEScene* CurrentScene = SCENE_MANAGER.GetScene(SceneList[i]); + if (CurrentScene == nullptr) + continue; + + FEEntity* MainCameraEntity = CAMERA_SYSTEM.GetMainCamera(CurrentScene); + if (MainCameraEntity != nullptr) + SceneIDToProperMainCameraID[CurrentScene->GetObjectID()] = MainCameraEntity->GetObjectID(); + } +} + +std::string FEProject::GetID() +{ + return ID; } \ No newline at end of file diff --git a/SubSystems/ProjectManagment/FEProject.h b/SubSystems/ProjectManagment/FEProject.h index edda89c..a0e1eba 100644 --- a/SubSystems/ProjectManagment/FEProject.h +++ b/SubSystems/ProjectManagment/FEProject.h @@ -7,11 +7,14 @@ class FEProject { friend class FEProjectManager; friend class FEEditor; - friend class FEEditorScriptingSystem; + friend class FEProjectBuildSystem; + friend class FEPrefabEditorManager; public: FEProject(std::string Name, std::string ProjectFolder); ~FEProject(); + std::string GetID(); + std::string GetName(); void SetName(std::string NewValue); @@ -30,6 +33,11 @@ class FEProject void SetModified(bool NewValue); void AddUnSavedObject(FEObject* Object); + + std::string GetEditorCameraIDBySceneID(std::string SceneID); + + std::string GetProperMainCameraIDBySceneID(std::string SceneID); + bool SetProperMainCameraIDBySceneID(std::string SceneID, std::string CameraID); private: std::string ID; std::string Name; @@ -45,11 +53,23 @@ class FEProject std::unordered_map SceneIDToEditorCameraID; void InjectEditorCamera(FEScene* Scene); - void LoadResources(std::string FilePath); - void SaveResourcesTo(std::string FilePath, bool bFullSave = false); + std::unordered_map SceneIDToProperMainCameraID; + + // FIX ME! Move that to a RESOURCE_MANAGER + void LoadResources(std::string DirectoryPath); + void SaveResources(std::string DirectoryPath, bool bFullSave = false); + + // TO-DO: Make that process in memory, not involving creating temporary files. + FEAssetPackage* SaveResourcesToAssetPackage(); + void LoadResourcesFromAssetPackage(FEAssetPackage* AssetPackage); + // FIX ME! Move that to a RESOURCE_MANAGER bool LoadVFSData(std::string FilePath); void AddMissingVFSData(); + + void SetProperMainCamerasInsteadOfEditorCameras(); + void SetEditorCamerasInsteadOfProperMainCameras(); + void SaveProperMainCameras(); }; #define PROJECTS_FILE_VER 0.05f diff --git a/UserScripts/NativeScriptProjectData/BuildManagement/DebugBuildActions.cmake b/UserScripts/NativeScriptProjectData/BuildManagement/DebugBuildActions.cmake deleted file mode 100644 index 4fe4bea..0000000 --- a/UserScripts/NativeScriptProjectData/BuildManagement/DebugBuildActions.cmake +++ /dev/null @@ -1,22 +0,0 @@ -if(EXISTS "${CMAKE_BINARY_DIR}/BuildManagement/Build_Recursion_Guard.txt") - file(REMOVE "${CMAKE_BINARY_DIR}/BuildManagement/Build_Recursion_Guard.txt") -else() - if(EXISTS "${CMAKE_BINARY_DIR}/BuildManagement/Force_Build_Finished.txt") - file(REMOVE "${CMAKE_BINARY_DIR}/BuildManagement/Force_Build_Finished.txt") - endif() - - file(TOUCH "${CMAKE_BINARY_DIR}/BuildManagement/Build_Recursion_Guard.txt") - - execute_process( - COMMAND ${CMAKE_COMMAND} --build "${CMAKE_BINARY_DIR}" --target PLACE_HOLDER --config Release - RESULT_VARIABLE BuildResult - OUTPUT_VARIABLE BuildOutput - ) - - if(BuildResult) - message("Release Build failed with error ${BuildResult}: ${BuildOutput}") - else() - message("Release Build succeeded: ${BuildOutput}") - file(TOUCH "${CMAKE_BINARY_DIR}/BuildManagement/Force_Build_Finished.txt") - endif() -endif() \ No newline at end of file diff --git a/UserScripts/NativeScriptProjectData/BuildManagement/EnsureBuildCompletion.cmake b/UserScripts/NativeScriptProjectData/BuildManagement/EnsureBuildCompletion.cmake deleted file mode 100644 index 75e1d6e..0000000 --- a/UserScripts/NativeScriptProjectData/BuildManagement/EnsureBuildCompletion.cmake +++ /dev/null @@ -1,9 +0,0 @@ -if(EXISTS "${CMAKE_BINARY_DIR}/BuildManagement/Debug_Build_Flag.txt") - file(REMOVE "${CMAKE_BINARY_DIR}/BuildManagement/Debug_Build_Flag.txt") - message("Debug build was conducted, forcing release build.") - include("${CMAKE_CURRENT_LIST_DIR}/DebugBuildActions.cmake") -elseif(EXISTS "${CMAKE_BINARY_DIR}/BuildManagement/Release_Build_Flag.txt") - file(REMOVE "${CMAKE_BINARY_DIR}/BuildManagement/Release_Build_Flag.txt") - message("Release build was conducted, forcing debug build.") - include("${CMAKE_CURRENT_LIST_DIR}/ReleaseBuildActions.cmake") -endif() \ No newline at end of file diff --git a/UserScripts/NativeScriptProjectData/BuildManagement/ReleaseBuildActions.cmake b/UserScripts/NativeScriptProjectData/BuildManagement/ReleaseBuildActions.cmake deleted file mode 100644 index 5335fd6..0000000 --- a/UserScripts/NativeScriptProjectData/BuildManagement/ReleaseBuildActions.cmake +++ /dev/null @@ -1,22 +0,0 @@ -if(EXISTS "${CMAKE_BINARY_DIR}/BuildManagement/Build_Recursion_Guard.txt") - file(REMOVE "${CMAKE_BINARY_DIR}/BuildManagement/Build_Recursion_Guard.txt") -else() - if(EXISTS "${CMAKE_BINARY_DIR}/BuildManagement/Force_Build_Finished.txt") - file(REMOVE "${CMAKE_BINARY_DIR}/BuildManagement/Force_Build_Finished.txt") - endif() - - file(TOUCH "${CMAKE_BINARY_DIR}/BuildManagement/Build_Recursion_Guard.txt") - - execute_process( - COMMAND ${CMAKE_COMMAND} --build "${CMAKE_BINARY_DIR}" --target PLACE_HOLDER --config Debug - RESULT_VARIABLE BuildResult - OUTPUT_VARIABLE BuildOutput - ) - - if(BuildResult) - message("Debug Build failed with error ${BuildResult}: ${BuildOutput}") - else() - message("Debug Build succeeded: ${BuildOutput}") - file(TOUCH "${CMAKE_BINARY_DIR}/BuildManagement/Force_Build_Finished.txt") - endif() -endif() \ No newline at end of file diff --git a/UserScripts/NativeScriptProjectData/CMakeLists.txt b/UserScripts/NativeScriptProjectData/CMakeLists.txt deleted file mode 100644 index 38834f8..0000000 --- a/UserScripts/NativeScriptProjectData/CMakeLists.txt +++ /dev/null @@ -1,83 +0,0 @@ -cmake_minimum_required(VERSION 3.10) - -set(BUILD_TYPE "Debug and Release" CACHE STRING "Choose Build type") -set(CMAKE_BUILD_TYPE Debug) -set(CMAKE_CONFIGURATION_TYPES Debug Release) - -add_definitions(-DUNICODE) -add_definitions(-D_UNICODE) - -set(PROJECT_NAME PLACE_HOLDER) - -project(${PROJECT_NAME}) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -# Set compiler flags based on USE_STATIC_RUNTIME -if(MSVC) - # Disable C4251 warning - add_compile_options(/wd4251) - - if(USE_STATIC_RUNTIME) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") - else() - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD") - endif() - - # Always add /MP for multi-processor compilation - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") -endif() - -# Turn on the ability to create folders to organize projects (.vcproj) -# It creates "CMakePredefinedTargets" folder by default and adds CMake -# defined projects like INSTALL.vcproj and ZERO_CHECK.vcproj -set_property(GLOBAL PROPERTY USE_FOLDERS ON) - -file(GLOB Connection_To_Engine_SRC - "SubSystems/FocalEngine/FENativeScriptConnector.cpp" - "SubSystems/FocalEngine/FENativeScriptConnector.h" -) - -file(GLOB Main_SRC PLACE_HOLDER) - -link_directories(${GLEW_LIB_DIR}) -link_directories(${GLFW_LIB_DIR}) - -add_library(${PROJECT_NAME} - SHARED - ${Main_SRC} - ${Connection_To_Engine_SRC} -) - -target_link_libraries(${PROJECT_NAME} - PRIVATE - FEBasicApplication.lib - FocalEngine.lib -) - -# FocalEngine is headers-only, we need to add its include directories -target_include_directories(${PROJECT_NAME} PRIVATE ${FOCAL_ENGINE_INCLUDES}) -target_compile_definitions(${PROJECT_NAME} PRIVATE FOCAL_ENGINE_HEADERS_ONLY) - -source_group("Source Files/" FILES ${Main_SRC}) -source_group("Source Files/Engine/" FILES ${Connection_To_Engine_SRC}) - -# set the startup project -set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME}) - -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication - ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/SubSystems - ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty - ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/glew2/include - ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine - ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/ThirdParty - ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/ThirdParty/entt -) - -add_custom_command( TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E echo "Build type: $" > $,${CMAKE_CURRENT_BINARY_DIR}/BuildManagement/Debug_Build_Flag.txt,${CMAKE_CURRENT_BINARY_DIR}/BuildManagement/Release_Build_Flag.txt> - COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_LIST_DIR}/BuildManagement/EnsureBuildCompletion.cmake" -) \ No newline at end of file diff --git a/main.cpp b/main.cpp index a207b58..d080acd 100644 --- a/main.cpp +++ b/main.cpp @@ -22,6 +22,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine PROFILING.StartProfiling(); ENGINE.BeginFrame(); + EDITOR.UpdateBeforeRender(); ENGINE.Render(); #ifdef EDITOR_SELECTION_DEBUG_MODE @@ -57,6 +58,14 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine bPutThisFrameToTimeline = true; } + if (PROJECT_MANAGER.GetCurrent() != nullptr) + { + if (ImGui::Button("Build")) + { + EDITOR_PROJECT_BUILD_SYSTEM.BuildExecutable(PROJECT_MANAGER.GetCurrent()); + } + } + //ImGui::ShowDemoWindow(); EDITOR.Render(); ENGINE.EndFrame(); From 70ad88be2e2ab4b0aa50dee8db5d02453788814f Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Sun, 27 Oct 2024 20:59:30 -0400 Subject: [PATCH 37/46] Updated the engine; Moved text replacement functionality from FEProjectBuildSystem to the engine; Updated BuildSystem/CMakeLists_Template to exclude FENativeScriptConnector files, as the engine will include them by default in static link mode; Editor now partially supports static linkage compilation. --- CMakeLists.txt | 33 ++++++-- FEEditorSelectedObject.cpp | 8 +- FEProjectBuildSystem.cpp | 81 ++++--------------- FEProjectBuildSystem.h | 10 --- .../BuildScripts/CMakeLists_Template.txt | 7 -- SubSystems/FocalEngine | 2 +- 6 files changed, 49 insertions(+), 92 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f125ebd..390f8a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,10 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /W3 /O2 /Oi /Gy /sdl /FC # defined projects like INSTALL.vcproj and ZERO_CHECK.vcproj set_property(GLOBAL PROPERTY USE_FOLDERS ON) +# Editor should be built with these options +set(BUILD_SHARED_LIBS ON CACHE BOOL "Build FEBasicApplication as a shared library" FORCE) +set(USE_STATIC_RUNTIME OFF CACHE BOOL "Use static runtime (/MT) instead of dynamic (/MD)" FORCE) + # Set up Visual node system set(DEAR_IMGUI_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/imgui CACHE PATH "Path to Dear ImGui directory." FORCE) if(BUILD_SHARED_LIBS) @@ -73,6 +77,15 @@ if(NOT TARGET FocalEngine) add_subdirectory(SubSystems/FocalEngine) endif() +if(USE_STATIC_RUNTIME) + # Add standard FocalEngine native scripts + # TODO: This should be done in the FocalEngine project, or make it simpler to add it user projects + file(GLOB Unpacked_NativeScript_2B7956623302254F620A675F_SRC + "SubSystems/FocalEngine/Resources/UserScriptsData/ExtractedScriptModules/2B7956623302254F620A675F/FirstScript.h" + "SubSystems/FocalEngine/Resources/UserScriptsData/ExtractedScriptModules/2B7956623302254F620A675F/FirstScript.cpp" + ) +endif() + # Extract the relative path of the engine folder file(RELATIVE_PATH RELATIVE_PATH_TO_ENGINE_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}" "${ENGINE_FOLDER}") # We need to re-configure the Config.h file for the engine @@ -82,8 +95,10 @@ set(ENGINE_FOLDER "${RELATIVE_PATH_TO_ENGINE_FOLDER}") configure_file(${ENGINE_FOLDER}/ResourceManager/Config.h.in ${ENGINE_FOLDER}/ResourceManager/Config.h @ONLY) # *************** EDITOR *************** -file(GLOB Editor_SRC - "main.cpp" + +set(EDITOR_SOURCE_FILES "") +list(APPEND EDITOR_SOURCE_FILES + "main.cpp" "FEEditor.cpp" "FEEditor.h" "FEEditorDragAndDropManager.cpp" @@ -104,6 +119,12 @@ file(GLOB Editor_SRC "FEProjectBuildSystem.h" ) +if(USE_STATIC_RUNTIME) + list(APPEND EDITOR_SOURCE_FILES + ${Unpacked_NativeScript_2B7956623302254F620A675F_SRC} + ) +endif() + file(GLOB ProjectManagment_SRC "SubSystems/ProjectManagment/FEProjectManager.cpp" "SubSystems/ProjectManagment/FEProjectManager.h" @@ -188,7 +209,7 @@ link_directories(${GLFW_LIB_DIR}) # add the executable add_executable(FocalEngineEditor WIN32 - ${Editor_SRC} + ${EDITOR_SOURCE_FILES} ${FEDearImguiWrapper_SRC} ${EditorWindows_BaseWindowClasses_SRC} ${EditorWindows_SRC} @@ -210,9 +231,11 @@ target_link_libraries(FocalEngineEditor opengl32.lib ) -source_group("Source Files" FILES ${Application_SRC}) # *************** EDITOR *************** -source_group("Source Files/" FILES ${Editor_SRC}) +source_group("Source Files/" FILES ${EDITOR_SOURCE_FILES}) +if(USE_STATIC_RUNTIME) + source_group("Source Files/FocalEngine/2B7956623302254F620A675F" FILES ${Unpacked_NativeScript_2B7956623302254F620A675F_SRC}) +endif() source_group("Source Files/FEDearImguiWrapper" FILES ${FEDearImguiWrapper_SRC}) source_group("Source Files/EditorWindows/BaseWindowClasses" FILES ${EditorWindows_BaseWindowClasses_SRC}) source_group("Source Files/EditorWindows" FILES ${EditorWindows_SRC}) diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index d7a2b54..4c3d96a 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -318,8 +318,8 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons return -1; CurrentSelectionData->PixelAccurateSelectionFB->Bind(); - glm::ivec4 OriginalViewport = RENDERER.GetViewport(); - RENDERER.SetViewport(0, 0, CurrentSelectionData->PixelAccurateSelectionFB->GetWidth(), CurrentSelectionData->PixelAccurateSelectionFB->GetHeight()); + glm::ivec4 OriginalViewport = RENDERER.GetGLViewport(); + RENDERER.SetGLViewport(0, 0, CurrentSelectionData->PixelAccurateSelectionFB->GetWidth(), CurrentSelectionData->PixelAccurateSelectionFB->GetHeight()); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); @@ -388,7 +388,7 @@ int FEEditorSelectedObject::GetIndexOfObjectUnderMouse(const double MouseX, cons FE_GL_ERROR(glReadPixels(static_cast(LocalMouseX), GLint(CameraComponent.GetRenderTargetHeight() - LocalMouseY), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, CurrentSelectionData->ColorUnderMouse)); CurrentSelectionData->PixelAccurateSelectionFB->UnBind(); - RENDERER.SetViewport(OriginalViewport); + RENDERER.SetGLViewport(OriginalViewport); #ifndef EDITOR_SELECTION_DEBUG_MODE if (!CurrentSelectionData->SceneEntitiesUnderMouse.empty()) @@ -573,7 +573,7 @@ void FEEditorSelectedObject::OnCameraUpdate() const HALO_SELECTION_EFFECT.HaloMaterial->ClearAllTexturesInfo(); FECameraComponent& CameraComponent = CurrentCamera->GetComponent(); - RENDERER.SetViewport(0, 0, CameraComponent.GetRenderTargetWidth(), CameraComponent.GetRenderTargetHeight()); + RENDERER.SetGLViewport(0, 0, CameraComponent.GetRenderTargetWidth(), CameraComponent.GetRenderTargetHeight()); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); FE_GL_ERROR(glClear(GL_COLOR_BUFFER_BIT)); diff --git a/FEProjectBuildSystem.cpp b/FEProjectBuildSystem.cpp index 0161c8e..fa831d8 100644 --- a/FEProjectBuildSystem.cpp +++ b/FEProjectBuildSystem.cpp @@ -31,54 +31,6 @@ std::string FEProjectBuildSystem::GetVSProjectName(FEProject* ProjectToBuild) return AppropriateProjectName; } -bool FEProjectBuildSystem::ReplaceInFile(std::string Path, std::vector Instructions) -{ - if (Path.empty()) - { - LOG.Add("FEProjectBuildSystem::ReplaceInFile: File path is empty", "FE_BUILD_EXECUTABLE", FE_LOG_WARNING); - return false; - } - - std::fstream File(Path, std::ios::in); - if (!File.is_open()) - { - LOG.Add("FEProjectBuildSystem::ReplaceInFile: Error opening file " + Path, "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); - return false; - } - - std::vector FileContent; - std::string Line; - while (std::getline(File, Line)) - FileContent.push_back(Line); - - File.close(); - - for (size_t i = 0; i < FileContent.size(); i++) - { - for (size_t j = 0; j < Instructions.size(); j++) - { - if (FileContent[i].find(Instructions[j].SubStringInLineToTrigger) != std::string::npos) - { - FileContent[i].replace(FileContent[i].find(Instructions[j].What), Instructions[j].What.size(), Instructions[j].ReplaceWith); - } - } - } - - File.open(Path, std::ios::out | std::ios::trunc); - if (!File.is_open()) - { - LOG.Add("FEProjectBuildSystem::ReplaceInFile: Error opening file " + Path, "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); - return false; - } - - // Write the modified content back to the file - for (size_t i = 0; i < FileContent.size(); i++) - File << FileContent[i] + "\n"; - - File.close(); - return true; -} - bool FEProjectBuildSystem::CopyVisualNodeSystemSubProjectFiles(const std::string& OutputPath) { if (!FILE_SYSTEM.DoesDirectoryExist(OutputPath)) @@ -283,7 +235,7 @@ bool FEProjectBuildSystem::BuildExecutable(FEProject* ProjectToBuild) return false; } - if (!CreateFinalExecutableDirectory(ProjectToBuild/*, VSProjectDirectory*/)) + if (!CreateFinalExecutableDirectory(ProjectToBuild)) { LOG.Add("FEProjectBuildSystem::BuildExecutable: Error creating final executable directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); return false; @@ -317,11 +269,11 @@ bool FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles(FEProject* ProjectT std::string CMakeFilePath = VSProjectDirectory + "CMakeLists.txt"; - std::vector Instructions; - InstructionWhatToReplaceInFile CurrentInstruction; - CurrentInstruction.SubStringInLineToTrigger = "set(PROJECT_NAME PLACE_HOLDER)"; - CurrentInstruction.What = "PLACE_HOLDER"; - CurrentInstruction.ReplaceWith = GetVSProjectName(ProjectToBuild); + std::vector Instructions; + FEFileSystem::TextReplacementRule CurrentInstruction; + CurrentInstruction.ContextPattern = "set(PROJECT_NAME PLACE_HOLDER)"; + CurrentInstruction.TargetText = "PLACE_HOLDER"; + CurrentInstruction.ReplacementText = GetVSProjectName(ProjectToBuild); Instructions.push_back(CurrentInstruction); std::string SourceFileListString = ""; @@ -389,23 +341,22 @@ bool FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles(FEProject* ProjectT } } - CurrentInstruction.SubStringInLineToTrigger = "#(PLACE_HOLDER) Here should be list of all script modules sources."; - CurrentInstruction.What = "#(PLACE_HOLDER) Here should be list of all script modules sources."; - CurrentInstruction.ReplaceWith = SourceFileListString; + CurrentInstruction.ContextPattern = "#(PLACE_HOLDER) Here should be list of all script modules sources."; + CurrentInstruction.TargetText = "#(PLACE_HOLDER) Here should be list of all script modules sources."; + CurrentInstruction.ReplacementText = SourceFileListString; Instructions.push_back(CurrentInstruction); - - CurrentInstruction.SubStringInLineToTrigger = " #(PLACE_HOLDER) Here should be list of all script modules."; - CurrentInstruction.What = " #(PLACE_HOLDER) Here should be list of all script modules."; - CurrentInstruction.ReplaceWith = ExecutableListString; + CurrentInstruction.ContextPattern = " #(PLACE_HOLDER) Here should be list of all script modules."; + CurrentInstruction.TargetText = " #(PLACE_HOLDER) Here should be list of all script modules."; + CurrentInstruction.ReplacementText = ExecutableListString; Instructions.push_back(CurrentInstruction); - CurrentInstruction.SubStringInLineToTrigger = "#(PLACE_HOLDER) Here should be list of all script modules and where to place them in VS project."; - CurrentInstruction.What = "#(PLACE_HOLDER) Here should be list of all script modules and where to place them in VS project."; - CurrentInstruction.ReplaceWith = FolderListInVSProjectString; + CurrentInstruction.ContextPattern = "#(PLACE_HOLDER) Here should be list of all script modules and where to place them in VS project."; + CurrentInstruction.TargetText = "#(PLACE_HOLDER) Here should be list of all script modules and where to place them in VS project."; + CurrentInstruction.ReplacementText = FolderListInVSProjectString; Instructions.push_back(CurrentInstruction); - if (!ReplaceInFile(CMakeFilePath, Instructions)) + if (!FILE_SYSTEM.PerformTextReplacements(CMakeFilePath, Instructions)) { LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: Error initializing CMakeLists.txt", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR); return false; diff --git a/FEProjectBuildSystem.h b/FEProjectBuildSystem.h index 0cbd6cc..61b185e 100644 --- a/FEProjectBuildSystem.h +++ b/FEProjectBuildSystem.h @@ -8,16 +8,6 @@ class FEProjectBuildSystem public: SINGLETON_PUBLIC_PART(FEProjectBuildSystem) - // Redundant functions(FENativeScriptProject). It should be unified ? - struct InstructionWhatToReplaceInFile - { - std::string SubStringInLineToTrigger; - std::string What; - std::string ReplaceWith; - }; - - bool ReplaceInFile(std::string FilePath, std::vector Instructions); - bool BuildExecutable(FEProject* ProjectToBuild); bool CopyVisualNodeSystemSubProjectFiles(const std::string& OutputPath); bool InitializeCMakeFileAndScriptFiles(FEProject* ProjectToBuild, const std::string& VSProjectDirectory); diff --git a/Resources/BuildScripts/CMakeLists_Template.txt b/Resources/BuildScripts/CMakeLists_Template.txt index 5def3ba..6cd2503 100644 --- a/Resources/BuildScripts/CMakeLists_Template.txt +++ b/Resources/BuildScripts/CMakeLists_Template.txt @@ -52,11 +52,6 @@ file(GLOB Main_SRC "Main.cpp" ) -file(GLOB Connection_To_Engine_SRC - "SubSystems/FocalEngine/Resources/UserScriptsData/FENativeScriptConnector.cpp" - "SubSystems/FocalEngine/Resources/UserScriptsData/FENativeScriptConnector.h" -) - #(PLACE_HOLDER) Here should be list of all script modules sources. link_directories(${GLEW_LIB_DIR}) link_directories(${GLFW_LIB_DIR}) @@ -64,7 +59,6 @@ link_directories(${GLFW_LIB_DIR}) add_executable(${PROJECT_NAME} WIN32 ${Main_SRC} - ${Connection_To_Engine_SRC} #(PLACE_HOLDER) Here should be list of all script modules. ) @@ -83,7 +77,6 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${FOCAL_ENGINE_INCLUDES}) target_compile_definitions(${PROJECT_NAME} PRIVATE FOCAL_ENGINE_HEADERS_ONLY) source_group("Source Files/" FILES ${Main_SRC}) -source_group("Source Files/Engine/" FILES ${Connection_To_Engine_SRC}) #(PLACE_HOLDER) Here should be list of all script modules and where to place them in VS project. # set the startup project diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 17d3d39..a652fdf 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 17d3d394379f0ad0a3e1a0a7608084ed51543f05 +Subproject commit a652fdf693e0c72a7bd326d23c970f59786901e5 From 0e361c1a6df7b076b549367814cbc30cc30b0033 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Fri, 1 Nov 2024 19:04:04 -0400 Subject: [PATCH 38/46] Adjustments made to align with Focal Engine updates related to shader uniforms; Fixed camera issues in the material editor window. --- EditorWindows/EditPopups.cpp | 18 ++++------- EditorWindows/InspectorWindow.cpp | 11 +++++-- EditorWindows/ShaderEditorWindow.cpp | 6 ++-- FEEditorGizmoManager.cpp | 24 +++++++------- FEEditorHaloSelectionEffect.cpp | 32 +++++++++---------- FEEditorSelectedObject.cpp | 12 +++---- SubSystems/FocalEngine | 2 +- .../CustomNodes/FEEditorMaterialNode.cpp | 8 ++--- 8 files changed, 56 insertions(+), 57 deletions(-) diff --git a/EditorWindows/EditPopups.cpp b/EditorWindows/EditPopups.cpp index 1171e60..763049b 100644 --- a/EditorWindows/EditPopups.cpp +++ b/EditorWindows/EditPopups.cpp @@ -755,6 +755,11 @@ FEEntity* EditMaterialWindow::InjectModelViewCamera(FEScene* Scene) } RESOURCE_MANAGER.SetTag(CameraEntity, EDITOR_RESOURCE_TAG); + FECameraComponent& CameraComponent = CameraEntity->GetComponent(); + CameraComponent.SetRenderTargetSize(512, 1020); + CameraComponent.SetDistanceFogEnabled(false); + FENativeScriptComponent& CameraScript = CameraEntity->GetComponent(); + CameraScript.SetVariableValue("DistanceToModel", 10.0f); CAMERA_SYSTEM.SetMainCamera(CameraEntity); return CameraEntity; @@ -771,7 +776,7 @@ EditMaterialWindow::EditMaterialWindow() CancelButton->SetActiveColor(ImVec4(0.1f, 1.0f, 0.1f, 1.0f)); NodeAreaTarget = DRAG_AND_DROP_MANAGER.AddTarget(FE_TEXTURE, DragAndDropnodeAreaTargetCallback, reinterpret_cast(&DragAndDropCallbackInfo), "Drop to add texture"); - PreviewScene = SCENE_MANAGER.CreateScene("MaterialEditor_Scene", "", FESceneFlag::Active); + PreviewScene = SCENE_MANAGER.CreateScene("MaterialEditor_Scene", "", FESceneFlag::Active | FESceneFlag::EditorMode); RESOURCE_MANAGER.SetTag(PreviewScene, EDITOR_RESOURCE_TAG); PreviewGameModel = new FEGameModel(nullptr, nullptr, "MaterialEditor_Preview_GameModel"); @@ -785,14 +790,6 @@ EditMaterialWindow::EditMaterialWindow() PreviewCameraEntity = InjectModelViewCamera(PreviewScene); PreviewCameraEntity->SetName("MaterialEditor_Scene_CameraEntity"); - //PreviewCameraEntity = PreviewScene->CreateEntity("MaterialEditor_Scene_CameraEntity"); - //PreviewCameraEntity->AddComponent(); - FECameraComponent& CameraComponent = PreviewCameraEntity->GetComponent(); - //CameraComponent.Type = 1; - //CameraComponent.DistanceToModel = 10.0; - CameraComponent.SetRenderTargetSize(512, 1020); - CameraComponent.SetDistanceFogEnabled(false); - CAMERA_SYSTEM.SetMainCamera(PreviewCameraEntity); PreviewLightEntity = PreviewScene->CreateEntity("MaterialEditor_Scene_LightEntity"); PreviewLightEntity->AddComponent(FE_DIRECTIONAL_LIGHT); @@ -819,18 +816,15 @@ void EditMaterialWindow::MouseButtonCallback(const int Button, const int Action, if (ImGui::GetIO().WantCaptureMouse && (!EDITOR_MATERIAL_WINDOW.bWindowHovered || !EDITOR_MATERIAL_WINDOW.bCameraOutputHovered)) { EDITOR_MATERIAL_WINDOW.PreviewCameraEntity->GetComponent().SetActive(false); - //CAMERA_SYSTEM.SetIsIndividualInputActive(EDITOR_MATERIAL_WINDOW.PreviewCameraEntity, false); } if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_PRESS && EDITOR_MATERIAL_WINDOW.bWindowHovered && EDITOR_MATERIAL_WINDOW.bCameraOutputHovered) { EDITOR_MATERIAL_WINDOW.PreviewCameraEntity->GetComponent().SetActive(true); - //CAMERA_SYSTEM.SetIsIndividualInputActive(EDITOR_MATERIAL_WINDOW.PreviewCameraEntity, true); } else if (Button == GLFW_MOUSE_BUTTON_2 && Action == GLFW_RELEASE) { EDITOR_MATERIAL_WINDOW.PreviewCameraEntity->GetComponent().SetActive(false); - //CAMERA_SYSTEM.SetIsIndividualInputActive(EDITOR_MATERIAL_WINDOW.PreviewCameraEntity, false); } } diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index 0b91add..4ef92c5 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -1614,9 +1614,14 @@ void FEEditorInspectorWindow::DisplayTerrainSettings(FEEntity* TerrainEntity) ImGui::Checkbox("WireframeMode", &bActive); TerrainComponent.SetWireframeMode(bActive); - int IData = *(int*)RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/)->GetParameterData("debugFlag"); - ImGui::SliderInt("debugFlag", &IData, 0, 10); - RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/)->UpdateParameterData("debugFlag", IData); + FEShaderUniformValue CurrentValue; + if (RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/)->GetUniformData("debugFlag", CurrentValue)) + { + + int IData = CurrentValue.GetValue(); + ImGui::SliderInt("debugFlag", &IData, 0, 10); + RESOURCE_MANAGER.GetShader("0800253C242B05321A332D09"/*"FEPBRShader"*/)->UpdateUniformData("debugFlag", IData); + } float DisplacementScale = TerrainComponent.GetDisplacementScale(); ImGui::DragFloat("displacementScale", &DisplacementScale, 0.02f, -10.0f, 10.0f); diff --git a/EditorWindows/ShaderEditorWindow.cpp b/EditorWindows/ShaderEditorWindow.cpp index 7819e60..f0620bd 100644 --- a/EditorWindows/ShaderEditorWindow.cpp +++ b/EditorWindows/ShaderEditorWindow.cpp @@ -397,7 +397,8 @@ void ShaderEditorWindow::Render() bComputeShaderUsed ? ComputeShaderEditor.GetText().c_str() : nullptr, true); - DummyShader->AddParametersFromShader(ShaderToEdit); + // FIX ME! Should it be here? + DummyShader->AddUniformsFromShader(ShaderToEdit); std::string Errors = DummyShader->GetCompilationErrors(); Errors += "\n"; @@ -419,7 +420,8 @@ void ShaderEditorWindow::Render() bGeometryShaderUsed ? GeometryShaderEditor.GetText().c_str() : nullptr, bComputeShaderUsed ? ComputeShaderEditor.GetText().c_str() : nullptr); - ReCompiledShader->AddParametersFromShader(ShaderToEdit); + // FIX ME! Should it be here? + ReCompiledShader->AddUniformsFromShader(ShaderToEdit); RESOURCE_MANAGER.ReplaceShader(ShaderToEdit->GetObjectID(), ReCompiledShader); diff --git a/FEEditorGizmoManager.cpp b/FEEditorGizmoManager.cpp index 0e087e3..0c40fd1 100644 --- a/FEEditorGizmoManager.cpp +++ b/FEEditorGizmoManager.cpp @@ -15,7 +15,7 @@ void GizmoManager::InitializeResources() FEMaterial* CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); + CurrentMaterial->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); TransformationXGizmoGM = RESOURCE_MANAGER.CreateGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationXGizmoGM"); @@ -25,7 +25,7 @@ void GizmoManager::InitializeResources() CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); + CurrentMaterial->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); TransformationYGizmoGM = RESOURCE_MANAGER.CreateGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationYGizmoGM"); @@ -35,7 +35,7 @@ void GizmoManager::InitializeResources() CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); + CurrentMaterial->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); TransformationZGizmoGM = RESOURCE_MANAGER.CreateGameModel(TransformationGizmoMesh, CurrentMaterial, "TransformationZGizmoGM"); @@ -45,7 +45,7 @@ void GizmoManager::InitializeResources() CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXYGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); + CurrentMaterial->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); TransformationXYGizmoGM = RESOURCE_MANAGER.CreateGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXYGizmoGM"); @@ -54,7 +54,7 @@ void GizmoManager::InitializeResources() CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationYZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); + CurrentMaterial->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); TransformationYZGizmoGM = RESOURCE_MANAGER.CreateGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationYZGizmoGM"); @@ -63,7 +63,7 @@ void GizmoManager::InitializeResources() CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("transformationXZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(1.0f, 1.0f, 1.0f), "baseColor")); + CurrentMaterial->SetBaseColor(glm::vec3(1.0f, 1.0f, 1.0f)); RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); TransformationXZGizmoGM = RESOURCE_MANAGER.CreateGameModel(RESOURCE_MANAGER.GetMesh("84251E6E0D0801363579317R"/*"cube"*/), CurrentMaterial, "TransformationXZGizmoGM"); @@ -77,7 +77,7 @@ void GizmoManager::InitializeResources() CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleXGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); + CurrentMaterial->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); ScaleXGizmoGM = RESOURCE_MANAGER.CreateGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleXGizmoGM"); @@ -87,7 +87,7 @@ void GizmoManager::InitializeResources() CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleYGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); + CurrentMaterial->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); ScaleYGizmoGM = RESOURCE_MANAGER.CreateGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleYGizmoGM"); @@ -97,7 +97,7 @@ void GizmoManager::InitializeResources() CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("scaleZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); + CurrentMaterial->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); ScaleZGizmoGM = RESOURCE_MANAGER.CreateGameModel(ScaleGizmoMesh, CurrentMaterial, "ScaleZGizmoGM"); @@ -111,7 +111,7 @@ void GizmoManager::InitializeResources() CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateXGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.9f, 0.1f, 0.1f), "baseColor")); + CurrentMaterial->SetBaseColor(glm::vec3(0.9f, 0.1f, 0.1f)); RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); RotateXGizmoGM = RESOURCE_MANAGER.CreateGameModel(RotateGizmoMesh, CurrentMaterial, "RotateXGizmoGM"); @@ -121,7 +121,7 @@ void GizmoManager::InitializeResources() CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateYGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.9f, 0.1f), "baseColor")); + CurrentMaterial->SetBaseColor(glm::vec3(0.1f, 0.9f, 0.1f)); RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); RotateYGizmoGM = RESOURCE_MANAGER.CreateGameModel(RotateGizmoMesh, CurrentMaterial, "RotateYGizmoGM"); @@ -131,7 +131,7 @@ void GizmoManager::InitializeResources() CurrentMaterial = RESOURCE_MANAGER.CreateMaterial("rotateZGizmoMaterial"); CurrentMaterial->SetAlbedoMap(RESOURCE_MANAGER.NoTexture); CurrentMaterial->Shader = RESOURCE_MANAGER.GetShader("6917497A5E0C05454876186F"/*"FESolidColorShader"*/); - CurrentMaterial->AddParameter(FEShaderParam(glm::vec3(0.1f, 0.1f, 0.9f), "baseColor")); + CurrentMaterial->SetBaseColor(glm::vec3(0.1f, 0.1f, 0.9f)); RESOURCE_MANAGER.SetTag(CurrentMaterial, EDITOR_RESOURCE_TAG); RotateZGizmoGM = RESOURCE_MANAGER.CreateGameModel(RotateGizmoMesh, CurrentMaterial, "RotateZGizmoGM"); diff --git a/FEEditorHaloSelectionEffect.cpp b/FEEditorHaloSelectionEffect.cpp index 20331b8..ba5b429 100644 --- a/FEEditorHaloSelectionEffect.cpp +++ b/FEEditorHaloSelectionEffect.cpp @@ -62,27 +62,27 @@ void FEEditorHaloSelectionEffect::UpdateResources(FEScene* Scene) FEShader* BlurShader = RESOURCE_MANAGER.GetShader("7F3E4F5C130B537F0846274F"/*"FEBloomBlur"*/); CurrentHaloSelectionData->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_OWN_TEXTURE, BlurShader)); - CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(1.0f, 0.0f), "FEBlurDirection")); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("FEBlurDirection", glm::vec2(1.0f, 0.0f))); // because input texture at first stage is full resolution, we should blur harder to get simular blur on both sides. - CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.5f * 4.0f, "BloomSize")); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("BloomSize", 1.5f * 4.0f)); CurrentHaloSelectionData->PostProcess->Stages.back()->InTexture.push_back(CurrentHaloSelectionData->HaloObjectsFB->GetColorAttachment()); CurrentHaloSelectionData->PostProcess->ReplaceOutTexture(0, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); CurrentHaloSelectionData->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); - CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(0.0f, 1.0f), "FEBlurDirection")); - CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.5f, "BloomSize")); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("FEBlurDirection", glm::vec2(0.0f, 1.0f))); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("BloomSize", 1.5f)); CurrentHaloSelectionData->PostProcess->Stages.back()->InTexture.push_back(CurrentHaloSelectionData->PostProcess->Stages[0]->OutTexture); CurrentHaloSelectionData->PostProcess->ReplaceOutTexture(1, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); CurrentHaloSelectionData->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); - CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(1.0f, 0.0f), "FEBlurDirection")); - CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.0f, "BloomSize")); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("FEBlurDirection", glm::vec2(1.0f, 0.0f))); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("BloomSize", 1.0f)); CurrentHaloSelectionData->PostProcess->Stages.back()->InTexture.push_back(CurrentHaloSelectionData->PostProcess->Stages[0]->OutTexture); CurrentHaloSelectionData->PostProcess->ReplaceOutTexture(2, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); CurrentHaloSelectionData->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); - CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(0.0f, 1.0f), "FEBlurDirection")); - CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.0f, "BloomSize")); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("FEBlurDirection", glm::vec2(0.0f, 1.0f))); + CurrentHaloSelectionData->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("BloomSize", 1.0f)); CurrentHaloSelectionData->PostProcess->Stages.back()->InTexture.push_back(CurrentHaloSelectionData->PostProcess->Stages[0]->OutTexture); CurrentHaloSelectionData->PostProcess->ReplaceOutTexture(3, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); @@ -143,27 +143,27 @@ void FEEditorHaloSelectionEffect::AddSceneData(const std::string& SceneID) FEShader* BlurShader = RESOURCE_MANAGER.GetShader("7F3E4F5C130B537F0846274F"/*"FEBloomBlur"*/); PerSceneData[SceneID]->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_OWN_TEXTURE, BlurShader)); - PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(1.0f, 0.0f), "FEBlurDirection")); + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("FEBlurDirection", glm::vec2(1.0f, 0.0f))); // because input texture at first stage is full resolution, we should blur harder to get simular blur on both sides. - PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.5f * 4.0f, "BloomSize")); + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("BloomSize", 1.5f * 4.0f)); PerSceneData[SceneID]->PostProcess->Stages.back()->InTexture.push_back(PerSceneData[SceneID]->HaloObjectsFB->GetColorAttachment()); PerSceneData[SceneID]->PostProcess->ReplaceOutTexture(0, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); PerSceneData[SceneID]->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); - PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(0.0f, 1.0f), "FEBlurDirection")); - PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.5f, "BloomSize")); + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("FEBlurDirection", glm::vec2(0.0f, 1.0f))); + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("BloomSize", 1.5f)); PerSceneData[SceneID]->PostProcess->Stages.back()->InTexture.push_back(PerSceneData[SceneID]->PostProcess->Stages[0]->OutTexture); PerSceneData[SceneID]->PostProcess->ReplaceOutTexture(1, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); PerSceneData[SceneID]->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); - PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(1.0f, 0.0f), "FEBlurDirection")); - PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.0f, "BloomSize")); + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("FEBlurDirection", glm::vec2(1.0f, 0.0f))); + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("BloomSize", 1.0f)); PerSceneData[SceneID]->PostProcess->Stages.back()->InTexture.push_back(PerSceneData[SceneID]->PostProcess->Stages[0]->OutTexture); PerSceneData[SceneID]->PostProcess->ReplaceOutTexture(2, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); PerSceneData[SceneID]->PostProcess->AddStage(new FEPostProcessStage(FE_POST_PROCESS_PREVIOUS_STAGE_RESULT0, BlurShader)); - PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(glm::vec2(0.0f, 1.0f), "FEBlurDirection")); - PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniforms.push_back(FEShaderParam(1.0f, "BloomSize")); + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("FEBlurDirection", glm::vec2(0.0f, 1.0f))); + PerSceneData[SceneID]->PostProcess->Stages.back()->StageSpecificUniformValues.push_back(FEShaderUniformValue("BloomSize", 1.0f)); PerSceneData[SceneID]->PostProcess->Stages.back()->InTexture.push_back(PerSceneData[SceneID]->PostProcess->Stages[0]->OutTexture); PerSceneData[SceneID]->PostProcess->ReplaceOutTexture(3, RESOURCE_MANAGER.CreateSameFormatTexture(CameraData->SceneToTextureFB->GetColorAttachment(), CameraData->SceneToTextureFB->GetWidth() / 4, CameraData->SceneToTextureFB->GetHeight() / 4)); diff --git a/FEEditorSelectedObject.cpp b/FEEditorSelectedObject.cpp index 4c3d96a..cc6aa67 100644 --- a/FEEditorSelectedObject.cpp +++ b/FEEditorSelectedObject.cpp @@ -32,9 +32,7 @@ void FEEditorSelectedObject::InitializeResources() "0E213D3542135C15471F0D6B"/*"FEPixelAccurateInstancedSelection"*/); RESOURCE_MANAGER.SetTag(FEPixelAccurateInstancedSelection, EDITOR_RESOURCE_TAG); - - const FEShaderParam ColorParam(glm::vec3(0.0f, 0.0f, 0.0f), "baseColor"); - PixelAccurateSelectionMaterial->AddParameter(ColorParam); + PixelAccurateSelectionMaterial->SetBaseColor(glm::vec3(0.0f, 0.0f, 0.0f)); } void FEEditorSelectedObject::UpdateResources(FEScene* Scene) @@ -234,9 +232,9 @@ void FEEditorSelectedObject::RenderEntitySelectionColorID(FEEntity* Entity, glm: return; TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); - TerrainComponent.Shader->UpdateParameterData("baseColor", ColorID); + TerrainComponent.Shader->UpdateUniformData("baseColor", ColorID); RENDERER.RenderTerrainComponent(Entity, CameraEntity); - TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); + TerrainComponent.Shader->UpdateUniformData("baseColor", glm::vec3(1.0f)); TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); } else if (Entity->HasComponent() && Entity->HasComponent()) @@ -495,14 +493,14 @@ void FEEditorSelectedObject::RenderEntityHaloEffectInternal(FEEntity* Entity, gl { FETerrainComponent& TerrainComponent = Entity->GetComponent(); TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("50064D3C4D0B537F0846274F"/*"FESMTerrainShader"*/); - TerrainComponent.Shader->UpdateParameterData("baseColor", Color); + TerrainComponent.Shader->UpdateUniformData("baseColor", Color); const float RegularLODLevel = TerrainComponent.GetLODLevel(); TerrainComponent.SetLODLevel(0.0f); RENDERER.RenderTerrainComponent(Entity, CameraEntity); TerrainComponent.SetLODLevel(RegularLODLevel); - TerrainComponent.Shader->UpdateParameterData("baseColor", glm::vec3(1.0f)); + TerrainComponent.Shader->UpdateUniformData("baseColor", glm::vec3(1.0f)); TerrainComponent.Shader = RESOURCE_MANAGER.GetShader("5A3E4F5C13115856401F1D1C"/*"FETerrainShader"*/); } else if (Entity->HasComponent() && Entity->HasComponent()) diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index a652fdf..8cc83c8 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit a652fdf693e0c72a7bd326d23c970f59786901e5 +Subproject commit 8cc83c8ebcebf94b8f63e1ee0601524526fe3df5 diff --git a/SubSystems/NodeSystem/CustomNodes/FEEditorMaterialNode.cpp b/SubSystems/NodeSystem/CustomNodes/FEEditorMaterialNode.cpp index e8363f2..155f157 100644 --- a/SubSystems/NodeSystem/CustomNodes/FEEditorMaterialNode.cpp +++ b/SubSystems/NodeSystem/CustomNodes/FEEditorMaterialNode.cpp @@ -46,20 +46,20 @@ void FEEditorMaterialNode::Draw() ImGui::Text("Compact packing"); Data->SetCompackPacking(bCompactFlag); - FEShaderParam* DebugFlag = Data->GetParameter("debugFlag"); - if (DebugFlag != nullptr) + FEShaderUniformValue CurrentValue; + if (Data->Shader->GetUniformData("debugFlag", CurrentValue)) { CurrentPosition.y += FieldStep; ImGui::SetCursorScreenPos(CurrentPosition); ImGui::Text("Debug flag:"); - int IData = *static_cast(DebugFlag->Data); + int IData = CurrentValue.GetValue(); CurrentPosition.y += FieldStep; ImGui::SetCursorScreenPos(CurrentPosition); ImGui::SetNextItemWidth(FieldWidth); ImGui::SliderInt("##Debug flag", &IData, 0, 10); - Data->Shader->UpdateParameterData("debugFlag", &IData); + Data->Shader->UpdateUniformData("debugFlag", IData); } // ************* Normal ************* From 84c8f84cd0f8072bb80c2359403bf3b745e5f16d Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Thu, 21 Nov 2024 21:15:26 -0500 Subject: [PATCH 39/46] FocalEngine update; VisualNodeSystem update; Fixed grammar in comments; Renamed variables to align with overall naming conventions. --- EditorWindows/DeletePopups.cpp | 2 +- EditorWindows/LogWindow.cpp | 18 +++++++++--------- EditorWindows/SceneGraphWindow.cpp | 8 ++++---- FEEditor.cpp | 3 +-- FEEditorPreviewManager.cpp | 12 ++++++------ SubSystems/FocalEngine | 2 +- .../CustomNodes/FEEditorTextureSourceNode.cpp | 2 +- .../CustomNodes/FEEditorTextureSourceNode.h | 2 +- SubSystems/NodeSystem/VisualNodeSystem | 2 +- 9 files changed, 25 insertions(+), 26 deletions(-) diff --git a/EditorWindows/DeletePopups.cpp b/EditorWindows/DeletePopups.cpp index 8d11d60..9ea266d 100644 --- a/EditorWindows/DeletePopups.cpp +++ b/EditorWindows/DeletePopups.cpp @@ -609,7 +609,7 @@ void DeleteDirectoryPopup::Render() PROJECT_MANAGER.GetCurrent()->SetModified(true); // I should do it in a way as windows FS is doing it. - // You can't delete non empty folder + // You can't delete non-empty folder // Firstly you recursively have to delete all files and folders in it diff --git a/EditorWindows/LogWindow.cpp b/EditorWindows/LogWindow.cpp index 17aeb8e..9cea44d 100644 --- a/EditorWindows/LogWindow.cpp +++ b/EditorWindows/LogWindow.cpp @@ -15,7 +15,7 @@ void FEEditor::DisplayLogWindow() const ImGui::Text("Channel:"); ImGui::SameLine(); ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 5); - if (ImGui::BeginCombo("##Channel", (SelectedChannel == "" ? "ALL" : SelectedChannel).c_str(), ImGuiWindowFlags_None)) + if (ImGui::BeginCombo("##Channel", (SelectedChannel.empty() ? "ALL" : SelectedChannel).c_str(), ImGuiWindowFlags_None)) { for (int i = -1; i < int(TopicList.size()); i++) { @@ -23,25 +23,25 @@ void FEEditor::DisplayLogWindow() const if (i == -1) { - const bool is_selected = (SelectedChannel == ""); + const bool bIsSelected = (SelectedChannel.empty()); - if (ImGui::Selectable("ALL", is_selected)) + if (ImGui::Selectable("ALL", bIsSelected)) { SelectedChannel = ""; } - if (is_selected) + if (bIsSelected) ImGui::SetItemDefaultFocus(); } else { - const bool is_selected = (SelectedChannel == TopicList[i]); - if (ImGui::Selectable(TopicList[i].c_str(), is_selected)) + const bool bIsSelected = (SelectedChannel == TopicList[i]); + if (ImGui::Selectable(TopicList[i].c_str(), bIsSelected)) { SelectedChannel = TopicList[i]; } - if (is_selected) + if (bIsSelected) ImGui::SetItemDefaultFocus(); } @@ -53,7 +53,7 @@ void FEEditor::DisplayLogWindow() const std::string LogMessages; std::vector LogItems; - if (SelectedChannel == "") + if (SelectedChannel.empty()) { std::vector TempItems; for (int i = 0; i < int(TopicList.size()); i++) @@ -91,7 +91,7 @@ void FEEditor::DisplayLogWindow() const LogMessages += " | SEVERITY: " + LOG.SeverityLevelToString(LogItems[i].Severity); - if (SelectedChannel == "") + if (SelectedChannel.empty()) { LogMessages += " | CHANNEL: " + LogItems[i].Topic; } diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 2750487..4a2bc11 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -396,16 +396,16 @@ int FEEditorSceneGraphWindow::FilterInputTextCallback(ImGuiInputTextCallbackData void FEEditorSceneGraphWindow::RenderFilterInput() { - bool bIsPlaceHolderTextUsedWasOn = bIsPlaceHolderTextUsed; + const bool bIsPlaceHolderTextUsedWasOn = bIsPlaceHolderTextUsed; if (bIsPlaceHolderTextUsedWasOn) ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 255, 255, 150)); // Setting up the callback for the input text. std::function Callback = std::bind(&FEEditorSceneGraphWindow::FilterInputTextCallback, std::placeholders::_1); - auto StaticCallback = [](ImGuiInputTextCallbackData* data) -> int { - auto& callback = *static_cast*>(data->UserData); - return callback(data); + auto StaticCallback = [](ImGuiInputTextCallbackData* Data) -> int { + const auto& Callback = *static_cast*>(Data->UserData); + return Callback(Data); }; if (ImGui::InputText("##SceneGraphWindowFilter", FilterForEntities, FilterInputBufferSize, ImGuiInputTextFlags_CallbackAlways, StaticCallback, &Callback)) diff --git a/FEEditor.cpp b/FEEditor.cpp index e8c8ec8..c836fc5 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -189,8 +189,7 @@ void FEEditor::KeyButtonCallback(int Key, int Scancode, int Action, int Mods) if (EDITOR.GetFocusedScene() != nullptr) { FEEntity* EntityToDuplicate = EDITOR.GetFocusedScene()->GetEntity(EDITOR.GetSceneEntityIDInClipboard()); - // Enitity could be deleted in the meantime - // or it could be from another scene + // Skip if entity was deleted or belongs to another scene if (EntityToDuplicate != nullptr) { FENaiveSceneGraphNode* NodeToDuplicate = EDITOR.GetFocusedScene()->SceneGraph.GetNodeByEntityID(EntityToDuplicate->GetObjectID()); diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index fdbac6d..ef9cc18 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -118,7 +118,7 @@ void FEEditorPreviewManager::CreateMeshPreview(const std::string MeshID) const float YSize = sqrt((Max.y - Min.y) * (Max.y - Min.y)); const float ZSize = sqrt((Max.z - Min.z) * (Max.z - Min.z)); - // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. + // Invert center point to get required translation vector for centering mesh at origin PreviewEntity->GetComponent().SetPosition(-glm::vec3(Max.x - XSize / 2.0f, Max.y - YSize / 2.0f, Max.z - ZSize / 2.0f)); LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); CAMERA_SYSTEM.IndividualUpdate(LocalCameraEntity, 0.0); @@ -142,7 +142,7 @@ FETexture* FEEditorPreviewManager::GetMeshPreview(const std::string MeshID) if (RESOURCE_MANAGER.GetMesh(MeshID)->IsDirty()) { CreateMeshPreview(MeshID); - // if some game model uses this mesh we should also update it's preview + // if some game model uses this mesh we should also update its preview const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelIDList(); for (size_t i = 0; i < GameModelList.size(); i++) @@ -220,7 +220,7 @@ FETexture* FEEditorPreviewManager::GetMaterialPreview(const std::string Material if (RESOURCE_MANAGER.GetMaterial(MaterialID)->IsDirty()) { CreateMaterialPreview(MaterialID); - // if some game model uses this material we should also update it's preview + // if some game model uses this material we should also update its preview const std::vector GameModelList = RESOURCE_MANAGER.GetGameModelIDList(); for (size_t i = 0; i < GameModelList.size(); i++) { @@ -230,7 +230,7 @@ FETexture* FEEditorPreviewManager::GetMaterialPreview(const std::string Material { CreateGameModelPreview(CurrentGameModel->GetObjectID()); - // If some Prefab uses this game model we should also update it's preview. + // If some Prefab uses this game model we should also update its preview. std::vector PrefabList = RESOURCE_MANAGER.GetPrefabIDList(); for (size_t j = 0; j < PrefabList.size(); j++) { @@ -276,7 +276,7 @@ void FEEditorPreviewManager::CreateGameModelPreview(const std::string GameModelI const float YSize = sqrt((max.y - min.y) * (max.y - min.y)); const float ZSize = sqrt((max.z - min.z) * (max.z - min.z)); - // invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. + // Invert center point to get required translation vector for centering mesh at origin PreviewEntity->GetComponent().SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); CAMERA_SYSTEM.IndividualUpdate(LocalCameraEntity, 0.0); @@ -314,7 +314,7 @@ void FEEditorPreviewManager::CreateGameModelPreview(const FEGameModel* GameModel const float YSize = sqrt((max.y - min.y) * (max.y - min.y)); const float ZSize = sqrt((max.z - min.z) * (max.z - min.z)); - // Invert center point and it will be exactly how much we need to translate mesh in order to place it in origin. + // Invert center point to get required translation vector for centering mesh at origin PreviewEntity->GetComponent().SetPosition(-glm::vec3(max.x - XSize / 2.0f, max.y - YSize / 2.0f, max.z - ZSize / 2.0f)); LocalCameraEntity->GetComponent().SetPosition(glm::vec3(0.0, 0.0, std::max(std::max(XSize, YSize), ZSize) * 1.75f)); CAMERA_SYSTEM.IndividualUpdate(LocalCameraEntity, 0.0); diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 8cc83c8..a1e22d8 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 8cc83c8ebcebf94b8f63e1ee0601524526fe3df5 +Subproject commit a1e22d8b3be5ce50d068ccc2492124fac1551b17 diff --git a/SubSystems/NodeSystem/CustomNodes/FEEditorTextureSourceNode.cpp b/SubSystems/NodeSystem/CustomNodes/FEEditorTextureSourceNode.cpp index 81e9d46..9ffd2f1 100644 --- a/SubSystems/NodeSystem/CustomNodes/FEEditorTextureSourceNode.cpp +++ b/SubSystems/NodeSystem/CustomNodes/FEEditorTextureSourceNode.cpp @@ -2,7 +2,7 @@ using namespace FocalEngine; using namespace VisNodeSys; -bool FEEditorTextureSourceNode::isRegistered = []() +bool FEEditorTextureSourceNode::IsRegistered = []() { NODE_FACTORY.RegisterNodeType("FEEditorTextureSourceNode", []() -> Node* { diff --git a/SubSystems/NodeSystem/CustomNodes/FEEditorTextureSourceNode.h b/SubSystems/NodeSystem/CustomNodes/FEEditorTextureSourceNode.h index 1ab5e1c..7d640d2 100644 --- a/SubSystems/NodeSystem/CustomNodes/FEEditorTextureSourceNode.h +++ b/SubSystems/NodeSystem/CustomNodes/FEEditorTextureSourceNode.h @@ -7,7 +7,7 @@ using namespace FocalEngine; class FEEditorTextureSourceNode : public VisNodeSys::Node { friend class NodeFactory; - static bool isRegistered; + static bool IsRegistered; FETexture* Texture = nullptr; diff --git a/SubSystems/NodeSystem/VisualNodeSystem b/SubSystems/NodeSystem/VisualNodeSystem index e9a34a4..11e16ec 160000 --- a/SubSystems/NodeSystem/VisualNodeSystem +++ b/SubSystems/NodeSystem/VisualNodeSystem @@ -1 +1 @@ -Subproject commit e9a34a44c99d0ea9562bb945efb8c2ceebe0055f +Subproject commit 11e16eca0e0d4e38816d4ee955f06442cb78e537 From 37bb495da9b0753cc1d6d2b66de273ad091d3184 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Sun, 5 Jan 2025 20:35:42 -0500 Subject: [PATCH 40/46] FocalEngine update; Repurposed the Effects window as the Editor Cameras window; Added a camera preview to camera components in the Inspector window to better inform users of what the game camera will render. --- EditorWindows/InspectorWindow.cpp | 40 +++++++++++++++++++++ FEEditor.cpp | 59 ++++++++++++++----------------- FEEditor.h | 4 +-- Resources/imgui.ini | 10 ++++-- SubSystems/FocalEngine | 2 +- 5 files changed, 78 insertions(+), 37 deletions(-) diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index 4ef92c5..a66226e 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -454,6 +454,9 @@ void FEEditorInspectorWindow::DisplayCameraProperties(FEEntity* CameraEntity) co { FECameraComponent& CameraComponent = CameraEntity->GetComponent(); + if (EDITOR.GetFocusedScene() == nullptr) + return; + // Because of editor camera system, we need to check if it is main camera in a different way. std::string MainCameraID = PROJECT_MANAGER.GetCurrent()->GetProperMainCameraIDBySceneID(EDITOR.GetFocusedScene()->GetObjectID()); bool bIsMainCamera = MainCameraID == CameraEntity->GetObjectID(); @@ -469,6 +472,43 @@ void FEEditorInspectorWindow::DisplayCameraProperties(FEEntity* CameraEntity) co } } + // Camera Preview + ImGui::Text("Camera Preview:"); + + FEScene* CurrentScene = CameraEntity->GetParentScene(); + FEEntity* OldMainCameraEntity = CAMERA_SYSTEM.GetMainCamera(EDITOR.GetFocusedScene()); + CAMERA_SYSTEM.SetMainCamera(CameraEntity); + + CameraComponent.SetRenderTargetSize(452, 256); + + // It would not render, because it does not have proper FEViewPort + RENDERER.Render(CurrentScene); + FETexture* PreviewTexture = RENDERER.GetCameraResult(CameraEntity); + if (PreviewTexture != nullptr) + ImGui::Image((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(452, 256), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); + + CAMERA_SYSTEM.SetMainCamera(OldMainCameraEntity); + + // Rendering pipeline settings + ImGui::Text("Rendering pipeline:"); + static const char* RenderingPipelineOptions[2] = { "Deferred", "Forward_Simplified" }; + FERenderingPipeline SelectedRenderingPipeline = CameraComponent.GetRenderingPipeline(); + static int CurrentIndex = 0; + if (SelectedRenderingPipeline == FERenderingPipeline::Deferred) + { + CurrentIndex = 0; + } + else if (SelectedRenderingPipeline == FERenderingPipeline::Forward_Simplified) + { + CurrentIndex = 1; + } + + ImGui::SetNextItemWidth(200); + if (ImGui::Combo("##RenderingPipeline", &CurrentIndex, RenderingPipelineOptions, 2)) + { + CAMERA_SYSTEM.SetCameraRenderingPipeline(CameraEntity, CurrentIndex == 0 ? FERenderingPipeline::Deferred : FERenderingPipeline::Forward_Simplified); + } + float FOV = CameraComponent.GetFOV(); ImGui::Text("Field of view : "); ImGui::SameLine(); diff --git a/FEEditor.cpp b/FEEditor.cpp index c836fc5..25b740d 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -363,9 +363,9 @@ void FEEditor::Render() CONTENT_BROWSER_WINDOW.bVisible = !CONTENT_BROWSER_WINDOW.bVisible; } - if (ImGui::MenuItem("Effects", nullptr, bEffectsWindowVisible)) + if (ImGui::MenuItem("Effects", nullptr, bEditorCamerasWindowVisible)) { - bEffectsWindowVisible = !bEffectsWindowVisible; + bEditorCamerasWindowVisible = !bEditorCamerasWindowVisible; } if (ImGui::MenuItem("Log", nullptr, bLogWindowVisible)) @@ -490,7 +490,7 @@ void FEEditor::Render() SCENE_GRAPH_WINDOW.Render(); CONTENT_BROWSER_WINDOW.Render(); INSPECTOR_WINDOW.Render(); - DisplayEffectsWindow(); + DisplayEditorCamerasWindow(); DisplayLogWindow(); if (!GyzmosSettingsWindowObject.IsVisible()) GyzmosSettingsWindowObject.Show(); @@ -611,48 +611,43 @@ void FEEditor::DropCallback(const int Count, const char** Paths) } } -void FEEditor::DisplayEffectsWindow() const +void FEEditor::DisplayEditorCamerasWindow() const { - if (!bEffectsWindowVisible) + if (!bEditorCamerasWindowVisible) return; ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); - ImGui::Begin("Effects settings", nullptr, ImGuiWindowFlags_None); + ImGui::Begin("Editor Cameras", nullptr, ImGuiWindowFlags_None); - int GUIID = 0; - static float ButtonWidth = 80.0f; - static float FieldWidth = 250.0f; - - static ImGuiButton* ResetButton = new ImGuiButton("Reset"); - static bool bFirstCall = true; - if (bFirstCall) + auto EditorCameraIterator = PROJECT_MANAGER.GetCurrent()->SceneIDToEditorCameraID.begin(); + while (EditorCameraIterator != PROJECT_MANAGER.GetCurrent()->SceneIDToEditorCameraID.end()) { - ResetButton->SetSize(ImVec2(ButtonWidth, 28.0f)); - bFirstCall = false; - } + FEScene* Scene = SCENE_MANAGER.GetScene(EditorCameraIterator->first); + if (Scene == nullptr) + { + EditorCameraIterator++; + continue; + } - if (ImGui::CollapsingHeader("Sky", 0)) - { - bool bEnabledSky = SKY_DOME_SYSTEM.IsEnabled(); - if (ImGui::Checkbox("enable sky", &bEnabledSky)) + FEEntity* CameraEntity = Scene->GetEntity(EditorCameraIterator->second); + if (CameraEntity == nullptr) { - SKY_DOME_SYSTEM.SetEnabled(bEnabledSky); + EditorCameraIterator++; + continue; } - /*ImGui::Text("Sphere size:"); - ImGui::SetNextItemWidth(FieldWidth); - float size = RENDERER.GetDistanceToSky(); - ImGui::DragFloat("##Sphere size", &size, 0.01f, 0.0f, 200.0f); - RENDERER.SetDistanceToSky(size); + if (!CameraEntity->HasComponent()) + { + EditorCameraIterator++; + continue; + } - ImGui::PushID(GUIID++); - ImGui::SameLine(); - ResetButton->Update(); - if (ResetButton->IsClicked()) + if (ImGui::CollapsingHeader(CameraEntity->GetObjectID().c_str(), 0)) { - RENDERER.SetDistanceToSky(50.0f); + INSPECTOR_WINDOW.DisplayCameraProperties(CameraEntity); } - ImGui::PopID();*/ + + EditorCameraIterator++; } ImGui::PopStyleVar(); diff --git a/FEEditor.h b/FEEditor.h index dad4539..8995dba 100644 --- a/FEEditor.h +++ b/FEEditor.h @@ -71,8 +71,8 @@ class FEEditor static void CloseWindowCallBack(); // Effects window - bool bEffectsWindowVisible = true; - void DisplayEffectsWindow() const; + bool bEditorCamerasWindowVisible = true; + void DisplayEditorCamerasWindow() const; // Log window bool bLogWindowVisible = true; diff --git a/Resources/imgui.ini b/Resources/imgui.ini index d1da1db..aa1f0ff 100644 --- a/Resources/imgui.ini +++ b/Resources/imgui.ini @@ -944,12 +944,18 @@ Size=2866,1604 Collapsed=0 DockId=0x0000000B,0 +[Window][Editor Cameras] +Pos=0,1698 +Size=3840,437 +Collapsed=0 +DockId=0x00000003,1 + [Table][0xD0F0C6E3,2] Column 0 Weight=1.0000 Column 1 Weight=1.0000 [Docking][Data] -DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,28 Size=3840,2043 Split=Y +DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,28 Size=3840,2107 Split=Y DockNode ID=0x00000005 Parent=0x8B93E3BD SizeRef=2524,1357 Split=Y Selected=0x18B8C0DE DockNode ID=0x00000002 Parent=0x00000005 SizeRef=3319,1604 Split=Y DockNode ID=0x00000009 Parent=0x00000002 SizeRef=2691,835 Split=X Selected=0x18B8C0DE @@ -960,6 +966,6 @@ DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,28 Size=3840,2043 Sp DockNode ID=0x0000000C Parent=0x00000007 SizeRef=2430,661 Selected=0x1DE2844E DockNode ID=0x00000008 Parent=0x00000004 SizeRef=466,1256 Selected=0xE7039252 DockNode ID=0x0000000A Parent=0x00000002 SizeRef=2691,700 Selected=0xA36F5690 - DockNode ID=0x00000003 Parent=0x00000005 SizeRef=3319,437 Selected=0x64F50EE5 + DockNode ID=0x00000003 Parent=0x00000005 SizeRef=3319,437 Selected=0xBF096F38 DockNode ID=0x00000006 Parent=0x8B93E3BD SizeRef=2524,771 Selected=0x81459842 diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index a1e22d8..2ddfcf0 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit a1e22d8b3be5ce50d068ccc2492124fac1551b17 +Subproject commit 2ddfcf026dea4bfe15f799b5e678396acf50a987 From 255fa96be7eef2e37ba88026925fd2a7cf5f9714 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Sun, 23 Feb 2025 21:11:27 -0500 Subject: [PATCH 41/46] Updated engine; Inspector window will no longer re-render the scene for editor cameras; Added an interface for adjusting the rendering scale in the Camera component; Small updates to README; Editor cameras now have an exposed Transform component for user adjustments. --- EditorWindows/EditPopups.cpp | 2 +- .../FEEditorSceneWindow.cpp | 4 +- EditorWindows/InspectorWindow.cpp | 59 +++++++++++++++---- FEEditor.cpp | 13 +++- FEEditorPreviewManager.cpp | 4 +- README.md | 1 + SubSystems/FocalEngine | 2 +- SubSystems/ProjectManagment/FEProject.cpp | 2 +- 8 files changed, 69 insertions(+), 18 deletions(-) diff --git a/EditorWindows/EditPopups.cpp b/EditorWindows/EditPopups.cpp index 763049b..1a3b204 100644 --- a/EditorWindows/EditPopups.cpp +++ b/EditorWindows/EditPopups.cpp @@ -756,7 +756,7 @@ FEEntity* EditMaterialWindow::InjectModelViewCamera(FEScene* Scene) RESOURCE_MANAGER.SetTag(CameraEntity, EDITOR_RESOURCE_TAG); FECameraComponent& CameraComponent = CameraEntity->GetComponent(); - CameraComponent.SetRenderTargetSize(512, 1020); + CameraComponent.TryToSetViewportSize(512, 1020); CameraComponent.SetDistanceFogEnabled(false); FENativeScriptComponent& CameraScript = CameraEntity->GetComponent(); CameraScript.SetVariableValue("DistanceToModel", 10.0f); diff --git a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp index ac25b17..4c5d922 100644 --- a/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp +++ b/EditorWindows/EditorBaseWindowClasses/FEEditorSceneWindow.cpp @@ -129,9 +129,9 @@ void FEEditorSceneWindow::Render() { FECameraComponent& CameraComponent = CameraEntity->GetComponent(); - if (CameraComponent.GetViewport() == nullptr) + if (CameraComponent.GetViewport() == nullptr || CameraComponent.GetViewport()->GetType() == FE_VIEWPORT_VIRTUAL) { - std::string NewViewportID = ENGINE.AddViewport(GetWindow()); + std::string NewViewportID = ENGINE.CreateViewport(GetWindow()); CAMERA_SYSTEM.SetCameraViewport(CameraEntity, NewViewportID); SELECTED.AddSceneData(Scene->GetObjectID()); GIZMO_MANAGER.AddSceneData(Scene->GetObjectID()); diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index a66226e..52ccb8d 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -472,22 +472,39 @@ void FEEditorInspectorWindow::DisplayCameraProperties(FEEntity* CameraEntity) co } } + // Rendering scale + ImGui::Text("Rendering scale:"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(200); + float RenderScale = CameraComponent.GetRenderScale(); + ImGui::DragFloat("##RenderScale", &RenderScale, 0.01f, 0.05f, 2.0f); + CAMERA_SYSTEM.SetCameraRenderScale(CameraEntity, RenderScale); + // Camera Preview ImGui::Text("Camera Preview:"); FEScene* CurrentScene = CameraEntity->GetParentScene(); - FEEntity* OldMainCameraEntity = CAMERA_SYSTEM.GetMainCamera(EDITOR.GetFocusedScene()); - CAMERA_SYSTEM.SetMainCamera(CameraEntity); + FETexture* CameraPreviewTexture = nullptr; - CameraComponent.SetRenderTargetSize(452, 256); - - // It would not render, because it does not have proper FEViewPort - RENDERER.Render(CurrentScene); - FETexture* PreviewTexture = RENDERER.GetCameraResult(CameraEntity); - if (PreviewTexture != nullptr) - ImGui::Image((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(452, 256), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); + // If it is an editor camera, we do not need to render scene again. + if (CameraEntity->GetObjectID() == PROJECT_MANAGER.GetCurrent()->GetEditorCameraIDBySceneID(CurrentScene->GetObjectID())) + { + CameraPreviewTexture = RENDERER.GetCameraResult(CameraEntity); + } + else + { + FEEntity* OldMainCameraEntity = CAMERA_SYSTEM.GetMainCamera(EDITOR.GetFocusedScene()); + CAMERA_SYSTEM.SetMainCamera(CameraEntity); + + CameraComponent.TryToSetViewportSize(452, 256); + RENDERER.Render(CurrentScene); + CameraPreviewTexture = RENDERER.GetCameraResult(CameraEntity); + + CAMERA_SYSTEM.SetMainCamera(OldMainCameraEntity); + } - CAMERA_SYSTEM.SetMainCamera(OldMainCameraEntity); + if (CameraPreviewTexture != nullptr) + ImGui::Image((void*)(intptr_t)CameraPreviewTexture->GetTextureID(), ImVec2(452, 256), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); // Rendering pipeline settings ImGui::Text("Rendering pipeline:"); @@ -583,6 +600,28 @@ void FEEditorInspectorWindow::DisplayCameraProperties(FEEntity* CameraEntity) co // *********** Anti-Aliasing(FXAA) *********** ImGui::Separator(); + + bool bTemporalJitterEnabled = CameraComponent.IsTemporalJitterEnabled(); + ImGui::Checkbox("Sub pixel jitter", &bTemporalJitterEnabled); + CameraComponent.SetTemporalJitterEnabled(bTemporalJitterEnabled); + + const std::vector SEQUENCE_OPTIONS = { 72, 32, 24, 18, 8 }; + static size_t TemporalJitterSequenceLength = 64; + + if (ImGui::BeginCombo("Jitter phase sequence Count", std::to_string(TemporalJitterSequenceLength).c_str())) + { + for (const auto& count : SEQUENCE_OPTIONS) + { + bool is_selected = (TemporalJitterSequenceLength == count); + if (ImGui::Selectable(std::to_string(count).c_str(), is_selected)) + TemporalJitterSequenceLength = count; + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } + CameraComponent.SetTemporalJitterSequenceLength(TemporalJitterSequenceLength); + ImGui::Text("Anti-Aliasing(FXAA)"); static const char* options[5] = { "none", "1x", "2x", "4x", "8x" }; static std::string SelectedOption = "1x"; diff --git a/FEEditor.cpp b/FEEditor.cpp index 25b740d..a8a4595 100644 --- a/FEEditor.cpp +++ b/FEEditor.cpp @@ -644,7 +644,18 @@ void FEEditor::DisplayEditorCamerasWindow() const if (ImGui::CollapsingHeader(CameraEntity->GetObjectID().c_str(), 0)) { - INSPECTOR_WINDOW.DisplayCameraProperties(CameraEntity); + ImGui::Indent(); + + if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) + { + FETransformComponent& Transform = CameraEntity->GetComponent(); + INSPECTOR_WINDOW.ShowTransformConfiguration(CameraEntity->GetName(), &Transform); + } + + if (ImGui::CollapsingHeader("Camera", ImGuiTreeNodeFlags_DefaultOpen)) + { + INSPECTOR_WINDOW.DisplayCameraProperties(CameraEntity); + } } EditorCameraIterator++; diff --git a/FEEditorPreviewManager.cpp b/FEEditorPreviewManager.cpp index ef9cc18..f8bf442 100644 --- a/FEEditorPreviewManager.cpp +++ b/FEEditorPreviewManager.cpp @@ -34,7 +34,7 @@ void FEEditorPreviewManager::InitializeResources() LocalCameraEntity = PreviewScene->CreateEntity("EditorPreview CameraEntity"); LocalCameraEntity->AddComponent(); FECameraComponent& CameraComponent = LocalCameraEntity->GetComponent(); - CameraComponent.SetRenderTargetSize(128, 128); + CameraComponent.TryToSetViewportSize(128, 128); CameraComponent.SetDistanceFogEnabled(false); CAMERA_SYSTEM.SetMainCamera(LocalCameraEntity); @@ -404,7 +404,7 @@ void FEEditorPreviewManager::CreatePrefabPreview(const std::string PrefabID) Camera->AddComponent(); Camera->GetComponent().SetPosition(glm::vec3(0.0, 0.0, SceneAABB.GetLongestAxisLength() * 2)); FECameraComponent& CameraComponent = Camera->GetComponent(); - CameraComponent.SetRenderTargetSize(128, 128); + CameraComponent.TryToSetViewportSize(128, 128); CameraComponent.SetDistanceFogEnabled(false); CameraComponent.SetSSAOEnabled(false); CAMERA_SYSTEM.SetMainCamera(Camera); diff --git a/README.md b/README.md index 8a59857..6b205ef 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ In the Editor, the following key windows are available: ![Editor](https://github.com/Azzinoth/FocalEngineEditor/blob/media/Editor.png) 5. **Effects Settings**: Allows adjustments of different effects available in the engine. +⚠️ This part needs to be updated due to ECS. ![Effects Settings](https://github.com/Azzinoth/FocalEngineEditor/blob/media/Effects%20Settings.png) diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 2ddfcf0..efccb3f 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 2ddfcf026dea4bfe15f799b5e678396acf50a987 +Subproject commit efccb3f4583ebecb852b6b3451a897781fe52bb4 diff --git a/SubSystems/ProjectManagment/FEProject.cpp b/SubSystems/ProjectManagment/FEProject.cpp index 03f33b5..606305a 100644 --- a/SubSystems/ProjectManagment/FEProject.cpp +++ b/SubSystems/ProjectManagment/FEProject.cpp @@ -887,7 +887,7 @@ void FEProject::InjectEditorCamera(FEScene* Scene) RESOURCE_MANAGER.SetTag(CameraEntity, EDITOR_RESOURCE_TAG); FECameraComponent& CameraComponent = CameraEntity->GetComponent(); - CameraComponent.SetRenderTargetSize(128, 128); + CameraComponent.TryToSetViewportSize(128, 128); CameraComponent.SetDistanceFogEnabled(false); CAMERA_SYSTEM.SetMainCamera(CameraEntity); FETransformComponent& CameraTransform = CameraEntity->GetComponent(); From 29dba85026233b71a82198257b7e43556d2bfbd9 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Tue, 25 Feb 2025 21:46:06 -0500 Subject: [PATCH 42/46] Engine update; Removed unused code and variables; Addressed some FIX ME statements, restated unresolved ones more clearly; Added new TODO items; Fixed incorrect behavior in SelectFEObjectPopUp when selecting an object. --- EditorWindows/InspectorWindow.cpp | 140 ++++++++++---------- EditorWindows/InspectorWindow.h | 6 +- EditorWindows/SceneGraphWindow.cpp | 151 ++++------------------ EditorWindows/SceneGraphWindow.h | 15 +-- EditorWindows/SelectPopups.cpp | 1 - EditorWindows/ShaderEditorWindow.cpp | 4 +- FEDearImguiWrapper/FEDearImguiWrapper.h | 2 +- SubSystems/FocalEngine | 2 +- SubSystems/ProjectManagment/FEProject.cpp | 2 +- SubSystems/ProjectManagment/FEProject.h | 7 +- 10 files changed, 102 insertions(+), 228 deletions(-) diff --git a/EditorWindows/InspectorWindow.cpp b/EditorWindows/InspectorWindow.cpp index 52ccb8d..5ef5b21 100644 --- a/EditorWindows/InspectorWindow.cpp +++ b/EditorWindows/InspectorWindow.cpp @@ -73,7 +73,7 @@ void FEEditorInspectorWindow::InitializeResources() LayerBrushButton = new ImGuiImageButton(DrawBrushIcon); LayerBrushButton->SetSize(ImVec2(48, 48)); - EntityChangePrefabTarget = DRAG_AND_DROP_MANAGER.AddTarget(FE_PREFAB, EntityChangePrefabTargetCallBack, nullptr, "Drop to assign prefab"); + EntityChangeGameModelTarget = DRAG_AND_DROP_MANAGER.AddTarget(FE_GAMEMODEL, EntityChangeGameModelTargetCallBack, nullptr, "Drop to assign game model"); // ************** Terrain Settings END ************** MouseCursorIcon = RESOURCE_MANAGER.LoadPNGTexture("Resources/Images/mouseCursorIcon.png", "mouseCursorIcon"); @@ -92,16 +92,19 @@ void FEEditorInspectorWindow::ShowTransformConfiguration(FEObject* Object, FETra ShowTransformConfiguration(Object->GetName(), Transform); } -bool FEEditorInspectorWindow::EntityChangePrefabTargetCallBack(FEObject* Object, void** EntityPointer) +bool FEEditorInspectorWindow::EntityChangeGameModelTargetCallBack(FEObject* Object, void** EntityPointer) { - // FIX ME! Prefabs - /*FEEntity* Entity = SELECTED.GetEntity(); + if (EDITOR.GetFocusedScene() == nullptr) + return false; + + FEEntity* Entity = SELECTED.GetSelected(EDITOR.GetFocusedScene()); if (Entity == nullptr) return false; - Entity->Prefab = (RESOURCE_MANAGER.GetPrefab(Object->GetObjectID())); - return true;*/ - return false; + FEGameModelComponent& GameModelComponent = Entity->GetComponent(); + GameModelComponent.SetGameModel(RESOURCE_MANAGER.GetGameModel(Object->GetObjectID())); + + return true; } bool FEEditorInspectorWindow::TerrainChangeMaterialTargetCallBack(FEObject* Object, void** LayerIndex) @@ -626,39 +629,33 @@ void FEEditorInspectorWindow::DisplayCameraProperties(FEEntity* CameraEntity) co static const char* options[5] = { "none", "1x", "2x", "4x", "8x" }; static std::string SelectedOption = "1x"; - // FIX ME! Was used with one camera only. - static bool bFirstLook = true; - if (bFirstLook) + const float FXAASpanMax = CameraComponent.GetFXAASpanMax(); + if (FXAASpanMax == 0.0f) { - const float FXAASpanMax = CameraComponent.GetFXAASpanMax(); - if (FXAASpanMax == 0.0f) - { - SelectedOption = options[0]; - } - else if (FXAASpanMax > 0.1f && FXAASpanMax < 1.1f) - { - SelectedOption = options[1]; - } - else if (FXAASpanMax > 1.1f && FXAASpanMax < 2.1f) - { - SelectedOption = options[2]; - } - else if (FXAASpanMax > 2.1f && FXAASpanMax < 4.1f) - { - SelectedOption = options[3]; - } - else if (FXAASpanMax > 4.1f && FXAASpanMax < 8.1f) - { - SelectedOption = options[4]; - } - else - { - SelectedOption = options[5]; - } - - bFirstLook = false; + SelectedOption = options[0]; + } + else if (FXAASpanMax > 0.1f && FXAASpanMax < 1.1f) + { + SelectedOption = options[1]; + } + else if (FXAASpanMax > 1.1f && FXAASpanMax < 2.1f) + { + SelectedOption = options[2]; + } + else if (FXAASpanMax > 2.1f && FXAASpanMax < 4.1f) + { + SelectedOption = options[3]; + } + else if (FXAASpanMax > 4.1f && FXAASpanMax < 8.1f) + { + SelectedOption = options[4]; + } + else + { + SelectedOption = options[5]; } + // TO-DO: it should be per camera. static bool bDebugSettings = false; if (ImGui::Checkbox("debug view", &bDebugSettings)) { @@ -808,35 +805,27 @@ void FEEditorInspectorWindow::DisplayCameraProperties(FEEntity* CameraEntity) co // *********** SSAO *********** static const char* SSAO_Options[5] = { "Off", "Low", "Medium", "High", "Custom" }; static std::string SSAO_SelectedOption = "Medium"; + const int SampleCount = CameraComponent.GetSSAOSampleCount(); - // FIX ME! Was used with one camera only. - static bool bSSAO_FirstLook = true; - if (bFirstLook) + if (!CameraComponent.IsSSAOEnabled()) { - const int SampleCount = CameraComponent.GetSSAOSampleCount(); - - if (!CameraComponent.IsSSAOEnabled()) - { - SSAO_SelectedOption = SSAO_Options[0]; - } - else if (SampleCount == 4) - { - SSAO_SelectedOption = SSAO_Options[1]; - } - else if (SampleCount == 16 && CameraComponent.GetSSAORadiusSmallDetails()) - { - SSAO_SelectedOption = SSAO_Options[2]; - } - else if (SampleCount == 32 && CameraComponent.GetSSAORadiusSmallDetails()) - { - SSAO_SelectedOption = SSAO_Options[3]; - } - else - { - SSAO_SelectedOption = SSAO_Options[4]; - } - - //bFirstLook = false; + SSAO_SelectedOption = SSAO_Options[0]; + } + else if (SampleCount == 4) + { + SSAO_SelectedOption = SSAO_Options[1]; + } + else if (SampleCount == 16 && CameraComponent.GetSSAORadiusSmallDetails()) + { + SSAO_SelectedOption = SSAO_Options[2]; + } + else if (SampleCount == 32 && CameraComponent.GetSSAORadiusSmallDetails()) + { + SSAO_SelectedOption = SSAO_Options[3]; + } + else + { + SSAO_SelectedOption = SSAO_Options[4]; } static bool bSSAO_DebugSettings = false; @@ -980,20 +969,20 @@ void FEEditorInspectorWindow::DisplayCameraProperties(FEEntity* CameraEntity) co } } -// FIX ME! -void FEEditorInspectorWindow::ChangePrefabOfEntityCallBack(const std::vector SelectionsResult) +void FEEditorInspectorWindow::ChangeGameModelOfEntityCallBack(const std::vector SelectionsResult) { - /*if (EntityToModify == nullptr) + if (EntityToModify == nullptr) return; - if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) + if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_GAMEMODEL) { - FEPrefab* SelectedPrefab = RESOURCE_MANAGER.GetPrefab(SelectionsResult[0]->GetObjectID()); - if (SelectedPrefab == nullptr) + FEGameModel* SelectedGameModel = RESOURCE_MANAGER.GetGameModel(SelectionsResult[0]->GetObjectID()); + if (SelectedGameModel == nullptr) return; - EntityToModify->Prefab = SelectedPrefab; - }*/ + FEGameModelComponent& GameModelComponent = EntityToModify->GetComponent(); + GameModelComponent.SetGameModel(SelectedGameModel); + } } void FEEditorInspectorWindow::AddLightComponent(FEEntity* Entity) @@ -1182,10 +1171,11 @@ void FEEditorInspectorWindow::Render() if (ImGui::ImageButton((void*)(intptr_t)PreviewTexture->GetTextureID(), ImVec2(128, 128), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f), 8, ImColor(0.0f, 0.0f, 0.0f, 0.0f), ImColor(1.0f, 1.0f, 1.0f, 1.0f))) { - //EntityToModify = EntitySelected; - //SELECT_FEOBJECT_POPUP.Show(FE_PREFAB, ChangePrefabOfEntityCallBack, Entity->Prefab); + EntityToModify = EntitySelected; + FEGameModelComponent& GameModelComponent = EntityToModify->GetComponent(); + SELECT_FEOBJECT_POPUP.Show(FE_GAMEMODEL, ChangeGameModelOfEntityCallBack, GameModelComponent.GetGameModel()); } - //EntityChangePrefabTarget->StickToItem(); + EntityChangeGameModelTarget->StickToItem(); bool bOpenContextMenu = false; if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1)) diff --git a/EditorWindows/InspectorWindow.h b/EditorWindows/InspectorWindow.h index 69adf11..594a177 100644 --- a/EditorWindows/InspectorWindow.h +++ b/EditorWindows/InspectorWindow.h @@ -29,10 +29,10 @@ class FEEditorInspectorWindow ImGuiImageButton* LevelBrushButton = nullptr; ImGuiImageButton* SmoothBrushButton = nullptr; ImGuiImageButton* LayerBrushButton = nullptr; - static bool EntityChangePrefabTargetCallBack(FEObject* Object, void** EntityPointer); + static bool EntityChangeGameModelTargetCallBack(FEObject* Object, void** EntityPointer); static bool TerrainChangeMaterialTargetCallBack(FEObject* Object, void** LayerIndex); - static void ChangePrefabOfEntityCallBack(std::vector SelectionsResult); - DragAndDropTarget* EntityChangePrefabTarget = nullptr; + static void ChangeGameModelOfEntityCallBack(std::vector SelectionsResult); + DragAndDropTarget* EntityChangeGameModelTarget = nullptr; std::vector TerrainChangeMaterialIndecies; std::vector TerrainChangeLayerMaterialTargets; int HoveredTerrainLayerItem = -1; diff --git a/EditorWindows/SceneGraphWindow.cpp b/EditorWindows/SceneGraphWindow.cpp index 4a2bc11..da7355e 100644 --- a/EditorWindows/SceneGraphWindow.cpp +++ b/EditorWindows/SceneGraphWindow.cpp @@ -1,8 +1,6 @@ #include "SceneGraphWindow.h" #include "../FEEditor.h" -FEEntity* FEEditorSceneGraphWindow::EntityToModify = nullptr; - FEEditorSceneGraphWindow::FEEditorSceneGraphWindow() { strcpy_s(FilterForEntities, "Filter entities..."); @@ -35,48 +33,6 @@ void FEEditorSceneGraphWindow::Clear() bLastFrameWasInvisible = true; } -void FEEditorSceneGraphWindow::SetCorrectItemColor(FEObject* SceneObject) const -{ - if (SceneObject->GetType() == FE_DIRECTIONAL_LIGHT || - SceneObject->GetType() == FE_SPOT_LIGHT || - SceneObject->GetType() == FE_POINT_LIGHT) - { - ImGui::PushStyleColor(ImGuiCol_Text, LightItemColor); - } - // FIX ME ! - /*else if (SceneObject->GetType() == FE_CAMERA_DEPRECATED) - { - ImGui::PushStyleColor(ImGuiCol_Text, CameraItemColor); - } - else if (SceneObject->GetType() == FE_TERRAIN_DEPRECATED) - { - ImGui::PushStyleColor(ImGuiCol_Text, TerrainItemColor); - }*/ - else if (SceneObject->GetType() == FE_ENTITY) - { - ImGui::PushStyleColor(ImGuiCol_Text, EntityItemColor); - } - /*else if (SceneObject->GetType() == FE_ENTITY_INSTANCED_DEPRECATED) - { - ImGui::PushStyleColor(ImGuiCol_Text, InstancedEntityItemColor); - }*/ -} - -void FEEditorSceneGraphWindow::PopCorrectItemColor(FEObject* SceneObject) -{ - // FIX ME ! - /*if (SceneObject->GetType() == FE_DIRECTIONAL_LIGHT || - SceneObject->GetType() == FE_SPOT_LIGHT || - SceneObject->GetType() == FE_POINT_LIGHT || - SceneObject->GetType() == FE_CAMERA_DEPRECATED || - SceneObject->GetType() == FE_TERRAIN_DEPRECATED || - SceneObject->GetType() == FE_ENTITY || - SceneObject->GetType() == FE_ENTITY_INSTANCED_DEPRECATED) - {*/ - ImGui::PopStyleColor(); - //} -} - static void CreateInstancedEntityCallBack(const std::vector SelectionsResult) { if (EDITOR.GetFocusedScene() == nullptr) @@ -121,75 +77,48 @@ static void CreateEntityCallBack(const std::vector SelectionsResult) } } -// FIX ME! -void FEEditorSceneGraphWindow::ChangePrefabOfEntityCallBack(const std::vector SelectionsResult) +// FIXME: Make icons colored and place them in the right place. +// Currently this function is not working properly. +void FEEditorSceneGraphWindow::DrawCorrectIcon(FEEntity* SceneEntity) const { - /*if (EntityToModify == nullptr) + if (SceneEntity == nullptr) return; - if (SelectionsResult.size() == 1 && SelectionsResult[0]->GetType() == FE_PREFAB) - { - FEPrefab* SelectedPrefab = RESOURCE_MANAGER.GetPrefab(SelectionsResult[0]->GetObjectID()); - if (SelectedPrefab == nullptr) - return; - - EntityToModify->Prefab = SelectedPrefab; - }*/ -} - -void FEEditorSceneGraphWindow::DrawCorrectIcon(const FEObject* SceneObject) const -{ - ImGui::SetCursorPosX(20); + float CurrentCursorPosX = ImGui::GetCursorPosX(); + ImGui::SameLine(); - // FIX ME! - /*if (SceneObject->GetType() == FE_ENTITY || SceneObject->GetType() == FE_ENTITY_INSTANCED_DEPRECATED) + if (SceneEntity->HasComponent()) { - const FEEntity* entity = SCENE.GetEntity(SceneObject->GetObjectID()); - - if (EDITOR_INTERNAL_RESOURCES.IsInInternalEditorList(entity)) - return; + ImGui::Image((void*)(intptr_t)InstancedEntityIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); + } - if (entity->GetType() == FE_ENTITY_INSTANCED_DEPRECATED) + if (SceneEntity->HasComponent()) + { + if (SceneEntity->GetComponent().GetType() == FE_DIRECTIONAL_LIGHT) { - - ImGui::Image((void*)(intptr_t)InstancedEntityIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); + ImGui::Image((void*)(intptr_t)DirectionalLightIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); } - else + if (SceneEntity->GetComponent().GetType() == FE_SPOT_LIGHT) { - ImGui::Image((void*)(intptr_t)EntityIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); + ImGui::Image((void*)(intptr_t)SpotLightIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); + } + if (SceneEntity->GetComponent().GetType() == FE_POINT_LIGHT) + { + ImGui::Image((void*)(intptr_t)PointLightIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); } - }*/ - - /*if (SceneObject->GetType() == FE_DIRECTIONAL_LIGHT) - { - ImGui::Image((void*)(intptr_t)DirectionalLightIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); - - } - - if (SceneObject->GetType() == FE_SPOT_LIGHT) - { - ImGui::Image((void*)(intptr_t)SpotLightIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); - - } - - if (SceneObject->GetType() == FE_POINT_LIGHT) - { - ImGui::Image((void*)(intptr_t)PointLightIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); - } - if (SceneObject->GetType() == FE_TERRAIN_DEPRECATED) + if (SceneEntity->HasComponent()) { ImGui::Image((void*)(intptr_t)TerrainIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); } - if (SceneObject->GetType() == FE_CAMERA_DEPRECATED) + if (SceneEntity->HasComponent()) { ImGui::Image((void*)(intptr_t)CameraIcon->GetTextureID(), ImVec2(16, 16), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); - }*/ + } - ImGui::SameLine(); - return; + ImGui::SetCursorPosX(CurrentCursorPosX); } DragAndDropTarget* FEEditorSceneGraphWindow::GetSceneNodeDragAndDropTarget(FENaiveSceneGraphNode* NodeToFind) @@ -280,6 +209,7 @@ ImRect FEEditorSceneGraphWindow::RenderSubTree(FENaiveSceneGraphNode* SubTreeRoo bool bOpened = ImGui::TreeNodeEx((void*)UniqueID, NodeFlags, Name.c_str(), 0); GetSceneNodeDragAndDropTarget(SubTreeRoot)->StickToItem(); const ImRect NodeRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); + //DrawCorrectIcon(SubTreeRoot->GetEntity()); ImVec2 VerticalLineStart = ImGui::GetCursorScreenPos(); VerticalLineStart.x += VerticalTreeLineXOffset; @@ -504,37 +434,6 @@ void FEEditorSceneGraphWindow::Render() ImGui::PopStyleColor(); ImGui::PopStyleColor(); - //for (size_t i = 0; i < FilteredSceneObjectsList.size(); i++) - //{ - // DrawCorrectIcon(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); - - // ImGuiTreeNodeFlags NodeFlags = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; - // if (SELECTED.GetSelected(CurrentScene) != nullptr) - // { - // if (SELECTED.GetSelected(CurrentScene)->GetObjectID() == FilteredSceneObjectsList[i]) - // { - // NodeFlags |= ImGuiTreeNodeFlags_Selected; - // } - // } - - // SetCorrectItemColor(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); - // ImGui::TreeNodeEx((void*)(intptr_t)i, NodeFlags, OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])->GetName().c_str(), i); - // PopCorrectItemColor(OBJECT_MANAGER.GetFEObject(FilteredSceneObjectsList[i])); - - // if (ImGui::IsItemClicked()) - // { - // // FIX ME! - // /*FEEntity* Entity = SCENE.GetEntity(FilteredSceneObjectsList[i]); - // SELECTED.SetSelected(Entity);*/ - // //SELECTED.SetDirtyFlag(false); - // } - - // if (ImGui::IsItemHovered()) - // { - // SceneObjectHoveredIndex = int(i); - // } - //} - bool bOpenContextMenu = false; if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(1)) bOpenContextMenu = true; @@ -587,7 +486,7 @@ void FEEditorSceneGraphWindow::Render() ImGui::EndPopup(); } - //// FIX ME! It should not be here. + // FIXME: Grid settings should be moved to other window, not scene graph window. //static bool bDisplayGrid = true; //ImGui::Checkbox("Display grid", &bDisplayGrid); diff --git a/EditorWindows/SceneGraphWindow.h b/EditorWindows/SceneGraphWindow.h index 9f386d8..03de875 100644 --- a/EditorWindows/SceneGraphWindow.h +++ b/EditorWindows/SceneGraphWindow.h @@ -10,17 +10,8 @@ class FEEditorSceneGraphWindow // Visibility bool bVisible = true; - // Item color management - void SetCorrectItemColor(FEObject* SceneObject) const; - void PopCorrectItemColor(FEObject* SceneObject); - ImVec4 TerrainItemColor = ImVec4(67.0f / 255.0f, 155.0f / 255.0f, 60.0f / 255.0f, 1.0f); - ImVec4 EntityItemColor = ImVec4(141.0f / 255.0f, 141.0f / 255.0f, 233.0f / 255.0f, 1.0f); - ImVec4 InstancedEntityItemColor = ImVec4(80.0f / 255.0f, 72.0f / 255.0f, 1.0f, 1.0f); - ImVec4 CameraItemColor = ImVec4(0.0f, 215.0f / 255.0f, 201.0f / 255.0f, 1.0f); - ImVec4 LightItemColor = ImVec4(243.0f / 255.0f, 230.0f / 255.0f, 31.0f / 255.0f, 1.0f); - // Icon management - void DrawCorrectIcon(const FEObject* SceneObject) const; + void DrawCorrectIcon(FEEntity* SceneEntity) const; FETexture* EntityIcon = nullptr; FETexture* InstancedEntityIcon = nullptr; FETexture* DirectionalLightIcon = nullptr; @@ -42,10 +33,6 @@ class FEEditorSceneGraphWindow bool bShouldOpenContextMenu = false; bool bLastFrameWasInvisible = true; - // Entity modification - static FEEntity* EntityToModify; - static void ChangePrefabOfEntityCallBack(std::vector SelectionsResult); - // Drag and drop int64_t ItemUnderMouse = 0; int SceneNodeDragAndDropTargetIndex = -1; diff --git a/EditorWindows/SelectPopups.cpp b/EditorWindows/SelectPopups.cpp index ccb9b03..5bf0b91 100644 --- a/EditorWindows/SelectPopups.cpp +++ b/EditorWindows/SelectPopups.cpp @@ -223,7 +223,6 @@ void SelectFEObjectPopUp::Render() SelectButton->Render(); if (SelectButton->IsClicked()) { - AddToSelected(OBJECT_MANAGER.GetFEObject(FilteredItemsList[IndexUnderMouse]->GetObjectID())); OnSelectAction(); Close(); diff --git a/EditorWindows/ShaderEditorWindow.cpp b/EditorWindows/ShaderEditorWindow.cpp index f0620bd..db8400d 100644 --- a/EditorWindows/ShaderEditorWindow.cpp +++ b/EditorWindows/ShaderEditorWindow.cpp @@ -397,7 +397,7 @@ void ShaderEditorWindow::Render() bComputeShaderUsed ? ComputeShaderEditor.GetText().c_str() : nullptr, true); - // FIX ME! Should it be here? + // TODO: Verify if this is needed. DummyShader->AddUniformsFromShader(ShaderToEdit); std::string Errors = DummyShader->GetCompilationErrors(); @@ -420,7 +420,7 @@ void ShaderEditorWindow::Render() bGeometryShaderUsed ? GeometryShaderEditor.GetText().c_str() : nullptr, bComputeShaderUsed ? ComputeShaderEditor.GetText().c_str() : nullptr); - // FIX ME! Should it be here? + // TODO: Verify if this is needed. ReCompiledShader->AddUniformsFromShader(ShaderToEdit); RESOURCE_MANAGER.ReplaceShader(ShaderToEdit->GetObjectID(), ReCompiledShader); diff --git a/FEDearImguiWrapper/FEDearImguiWrapper.h b/FEDearImguiWrapper/FEDearImguiWrapper.h index 5c239ea..d3a4468 100644 --- a/FEDearImguiWrapper/FEDearImguiWrapper.h +++ b/FEDearImguiWrapper/FEDearImguiWrapper.h @@ -26,7 +26,7 @@ class WindowsManager void UnRegisterWindow(FEImGuiWindow* Window); - // FIX ME! Here I am using internal ImGui functions. Need to find a way to avoid it. + // FIXME: Currently using internal ImGui functions. Need to find an alternative approach. ImGuiWindow* GetCurrentWindowImpl(); private: SINGLETON_PRIVATE_PART(WindowsManager) diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index efccb3f..6f405d0 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit efccb3f4583ebecb852b6b3451a897781fe52bb4 +Subproject commit 6f405d00917ea4ee1202b0b09f07fdfd839d27ce diff --git a/SubSystems/ProjectManagment/FEProject.cpp b/SubSystems/ProjectManagment/FEProject.cpp index 606305a..c47f35e 100644 --- a/SubSystems/ProjectManagment/FEProject.cpp +++ b/SubSystems/ProjectManagment/FEProject.cpp @@ -240,7 +240,7 @@ void FEProject::SaveResources(std::string DirectoryPath, bool bFullSave) ResourcesFile.close(); } -// TO-DO: Make that process in memory, not involving creating temporary files. +// TODO: Make that process in memory, not involving creating temporary files. FEAssetPackage* FEProject::SaveResourcesToAssetPackage() { FEAssetPackage* Result = new FEAssetPackage(); diff --git a/SubSystems/ProjectManagment/FEProject.h b/SubSystems/ProjectManagment/FEProject.h index a0e1eba..00c2729 100644 --- a/SubSystems/ProjectManagment/FEProject.h +++ b/SubSystems/ProjectManagment/FEProject.h @@ -55,14 +55,13 @@ class FEProject std::unordered_map SceneIDToProperMainCameraID; - // FIX ME! Move that to a RESOURCE_MANAGER + // FIXME: Consider moving this to RESOURCE_MANAGER void LoadResources(std::string DirectoryPath); void SaveResources(std::string DirectoryPath, bool bFullSave = false); - - // TO-DO: Make that process in memory, not involving creating temporary files. + // TODO: Implement in-memory processing instead of creating temporary files. + // FIXME: Consider moving this to RESOURCE_MANAGER FEAssetPackage* SaveResourcesToAssetPackage(); void LoadResourcesFromAssetPackage(FEAssetPackage* AssetPackage); - // FIX ME! Move that to a RESOURCE_MANAGER bool LoadVFSData(std::string FilePath); void AddMissingVFSData(); From 3987064d8a725116af2ddde1b3d4240f8f04d959 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Thu, 27 Feb 2025 22:21:43 -0500 Subject: [PATCH 43/46] Engine update; Added UI for the mesh export option. --- EditorWindows/ContentBrowserWindow.cpp | 22 ++++++++++++++++++++++ SubSystems/FocalEngine | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/EditorWindows/ContentBrowserWindow.cpp b/EditorWindows/ContentBrowserWindow.cpp index 4903147..ca6df2c 100644 --- a/EditorWindows/ContentBrowserWindow.cpp +++ b/EditorWindows/ContentBrowserWindow.cpp @@ -397,6 +397,28 @@ void FEEditorContentBrowserWindow::Render() } } + if (FilteredResources[ItemUnderMouse]->GetType() == FE_MESH) + { + if (ImGui::BeginMenu("Export")) + { + FEMesh* MeshToExport = RESOURCE_MANAGER.GetMesh(FilteredResources[ItemUnderMouse]->GetObjectID()); + + if (ImGui::MenuItem("as OBJ")) + { + std::string FilePath; + FILE_SYSTEM.ShowFileSaveDialog(FilePath, TEXTURE_LOAD_FILTER, 1); + + if (!FilePath.empty()) + { + FilePath += ".obj"; + RESOURCE_MANAGER.ExportFEMeshToOBJ(MeshToExport, FilePath.c_str()); + } + } + + ImGui::EndMenu(); + } + } + if (FilteredResources[ItemUnderMouse]->GetType() == FE_TEXTURE) { if (ImGui::BeginMenu("Convert")) diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 6f405d0..913b951 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 6f405d00917ea4ee1202b0b09f07fdfd839d27ce +Subproject commit 913b951e8405f3c9d1d0f69913e4c55d38e552ba From 15fcbede3e66c943a7f1f852761a0a4b4a3284e2 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Tue, 4 Mar 2025 22:26:29 -0500 Subject: [PATCH 44/46] Engine update; README update. --- EditorWindows/LogWindow.cpp | 1 + README.md | 142 ++++++++++++++++++++++++++++++------ SubSystems/FocalEngine | 2 +- 3 files changed, 123 insertions(+), 22 deletions(-) diff --git a/EditorWindows/LogWindow.cpp b/EditorWindows/LogWindow.cpp index 9cea44d..5b9d795 100644 --- a/EditorWindows/LogWindow.cpp +++ b/EditorWindows/LogWindow.cpp @@ -15,6 +15,7 @@ void FEEditor::DisplayLogWindow() const ImGui::Text("Channel:"); ImGui::SameLine(); ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 5); + ImGui::SetNextItemWidth(200); if (ImGui::BeginCombo("##Channel", (SelectedChannel.empty() ? "ALL" : SelectedChannel).c_str(), ImGuiWindowFlags_None)) { for (int i = -1; i < int(TopicList.size()); i++) diff --git a/README.md b/README.md index 6b205ef..565d163 100644 --- a/README.md +++ b/README.md @@ -2,35 +2,122 @@ ![build](https://github.com/Azzinoth/FocalEngineEditor/actions/workflows/Build.yml/badge.svg?branch=master) -The Focal Engine Editor is a comprehensive tool for the [Focal Engine](https://github.com/Azzinoth/FocalEngine/), providing a variety of utilities for creating and managing your scene. The engine has been designed to function independently from the editor, ensuring modularity. For this reason, the engine and editor are separate projects. - -Here are some images from scene created using the Focal Engine Editor: +The Focal Engine Editor is a creation environment for the [Focal Engine](https://github.com/Azzinoth/FocalEngine/), providing an suite of tools for developing 3D application/games. With an intuitive interface for scene design, entity management, and asset organization, the editor streamlines the entire development workflow from concept to deployment. It features a comprehensive project system, real-time shader editing, terrain creation tools and material editor. Importantly, the editor includes build functionality that allows developers to compile their projects into standalone executable applications with packaged resources. +⚠️ Important to note that a part of functionality is still in development and will be improved over time. ⚠️ + ![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/1.png) ![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/2.png) -![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/3.png) ![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/4.png) -![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/5.png) +![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/6.png) + +## Focal Engine Ecosystem + +The Focal Engine project consists of four modular components that work together to provide a complete development environment: + +[Basic Application Module](https://github.com/Azzinoth/FEBasicApplication) - A foundation layer for OpenGL and ImGui applications that provides essential utilities including time measurement, thread pooling, logging, TCP networking, and profiling capabilities. + +[Visual Node System](https://github.com/Azzinoth/VisualNodeSystem) - A framework for creating visual node-based interfaces with features like zoom, reroute nodes, group comments, and JSON serialization, ideal for material editors and visual scripting. + +[Focal Engine](https://github.com/Azzinoth/FocalEngine) - The engine with all core functionality. + +Focal Engine Editor (this repository) - A comprehensive editor for the engine. + +This modularity makes it easier to include just the engine in applications that don't need the editor's complexity. It also simplifies the implementation of export functionality in the editor, allowing users to compile their projects into standalone executable applications with all necessary resources. + +## Projects Using Focal Engine + +[HabiCAT 3D](https://github.com/Azzinoth/HabiCAT3D) - An open-source software that implements novel algorithms for generating multi-scale complexity metrics maps(like rugosity, fractal dimension, vector dispersion and others) for complex 3D habitat models. + +## Graphical Features + +- Physically-based rendering +- High dynamic range (HDR) rendering internally +- Gamma correction +- Deferred shading +- Screen-Space Ambient Occlusion (SSAO) +- Cascaded soft shadows +- Sky with atmospheric scattering +- Compressed textures support with multi-threaded loading +- Fast Approximate Anti-Aliasing (FXAA) +- Dynamic render scale adjustment +- Camera temporal jitter and partial motion vector calculations, needed for future TAA and third-party upscalers +- Each camera has its own unique rendering pipeline with customizable settings + +## Advanced Point Cloud Handling + +The Focal Engine provides specialized capabilities for working with large-scale point cloud data: + +- LAS/LAZ File Format Support + + ⚠️ Work in progress ⚠️ + +- High-Performance Rendering: Support for real-time visualization of massive point clouds (hundreds of millions to billions of points) + ⚠️ Work in progress ⚠️ + +- GPU-Accelerated Editing: Tools for manipulating and editing huge point clouds directly in GPU memory + ⚠️ Work in progress ⚠️ + +## Terrain + +- Chunked terrain with tessellation for LOD +- Frustum culling of sub chunks +- Up to 8 terrain layer materials +- Each layer can define foliage spawn rules + +## Performance + +Focal Engine features a GPU-driven rendering pipeline (⚠️ Work in progress ⚠️: currently not working with all entity components) that includes GPU Frustum Culling and GPU Occlusion Culling. The latter utilizes a custom Hierarchical Z-Buffer (HZB). Both culling techniques are implemented using compute shaders. These advanced optimization techniques enable the Focal Engine to render a substantial number of objects per scene (up to millions, depending on object types). + +### Profiling -## Features +Engine submodule includes a profiling system that provides detailed analysis of CPU utilization across threads. This system is designed to handle complex, highly multithreaded workloads, allowing to identify and address performance bottlenecks. -The Focal Engine Editor provides the ability to load, save, create new projects, and delete existing ones through the Project Browser window: +![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/7.png) + +## VR Support + +The Focal Engine leverages OpenXR integration to provide support for a wide range of VR headsets and controllers. The engine has a virtual UI system specifically designed for comfortable and intuitive interaction in VR space. + +![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/8.png) + +## Entity Component System (ECS) + +Engine uses EnTT library (also used in Minecraft) to implement an Entity Component System architecture. This approach helps to: +- Separate data from logic for better code organization +- Enable better performance through data-oriented design +- Provide flexible component-based object composition + +Additionally, Prefabs were introduced to make it easy to predefine an entity or group of entities along with all their components. A Prefab (internally implemented as a scene) can be instantiated multiple times, allowing for efficient reuse of complex entity configurations. + +## C++ Scripting System + +Native script component gives ability to attach custom C++ code to entities, allowing for runtime behavior definition or custom game logic implementation. + +As a practical example, the default cameras are organized as Prefabs containing both a camera component and a script component that defines the interaction logic. + +This demonstrates how the scripting system can be used to create reusable, modular gameplay elements. + +## Editor Overview + +The Focal Engine Editor provides project management capabilities through its project browser window: ![Project Browser](https://github.com/Azzinoth/FocalEngineEditor/blob/media/Project%20Browser.png) -In the Editor, the following key windows are available: +The editor interface includes several key windows: -1. **Scene Entities**: Displays all objects, cameras, light sources, and terrains in the scene. -2. **Scene**: Presents the main in-game camera view. -3. **Inspector**: Provides the properties of the selected object. -4. **Content Browser**: Serves as an explorer window for the current project's virtual file system with all resources structured. +1. **Scene Entities**: Displays entities in a hierarchical graph structure. +2. **Scene/Scenes**: Supports multiple scene windows simultaneously. Prefabs are handled as simplified scenes for modular design. +3. **Inspector**: Provides list of components of the selected entity for viewing and editing. +4. **Content Browser**: Serves as an explorer for the project's virtual file system with structured access to all resources. +5. **Editor Cameras**: Provides settings for editor-specific cameras. While game cameras (entities with camera components) are only functional in game mode, editor cameras allow navigation through scenes even when no game camera is present. +6. **Log Window**: Displays filtered categories of warnings, errors, and informational messages for debugging. -![Editor](https://github.com/Azzinoth/FocalEngineEditor/blob/media/Editor.png) +![Log window](https://github.com/Azzinoth/FocalEngineEditor/blob/media/Log%20window.png) -5. **Effects Settings**: Allows adjustments of different effects available in the engine. -⚠️ This part needs to be updated due to ECS. +Standard editor layout: -![Effects Settings](https://github.com/Azzinoth/FocalEngineEditor/blob/media/Effects%20Settings.png) +![Editor](https://github.com/Azzinoth/FocalEngineEditor/blob/media/Editor.png) The Material Editor employs the [Visual Node System](https://github.com/Azzinoth/VisualNodeSystem) to enhance editing intuitiveness. @@ -40,23 +127,36 @@ Terrain editing is facilitated with different brushes (sculpt, smooth, paint lay ![Terrain](https://github.com/Azzinoth/FocalEngineEditor/blob/media/Terrain.png) -## Debugging +## Build System -Multiple additional debugging windows are available for users to toggle: +⚠️ Work in progress ⚠️ -![Debug Render Targets](https://github.com/Azzinoth/FocalEngineEditor/blob/media/Debug%20Render%20Targets.png) +The Focal Engine Editor includes functionality to compile projects into standalone executable (.exe) files, along with packaged resource files containing all necessary scripts, assets, and resources. This allows for easy distribution of completed applications without requiring the editor or engine development environment. + + +## Shader debugging Users can edit shaders on-the-fly in the built-in shader editor and debug compilation errors: ![Shader Compilation errors](https://github.com/Azzinoth/FocalEngineEditor/blob/media/Shader%20Compilation%20errors.png) +⚠️ Work in progress ⚠️ + In addition, the editor supports real-time retrieval of shader variable values from the GPU. (Please note that not all variables are supported and further testing is needed for this feature.) ![Shader values read back](https://github.com/Azzinoth/FocalEngineEditor/blob/media/Shader%20values%20read%20back.png) -The Log window will display chosen categories of warnings, errors, and info. +## Testing -![Log window](https://github.com/Azzinoth/FocalEngineEditor/blob/media/Log%20window.png) +During the development of the engine and its tools, inadequate testing was identified as a source of setbacks. To address this, a multi-layered testing approach has been implemented: + +1. **Continuous Integration** - GitHub Actions run on every push as a sanity check to ensure the engine compiles successfully. + +2. **Unit Testing** - Using Google Test framework to verify individual components. Currently limited to scene graph testing, with plans to expand coverage to more subsystems over time. + +3. **Visual Testing Platform** - Due to the graphical nature of the engine, unit tests and GitHub Actions are insufficient for comprehensive testing. A specialized testing platform is being developed that will evaluate the engine's visual output and UI functionality. + +This comprehensive testing strategy will enable more confident feature iteration and establish a proper regression testing pipeline. ## Building the Project for Visual Studio (Windows) diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 913b951..3836a06 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 913b951e8405f3c9d1d0f69913e4c55d38e552ba +Subproject commit 3836a06d74c25b3d29e89088dcf83ee35702dac1 From 488f43c1889e65efe14160c98ac47961ae213261 Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Wed, 5 Mar 2025 19:34:24 -0500 Subject: [PATCH 45/46] Further README refinements. --- README.md | 62 ++++++++++++++++++++++++++---------------- SubSystems/FocalEngine | 2 +- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 565d163..86bd096 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,30 @@ The Focal Engine Editor is a creation environment for the [Focal Engine](https://github.com/Azzinoth/FocalEngine/), providing an suite of tools for developing 3D application/games. With an intuitive interface for scene design, entity management, and asset organization, the editor streamlines the entire development workflow from concept to deployment. It features a comprehensive project system, real-time shader editing, terrain creation tools and material editor. Importantly, the editor includes build functionality that allows developers to compile their projects into standalone executable applications with packaged resources. -⚠️ Important to note that a part of functionality is still in development and will be improved over time. ⚠️ +⚠️ **Currently in Alpha**: Expect breaking changes and ongoing development. ![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/1.png) ![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/2.png) ![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/4.png) ![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/6.png) +## Table of Contents +- [Focal Engine Ecosystem](#focal-engine-ecosystem) +- [Projects Using Focal Engine](#projects-using-focal-engine) +- [Features](#features) + - [Graphical Features](#graphical-features) + - [Point Cloud Handling](#advanced-point-cloud-handling) + - [Terrain](#terrain) + - [Performance](#performance) + - [VR Support](#vr-support) + - [Entity Component System (ECS)](#entity-component-system-ecs) + - [Prefab System](#prefab-system) + - [C++ Scripting](#c-scripting) +- [Editor](#editor-overview) +- [Build and Setup](#build-system) +- [Testing](#testing) +- [Third-Party Licenses](#third-party-licenses) + ## Focal Engine Ecosystem The Focal Engine project consists of four modular components that work together to provide a complete development environment: @@ -29,7 +46,9 @@ This modularity makes it easier to include just the engine in applications that [HabiCAT 3D](https://github.com/Azzinoth/HabiCAT3D) - An open-source software that implements novel algorithms for generating multi-scale complexity metrics maps(like rugosity, fractal dimension, vector dispersion and others) for complex 3D habitat models. -## Graphical Features +## Features + +### Graphical Features - Physically-based rendering - High dynamic range (HDR) rendering internally @@ -44,7 +63,7 @@ This modularity makes it easier to include just the engine in applications that - Camera temporal jitter and partial motion vector calculations, needed for future TAA and third-party upscalers - Each camera has its own unique rendering pipeline with customizable settings -## Advanced Point Cloud Handling +### Advanced Point Cloud Handling The Focal Engine provides specialized capabilities for working with large-scale point cloud data: @@ -58,45 +77,40 @@ The Focal Engine provides specialized capabilities for working with large-scale - GPU-Accelerated Editing: Tools for manipulating and editing huge point clouds directly in GPU memory ⚠️ Work in progress ⚠️ -## Terrain +### Terrain - Chunked terrain with tessellation for LOD - Frustum culling of sub chunks - Up to 8 terrain layer materials - Each layer can define foliage spawn rules -## Performance +### VR Support -Focal Engine features a GPU-driven rendering pipeline (⚠️ Work in progress ⚠️: currently not working with all entity components) that includes GPU Frustum Culling and GPU Occlusion Culling. The latter utilizes a custom Hierarchical Z-Buffer (HZB). Both culling techniques are implemented using compute shaders. These advanced optimization techniques enable the Focal Engine to render a substantial number of objects per scene (up to millions, depending on object types). +The Focal Engine leverages OpenXR integration to provide support for a wide range of VR headsets and controllers. The engine has a virtual UI system specifically designed for comfortable and intuitive interaction in VR space. + +![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/8.png) -### Profiling +### Entity Component System (ECS) -Engine submodule includes a profiling system that provides detailed analysis of CPU utilization across threads. This system is designed to handle complex, highly multithreaded workloads, allowing to identify and address performance bottlenecks. +Focal Engine employs EnTT ECS for optimized performance and flexible architecture. Easily compose entities from modular components, enabling scalable and maintainable code. -![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/7.png) +#### Prefab System -## VR Support +Easily define reusable entities or groups of entities as Prefabs. Prefabs encapsulate entities and their component configurations as scenes, allowing you to instantiate complex object setups multiple times efficiently. Prefabs simplify asset management and accelerate level design. -The Focal Engine leverages OpenXR integration to provide support for a wide range of VR headsets and controllers. The engine has a virtual UI system specifically designed for comfortable and intuitive interaction in VR space. - -![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/8.png) +### C++ Scripting: -## Entity Component System (ECS) +Attach custom scripts directly to entities for rapid prototyping, modular gameplay logic, and efficient runtime performance. -Engine uses EnTT library (also used in Minecraft) to implement an Entity Component System architecture. This approach helps to: -- Separate data from logic for better code organization -- Enable better performance through data-oriented design -- Provide flexible component-based object composition - -Additionally, Prefabs were introduced to make it easy to predefine an entity or group of entities along with all their components. A Prefab (internally implemented as a scene) can be instantiated multiple times, allowing for efficient reuse of complex entity configurations. +## Performance -## C++ Scripting System +Focal Engine features a GPU-driven rendering pipeline (⚠️ Work in progress ⚠️: currently not working with all entity components) that includes GPU Frustum Culling and GPU Occlusion Culling. The latter utilizes a custom Hierarchical Z-Buffer (HZB). Both culling techniques are implemented using compute shaders. These advanced optimization techniques enable the Focal Engine to render a substantial number of objects per scene (up to millions, depending on object types). -Native script component gives ability to attach custom C++ code to entities, allowing for runtime behavior definition or custom game logic implementation. +### Profiling -As a practical example, the default cameras are organized as Prefabs containing both a camera component and a script component that defines the interaction logic. +Engine submodule includes a profiling system that provides detailed analysis of CPU utilization across threads. This system is designed to handle complex, highly multithreaded workloads, allowing to identify and address performance bottlenecks. -This demonstrates how the scripting system can be used to create reusable, modular gameplay elements. +![3D scene in the Focal Engine](https://github.com/Azzinoth/FocalEngine/blob/media/7.png) ## Editor Overview diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index 3836a06..ec76a49 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit 3836a06d74c25b3d29e89088dcf83ee35702dac1 +Subproject commit ec76a493f196c6ada339244f61b40742f2a03c6c From 847f8363b4f9fadef32ed1e41ac9de484b00614c Mon Sep 17 00:00:00 2001 From: Kindrat Beregovyi Date: Wed, 5 Mar 2025 20:25:23 -0500 Subject: [PATCH 46/46] Engine update. --- SubSystems/FocalEngine | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SubSystems/FocalEngine b/SubSystems/FocalEngine index ec76a49..34dd4a5 160000 --- a/SubSystems/FocalEngine +++ b/SubSystems/FocalEngine @@ -1 +1 @@ -Subproject commit ec76a493f196c6ada339244f61b40742f2a03c6c +Subproject commit 34dd4a572bb18f0e7f9269ab8411cc2fd51d0ee1