1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00

106 lines
2.9 KiB
C++
Raw Normal View History

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
#include <components/bullethelpers/operators.hpp>
#include <osg/Vec3f>
2018-03-14 01:49:08 +03:00
#include <memory>
#include <string>
2018-03-14 01:49:08 +03:00
#include <vector>
#include <tuple>
2018-03-14 01:49:08 +03:00
namespace DetourNavigator
{
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 22:00:16 +02:00
int mSize;
osg::Vec3f mShift;
};
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
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;
Mesh mMesh;
2021-07-14 22:00:16 +02:00
std::vector<Cell> mWater;
2018-10-13 20:59:00 +03:00
Bounds mBounds;
friend inline bool operator <(const RecastMesh& lhs, const RecastMesh& rhs) noexcept
{
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);
}
2018-03-14 01:49:08 +03:00
};
2021-07-14 22:00:16 +02:00
inline bool operator<(const Cell& lhs, const Cell& rhs) noexcept
{
2021-07-14 22:00:16 +02:00
return std::tie(lhs.mSize, lhs.mShift) < std::tie(rhs.mSize, rhs.mShift);
}
2018-03-14 01:49:08 +03:00
}
#endif