1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-06 00:55:50 +00:00

Merge branch 'fix_write_recast_mesh' into 'master'

Fix writing to file for RecastMesh

See merge request OpenMW/openmw!1278
This commit is contained in:
psi29a 2021-10-11 08:20:33 +00:00
commit f014edd27c
3 changed files with 12 additions and 15 deletions

View File

@ -409,7 +409,7 @@ namespace DetourNavigator
}
if (recastMesh && mSettings.get().mEnableWriteRecastMeshToFile)
writeToFile(*recastMesh, mSettings.get().mRecastMeshPathPrefix + std::to_string(job.mChangedTile.x())
+ "_" + std::to_string(job.mChangedTile.y()) + "_", recastMeshRevision);
+ "_" + std::to_string(job.mChangedTile.y()) + "_", recastMeshRevision, mSettings);
if (mSettings.get().mEnableWriteNavMeshToFile)
if (const auto shared = job.mNavMeshCacheItem.lock())
writeToFile(shared->lockConst()->getImpl(), mSettings.get().mNavMeshPathPrefix, navMeshRevision);

View File

@ -1,6 +1,8 @@
#include "debug.hpp"
#include "exceptions.hpp"
#include "recastmesh.hpp"
#include "settings.hpp"
#include "settingsutils.hpp"
#include <DetourNavMesh.h>
@ -9,7 +11,7 @@
namespace DetourNavigator
{
void writeToFile(const RecastMesh& recastMesh, const std::string& pathPrefix, const std::string& revision)
void writeToFile(const RecastMesh& recastMesh, const std::string& pathPrefix, const std::string& revision, const Settings& settings)
{
const auto path = pathPrefix + "recastmesh" + revision + ".obj";
boost::filesystem::ofstream file(boost::filesystem::path(path), std::ios::out);
@ -17,20 +19,14 @@ namespace DetourNavigator
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 (float v : recastMesh.getMesh().getVertices())
std::vector<float> vertices = recastMesh.getMesh().getVertices();
for (std::size_t i = 0; i < vertices.size(); i += 3)
{
if (count % 3 == 0)
{
if (count != 0)
file << '\n';
file << 'v';
}
file << ' ' << v;
++count;
file << "v " << toNavMeshCoordinates(settings, vertices[i]) << ' '
<< toNavMeshCoordinates(settings, vertices[i + 2]) << ' '
<< toNavMeshCoordinates(settings, vertices[i + 1]) << '\n';
}
file << '\n';
count = 0;
std::size_t count = 0;
for (int v : recastMesh.getMesh().getIndices())
{
if (count % 3 == 0)

View File

@ -48,8 +48,9 @@ namespace DetourNavigator
}
class RecastMesh;
struct Settings;
void writeToFile(const RecastMesh& recastMesh, const std::string& pathPrefix, const std::string& revision);
void writeToFile(const RecastMesh& recastMesh, const std::string& pathPrefix, const std::string& revision, const Settings& settings);
void writeToFile(const dtNavMesh& navMesh, const std::string& pathPrefix, const std::string& revision);
}