From f8909218ee4ee52943b17b97d315fc797c33e24e Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 1 Apr 2018 22:17:04 +0300 Subject: [PATCH] Store recast mesh bounds --- components/detournavigator/makenavmesh.cpp | 6 ++---- components/detournavigator/recastmesh.cpp | 4 +++- components/detournavigator/recastmesh.hpp | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/components/detournavigator/makenavmesh.cpp b/components/detournavigator/makenavmesh.cpp index b08cba2382..9be9ca5c30 100644 --- a/components/detournavigator/makenavmesh.cpp +++ b/components/detournavigator/makenavmesh.cpp @@ -252,10 +252,8 @@ namespace DetourNavigator getRadius(settings, agentHalfExtents), " changedTile=", changedTile); - osg::Vec3f boundsMin; - osg::Vec3f boundsMax; - rcCalcBounds(recastMesh.getVertices().data(), int(recastMesh.getVerticesCount()), - boundsMin.ptr(), boundsMax.ptr()); + const auto& boundsMin = recastMesh.getBoundsMin(); + const auto& boundsMax = recastMesh.getBoundsMax(); const auto& params = *navMesh.lock()->getParams(); const osg::Vec3f origin(params.orig[0], params.orig[1], params.orig[2]); diff --git a/components/detournavigator/recastmesh.cpp b/components/detournavigator/recastmesh.cpp index 866fdfa408..45c2f98e78 100644 --- a/components/detournavigator/recastmesh.cpp +++ b/components/detournavigator/recastmesh.cpp @@ -1,7 +1,8 @@ #include "recastmesh.hpp" -#include "chunkytrimesh.hpp" #include "settings.hpp" +#include + namespace DetourNavigator { RecastMesh::RecastMesh(std::vector indices, std::vector vertices, const Settings& settings) @@ -9,5 +10,6 @@ namespace DetourNavigator , mVertices(std::move(vertices)) , mChunkyTriMesh(mVertices, mIndices, settings.mTrianglesPerChunk) { + rcCalcBounds(mVertices.data(), static_cast(getVerticesCount()), mBoundsMin.ptr(), mBoundsMax.ptr()); } } diff --git a/components/detournavigator/recastmesh.hpp b/components/detournavigator/recastmesh.hpp index 35d5cb2472..8dcb717e23 100644 --- a/components/detournavigator/recastmesh.hpp +++ b/components/detournavigator/recastmesh.hpp @@ -6,6 +6,8 @@ #include #include +#include + namespace DetourNavigator { struct Settings; @@ -40,10 +42,22 @@ namespace DetourNavigator return mChunkyTriMesh; } + const osg::Vec3f& getBoundsMin() const + { + return mBoundsMin; + } + + const osg::Vec3f& getBoundsMax() const + { + return mBoundsMax; + } + private: std::vector mIndices; std::vector mVertices; ChunkyTriMesh mChunkyTriMesh; + osg::Vec3f mBoundsMin; + osg::Vec3f mBoundsMax; }; }