Add stream based material reader implementation

This commit is contained in:
Merlyn Morgan-Graham
2016-10-02 00:52:45 -07:00
parent 71cc967f42
commit 7fc9b0fe97

View File

@@ -179,6 +179,19 @@ class MaterialFileReader : public MaterialReader {
std::string m_mtlBasePath; std::string m_mtlBasePath;
}; };
class MaterialStreamReader : public MaterialReader {
public:
explicit MaterialStreamReader(std::istream &inStream)
: m_inStream(inStream) {}
virtual ~MaterialStreamReader() {}
virtual bool operator()(const std::string &matId,
std::vector<material_t> *materials,
std::map<std::string, int> *matMap, std::string *err);
private:
std::istream &m_inStream;
};
/// Loads .obj from a file. /// Loads .obj from a file.
/// 'attrib', 'shapes' and 'materials' will be filled with parsed shape data /// 'attrib', 'shapes' and 'materials' will be filled with parsed shape data
/// 'shapes' will be filled with parsed shape data /// 'shapes' will be filled with parsed shape data
@@ -1010,6 +1023,22 @@ bool MaterialFileReader::operator()(const std::string &matId,
return true; return true;
} }
bool MaterialStreamReader::operator()(const std::string &matId,
std::vector<material_t> *materials,
std::map<std::string, int> *matMap,
std::string *err) {
LoadMtl(matMap, materials, &m_inStream);
if (!m_inStream) {
std::stringstream ss;
ss << "WARN: Material stream in error state."
<< " Created a default material.";
if (err) {
(*err) += ss.str();
}
}
return true;
}
bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes, bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
std::vector<material_t> *materials, std::string *err, std::vector<material_t> *materials, std::string *err,
const char *filename, const char *mtl_basepath, const char *filename, const char *mtl_basepath,