From d0399a8f8c87907843ade07d962f3ab08fcacc9a Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Wed, 24 Jul 2024 23:00:05 -0400 Subject: [PATCH] Now storing recast config in component --- .../src/ComponentsPanel/NavMeshVolumePanel.h | 3 +- Editor/src/ComponentsPanel/QuakeMapPanel.h | 36 +++---------------- Nuake/src/AI/NavManager.cpp | 32 +++++++++-------- Nuake/src/AI/NavManager.h | 4 ++- Nuake/src/AI/RecastConfig.cpp | 24 +++++++++++++ Nuake/src/AI/RecastConfig.h | 30 ++++++++++++++++ .../Scene/Components/NavMeshVolumeComponent.h | 18 ++++++++++ 7 files changed, 98 insertions(+), 49 deletions(-) create mode 100644 Nuake/src/AI/RecastConfig.cpp create mode 100644 Nuake/src/AI/RecastConfig.h diff --git a/Editor/src/ComponentsPanel/NavMeshVolumePanel.h b/Editor/src/ComponentsPanel/NavMeshVolumePanel.h index 45e82f48..9843f452 100644 --- a/Editor/src/ComponentsPanel/NavMeshVolumePanel.h +++ b/Editor/src/ComponentsPanel/NavMeshVolumePanel.h @@ -4,6 +4,7 @@ #include #include #include +#include class NavMeshVolumePanel : ComponentPanel { @@ -94,7 +95,7 @@ public: } } - NavManager::Get().BuildNavMesh(); + NavManager::Get().BuildNavMesh(RecastConfig(component)); } } } diff --git a/Editor/src/ComponentsPanel/QuakeMapPanel.h b/Editor/src/ComponentsPanel/QuakeMapPanel.h index 228eb443..0d1ae920 100644 --- a/Editor/src/ComponentsPanel/QuakeMapPanel.h +++ b/Editor/src/ComponentsPanel/QuakeMapPanel.h @@ -4,7 +4,7 @@ #include "src/Scene/Systems/QuakeMapBuilder.h" #include #include - +#include class QuakeMapPanel : ComponentPanel { @@ -13,6 +13,8 @@ public: void Draw(Nuake::Entity entity) override { + using namespace Nuake; + if (!entity.HasComponent()) return; @@ -65,41 +67,11 @@ public: ImGui::Text("Build"); ImGui::TableNextColumn(); - if (ImGui::Button("Build")) + if (UI::SecondaryButton("Build Geometry")) { Nuake::QuakeMapBuilder builder; builder.BuildQuakeMap(entity, component.HasCollisions); } - - ImGui::TableNextColumn(); - - //ComponentTableReset(component.Class, ""); - } - ImGui::TableNextColumn(); - { - using namespace Nuake; - - ImGui::Text("Build Navigation Mesh"); - ImGui::TableNextColumn(); - - if (ImGui::Button("Build Navigation")) - { - for (auto& mesh : component.m_Brushes) - { - if (mesh.HasComponent()) - { - TransformComponent& transformComponent = mesh.GetComponent(); - for (auto& mesh : mesh.GetComponent().ModelResource->GetMeshes()) - { - Nuake::NavManager::Get().PushMesh(mesh, transformComponent.GetGlobalTransform()); - } - } - } - - Nuake::NavManager::Get().BuildNavMesh(); - } - - ImGui::TableNextColumn(); } } EndComponentTable(); diff --git a/Nuake/src/AI/NavManager.cpp b/Nuake/src/AI/NavManager.cpp index 702976e6..3a0e0229 100644 --- a/Nuake/src/AI/NavManager.cpp +++ b/Nuake/src/AI/NavManager.cpp @@ -12,6 +12,8 @@ #include "src/Scene/Entities/Entity.h" #include "src/Core/Maths.h" +#include "src/AI/RecastConfig.h" + namespace Nuake { void NavManager::Initialize() @@ -29,7 +31,7 @@ namespace Nuake { m_Meshes.push_back({ mesh, transform }); } - void NavManager::BuildNavMesh() + void NavManager::BuildNavMesh(const RecastConfig& config) { // Merge all meshes togheter std::vector vertices; @@ -59,20 +61,20 @@ namespace Nuake { float bmin[3] = { -100.0f, -100.0f, -100.0f }; float bmax[3] = { 100.0f, 100.0f, 100.0f }; rcConfig recastConfig; - recastConfig.cs = 0.2f; - recastConfig.ch = 0.2f; - recastConfig.tileSize = 10.0f; - recastConfig.walkableSlopeAngle = 45.0f; - recastConfig.maxEdgeLen = 12.0f; - recastConfig.maxVertsPerPoly = 6.0f; - recastConfig.walkableHeight = 1.0f; - recastConfig.walkableClimb = 1.0f; - recastConfig.walkableRadius = 1.0f; - recastConfig.maxSimplificationError = 1.3f; - recastConfig.minRegionArea = 4.0f; - recastConfig.mergeRegionArea = 10.0f; - recastConfig.detailSampleDist = 2.0f; - recastConfig.detailSampleMaxError = 1.0f; + recastConfig.cs = config.CellSize; + recastConfig.ch = config.CellHeight; + recastConfig.tileSize = config.TileSize; + recastConfig.walkableSlopeAngle = config.WalkableSlopeAngle; + recastConfig.maxEdgeLen = config.MaxEdgeLength; + recastConfig.maxVertsPerPoly = config.MaxVertsPerPoly; + recastConfig.walkableHeight = config.WalkableHeight; + recastConfig.walkableClimb = config.WalkableClimb; + recastConfig.walkableRadius = config.WalkableRadius; + recastConfig.maxSimplificationError = config.MaxSimplificationError; + recastConfig.minRegionArea = config.MinRegionArea; + recastConfig.mergeRegionArea = config.MergeRegionArea; + recastConfig.detailSampleDist = config.DetailSampleDistance; + recastConfig.detailSampleMaxError = config.DetailsampleMaxError; rcVcopy(recastConfig.bmin, bmin); rcVcopy(recastConfig.bmax, bmax); diff --git a/Nuake/src/AI/NavManager.h b/Nuake/src/AI/NavManager.h index 08f0c521..0aca9cea 100644 --- a/Nuake/src/AI/NavManager.h +++ b/Nuake/src/AI/NavManager.h @@ -10,6 +10,8 @@ class dtNavMeshQuery; namespace Nuake { + struct RecastConfig; + struct MeshTransformKeyPair { Ref mesh; @@ -28,7 +30,7 @@ namespace Nuake { void Initialize(); void PushMesh(const Ref& mesh, const Matrix4& transform); - void BuildNavMesh(); + void BuildNavMesh(const RecastConfig& config); void DrawNavMesh(); diff --git a/Nuake/src/AI/RecastConfig.cpp b/Nuake/src/AI/RecastConfig.cpp new file mode 100644 index 00000000..ffdd0da2 --- /dev/null +++ b/Nuake/src/AI/RecastConfig.cpp @@ -0,0 +1,24 @@ +#include "RecastConfig.h" +#include "src/Scene/Components/NavMeshVolumeComponent.h" + + +namespace Nuake { + + RecastConfig::RecastConfig(const NavMeshVolumeComponent& component) + { + CellSize = component.CellSize; + CellHeight = component.CellHeight; + TileSize = component.TileSize; + WalkableSlopeAngle = component.WalkableSlopeAngle; + MaxEdgeLength = component.MaxEdgeLength; + MaxVertsPerPoly = component.MaxVertsPerPoly; + WalkableHeight = component.WalkableHeight; + WalkableClimb = component.WalkableClimb; + WalkableRadius = component.WalkableRadius; + MaxSimplificationError = component.MaxSimplificationError; + MinRegionArea = component.MinRegionArea; + MergeRegionArea = component.MergeRegionArea; + DetailSampleDistance = component.DetailSampleDistance; + DetailsampleMaxError = component.DetailsampleMaxError; + } +} \ No newline at end of file diff --git a/Nuake/src/AI/RecastConfig.h b/Nuake/src/AI/RecastConfig.h new file mode 100644 index 00000000..793de94c --- /dev/null +++ b/Nuake/src/AI/RecastConfig.h @@ -0,0 +1,30 @@ +#pragma once + +namespace Nuake { + + struct NavMeshVolumeComponent; + + class RecastConfig + { + public: + float CellSize = 0.2f; + float CellHeight = 0.2f; + float TileSize = 10.0f; + float WalkableSlopeAngle = 45.0f; + float MaxEdgeLength = 12.0f; + float MaxVertsPerPoly = 6.0f; + float WalkableHeight = 1.0f; + float WalkableClimb = 1.0f; + float WalkableRadius = 1.0f; + float MaxSimplificationError = 1.3f; + float MinRegionArea = 4.0f; + float MergeRegionArea = 10.0f; + float DetailSampleDistance = 2.0f; + float DetailsampleMaxError = 1.0f; + + RecastConfig(const NavMeshVolumeComponent& component); + RecastConfig() = default; + + ~RecastConfig() = default; + }; +} \ No newline at end of file diff --git a/Nuake/src/Scene/Components/NavMeshVolumeComponent.h b/Nuake/src/Scene/Components/NavMeshVolumeComponent.h index 0d616114..3ed48ea5 100644 --- a/Nuake/src/Scene/Components/NavMeshVolumeComponent.h +++ b/Nuake/src/Scene/Components/NavMeshVolumeComponent.h @@ -9,11 +9,29 @@ namespace Nuake Vector3 VolumeSize = { 1.0f, 1.0f, 1.0f }; bool OnlyIncludeMapGeometry = true; + // Generation config + float CellSize = 0.2f; + float CellHeight = 0.2f; + float TileSize = 10.0f; + float WalkableSlopeAngle = 45.0f; + float MaxEdgeLength = 12.0f; + float MaxVertsPerPoly = 6.0f; + float WalkableHeight = 1.0f; + float WalkableClimb = 1.0f; + float WalkableRadius = 1.0f; + float MaxSimplificationError = 1.3f; + float MinRegionArea = 4.0f; + float MergeRegionArea = 10.0f; + float DetailSampleDistance = 2.0f; + float DetailsampleMaxError = 1.0f; + json Serialize() { BEGIN_SERIALIZE(); SERIALIZE_VEC3(VolumeSize); SERIALIZE_VAL(OnlyIncludeMapGeometry); + + // Generation config END_SERIALIZE(); }