Added a LoadObj function that reads from a std::istream.

+ Added a LoadObj function that reads from a std::istream.  This should allow
   more generic usage and possibly make testing a little easier.
   o This LoadObj accepts a function that returns a
     std::unique_ptr<std::istream> for a material.
 + Modified LoadMtl to read from a std::istream to allow more generic
   usage.
 + Modified test.cc to check that the changes work as expected and nothing was
   broken.

Tests:
 + Compiled test.cc, checked diff of output against pre change output.
   Same output where expected.
This commit is contained in:
E J Burns
2014-04-28 14:37:32 +01:00
parent c33b0cf6cc
commit 08ff49d2d0
3 changed files with 179 additions and 42 deletions

View File

@@ -9,6 +9,8 @@
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <memory>
namespace tinyobj {
@@ -49,6 +51,13 @@ typedef struct
mesh_t mesh;
} shape_t;
/// typedef for a function that returns a pointer to an istream for
/// the material identified by the const std::string&
typedef std::function<
std::unique_ptr<std::istream>(
const std::string&)
> GetMtlIStreamFn;
/// Loads .obj from a file.
/// 'shapes' will be filled with parsed shape data
/// The function returns error string.
@@ -59,6 +68,13 @@ std::string LoadObj(
const char* filename,
const char* mtl_basepath = NULL);
/// Loads object from a std::istream, uses GetMtlIStreamFn to retrieve
/// std::istream for materials.
/// Returns empty string when loading .obj success.
std::string LoadObj(
std::vector<shape_t>& shapes, // [output]
std::istream& inStream,
GetMtlIStreamFn getMatFn);
};
#endif // _TINY_OBJ_LOADER_H