Plasma Engine  2.0
Loading...
Searching...
No Matches
NavMeshBuilder.h
1#pragma once
2
3#include <Foundation/Reflection/Reflection.h>
4#include <Foundation/Types/UniquePtr.h>
5#include <RecastPlugin/RecastPluginDLL.h>
6#include <RendererCore/Utils/WorldGeoExtractionUtil.h>
7
8class plRcBuildContext;
9struct rcPolyMesh;
10struct rcPolyMeshDetail;
11class plWorld;
12class dtNavMesh;
14class plProgress;
15class plStreamWriter;
16class plStreamReader;
17
18struct PL_RECASTPLUGIN_DLL plRecastConfig
19{
20 float m_fAgentHeight = 1.5f;
21 float m_fAgentRadius = 0.3f;
22 float m_fAgentClimbHeight = 0.4f;
23 plAngle m_WalkableSlope = plAngle::MakeFromDegree(45);
24 float m_fCellSize = 0.2f;
25 float m_fCellHeight = 0.2f;
26 float m_fMaxEdgeLength = 4.0f;
27 float m_fMaxSimplificationError = 1.3f;
28 float m_fMinRegionSize = 3.0f;
29 float m_fRegionMergeSize = 20.0f;
30 float m_fDetailMeshSampleDistanceFactor = 1.0f;
31 float m_fDetailMeshSampleErrorFactor = 1.0f;
32
33 plResult Serialize(plStreamWriter& inout_stream) const;
34 plResult Deserialize(plStreamReader& inout_stream);
35};
36
37PL_DECLARE_REFLECTABLE_TYPE(PL_RECASTPLUGIN_DLL, plRecastConfig);
38
39
40
41class PL_RECASTPLUGIN_DLL plRecastNavMeshBuilder
42{
43public:
46
47 static plResult ExtractWorldGeometry(const plWorld& world, plWorldGeoExtractionUtil::MeshObjectList& out_worldGeo);
48
50 plProgress& ref_progress);
51
52private:
53 static void FillOutConfig(struct rcConfig& cfg, const plRecastConfig& config, const plBoundingBox& bbox);
54
55 void Clear();
56 void GenerateTriangleMeshFromDescription(const plWorldGeoExtractionUtil::MeshObjectList& objects);
57 void ComputeBoundingBox();
58 plResult BuildRecastPolyMesh(const plRecastConfig& config, rcPolyMesh& out_polyMesh, plProgress& progress);
59 static plResult BuildDetourNavMeshData(const plRecastConfig& config, const rcPolyMesh& polyMesh, plDataBuffer& NavmeshData);
60
61 struct Triangle
62 {
63 PL_DECLARE_POD_TYPE();
64
65 Triangle() = default;
66 Triangle(plInt32 a, plInt32 b, plInt32 c)
67 {
68 m_VertexIdx[0] = a;
69 m_VertexIdx[1] = b;
70 m_VertexIdx[2] = c;
71 }
72
73 plInt32 m_VertexIdx[3];
74 };
75
76 plBoundingBox m_BoundingBox;
77 plDynamicArray<plVec3> m_Vertices;
78 plDynamicArray<Triangle> m_Triangles;
79 plDynamicArray<plUInt8> m_TriangleAreaIDs;
80 plRcBuildContext* m_pRecastContext = nullptr;
81};
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
static constexpr plAngle MakeFromDegree(float fDegree)
Creates an instance of plAngle that was initialized from degree. (Performs a conversion)
Definition Angle_inl.h:33
Manages the way a progress bar is subdivided and advanced.
Definition Progress.h:36
Definition NavMeshBuilder.h:42
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
Definition NavMeshBuilder.h:19
Definition RecastNavMeshResource.h:12
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54