2018-03-13 22:49:08 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESHBUILDER_H
|
|
|
|
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESHBUILDER_H
|
|
|
|
|
|
|
|
#include "recastmesh.hpp"
|
2018-04-15 22:07:18 +00:00
|
|
|
#include "tilebounds.hpp"
|
2018-03-13 22:49:08 +00:00
|
|
|
|
2021-11-04 00:57:27 +00:00
|
|
|
#include <components/resource/bulletshape.hpp>
|
|
|
|
|
2021-07-11 19:43:19 +00:00
|
|
|
#include <osg/Vec3f>
|
|
|
|
|
2018-07-20 19:11:34 +00:00
|
|
|
#include <LinearMath/btTransform.h>
|
|
|
|
|
2021-07-11 19:43:19 +00:00
|
|
|
#include <array>
|
|
|
|
#include <memory>
|
|
|
|
#include <tuple>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-04-07 20:09:42 +00:00
|
|
|
class btBoxShape;
|
2018-04-02 21:04:19 +00:00
|
|
|
class btCollisionShape;
|
|
|
|
class btCompoundShape;
|
2018-03-13 22:49:08 +00:00
|
|
|
class btConcaveShape;
|
|
|
|
class btHeightfieldTerrainShape;
|
|
|
|
class btTriangleCallback;
|
|
|
|
|
|
|
|
namespace DetourNavigator
|
|
|
|
{
|
2021-07-11 19:43:19 +00:00
|
|
|
struct RecastMeshTriangle
|
|
|
|
{
|
|
|
|
AreaType mAreaType;
|
|
|
|
std::array<osg::Vec3f, 3> mVertices;
|
|
|
|
|
|
|
|
friend inline bool operator<(const RecastMeshTriangle& lhs, const RecastMeshTriangle& rhs)
|
|
|
|
{
|
|
|
|
return std::tie(lhs.mAreaType, lhs.mVertices) < std::tie(rhs.mAreaType, rhs.mVertices);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-13 22:49:08 +00:00
|
|
|
class RecastMeshBuilder
|
|
|
|
{
|
|
|
|
public:
|
2021-07-16 18:19:11 +00:00
|
|
|
explicit RecastMeshBuilder(const TileBounds& bounds) noexcept;
|
2018-03-13 22:49:08 +00:00
|
|
|
|
2021-11-04 00:57:27 +00:00
|
|
|
void addObject(const btCollisionShape& shape, const btTransform& transform, const AreaType areaType,
|
|
|
|
osg::ref_ptr<const Resource::BulletShape> source, const ObjectTransform& objectTransform);
|
2018-04-02 21:04:19 +00:00
|
|
|
|
2018-07-18 19:09:50 +00:00
|
|
|
void addObject(const btCompoundShape& shape, const btTransform& transform, const AreaType areaType);
|
2018-04-02 21:04:19 +00:00
|
|
|
|
2018-07-18 19:09:50 +00:00
|
|
|
void addObject(const btConcaveShape& shape, const btTransform& transform, const AreaType areaType);
|
2018-03-13 22:49:08 +00:00
|
|
|
|
2018-07-18 19:09:50 +00:00
|
|
|
void addObject(const btHeightfieldTerrainShape& shape, const btTransform& transform, const AreaType areaType);
|
2018-03-13 22:49:08 +00:00
|
|
|
|
2018-07-18 19:09:50 +00:00
|
|
|
void addObject(const btBoxShape& shape, const btTransform& transform, const AreaType areaType);
|
2018-04-07 20:09:42 +00:00
|
|
|
|
2021-11-04 01:48:32 +00:00
|
|
|
void addWater(const osg::Vec2i& cellPosition, const Water& water);
|
2018-07-20 19:11:34 +00:00
|
|
|
|
2021-11-04 02:19:41 +00:00
|
|
|
void addHeightfield(const osg::Vec2i& cellPosition, int cellSize, float height);
|
2021-07-14 18:57:52 +00:00
|
|
|
|
2021-11-04 02:19:41 +00:00
|
|
|
void addHeightfield(const osg::Vec2i& cellPosition, int cellSize, const float* heights, std::size_t size,
|
2021-07-14 18:57:52 +00:00
|
|
|
float minHeight, float maxHeight);
|
|
|
|
|
2022-08-29 22:11:34 +00:00
|
|
|
std::shared_ptr<RecastMesh> create(const Version& version) &&;
|
2018-03-13 22:49:08 +00:00
|
|
|
|
|
|
|
private:
|
2021-07-16 18:19:11 +00:00
|
|
|
const TileBounds mBounds;
|
2021-07-11 19:43:19 +00:00
|
|
|
std::vector<RecastMeshTriangle> mTriangles;
|
2021-11-04 01:48:32 +00:00
|
|
|
std::vector<CellWater> mWater;
|
2021-07-14 18:57:52 +00:00
|
|
|
std::vector<Heightfield> mHeightfields;
|
|
|
|
std::vector<FlatHeightfield> mFlatHeightfields;
|
2021-11-04 00:57:27 +00:00
|
|
|
std::vector<MeshSource> mSources;
|
|
|
|
|
|
|
|
inline void addObject(const btCollisionShape& shape, const btTransform& transform, const AreaType areaType);
|
2018-03-13 22:49:08 +00:00
|
|
|
|
2018-04-15 22:07:18 +00:00
|
|
|
void addObject(const btConcaveShape& shape, const btTransform& transform, btTriangleCallback&& callback);
|
2018-03-13 22:49:08 +00:00
|
|
|
|
2019-11-29 20:17:52 +00:00
|
|
|
void addObject(
|
|
|
|
const btHeightfieldTerrainShape& shape, const btTransform& transform, btTriangleCallback&& callback);
|
2018-03-13 22:49:08 +00:00
|
|
|
};
|
2021-07-11 19:43:19 +00:00
|
|
|
|
2021-07-14 18:57:52 +00:00
|
|
|
Mesh makeMesh(std::vector<RecastMeshTriangle>&& triangles, const osg::Vec3f& shift = osg::Vec3f());
|
|
|
|
|
|
|
|
Mesh makeMesh(const Heightfield& heightfield);
|
2018-03-13 22:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|