Options to enable/disable write recast mesh and nav mesh into file

pull/541/head
elsid 7 years ago
parent 6d233ae868
commit 41caca24ee
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -184,6 +184,10 @@ namespace MWWorld
navigatorSettings.mMaxPolygonPathSize = static_cast<std::size_t>(Settings::Manager::getInt("max polygon path size", "Navigator"));
navigatorSettings.mMaxSmoothPathSize = static_cast<std::size_t>(Settings::Manager::getInt("max smooth path size", "Navigator"));
navigatorSettings.mTrianglesPerChunk = static_cast<std::size_t>(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));

@ -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;

@ -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);
}
}

@ -1,62 +1,23 @@
#include "debug.hpp"
#define OPENMW_WRITE_TO_FILE
#define OPENMW_WRITE_OBJ
#ifdef OPENMW_WRITE_OBJ
#include "exceptions.hpp"
#include <fstream>
#endif
#ifdef OPENMW_WRITE_TO_FILE
#include "exceptions.hpp"
#include "recastmesh.hpp"
#include <DetourNavMesh.h>
#include <fstream>
#endif
#include <iomanip>
#include <limits>
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<float>& vertices, const std::vector<int>& 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";
const auto path = pathPrefix + "recastmesh." + revision + ".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<float>::max_exponent10);
std::size_t count = 0;
for (auto v : vertices)
for (auto v : recastMesh.getVertices())
{
if (count % 3 == 0)
{
@ -69,7 +30,7 @@ namespace DetourNavigator
}
file << '\n';
count = 0;
for (auto v : indices)
for (auto v : recastMesh.getIndices())
{
if (count % 3 == 0)
{
@ -82,56 +43,35 @@ namespace DetourNavigator
}
file << '\n';
}
#endif
#ifdef OPENMW_WRITE_TO_FILE
void writeToFile(const RecastMesh& recastMesh, const std::string& revision)
void writeToFile(const dtNavMesh& navMesh, const std::string& pathPrefix, const std::string& revision)
{
const auto path = "recastmesh." + revision + ".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<float>::max_exponent10);
std::size_t count = 0;
for (auto v : recastMesh.getVertices())
const int navMeshSetMagic = 'M' << 24 | 'S' << 16 | 'E' << 8 | 'T'; //'MSET';
const int navMeshSetVersion = 1;
struct NavMeshSetHeader
{
if (count % 3 == 0)
{
if (count != 0)
file << '\n';
file << 'v';
}
file << ' ' << v;
++count;
}
file << '\n';
count = 0;
for (auto v : recastMesh.getIndices())
int magic;
int version;
int numTiles;
dtNavMeshParams params;
};
struct NavMeshTileHeader
{
if (count % 3 == 0)
{
if (count != 0)
file << '\n';
file << 'f';
}
file << ' ' << (v + 1);
++count;
}
file << '\n';
}
dtTileRef tileRef;
int dataSize;
};
void writeToFile(const dtNavMesh& navMesh, const std::string& revision)
{
const auto path = "navmesh." + revision + ".bin";
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
}

@ -11,13 +11,7 @@
#include <sstream>
#include <string>
#ifdef OPENMW_WRITE_OBJ
#include <vector>
#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<float>& vertices, const std::vector<int>& 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<Ts>(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

@ -13,6 +13,9 @@
#include <Recast.h>
#include <RecastAlloc.h>
#include <iomanip>
#include <limits>
namespace
{
using namespace DetourNavigator;

@ -1,4 +1,5 @@
#include "recastmesh.hpp"
#include "chunkytrimesh.hpp"
#include "settings.hpp"
namespace DetourNavigator

@ -1,4 +1,5 @@
#include "recastmeshbuilder.hpp"
#include "chunkytrimesh.hpp"
#include "settings.hpp"
#include "settingsutils.hpp"

@ -1,12 +1,14 @@
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGS_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGS_H
#include <cstdint>
#include <string>
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;
};
}

@ -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 =

Loading…
Cancel
Save