1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-21 04:09:42 +00:00

Fix writing to file for RecastMesh

Add missing scaling and y, z coordinates swap.
This commit is contained in:
elsid 2021-10-06 17:36:05 +02:00
parent b61140b8ba
commit 88ac77df1f
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
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);
}