-
Notifications
You must be signed in to change notification settings - Fork 933
/
recastmeshbuilder.hpp
84 lines (59 loc) · 2.81 KB
/
recastmeshbuilder.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESHBUILDER_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESHBUILDER_H
#include "recastmesh.hpp"
#include "tilebounds.hpp"
#include <components/resource/bulletshape.hpp>
#include <osg/Vec3f>
#include <LinearMath/btTransform.h>
#include <array>
#include <memory>
#include <tuple>
#include <vector>
class btBoxShape;
class btCollisionShape;
class btCompoundShape;
class btConcaveShape;
class btHeightfieldTerrainShape;
class btTriangleCallback;
namespace DetourNavigator
{
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);
}
};
class RecastMeshBuilder
{
public:
explicit RecastMeshBuilder(const TileBounds& bounds) noexcept;
void addObject(const btCollisionShape& shape, const btTransform& transform, const AreaType areaType,
osg::ref_ptr<const Resource::BulletShape> source, const ObjectTransform& objectTransform);
void addObject(const btCompoundShape& shape, const btTransform& transform, const AreaType areaType);
void addObject(const btConcaveShape& shape, const btTransform& transform, const AreaType areaType);
void addObject(const btHeightfieldTerrainShape& shape, const btTransform& transform, const AreaType areaType);
void addObject(const btBoxShape& shape, const btTransform& transform, const AreaType areaType);
void addWater(const osg::Vec2i& cellPosition, const Water& water);
void addHeightfield(const osg::Vec2i& cellPosition, int cellSize, float height);
void addHeightfield(const osg::Vec2i& cellPosition, int cellSize, const float* heights, std::size_t size,
float minHeight, float maxHeight);
std::shared_ptr<RecastMesh> create(const Version& version) &&;
private:
const TileBounds mBounds;
std::vector<RecastMeshTriangle> mTriangles;
std::vector<CellWater> mWater;
std::vector<Heightfield> mHeightfields;
std::vector<FlatHeightfield> mFlatHeightfields;
std::vector<MeshSource> mSources;
inline void addObject(const btCollisionShape& shape, const btTransform& transform, const AreaType areaType);
void addObject(const btConcaveShape& shape, const btTransform& transform, btTriangleCallback&& callback);
void addObject(
const btHeightfieldTerrainShape& shape, const btTransform& transform, btTriangleCallback&& callback);
};
Mesh makeMesh(std::vector<RecastMeshTriangle>&& triangles, const osg::Vec3f& shift = osg::Vec3f());
Mesh makeMesh(const Heightfield& heightfield);
}
#endif