diff --git a/RecastDemo/Include/MeshLoaderObj.h b/RecastDemo/Include/MeshLoaderObj.h index d32db484..2d388d5f 100644 --- a/RecastDemo/Include/MeshLoaderObj.h +++ b/RecastDemo/Include/MeshLoaderObj.h @@ -24,7 +24,6 @@ class MeshLoaderObj { public: - bool load(const std::string& fileName); void load(char* buf, size_t bufLen); [[nodiscard]] const float* getVerts() const { return verts.data(); } diff --git a/RecastDemo/Source/InputGeom.cpp b/RecastDemo/Source/InputGeom.cpp index fce2d963..af837dfe 100644 --- a/RecastDemo/Source/InputGeom.cpp +++ b/RecastDemo/Source/InputGeom.cpp @@ -20,6 +20,7 @@ #include "ChunkyTriMesh.h" #include "DebugDraw.h" +#include "Filelist.h" #include "MeshLoaderObj.h" #include "Recast.h" #include "Sample.h" @@ -135,6 +136,14 @@ static char* parseRow(char* buf, char* bufEnd, char* row, int len) bool InputGeom::loadMesh(rcContext* ctx, const std::string& filepath) { + char* buffer; + size_t bufferLen; + if (!tryReadFile(filepath, &buffer, &bufferLen)) + { + ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not load '%s'", filepath.c_str()); + return false; + } + if (meshLoader) { delete chunkyMesh; @@ -146,16 +155,7 @@ bool InputGeom::loadMesh(rcContext* ctx, const std::string& filepath) volumeCount = 0; meshLoader = new MeshLoaderObj; - if (!meshLoader) - { - ctx->log(RC_LOG_ERROR, "loadMesh: Out of memory 'm_mesh'."); - return false; - } - if (!meshLoader->load(filepath)) - { - ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not load '%s'", filepath.c_str()); - return false; - } + meshLoader->load(buffer, bufferLen); rcCalcBounds(meshLoader->getVerts(), meshLoader->getVertCount(), meshBMin, meshBMax); diff --git a/RecastDemo/Source/MeshLoaderObj.cpp b/RecastDemo/Source/MeshLoaderObj.cpp index 8efc3519..f704045d 100644 --- a/RecastDemo/Source/MeshLoaderObj.cpp +++ b/RecastDemo/Source/MeshLoaderObj.cpp @@ -102,51 +102,6 @@ int readFace(char* row, int* data, int maxDataLen, int vertCount) } } -bool MeshLoaderObj::load(const std::string& newFilename) -{ - char* buf = 0; - FILE* fp = fopen(newFilename.c_str(), "rb"); - if (!fp) - { - return false; - } - if (fseek(fp, 0, SEEK_END) != 0) - { - fclose(fp); - return false; - } - long bufSize = ftell(fp); - if (bufSize < 0) - { - fclose(fp); - return false; - } - if (fseek(fp, 0, SEEK_SET) != 0) - { - fclose(fp); - return false; - } - buf = new char[bufSize]; - if (!buf) - { - fclose(fp); - return false; - } - size_t readLen = fread(buf, bufSize, 1, fp); - fclose(fp); - - if (readLen != 1) - { - delete[] buf; - return false; - } - - load(buf, bufSize); - delete[] buf; - filename = newFilename; - return true; -} - void MeshLoaderObj::load(char* buf, size_t bufLen) { char* src = buf;