2018-03-14 01:49:08 +03:00
|
|
|
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESH_H
|
|
|
|
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESH_H
|
|
|
|
|
2018-07-18 22:09:50 +03:00
|
|
|
#include "areatype.hpp"
|
2018-10-13 20:59:00 +03:00
|
|
|
#include "bounds.hpp"
|
2018-03-14 01:49:08 +03:00
|
|
|
|
2021-02-04 00:14:29 +01:00
|
|
|
#include <components/bullethelpers/operators.hpp>
|
|
|
|
|
2021-07-14 21:54:41 +02:00
|
|
|
#include <osg/Vec3f>
|
|
|
|
|
2018-03-14 01:49:08 +03:00
|
|
|
#include <memory>
|
2018-10-01 01:33:25 +03:00
|
|
|
#include <string>
|
2018-03-14 01:49:08 +03:00
|
|
|
#include <vector>
|
2021-02-04 00:14:29 +01:00
|
|
|
#include <tuple>
|
2018-03-14 01:49:08 +03:00
|
|
|
|
|
|
|
namespace DetourNavigator
|
|
|
|
{
|
2021-07-11 21:43:19 +02:00
|
|
|
class Mesh
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Mesh(std::vector<int>&& indices, std::vector<float>&& vertices, std::vector<AreaType>&& areaTypes);
|
|
|
|
|
|
|
|
const std::vector<int>& getIndices() const noexcept { return mIndices; }
|
|
|
|
const std::vector<float>& getVertices() const noexcept { return mVertices; }
|
|
|
|
const std::vector<AreaType>& getAreaTypes() const noexcept { return mAreaTypes; }
|
|
|
|
std::size_t getVerticesCount() const noexcept { return mVertices.size() / 3; }
|
|
|
|
std::size_t getTrianglesCount() const noexcept { return mAreaTypes.size(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<int> mIndices;
|
|
|
|
std::vector<float> mVertices;
|
|
|
|
std::vector<AreaType> mAreaTypes;
|
|
|
|
|
|
|
|
friend inline bool operator<(const Mesh& lhs, const Mesh& rhs) noexcept
|
|
|
|
{
|
|
|
|
return std::tie(lhs.mIndices, lhs.mVertices, lhs.mAreaTypes)
|
|
|
|
< std::tie(rhs.mIndices, rhs.mVertices, rhs.mAreaTypes);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend inline std::size_t getSize(const Mesh& value) noexcept
|
|
|
|
{
|
|
|
|
return value.mIndices.size() * sizeof(int)
|
|
|
|
+ value.mVertices.size() * sizeof(float)
|
|
|
|
+ value.mAreaTypes.size() * sizeof(AreaType);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-14 22:00:16 +02:00
|
|
|
struct Cell
|
2021-07-14 17:30:47 +02:00
|
|
|
{
|
2021-07-14 22:00:16 +02:00
|
|
|
int mSize;
|
2021-07-14 21:54:41 +02:00
|
|
|
osg::Vec3f mShift;
|
2021-07-14 17:30:47 +02:00
|
|
|
};
|
|
|
|
|
2018-03-14 01:49:08 +03:00
|
|
|
class RecastMesh
|
|
|
|
{
|
|
|
|
public:
|
2021-07-14 22:00:16 +02:00
|
|
|
RecastMesh(std::size_t generation, std::size_t revision, Mesh mesh, std::vector<Cell> water);
|
2019-11-27 23:45:01 +01:00
|
|
|
|
|
|
|
std::size_t getGeneration() const
|
|
|
|
{
|
|
|
|
return mGeneration;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t getRevision() const
|
|
|
|
{
|
|
|
|
return mRevision;
|
|
|
|
}
|
2018-03-14 01:49:08 +03:00
|
|
|
|
2021-07-11 21:43:19 +02:00
|
|
|
const Mesh& getMesh() const noexcept { return mMesh; }
|
2018-07-12 11:44:11 +03:00
|
|
|
|
2021-07-14 22:00:16 +02:00
|
|
|
const std::vector<Cell>& getWater() const
|
2018-07-20 22:11:34 +03:00
|
|
|
{
|
|
|
|
return mWater;
|
|
|
|
}
|
|
|
|
|
2018-10-13 20:59:00 +03:00
|
|
|
const Bounds& getBounds() const
|
2018-04-01 22:17:04 +03:00
|
|
|
{
|
2018-10-13 20:59:00 +03:00
|
|
|
return mBounds;
|
2018-04-01 22:17:04 +03:00
|
|
|
}
|
|
|
|
|
2018-03-14 01:49:08 +03:00
|
|
|
private:
|
2019-11-27 23:45:01 +01:00
|
|
|
std::size_t mGeneration;
|
|
|
|
std::size_t mRevision;
|
2021-07-11 21:43:19 +02:00
|
|
|
Mesh mMesh;
|
2021-07-14 22:00:16 +02:00
|
|
|
std::vector<Cell> mWater;
|
2018-10-13 20:59:00 +03:00
|
|
|
Bounds mBounds;
|
2021-07-14 00:03:10 +02:00
|
|
|
|
2021-07-11 21:43:19 +02:00
|
|
|
friend inline bool operator <(const RecastMesh& lhs, const RecastMesh& rhs) noexcept
|
2021-07-14 00:03:10 +02:00
|
|
|
{
|
2021-07-11 21:43:19 +02:00
|
|
|
return std::tie(lhs.mMesh, lhs.mWater) < std::tie(rhs.mMesh, rhs.mWater);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend inline std::size_t getSize(const RecastMesh& value) noexcept
|
|
|
|
{
|
2021-07-14 22:00:16 +02:00
|
|
|
return getSize(value.mMesh) + value.mWater.size() * sizeof(Cell);
|
2021-07-14 00:03:10 +02:00
|
|
|
}
|
2018-03-14 01:49:08 +03:00
|
|
|
};
|
2021-02-04 00:14:29 +01:00
|
|
|
|
2021-07-14 22:00:16 +02:00
|
|
|
inline bool operator<(const Cell& lhs, const Cell& rhs) noexcept
|
2021-02-04 00:14:29 +01:00
|
|
|
{
|
2021-07-14 22:00:16 +02:00
|
|
|
return std::tie(lhs.mSize, lhs.mShift) < std::tie(rhs.mSize, rhs.mShift);
|
2021-02-04 00:14:29 +01:00
|
|
|
}
|
2018-03-14 01:49:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|