From 4f7d1850afacdd6ea3bddb5d7d7585d0bb807a20 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Fri, 24 Mar 2023 16:33:45 +0800 Subject: [PATCH] Added editor window for generating nav data --- .../EditorWindow/MenuBar/SHEditorMenuBar.cpp | 34 +++++++++++++++++++ .../EditorWindow/MenuBar/SHEditorMenuBar.h | 1 + .../src/Navigation/SHNavigationSystem.cpp | 22 +++++++++++- .../src/Navigation/SHNavigationSystem.h | 17 +++++++++- 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp index 65e497aa..fd0d6581 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp @@ -29,6 +29,7 @@ #include "Physics/System/SHPhysicsDebugDrawSystem.h" #include "Camera/SHCameraSystem.h" #include "Tools/Utilities/SHClipboardUtilities.h" +#include const std::string LAYOUT_FOLDER_PATH{ std::string(ASSET_ROOT) + "/Editor/Layouts" }; @@ -93,6 +94,7 @@ namespace SHADE DrawLayoutMenu(); DrawApplicationConfig(); DrawPhysicsSettings(); + DrawNavMenu(); std::string const sceneName{std::format("Current Scene: {}",SHSceneManager::GetSceneName().data())}; auto const size = ImGui::CalcTextSize(sceneName.data()); @@ -418,6 +420,38 @@ namespace SHADE + ImGui::EndMenu(); + } + } + + void SHEditorMenuBar::DrawNavMenu() noexcept + { + ImGui::SetNextWindowSize({ 400.0f, 0.0f }); + if (ImGui::BeginMenu("Nav")) + { + if (auto navSystem = SHSystemManager::GetSystem()) + { + if (SHEditorWidgets::DragN("Origin", { "X", "Y", "Z" }, {&navSystem->origin_editor.x, &navSystem->origin_editor .y, &navSystem->origin_editor.z})) + { + + } + if (SHEditorWidgets::DragN("Size", { "X", "Y", "Z" }, { &navSystem->size_editor.x, &navSystem->size_editor.y, &navSystem->size_editor.z })) + { + + } + + if (ImGui::DragScalar("Col", ImGuiDataType_U16, &navSystem->numCols_editor)) {} + if(ImGui::DragScalar("Row", ImGuiDataType_U16, &navSystem->numRows_editor)){} + + if (ImGui::Button("Generate")) + { + navSystem->Clear(); + navSystem->GenerateNavigationGridData(); + + } + } + + ImGui::EndMenu(); } } diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.h b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.h index 945ee81b..e132d042 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.h +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.h @@ -27,6 +27,7 @@ namespace SHADE void DrawLayoutMenu() noexcept; void DrawApplicationConfig() noexcept; void DrawPhysicsSettings() noexcept; + void DrawNavMenu() noexcept; float menuBarHeight = 20.0f; std::vector layoutPaths; diff --git a/SHADE_Engine/src/Navigation/SHNavigationSystem.cpp b/SHADE_Engine/src/Navigation/SHNavigationSystem.cpp index 1d7d6612..a517a105 100644 --- a/SHADE_Engine/src/Navigation/SHNavigationSystem.cpp +++ b/SHADE_Engine/src/Navigation/SHNavigationSystem.cpp @@ -7,7 +7,7 @@ #include "Editor/SHEditor.h" #include "Scene/SHSceneManager.h" #include "Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h" - +#include "Assets/SHAssetManager.h" #include #include @@ -82,6 +82,21 @@ namespace SHADE return result; } + void SHNavigationSystem::Clear() noexcept + { + numRows = 0; + numCols = 0; + origin = SHVec3{ 0.0f }; + size = SHVec3{ 0.0f }; + navigationGrid.clear(); + } + + void SHNavigationSystem::SaveToFile(std::string const& name) noexcept + { + + + } + SHVec3 SHNavigationSystem::GetGridWorldPos(NavigationGridIndex index) noexcept { SHVec3 result{0.0f}; @@ -164,6 +179,11 @@ namespace SHADE } + void SHNavigationSystem::GenerateNavigationGridData() noexcept + { + GenerateNavigationGridData(origin_editor, size_editor, numRows_editor, numCols_editor); + } + void SHNavigationSystem::NavigationSystemGenerateRoutine::Execute(double dt) noexcept diff --git a/SHADE_Engine/src/Navigation/SHNavigationSystem.h b/SHADE_Engine/src/Navigation/SHNavigationSystem.h index d9a5209f..ce73f9a0 100644 --- a/SHADE_Engine/src/Navigation/SHNavigationSystem.h +++ b/SHADE_Engine/src/Navigation/SHNavigationSystem.h @@ -61,8 +61,22 @@ namespace SHADE virtual void Init(); virtual void Exit(); + + //Number of subdivision on the x axis + uint16_t numRows_editor{ 0 }; + //Number of subdivision on the z axis + uint16_t numCols_editor{ 0 }; + + //The center of the navigation area. + SHVec3 origin_editor{ 0.0f }; + + //Size of the navigation area + SHVec3 size_editor{ 0.0f }; + + void GenerateNavigationGridData(SHVec3 origin, SHVec3 size, uint16_t numRow, uint16_t numCol) noexcept; + void GenerateNavigationGridData() noexcept; void GeneratePath(SHNavigationComponent& comp) noexcept; bool GetNavigationData(uint16_t row, uint16_t col) noexcept; @@ -70,8 +84,9 @@ namespace SHADE NavigationGridIndex GetNavigationGridIndex(SHVec3 const& worldPosition) noexcept; + void Clear() noexcept; - + void SaveToFile(std::string const& name) noexcept; class SH_API NavigationSystemGenerateRoutine final: public SHSystemRoutine {