diff --git a/cpp/inputgeom.cc b/cpp/inputgeom.cc index deb29d2..268b9d5 100644 --- a/cpp/inputgeom.cc +++ b/cpp/inputgeom.cc @@ -1,5 +1,7 @@ #include "precompile.h" +#include "Recast.h" + #include "inputgeom.h" struct BoundsItem @@ -224,7 +226,38 @@ namespace f8 void InputGeom::Init(float width, float height) { + { + verts_.reserve(3 * 4); + verts_.push_back(0); + verts_.push_back(0); + verts_.push_back(0); + + verts_.push_back(0); + verts_.push_back(0); + verts_.push_back(height); + + verts_.push_back(width); + verts_.push_back(0); + verts_.push_back(height); + + verts_.push_back(width); + verts_.push_back(0); + verts_.push_back(0); + } + { + tris_.push_back(0); + tris_.push_back(1); + tris_.push_back(2); + + tris_.push_back(0); + tris_.push_back(2); + tris_.push_back(3); + } + rcCalcBounds(GetVerts(), GetVertCount(), min_, max_); + if (!rcCreateChunkyTriMesh(GetVerts(), GetTris(), GetTriCount(), 256, &chunky_mesh_)) { + abort(); + } } } diff --git a/cpp/inputgeom.h b/cpp/inputgeom.h index bd9895b..67b5b27 100644 --- a/cpp/inputgeom.h +++ b/cpp/inputgeom.h @@ -36,13 +36,16 @@ namespace f8 const float* GetMeshBoundsMin() const { return min_; } const float* GetMeshBoundsMax() const { return max_; } const float* GetVerts() const { return !verts_.empty() ? &verts_[0] : nullptr; } - int GetVertCount() const { return verts_.size(); } + int GetVertCount() const { return verts_.size() / 3; } + const int* GetTris() const { return !tris_.empty() ? &tris_[0] : nullptr; } + int GetTriCount() const { return tris_.size() / 3; } const rcChunkyTriMesh* GetChunkyMesh() { return &chunky_mesh_; } private: float min_[3] = {0}; float max_[3] = {0}; std::vector verts_; + std::vector tris_; rcChunkyTriMesh chunky_mesh_; }; @@ -51,3 +54,4 @@ namespace f8 int rcGetChunksOverlappingRect(const rcChunkyTriMesh* cm, float bmin[2], float bmax[2], int* ids, const int maxIds); +