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