diff --git a/src/tools/pcb_reader/nav/TiledNavmeshGenerator.cpp b/src/tools/pcb_reader/nav/TiledNavmeshGenerator.cpp index 3fa19668..55f00c19 100644 --- a/src/tools/pcb_reader/nav/TiledNavmeshGenerator.cpp +++ b/src/tools/pcb_reader/nav/TiledNavmeshGenerator.cpp @@ -87,10 +87,13 @@ bool TiledNavmeshGenerator::init( const std::string& path ) TiledNavmeshGenerator::~TiledNavmeshGenerator() { - delete m_mesh; - delete m_chunkyMesh; + if( m_mesh ) + delete m_mesh; + if( m_chunkyMesh ) + delete m_chunkyMesh; - delete m_ctx; + if( m_ctx ) + delete m_ctx; dtFreeNavMesh( m_navMesh ); dtFreeNavMeshQuery( m_navQuery ); diff --git a/src/tools/pcb_reader/navmesh_exporter.h b/src/tools/pcb_reader/navmesh_exporter.h index f9d57a4e..79608607 100644 --- a/src/tools/pcb_reader/navmesh_exporter.h +++ b/src/tools/pcb_reader/navmesh_exporter.h @@ -9,6 +9,7 @@ #include #include "exporter.h" +#include "obj_exporter.h" #include "nav/TiledNavmeshGenerator.h" #include @@ -25,13 +26,18 @@ public: static std::string currPath = std::experimental::filesystem::current_path().string(); 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; - 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; } @@ -45,13 +51,46 @@ public: auto end = std::chrono::high_resolution_clock::now(); 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() ); } 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