From f15894920f91b0bd362f6e32debaf2e36ad05040 Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Wed, 24 Jul 2024 20:58:48 -0400 Subject: [PATCH] Added NavMeshVolume component --- .../src/ComponentsPanel/NavMeshVolumePanel.h | 70 +++++++++++++++++++ Editor/src/Misc/GizmoDrawer.cpp | 22 ++++++ Editor/src/Windows/EditorInterface.cpp | 4 ++ Editor/src/Windows/EditorSelectionPanel.cpp | 3 +- Editor/src/Windows/EditorSelectionPanel.h | 2 + Nuake/src/AI/NavManager.cpp | 2 + .../Scene/Components/NavMeshVolumeComponent.h | 28 ++++++++ Nuake/src/Scene/Entities/Entity.cpp | 5 ++ 8 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 Editor/src/ComponentsPanel/NavMeshVolumePanel.h create mode 100644 Nuake/src/Scene/Components/NavMeshVolumeComponent.h diff --git a/Editor/src/ComponentsPanel/NavMeshVolumePanel.h b/Editor/src/ComponentsPanel/NavMeshVolumePanel.h new file mode 100644 index 00000000..c87b9e98 --- /dev/null +++ b/Editor/src/ComponentsPanel/NavMeshVolumePanel.h @@ -0,0 +1,70 @@ +#pragma once +#include "ComponentPanel.h" + +#include +#include +#include + +class NavMeshVolumePanel : ComponentPanel { + +public: + NavMeshVolumePanel() {} + + void Draw(Nuake::Entity entity) override + { + using namespace Nuake; + + if (!entity.HasComponent()) + { + return; + } + + auto& component = entity.GetComponent(); + BeginComponentTable(NAVMESH VOLUME, NavMeshVolumeComponent); + { + { + CompononentPropertyName("Volume Bounds"); + ImGui::TableNextColumn(); + + Vector3 volumeSize = component.VolumeSize; + + ImGuiHelper::DrawVec3("VolumeSize", &volumeSize); + + if (volumeSize.x > 0 && volumeSize.y > 0 && volumeSize.z > 0) + { + component.VolumeSize = volumeSize; + } + + ImGui::TableNextColumn(); + + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1, 1, 1, 0)); + + std::string resetLabel = std::string(ICON_FA_UNDO) + "##ResetVolumeSize"; + if (ImGui::Button(resetLabel.c_str())) + { + volumeSize = { 1.0, 1.0, 1.0 }; + } + + ImGui::PopStyleColor(); + } + ImGui::TableNextColumn(); + { + CompononentPropertyName("Generate"); + + ImGui::TableNextColumn(); + + if (UI::SecondaryButton("Generate")) + { + + } + + ImGui::TableNextColumn(); + + // No reset button + + ImGui::TableNextColumn(); + } + } + EndComponentTable(); + } +}; \ No newline at end of file diff --git a/Editor/src/Misc/GizmoDrawer.cpp b/Editor/src/Misc/GizmoDrawer.cpp index 2bd5241b..82476a7d 100644 --- a/Editor/src/Misc/GizmoDrawer.cpp +++ b/Editor/src/Misc/GizmoDrawer.cpp @@ -204,6 +204,28 @@ void GizmoDrawer::DrawGizmos(Ref scene, bool occluded) Nuake::RenderCommand::DrawLines(0, 26); } + auto navMeshVolumeView = scene->m_Registry.view(); + for (auto e : navMeshVolumeView) + { + if (!IsEntityInSelection(Nuake::Entity{ (entt::entity)e, scene.get() })) + { + continue; + } + + auto [transform, volume] = scene->m_Registry.get(e); + + const Quat& globalRotation = glm::normalize(transform.GetGlobalRotation()); + const Matrix4& rotationMatrix = glm::mat4_cast(globalRotation); + + m_LineShader->Bind(); + m_LineShader->SetUniform1f("u_Opacity", 0.9f); + m_LineShader->SetUniformMat4f("u_View", glm::scale(glm::translate(scene->m_EditorCamera->GetTransform(), Vector3(transform.GetGlobalTransform()[3])) * rotationMatrix, volume.VolumeSize)); + m_LineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective()); + + m_BoxBuffer->Bind(); + Nuake::RenderCommand::DrawLines(0, 26); + } + auto sphereColliderView = scene->m_Registry.view(); for (auto e : sphereColliderView) { diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 57adb74d..6d0b4a66 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -1770,6 +1770,10 @@ namespace Nuake { { Engine::GetCurrentScene()->CreateEntity("Quake Map").AddComponent(); } + if (ImGui::MenuItem("NavMesh Volume")) + { + Engine::GetCurrentScene()->CreateEntity("NavMesh Volume").AddComponent(); + } ImGui::EndMenu(); } diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index d4d626ea..c2c378e8 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -129,6 +129,7 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity) mMeshColliderPanel.Draw(entity); mCharacterControllerPanel.Draw(entity); mAudioEmitterPanel.Draw(entity); + mNavMeshVolumePanel.Draw(entity); using namespace Nuake; @@ -169,7 +170,7 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity) ImGui::Separator(); MenuItemComponent("Audio Emitter", AudioEmitterComponent); ImGui::Separator(); - MenuItemComponent("Path", AudioEmitterComponent); + MenuItemComponent("NavMesh Volume", NavMeshVolumeComponent); ImGui::EndPopup(); } diff --git a/Editor/src/Windows/EditorSelectionPanel.h b/Editor/src/Windows/EditorSelectionPanel.h index a84c4325..a8c8586c 100644 --- a/Editor/src/Windows/EditorSelectionPanel.h +++ b/Editor/src/Windows/EditorSelectionPanel.h @@ -24,6 +24,7 @@ #include "../ComponentsPanel/BonePanel.h" #include "../ComponentsPanel/AudioEmitterPanel.h" #include "../ComponentsPanel/NetScriptPanel.h" +#include "../ComponentsPanel/NavMeshVolumePanel.h" class EditorSelectionPanel { @@ -47,6 +48,7 @@ private: ParticleEmitterPanel mParticleEmitterPanel; BonePanel mBonePanel; AudioEmitterPanel mAudioEmitterPanel; + NavMeshVolumePanel mNavMeshVolumePanel; Ref currentFile; Ref selectedResource; diff --git a/Nuake/src/AI/NavManager.cpp b/Nuake/src/AI/NavManager.cpp index 69a53a59..702976e6 100644 --- a/Nuake/src/AI/NavManager.cpp +++ b/Nuake/src/AI/NavManager.cpp @@ -274,6 +274,8 @@ namespace Nuake { { Logger::Log("Could not init Detour navmesh query", "NavManager", CRITICAL); } + + m_Meshes.clear(); } void NavManager::DrawNavMesh() diff --git a/Nuake/src/Scene/Components/NavMeshVolumeComponent.h b/Nuake/src/Scene/Components/NavMeshVolumeComponent.h new file mode 100644 index 00000000..a94f66c8 --- /dev/null +++ b/Nuake/src/Scene/Components/NavMeshVolumeComponent.h @@ -0,0 +1,28 @@ +#pragma once +#include "../Entities/Entity.h" +#include "Engine.h" + +namespace Nuake +{ + struct NavMeshVolumeComponent + { + Vector3 VolumeSize = { 1.0f, 1.0f, 1.0f }; + + json Serialize() + { + BEGIN_SERIALIZE(); + SERIALIZE_VEC3(VolumeSize); + END_SERIALIZE(); + } + + bool Deserialize(const json& j) + { + if (j.contains("VolumeSize")); + { + DESERIALIZE_VEC3(j["VolumeSize"], VolumeSize); + } + + return true; + } + }; +} diff --git a/Nuake/src/Scene/Entities/Entity.cpp b/Nuake/src/Scene/Entities/Entity.cpp index 4c598afa..b221ac63 100644 --- a/Nuake/src/Scene/Entities/Entity.cpp +++ b/Nuake/src/Scene/Entities/Entity.cpp @@ -18,6 +18,7 @@ #include "src/Scene/Components/ParticleEmitterComponent.h" #include "src/Scene/Components/BoneComponent.h" #include "src/Scene/Components/SkinnedModelComponent.h" +#include namespace Nuake { @@ -79,6 +80,9 @@ namespace Nuake SERIALIZE_OBJECT_REF_LBL("AudioEmitterComponent", GetComponent()) if (HasComponent()) SERIALIZE_OBJECT_REF_LBL("NetScriptComponent", GetComponent()) + if (HasComponent()) + SERIALIZE_OBJECT_REF_LBL("NavMeshVolumeComponent", GetComponent()) + END_SERIALIZE(); } @@ -111,6 +115,7 @@ namespace Nuake DESERIALIZE_COMPONENT(SkinnedModelComponent); DESERIALIZE_COMPONENT(AudioEmitterComponent); DESERIALIZE_COMPONENT(NetScriptComponent); + DESERIALIZE_COMPONENT(NavMeshVolumeComponent); return true; }