From 275aad82b92461588a4cb94b989afb16f754538c Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Fri, 9 Aug 2024 21:21:41 -0400 Subject: [PATCH] Serialized navmesh props --- Nuake/src/AI/NavManager.cpp | 12 ++---- .../Scene/Components/NavMeshVolumeComponent.h | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/Nuake/src/AI/NavManager.cpp b/Nuake/src/AI/NavManager.cpp index c7d94aa9..833426e9 100644 --- a/Nuake/src/AI/NavManager.cpp +++ b/Nuake/src/AI/NavManager.cpp @@ -101,7 +101,7 @@ namespace Nuake { float* verts = reinterpret_cast(vertices.data()); int* tris = reinterpret_cast(indices.data()); - rcMarkWalkableTriangles(m_RecastContext.get(), 45.0f, verts, std::size(vertices), tris, std::size(indices) / 3, m_triareas); + rcMarkWalkableTriangles(m_RecastContext.get(), config.WalkableSlopeAngle, verts, std::size(vertices), tris, std::size(indices) / 3, m_triareas); if (!rcRasterizeTriangles(m_RecastContext.get(), verts, std::size(vertices), tris, m_triareas, std::size(indices) / 3, *voxelHeightField, recastConfig.walkableClimb)) { Logger::Log("buildNavigation: Could not rasterize triangles.", "NavManager", CRITICAL); @@ -218,7 +218,6 @@ namespace Nuake { params.detailVertsCount = detailMesh->nverts; params.detailTris = detailMesh->tris; params.detailTriCount = detailMesh->ntris; - // Off connection, might be useful for user defined jump points? // Maybe useful for ziplines, scripted jumppad, idk // See sample OffMeshConnectionTool.cpp in RecastDemo project. @@ -231,12 +230,9 @@ namespace Nuake { //params.offMeshConUserID = m_geom->getOffMeshConnectionId(); //params.offMeshConCount = m_geom->getOffMeshConnectionCount(); - const float agentHeight = 0.5f; - const float agentRadius = 0.1f; - const float agentMaxClimb = 0.01f; - params.walkableHeight = agentHeight; - params.walkableRadius = agentRadius; - params.walkableClimb = agentMaxClimb; + params.walkableHeight = config.WalkableHeight; + params.walkableRadius = config.WalkableRadius; + params.walkableClimb = config.WalkableClimb; rcVcopy(params.bmin, polygonMesh->bmin); rcVcopy(params.bmax, polygonMesh->bmax); diff --git a/Nuake/src/Scene/Components/NavMeshVolumeComponent.h b/Nuake/src/Scene/Components/NavMeshVolumeComponent.h index f8625786..5e4a9411 100644 --- a/Nuake/src/Scene/Components/NavMeshVolumeComponent.h +++ b/Nuake/src/Scene/Components/NavMeshVolumeComponent.h @@ -26,6 +26,10 @@ namespace Nuake float DetailSampleDistance = 2.0f; float DetailsampleMaxError = 1.0f; + float AgentHeight = 0.5f; + float AgentRadius = 0.1f; + float AgentMaxClimb = 0.01f; + Ref NavMeshData; json Serialize() @@ -34,6 +38,24 @@ namespace Nuake SERIALIZE_VEC3(VolumeSize); SERIALIZE_VAL(OnlyIncludeMapGeometry); + SERIALIZE_VAL(CellSize); + SERIALIZE_VAL(CellHeight); + SERIALIZE_VAL(TileSize); + SERIALIZE_VAL(WalkableSlopeAngle); + SERIALIZE_VAL(MaxEdgeLength); + SERIALIZE_VAL(MaxVertsPerPoly); + SERIALIZE_VAL(WalkableHeight); + SERIALIZE_VAL(WalkableClimb); + SERIALIZE_VAL(WalkableRadius); + SERIALIZE_VAL(MaxSimplificationError); + SERIALIZE_VAL(MinRegionArea); + SERIALIZE_VAL(DetailSampleDistance); + SERIALIZE_VAL(DetailsampleMaxError); + + SERIALIZE_VAL(AgentHeight); + SERIALIZE_VAL(AgentRadius); + SERIALIZE_VAL(AgentMaxClimb); + if (NavMeshData != nullptr) { SERIALIZE_OBJECT(NavMeshData); @@ -55,6 +77,23 @@ namespace Nuake DESERIALIZE_VAL(OnlyIncludeMapGeometry); } + DESERIALIZE_VAL(CellSize); + DESERIALIZE_VAL(CellHeight); + DESERIALIZE_VAL(TileSize); + DESERIALIZE_VAL(WalkableSlopeAngle); + DESERIALIZE_VAL(MaxEdgeLength); + DESERIALIZE_VAL(MaxVertsPerPoly); + DESERIALIZE_VAL(WalkableHeight); + DESERIALIZE_VAL(WalkableClimb); + DESERIALIZE_VAL(WalkableRadius); + DESERIALIZE_VAL(MaxSimplificationError); + DESERIALIZE_VAL(MinRegionArea); + DESERIALIZE_VAL(DetailSampleDistance); + DESERIALIZE_VAL(DetailsampleMaxError); + DESERIALIZE_VAL(AgentHeight); + DESERIALIZE_VAL(AgentRadius); + DESERIALIZE_VAL(AgentMaxClimb); + if (j.contains("NavMeshData")) { NavMeshData = CreateRef();