Now storing recast config in component
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <src/Scene/Entities/ImGuiHelper.h>
|
||||
#include <src/Scene/Components/NavMeshVolumeComponent.h>
|
||||
#include <src/Core/Maths.h>
|
||||
#include <src/AI/RecastConfig.h>
|
||||
|
||||
class NavMeshVolumePanel : ComponentPanel {
|
||||
|
||||
@@ -94,7 +95,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
NavManager::Get().BuildNavMesh();
|
||||
NavManager::Get().BuildNavMesh(RecastConfig(component));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "src/Scene/Systems/QuakeMapBuilder.h"
|
||||
#include <src/Core/FileSystem.h>
|
||||
#include <src/AI/NavManager.h>
|
||||
|
||||
#include <src/UI/ImUI.h>
|
||||
|
||||
class QuakeMapPanel : ComponentPanel {
|
||||
|
||||
@@ -13,6 +13,8 @@ public:
|
||||
|
||||
void Draw(Nuake::Entity entity) override
|
||||
{
|
||||
using namespace Nuake;
|
||||
|
||||
if (!entity.HasComponent<Nuake::QuakeMapComponent>())
|
||||
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<ModelComponent>())
|
||||
{
|
||||
TransformComponent& transformComponent = mesh.GetComponent<TransformComponent>();
|
||||
for (auto& mesh : mesh.GetComponent<ModelComponent>().ModelResource->GetMeshes())
|
||||
{
|
||||
Nuake::NavManager::Get().PushMesh(mesh, transformComponent.GetGlobalTransform());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Nuake::NavManager::Get().BuildNavMesh();
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
}
|
||||
}
|
||||
EndComponentTable();
|
||||
|
||||
@@ -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<Vector3> 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);
|
||||
|
||||
@@ -10,6 +10,8 @@ class dtNavMeshQuery;
|
||||
|
||||
namespace Nuake {
|
||||
|
||||
struct RecastConfig;
|
||||
|
||||
struct MeshTransformKeyPair
|
||||
{
|
||||
Ref<Mesh> mesh;
|
||||
@@ -28,7 +30,7 @@ namespace Nuake {
|
||||
void Initialize();
|
||||
void PushMesh(const Ref<Mesh>& mesh, const Matrix4& transform);
|
||||
|
||||
void BuildNavMesh();
|
||||
void BuildNavMesh(const RecastConfig& config);
|
||||
|
||||
void DrawNavMesh();
|
||||
|
||||
|
||||
24
Nuake/src/AI/RecastConfig.cpp
Normal file
24
Nuake/src/AI/RecastConfig.cpp
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
30
Nuake/src/AI/RecastConfig.h
Normal file
30
Nuake/src/AI/RecastConfig.h
Normal file
@@ -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;
|
||||
};
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user