Merge pull request #107 from Warezovvv/master

Little intuitive improvements
This commit is contained in:
Syoyo Fujita
2016-11-03 17:39:16 +09:00
committed by GitHub

View File

@@ -266,15 +266,15 @@ class MaterialReader {
class MaterialFileReader : public MaterialReader { class MaterialFileReader : public MaterialReader {
public: public:
explicit MaterialFileReader(const std::string &mtl_basepath) explicit MaterialFileReader(const std::string &mtl_basedir)
: m_mtlBasePath(mtl_basepath) {} : m_mtlBaseDir(mtl_basedir) {}
virtual ~MaterialFileReader() {} virtual ~MaterialFileReader() {}
virtual bool operator()(const std::string &matId, virtual bool operator()(const std::string &matId,
std::vector<material_t> *materials, std::vector<material_t> *materials,
std::map<std::string, int> *matMap, std::string *err); std::map<std::string, int> *matMap, std::string *err);
private: private:
std::string m_mtlBasePath; std::string m_mtlBaseDir;
}; };
class MaterialStreamReader : public MaterialReader { class MaterialStreamReader : public MaterialReader {
@@ -295,12 +295,12 @@ class MaterialStreamReader : public MaterialReader {
/// 'shapes' will be filled with parsed shape data /// 'shapes' will be filled with parsed shape data
/// Returns true when loading .obj become success. /// Returns true when loading .obj become success.
/// Returns warning and error message into `err` /// Returns warning and error message into `err`
/// 'mtl_basepath' is optional, and used for base path for .mtl file. /// 'mtl_basedir' is optional, and used for base directory for .mtl file.
/// 'triangulate' is optional, and used whether triangulate polygon face in .obj /// 'triangulate' is optional, and used whether triangulate polygon face in .obj
/// or not. /// or not.
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 = NULL, const char *filename, const char *mtl_basedir = NULL,
bool triangulate = true); bool triangulate = true);
/// Loads .obj from a file with custom user callback. /// Loads .obj from a file with custom user callback.
@@ -1279,8 +1279,8 @@ bool MaterialFileReader::operator()(const std::string &matId,
std::string *err) { std::string *err) {
std::string filepath; std::string filepath;
if (!m_mtlBasePath.empty()) { if (!m_mtlBaseDir.empty()) {
filepath = std::string(m_mtlBasePath) + matId; filepath = std::string(m_mtlBaseDir) + matId;
} else { } else {
filepath = matId; filepath = matId;
} }
@@ -1317,7 +1317,7 @@ bool MaterialStreamReader::operator()(const std::string &matId,
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_basedir,
bool trianglulate) { bool trianglulate) {
attrib->vertices.clear(); attrib->vertices.clear();
attrib->normals.clear(); attrib->normals.clear();
@@ -1335,11 +1335,11 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
return false; return false;
} }
std::string basePath; std::string baseDir;
if (mtl_basepath) { if (mtl_basedir) {
basePath = mtl_basepath; baseDir = mtl_basedir;
} }
MaterialFileReader matFileReader(basePath); MaterialFileReader matFileReader(baseDir);
return LoadObj(attrib, shapes, materials, err, &ifs, &matFileReader, return LoadObj(attrib, shapes, materials, err, &ifs, &matFileReader,
trianglulate); trianglulate);