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