mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 07:09:40 +00:00
Options to enable/disable write recast mesh and nav mesh into file
This commit is contained in:
parent
6d233ae868
commit
41caca24ee
10 changed files with 54 additions and 108 deletions
|
@ -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,93 +1,16 @@
|
|||
#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";
|
||||
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)
|
||||
{
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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…
Reference in a new issue