diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index f9c2019a98..b07d96585f 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -184,6 +184,10 @@ namespace MWWorld navigatorSettings.mMaxPolygonPathSize = static_cast(Settings::Manager::getInt("max polygon path size", "Navigator")); navigatorSettings.mMaxSmoothPathSize = static_cast(Settings::Manager::getInt("max smooth path size", "Navigator")); navigatorSettings.mTrianglesPerChunk = static_cast(Settings::Manager::getInt("triangles per chunk", "Navigator")); + navigatorSettings.mEnableWriteRecastMeshToFile = Settings::Manager::getBool("enable write recast mesh to file", "Navigator"); + navigatorSettings.mEnableWriteNavMeshToFile = Settings::Manager::getBool("enable write nav mesh to file", "Navigator"); + navigatorSettings.mRecastMeshPathPrefix = Settings::Manager::getString("recast mesh path prefix", "Navigator"); + navigatorSettings.mNavMeshPathPrefix = Settings::Manager::getString("nav mesh path prefix", "Navigator"); DetourNavigator::Log::instance().setEnabled(Settings::Manager::getBool("enable log", "Navigator")); mNavigator.reset(new DetourNavigator::Navigator(navigatorSettings)); diff --git a/apps/openmw_test_suite/detournavigator/navigator.cpp b/apps/openmw_test_suite/detournavigator/navigator.cpp index 1a317da843..0e30dd9ce2 100644 --- a/apps/openmw_test_suite/detournavigator/navigator.cpp +++ b/apps/openmw_test_suite/detournavigator/navigator.cpp @@ -33,6 +33,8 @@ namespace , mEnd(215, -215, 1) , mOut(mPath) { + mSettings.mEnableWriteRecastMeshToFile = false; + mSettings.mEnableWriteNavMeshToFile = false; mSettings.mCellHeight = 0.2f; mSettings.mCellSize = 0.2f; mSettings.mDetailSampleDist = 6; diff --git a/components/detournavigator/asyncnavmeshupdater.cpp b/components/detournavigator/asyncnavmeshupdater.cpp index ba4bd3ab87..12abe63995 100644 --- a/components/detournavigator/asyncnavmeshupdater.cpp +++ b/components/detournavigator/asyncnavmeshupdater.cpp @@ -108,11 +108,13 @@ namespace DetourNavigator void AsyncNavMeshUpdater::writeDebugFiles(const Job& job) const { -#ifdef OPENMW_WRITE_TO_FILE - const auto revision = std::to_string((std::chrono::steady_clock::now() - - std::chrono::steady_clock::time_point()).count()); - writeToFile(*job.mRecastMesh, revision); - writeToFile(*job.mNavMeshCacheItem->mValue, revision); -#endif + std::string revision; + if (mSettings.get().mEnableWriteNavMeshToFile || mSettings.get().mEnableWriteRecastMeshToFile) + revision = std::to_string((std::chrono::steady_clock::now() + - std::chrono::steady_clock::time_point()).count()); + if (mSettings.get().mEnableWriteRecastMeshToFile) + writeToFile(*job.mRecastMesh, mSettings.get().mRecastMeshPathPrefix, revision); + if (mSettings.get().mEnableWriteNavMeshToFile) + writeToFile(*job.mNavMeshCacheItem->mValue, mSettings.get().mNavMeshPathPrefix, revision); } } diff --git a/components/detournavigator/debug.cpp b/components/detournavigator/debug.cpp index 0b783fd908..d1c6edefdb 100644 --- a/components/detournavigator/debug.cpp +++ b/components/detournavigator/debug.cpp @@ -1,93 +1,16 @@ #include "debug.hpp" - -#define OPENMW_WRITE_TO_FILE -#define OPENMW_WRITE_OBJ - -#ifdef OPENMW_WRITE_OBJ -#include "exceptions.hpp" - -#include -#endif - -#ifdef OPENMW_WRITE_TO_FILE #include "exceptions.hpp" #include "recastmesh.hpp" #include #include -#endif - -#include -#include - -namespace -{ -#ifdef OPENMW_WRITE_TO_FILE - static const int NAVMESHSET_MAGIC = 'M' << 24 | 'S' << 16 | 'E' << 8 | 'T'; //'MSET'; - static const int NAVMESHSET_VERSION = 1; - - struct NavMeshSetHeader - { - int magic; - int version; - int numTiles; - dtNavMeshParams params; - }; - - struct NavMeshTileHeader - { - dtTileRef tileRef; - int dataSize; - }; -#endif -} namespace DetourNavigator { -// Use to dump scene to load from recastnavigation demo tool -#ifdef OPENMW_WRITE_OBJ - void writeObj(const std::vector& vertices, const std::vector& indices) + void writeToFile(const RecastMesh& recastMesh, const std::string& pathPrefix, const std::string& revision) { - const auto path = std::string("scene.") + std::to_string(std::time(nullptr)) + ".obj"; - std::ofstream file(path); - if (!file.is_open()) - throw NavigatorException("Open file failed: " + path); - file.exceptions(std::ios::failbit | std::ios::badbit); - file.precision(std::numeric_limits::max_exponent10); - std::size_t count = 0; - for (auto v : vertices) - { - if (count % 3 == 0) - { - if (count != 0) - file << '\n'; - file << 'v'; - } - file << ' ' << v; - ++count; - } - file << '\n'; - count = 0; - for (auto v : indices) - { - if (count % 3 == 0) - { - if (count != 0) - file << '\n'; - file << 'f'; - } - file << ' ' << (v + 1); - ++count; - } - file << '\n'; - } -#endif - -#ifdef OPENMW_WRITE_TO_FILE - void writeToFile(const RecastMesh& recastMesh, const std::string& revision) - { - const auto path = "recastmesh." + revision + ".obj"; + const auto path = pathPrefix + "recastmesh." + revision + ".obj"; std::ofstream file(path); if (!file.is_open()) throw NavigatorException("Open file failed: " + path); @@ -121,17 +44,34 @@ namespace DetourNavigator file << '\n'; } - void writeToFile(const dtNavMesh& navMesh, const std::string& revision) + void writeToFile(const dtNavMesh& navMesh, const std::string& pathPrefix, const std::string& revision) { - const auto path = "navmesh." + revision + ".bin"; + const int navMeshSetMagic = 'M' << 24 | 'S' << 16 | 'E' << 8 | 'T'; //'MSET'; + const int navMeshSetVersion = 1; + + struct NavMeshSetHeader + { + int magic; + int version; + int numTiles; + dtNavMeshParams params; + }; + + struct NavMeshTileHeader + { + dtTileRef tileRef; + int dataSize; + }; + + const auto path = pathPrefix + "navmesh." + revision + ".bin"; std::ofstream file(path, std::ios::binary); if (!file.is_open()) throw NavigatorException("Open file failed: " + path); file.exceptions(std::ios::failbit | std::ios::badbit); NavMeshSetHeader header; - header.magic = NAVMESHSET_MAGIC; - header.version = NAVMESHSET_VERSION; + header.magic = navMeshSetMagic; + header.version = navMeshSetVersion; header.numTiles = 0; for (int i = 0; i < navMesh.getMaxTiles(); ++i) { @@ -159,5 +99,4 @@ namespace DetourNavigator file.write(const_char_ptr(tile->data), tile->dataSize); } } -#endif } diff --git a/components/detournavigator/debug.hpp b/components/detournavigator/debug.hpp index 59bfb73d44..2a9f851a36 100644 --- a/components/detournavigator/debug.hpp +++ b/components/detournavigator/debug.hpp @@ -11,13 +11,7 @@ #include #include -#ifdef OPENMW_WRITE_OBJ -#include -#endif - -#ifdef OPENMW_WRITE_TO_FILE class dtNavMesh; -#endif namespace DetourNavigator { @@ -26,19 +20,8 @@ namespace DetourNavigator return stream << "TileBounds {" << value.mMin << ", " << value.mMax << "}"; } -// Use to dump scene to load from recastnavigation demo tool -#ifdef OPENMW_WRITE_OBJ - void writeObj(const std::vector& vertices, const std::vector& indices); -#endif - -#ifdef OPENMW_WRITE_TO_FILE class RecastMesh; - void writeToFile(const RecastMesh& recastMesh, const std::string& revision); - - void writeToFile(const dtNavMesh& navMesh, const std::string& revision); -#endif - class Log { public: @@ -92,6 +75,9 @@ namespace DetourNavigator write(stream, std::forward(values) ...); log.write(stream.str()); } + + void writeToFile(const RecastMesh& recastMesh, const std::string& pathPrefix, const std::string& revision); + void writeToFile(const dtNavMesh& navMesh, const std::string& pathPrefix, const std::string& revision); } #endif diff --git a/components/detournavigator/makenavmesh.cpp b/components/detournavigator/makenavmesh.cpp index eb9cd6c5a3..1c711048d3 100644 --- a/components/detournavigator/makenavmesh.cpp +++ b/components/detournavigator/makenavmesh.cpp @@ -13,6 +13,9 @@ #include #include +#include +#include + namespace { using namespace DetourNavigator; diff --git a/components/detournavigator/recastmesh.cpp b/components/detournavigator/recastmesh.cpp index eaeea92f18..866fdfa408 100644 --- a/components/detournavigator/recastmesh.cpp +++ b/components/detournavigator/recastmesh.cpp @@ -1,4 +1,5 @@ #include "recastmesh.hpp" +#include "chunkytrimesh.hpp" #include "settings.hpp" namespace DetourNavigator diff --git a/components/detournavigator/recastmeshbuilder.cpp b/components/detournavigator/recastmeshbuilder.cpp index 83caa52878..ba9b8a3de8 100644 --- a/components/detournavigator/recastmeshbuilder.cpp +++ b/components/detournavigator/recastmeshbuilder.cpp @@ -1,4 +1,5 @@ #include "recastmeshbuilder.hpp" +#include "chunkytrimesh.hpp" #include "settings.hpp" #include "settingsutils.hpp" diff --git a/components/detournavigator/settings.hpp b/components/detournavigator/settings.hpp index 11e1f99904..e06b8159f2 100644 --- a/components/detournavigator/settings.hpp +++ b/components/detournavigator/settings.hpp @@ -1,12 +1,14 @@ #ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGS_H #define OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGS_H -#include +#include namespace DetourNavigator { struct Settings { + bool mEnableWriteRecastMeshToFile; + bool mEnableWriteNavMeshToFile; float mCellHeight; float mCellSize; float mDetailSampleDist; @@ -24,6 +26,8 @@ namespace DetourNavigator std::size_t mMaxPolygonPathSize; std::size_t mMaxSmoothPathSize; std::size_t mTrianglesPerChunk; + std::string mRecastMeshPathPrefix; + std::string mNavMeshPathPrefix; }; } diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 7bc9ac6c06..58213f0893 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -593,3 +593,7 @@ triangles per chunk = 256 # Enable debug log (true, false) enable log = false +enable write recast mesh to file = false +enable write nav mesh to file = false +recast mesh path prefix = +nav mesh path prefix =