1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-28 07:07:45 +00:00

pcb_reader:

- export obj if it doesnt exist already
This commit is contained in:
Tahir Akhlaq 2019-01-26 11:30:25 +00:00
parent 4c15aae042
commit c2dab83c8b
2 changed files with 49 additions and 7 deletions

View file

@ -87,10 +87,13 @@ bool TiledNavmeshGenerator::init( const std::string& path )
TiledNavmeshGenerator::~TiledNavmeshGenerator() TiledNavmeshGenerator::~TiledNavmeshGenerator()
{ {
delete m_mesh; if( m_mesh )
delete m_chunkyMesh; delete m_mesh;
if( m_chunkyMesh )
delete m_chunkyMesh;
delete m_ctx; if( m_ctx )
delete m_ctx;
dtFreeNavMesh( m_navMesh ); dtFreeNavMesh( m_navMesh );
dtFreeNavMeshQuery( m_navQuery ); dtFreeNavMeshQuery( m_navQuery );

View file

@ -9,6 +9,7 @@
#include <chrono> #include <chrono>
#include "exporter.h" #include "exporter.h"
#include "obj_exporter.h"
#include "nav/TiledNavmeshGenerator.h" #include "nav/TiledNavmeshGenerator.h"
#include <experimental/filesystem> #include <experimental/filesystem>
@ -25,13 +26,18 @@ public:
static std::string currPath = std::experimental::filesystem::current_path().string(); static std::string currPath = std::experimental::filesystem::current_path().string();
auto dir = fs::current_path().string() + "/pcb_export/" + zone.name + "/"; auto dir = fs::current_path().string() + "/pcb_export/" + zone.name + "/";
auto fileName = dir + zone.name + ".obj"; auto fileName = dir + zone.name;
std::error_code e;
if( !fs::exists( fileName, e ) )
ObjExporter::exportZone( zone );
TiledNavmeshGenerator gen; TiledNavmeshGenerator gen;
if( !gen.init( fileName ) ) auto objName = fileName + ".obj";
if( !gen.init( objName ) )
{ {
printf( "[Navmesh] failed to init TiledNavmeshGenerator for file '%s'\n", fileName.c_str() ); printf( "[Navmesh] failed to init TiledNavmeshGenerator for file '%s'\n", zone.name.c_str() );
return; return;
} }
@ -45,13 +51,46 @@ public:
auto end = std::chrono::high_resolution_clock::now(); auto end = std::chrono::high_resolution_clock::now();
printf( "[Navmesh] Finished exporting %s in %lu ms\n", printf( "[Navmesh] Finished exporting %s in %lu ms\n",
fileName.c_str(), zone.name.c_str(),
std::chrono::duration_cast< std::chrono::milliseconds >( end - start ).count() ); std::chrono::duration_cast< std::chrono::milliseconds >( end - start ).count() );
} }
static void exportGroup( const std::string& zoneName, const ExportedGroup& group ) 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 #endif // !OBJ_EXPORTER_H