From ac56acdd9f5cbfb1bb2b1199ebe93c60192b0fd9 Mon Sep 17 00:00:00 2001 From: cignoni Date: Thu, 11 Dec 2014 21:34:46 +0000 Subject: [PATCH] Added the OpenMem and OpenStream version of the OFF importer to allow generic use of the importer --- wrap/io_trimesh/import_off.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/wrap/io_trimesh/import_off.h b/wrap/io_trimesh/import_off.h index 7fe2551b..d4f9bb8e 100644 --- a/wrap/io_trimesh/import_off.h +++ b/wrap/io_trimesh/import_off.h @@ -98,6 +98,15 @@ public: return Open(mesh,filename,loadmask,cb); } + static int OpenMem(MESH_TYPE &mesh, const char *mem, size_t sz, int &loadmask, + CallBackPos *cb=0) + { + std::string str; + str.append(mem,sz); + std::istringstream strm(str); + return OpenStream(mesh,strm,loadmask,cb); + } + /*! * Standard call for reading a mesh. * @@ -111,7 +120,12 @@ public: std::ifstream stream(filename); if (stream.fail()) return CantOpen; + return OpenStream(mesh,stream,loadmask,cb); + } + static int OpenStream(MESH_TYPE &mesh, std::istream &stream, int &loadmask, + CallBackPos *cb=0) + { std::vector< std::string > tokens; TokenizeNextLine(stream, tokens); if(tokens.empty()) return InvalidFile_MissingOFF; @@ -593,7 +607,7 @@ protected: * \param stream The object providing the input stream * \param tokens The "tokens" in the next line */ - inline static void TokenizeNextLine(std::ifstream &stream, std::vector< std::string > &tokens) + inline static void TokenizeNextLine(std::istream &stream, std::vector< std::string > &tokens) { std::string line; do