1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-03 09:17:47 +00:00
sapphire/src/tools/pcb_reader/navmesh_exporter.h

97 lines
2.5 KiB
C
Raw Normal View History

#ifndef NAVMESH_EXPORTER_H
#define NAVMESH_EXPORTER_H
#include <iostream>
#include <cstdint>
#include <fstream>
#include <string>
#include <chrono>
#include "exporter.h"
#include "obj_exporter.h"
#include "nav/TiledNavmeshGenerator.h"
2019-01-26 18:45:37 +11:00
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
2019-01-23 14:26:17 +00:00
2019-01-20 21:24:36 +00:00
class NavmeshExporter
{
public:
2019-01-26 21:34:16 +11:00
static void exportZone( const ExportedZone& zone )
{
2019-01-26 21:34:16 +11:00
auto start = std::chrono::high_resolution_clock::now();
static std::string currPath = std::experimental::filesystem::current_path().string();
2019-01-26 18:45:37 +11:00
auto dir = fs::current_path().string() + "/pcb_export/" + zone.name + "/";
auto fileName = dir + zone.name;
std::error_code e;
if( !fs::exists( fileName, e ) )
ObjExporter::exportZone( zone );
2019-01-26 18:45:37 +11:00
TiledNavmeshGenerator gen;
auto objName = fileName + ".obj";
if( !gen.init( objName ) )
{
printf( "[Navmesh] failed to init TiledNavmeshGenerator for file '%s'\n", zone.name.c_str() );
return;
}
if( !gen.buildNavmesh() )
{
printf( "[Navmesh] Failed to build navmesh for '%s'\n", zone.name.c_str() );
return;
}
2019-01-26 18:45:37 +11:00
gen.saveNavmesh( zone.name );
auto end = std::chrono::high_resolution_clock::now();
2019-01-24 19:04:37 +11:00
printf( "[Navmesh] Finished exporting %s in %lu ms\n",
zone.name.c_str(),
std::chrono::duration_cast< std::chrono::milliseconds >( end - start ).count() );
}
static void exportGroup( const std::string& zoneName, const ExportedGroup& group )
{
auto start = std::chrono::high_resolution_clock::now();
static std::string currPath = std::experimental::filesystem::current_path().string();
auto dir = fs::current_path().string() + "/pcb_export/" + zoneName + "/";
auto fileName = dir + zoneName + "_" + group.name;
std::error_code e;
if( !fs::exists( fileName, e ) )
ObjExporter::exportGroup( zoneName, group );
TiledNavmeshGenerator gen;
auto objName = fileName + ".obj";
if( !gen.init( objName ) )
{
printf( "[Navmesh] failed to init TiledNavmeshGenerator for file '%s'\n", fileName.c_str() );
return;
}
if( !gen.buildNavmesh() )
{
printf( "[Navmesh] Failed to build navmesh for '%s'\n", fileName.c_str() );
return;
}
gen.saveNavmesh( fileName );
auto end = std::chrono::high_resolution_clock::now();
printf( "[Navmesh] Finished exporting %s in %lu ms\n",
fileName.c_str(),
std::chrono::duration_cast< std::chrono::milliseconds >( end - start ).count() );
}
};
#endif // !OBJ_EXPORTER_H