Separate error message into warning and error. Breaks API, so bump to version 1.3.0
This commit is contained in:
@@ -129,6 +129,7 @@ int main(int argc, char **argv) {
|
|||||||
cb.object_cb = object_cb;
|
cb.object_cb = object_cb;
|
||||||
|
|
||||||
MyMesh mesh;
|
MyMesh mesh;
|
||||||
|
std::string warn;
|
||||||
std::string err;
|
std::string err;
|
||||||
std::string filename = "../../models/cornell_box.obj";
|
std::string filename = "../../models/cornell_box.obj";
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
@@ -143,7 +144,11 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
tinyobj::MaterialFileReader mtlReader("../../models/");
|
tinyobj::MaterialFileReader mtlReader("../../models/");
|
||||||
|
|
||||||
bool ret = tinyobj::LoadObjWithCallback(ifs, cb, &mesh, &mtlReader, &err);
|
bool ret = tinyobj::LoadObjWithCallback(ifs, cb, &mesh, &mtlReader, &warn, &err);
|
||||||
|
|
||||||
|
if (!warn.empty()) {
|
||||||
|
std::cout << "WARN: " << warn << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
std::cerr << err << std::endl;
|
std::cerr << err << std::endl;
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
//
|
//
|
||||||
// Stiches multiple .obj files into one .obj.
|
// Stiches multiple .obj files into one .obj.
|
||||||
//
|
//
|
||||||
|
|
||||||
#define TINYOBJLOADER_IMPLEMENTATION
|
|
||||||
#include "../../tiny_obj_loader.h"
|
|
||||||
#include "obj_writer.h"
|
#include "obj_writer.h"
|
||||||
|
|
||||||
|
#include "../../tiny_obj_loader.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -134,8 +133,9 @@ int main(int argc, char **argv)
|
|||||||
for (int i = 0; i < num_objfiles; i++) {
|
for (int i = 0; i < num_objfiles; i++) {
|
||||||
std::cout << "Loading " << argv[i+1] << " ... " << std::flush;
|
std::cout << "Loading " << argv[i+1] << " ... " << std::flush;
|
||||||
|
|
||||||
|
std::string warn;
|
||||||
std::string err;
|
std::string err;
|
||||||
bool ret = tinyobj::LoadObj(&attributes[i], &shapes[i], &materials[i], &err, argv[i+1]);
|
bool ret = tinyobj::LoadObj(&attributes[i], &shapes[i], &materials[i], &warn, &err, argv[i+1]);
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
std::cerr << err << std::endl;
|
std::cerr << err << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -308,9 +308,13 @@ static bool LoadObjAndConvert(float bmin[3], float bmax[3],
|
|||||||
base_dir += "/";
|
base_dir += "/";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
std::string warn;
|
||||||
std::string err;
|
std::string err;
|
||||||
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, filename,
|
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, filename,
|
||||||
base_dir.c_str());
|
base_dir.c_str());
|
||||||
|
if (!warn.empty()) {
|
||||||
|
std::cout << "WARN: " << warn << std::endl;
|
||||||
|
}
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
std::cerr << err << std::endl;
|
std::cerr << err << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ bool Voxelize(const char* filename, float voxelsizex, float voxelsizey, float vo
|
|||||||
tinyobj::attrib_t attrib;
|
tinyobj::attrib_t attrib;
|
||||||
std::vector<tinyobj::shape_t> shapes;
|
std::vector<tinyobj::shape_t> shapes;
|
||||||
std::vector<tinyobj::material_t> materials;
|
std::vector<tinyobj::material_t> materials;
|
||||||
|
std::string warn;
|
||||||
std::string err;
|
std::string err;
|
||||||
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, filename);
|
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, filename);
|
||||||
|
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
printf("err: %s\n", err.c_str());
|
printf("err: %s\n", err.c_str());
|
||||||
|
|||||||
@@ -285,14 +285,19 @@ static bool TestLoadObj(const char* filename, const char* basepath = NULL,
|
|||||||
|
|
||||||
timerutil t;
|
timerutil t;
|
||||||
t.start();
|
t.start();
|
||||||
|
std::string warn;
|
||||||
std::string err;
|
std::string err;
|
||||||
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, filename,
|
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, filename,
|
||||||
basepath, triangulate);
|
basepath, triangulate);
|
||||||
t.end();
|
t.end();
|
||||||
printf("Parsing time: %lu [msecs]\n", t.msec());
|
printf("Parsing time: %lu [msecs]\n", t.msec());
|
||||||
|
|
||||||
|
if (!warn.empty()) {
|
||||||
|
std::cout << "WARN: " << warn << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
std::cerr << err << std::endl;
|
std::cerr << "ERR: " << err << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
@@ -376,16 +381,12 @@ static bool TestStreamLoadObj() {
|
|||||||
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::map<std::string, int>* matMap,
|
||||||
|
std::string* warn,
|
||||||
std::string* err) {
|
std::string* err) {
|
||||||
|
(void)err;
|
||||||
(void)matId;
|
(void)matId;
|
||||||
std::string warning;
|
LoadMtl(matMap, materials, &m_matSStream, warn);
|
||||||
LoadMtl(matMap, materials, &m_matSStream, &warning);
|
|
||||||
|
|
||||||
if (!warning.empty()) {
|
|
||||||
if (err) {
|
|
||||||
(*err) += warning;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,8 +398,9 @@ static bool TestStreamLoadObj() {
|
|||||||
tinyobj::attrib_t attrib;
|
tinyobj::attrib_t attrib;
|
||||||
std::vector<tinyobj::shape_t> shapes;
|
std::vector<tinyobj::shape_t> shapes;
|
||||||
std::vector<tinyobj::material_t> materials;
|
std::vector<tinyobj::material_t> materials;
|
||||||
|
std::string warn;
|
||||||
std::string err;
|
std::string err;
|
||||||
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, &objStream,
|
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, &objStream,
|
||||||
&matSSReader);
|
&matSSReader);
|
||||||
|
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
|
|||||||
660
tests/tester.cc
660
tests/tester.cc
File diff suppressed because it is too large
Load Diff
@@ -23,6 +23,7 @@ THE SOFTWARE.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//
|
//
|
||||||
|
// version 1.3.0 : Separate warning and error message(breaking API of LoadObj)
|
||||||
// version 1.2.3 : Added color space extension('-colorspace') to tex opts.
|
// version 1.2.3 : Added color space extension('-colorspace') to tex opts.
|
||||||
// version 1.2.2 : Parse multiple group names.
|
// version 1.2.2 : Parse multiple group names.
|
||||||
// version 1.2.1 : Added initial support for line('l') primitive(PR #178)
|
// version 1.2.1 : Added initial support for line('l') primitive(PR #178)
|
||||||
@@ -117,7 +118,8 @@ namespace tinyobj {
|
|||||||
//
|
//
|
||||||
// TinyObjLoader extension.
|
// TinyObjLoader extension.
|
||||||
//
|
//
|
||||||
// -colorspace SPACE # Color space of the texture. e.g. 'sRGB` or 'linear'
|
// -colorspace SPACE # Color space of the texture. e.g.
|
||||||
|
// 'sRGB` or 'linear'
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifdef TINYOBJLOADER_USE_DOUBLE
|
#ifdef TINYOBJLOADER_USE_DOUBLE
|
||||||
@@ -155,7 +157,8 @@ typedef struct {
|
|||||||
real_t bump_multiplier; // -bm (for bump maps only, default 1.0)
|
real_t bump_multiplier; // -bm (for bump maps only, default 1.0)
|
||||||
|
|
||||||
// extension
|
// extension
|
||||||
std::string colorspace; // Explicitly specify color space of stored value. Usually `sRGB` or `linear` (default empty).
|
std::string colorspace; // Explicitly specify color space of stored value.
|
||||||
|
// Usually `sRGB` or `linear` (default empty).
|
||||||
} texture_option_t;
|
} texture_option_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -307,7 +310,7 @@ class MaterialReader {
|
|||||||
|
|
||||||
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::map<std::string, int> *matMap, std::string *warn,
|
||||||
std::string *err) = 0;
|
std::string *err) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -318,7 +321,8 @@ class MaterialFileReader : public MaterialReader {
|
|||||||
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 *warn,
|
||||||
|
std::string *err);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_mtlBaseDir;
|
std::string m_mtlBaseDir;
|
||||||
@@ -331,7 +335,8 @@ class MaterialStreamReader : public MaterialReader {
|
|||||||
virtual ~MaterialStreamReader() {}
|
virtual ~MaterialStreamReader() {}
|
||||||
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 *warn,
|
||||||
|
std::string *err);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::istream &m_inStream;
|
std::istream &m_inStream;
|
||||||
@@ -341,7 +346,7 @@ class MaterialStreamReader : public MaterialReader {
|
|||||||
/// '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
|
||||||
/// Returns true when loading .obj become success.
|
/// Returns true when loading .obj become success.
|
||||||
/// Returns warning and error message into `err`
|
/// Returns warning message into `warn`, and error message into `err`
|
||||||
/// 'mtl_basedir' is optional, and used for base directory for .mtl file.
|
/// 'mtl_basedir' is optional, and used for base directory for .mtl file.
|
||||||
/// In default(`NULL'), .mtl file is searched from an application's working
|
/// In default(`NULL'), .mtl file is searched from an application's working
|
||||||
/// directory.
|
/// directory.
|
||||||
@@ -350,34 +355,36 @@ class MaterialStreamReader : public MaterialReader {
|
|||||||
/// Option 'default_vcols_fallback' specifies whether vertex colors should
|
/// Option 'default_vcols_fallback' specifies whether vertex colors should
|
||||||
/// always be defined, even if no colors are given (fallback to white).
|
/// always be defined, even if no colors are given (fallback to white).
|
||||||
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 *warn,
|
||||||
const char *filename, const char *mtl_basedir = NULL,
|
std::string *err, const char *filename,
|
||||||
bool triangulate = true, bool default_vcols_fallback = true);
|
const char *mtl_basedir = NULL, bool triangulate = true,
|
||||||
|
bool default_vcols_fallback = true);
|
||||||
|
|
||||||
/// Loads .obj from a file with custom user callback.
|
/// Loads .obj from a file with custom user callback.
|
||||||
/// .mtl is loaded as usual and parsed material_t data will be passed to
|
/// .mtl is loaded as usual and parsed material_t data will be passed to
|
||||||
/// `callback.mtllib_cb`.
|
/// `callback.mtllib_cb`.
|
||||||
/// Returns true when loading .obj/.mtl become success.
|
/// Returns true when loading .obj/.mtl become success.
|
||||||
/// Returns warning and error message into `err`
|
/// Returns warning message into `warn`, and error message into `err`
|
||||||
/// See `examples/callback_api/` for how to use this function.
|
/// See `examples/callback_api/` for how to use this function.
|
||||||
bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
|
bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
|
||||||
void *user_data = NULL,
|
void *user_data = NULL,
|
||||||
MaterialReader *readMatFn = NULL,
|
MaterialReader *readMatFn = NULL,
|
||||||
std::string *err = NULL);
|
std::string *warn = NULL, std::string *err = NULL);
|
||||||
|
|
||||||
/// Loads object from a std::istream, uses GetMtlIStreamFn to retrieve
|
/// Loads object from a std::istream, uses GetMtlIStreamFn to retrieve
|
||||||
/// std::istream for materials.
|
/// std::istream for materials.
|
||||||
/// 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`
|
||||||
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 *warn,
|
||||||
std::istream *inStream, MaterialReader *readMatFn = NULL,
|
std::string *err, std::istream *inStream,
|
||||||
bool triangulate = true, bool default_vcols_fallback = true);
|
MaterialReader *readMatFn = NULL, bool triangulate = true,
|
||||||
|
bool default_vcols_fallback = true);
|
||||||
|
|
||||||
/// Loads materials into std::map
|
/// Loads materials into std::map
|
||||||
void LoadMtl(std::map<std::string, int> *material_map,
|
void LoadMtl(std::map<std::string, int> *material_map,
|
||||||
std::vector<material_t> *materials, std::istream *inStream,
|
std::vector<material_t> *materials, std::istream *inStream,
|
||||||
std::string *warning);
|
std::string *warning, std::string *err);
|
||||||
|
|
||||||
} // namespace tinyobj
|
} // namespace tinyobj
|
||||||
|
|
||||||
@@ -721,7 +728,8 @@ static inline bool parseVertexWithColor(real_t *x, real_t *y, real_t *z,
|
|||||||
(*y) = parseReal(token, default_y);
|
(*y) = parseReal(token, default_y);
|
||||||
(*z) = parseReal(token, default_z);
|
(*z) = parseReal(token, default_z);
|
||||||
|
|
||||||
const bool found_color = parseReal(token, r) && parseReal(token, g) && parseReal(token, b);
|
const bool found_color =
|
||||||
|
parseReal(token, r) && parseReal(token, g) && parseReal(token, b);
|
||||||
|
|
||||||
if (!found_color) {
|
if (!found_color) {
|
||||||
(*r) = (*g) = (*b) = 1.0;
|
(*r) = (*g) = (*b) = 1.0;
|
||||||
@@ -959,11 +967,12 @@ static bool ParseTextureNameAndOption(std::string *texname,
|
|||||||
} else if ((0 == strncmp(token, "-mm", 3)) && IS_SPACE((token[3]))) {
|
} else if ((0 == strncmp(token, "-mm", 3)) && IS_SPACE((token[3]))) {
|
||||||
token += 4;
|
token += 4;
|
||||||
parseReal2(&(texopt->brightness), &(texopt->contrast), &token, 0.0, 1.0);
|
parseReal2(&(texopt->brightness), &(texopt->contrast), &token, 0.0, 1.0);
|
||||||
} else if ((0 == strncmp(token, "-colorspace", 11)) && IS_SPACE((token[11]))) {
|
} else if ((0 == strncmp(token, "-colorspace", 11)) &&
|
||||||
|
IS_SPACE((token[11]))) {
|
||||||
token += 12;
|
token += 12;
|
||||||
texopt->colorspace = parseString(&token);
|
texopt->colorspace = parseString(&token);
|
||||||
} else {
|
} else {
|
||||||
// Assume texture filename
|
// Assume texture filename
|
||||||
#if 0
|
#if 0
|
||||||
size_t len = strcspn(token, " \t\r"); // untile next space
|
size_t len = strcspn(token, " \t\r"); // untile next space
|
||||||
texture_name = std::string(token, token + len);
|
texture_name = std::string(token, token + len);
|
||||||
@@ -1303,7 +1312,9 @@ static void SplitString(const std::string &s, char delim,
|
|||||||
|
|
||||||
void LoadMtl(std::map<std::string, int> *material_map,
|
void LoadMtl(std::map<std::string, int> *material_map,
|
||||||
std::vector<material_t> *materials, std::istream *inStream,
|
std::vector<material_t> *materials, std::istream *inStream,
|
||||||
std::string *warning) {
|
std::string *warning, std::string *err) {
|
||||||
|
(void)err;
|
||||||
|
|
||||||
// Create a default material anyway.
|
// Create a default material anyway.
|
||||||
material_t material;
|
material_t material;
|
||||||
InitMaterial(&material);
|
InitMaterial(&material);
|
||||||
@@ -1312,7 +1323,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|||||||
bool has_d = false;
|
bool has_d = false;
|
||||||
bool has_tr = false;
|
bool has_tr = false;
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream warn_ss;
|
||||||
|
|
||||||
std::string linebuf;
|
std::string linebuf;
|
||||||
while (inStream->peek() != -1) {
|
while (inStream->peek() != -1) {
|
||||||
@@ -1455,9 +1466,9 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|||||||
material.dissolve = parseReal(&token);
|
material.dissolve = parseReal(&token);
|
||||||
|
|
||||||
if (has_tr) {
|
if (has_tr) {
|
||||||
ss << "WARN: Both `d` and `Tr` parameters defined for \""
|
warn_ss << "Both `d` and `Tr` parameters defined for \""
|
||||||
<< material.name << "\". Use the value of `d` for dissolve."
|
<< material.name << "\". Use the value of `d` for dissolve."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
has_d = true;
|
has_d = true;
|
||||||
continue;
|
continue;
|
||||||
@@ -1466,9 +1477,9 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|||||||
token += 2;
|
token += 2;
|
||||||
if (has_d) {
|
if (has_d) {
|
||||||
// `d` wins. Ignore `Tr` value.
|
// `d` wins. Ignore `Tr` value.
|
||||||
ss << "WARN: Both `d` and `Tr` parameters defined for \""
|
warn_ss << "Both `d` and `Tr` parameters defined for \""
|
||||||
<< material.name << "\". Use the value of `d` for dissolve."
|
<< material.name << "\". Use the value of `d` for dissolve."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
} else {
|
} else {
|
||||||
// We invert value of Tr(assume Tr is in range [0, 1])
|
// We invert value of Tr(assume Tr is in range [0, 1])
|
||||||
// NOTE: Interpretation of Tr is application(exporter) dependent. For
|
// NOTE: Interpretation of Tr is application(exporter) dependent. For
|
||||||
@@ -1683,14 +1694,14 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|||||||
materials->push_back(material);
|
materials->push_back(material);
|
||||||
|
|
||||||
if (warning) {
|
if (warning) {
|
||||||
(*warning) = ss.str();
|
(*warning) = warn_ss.str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MaterialFileReader::operator()(const std::string &matId,
|
bool MaterialFileReader::operator()(const std::string &matId,
|
||||||
std::vector<material_t> *materials,
|
std::vector<material_t> *materials,
|
||||||
std::map<std::string, int> *matMap,
|
std::map<std::string, int> *matMap,
|
||||||
std::string *err) {
|
std::string *warn, std::string *err) {
|
||||||
std::string filepath;
|
std::string filepath;
|
||||||
|
|
||||||
if (!m_mtlBaseDir.empty()) {
|
if (!m_mtlBaseDir.empty()) {
|
||||||
@@ -1702,21 +1713,14 @@ bool MaterialFileReader::operator()(const std::string &matId,
|
|||||||
std::ifstream matIStream(filepath.c_str());
|
std::ifstream matIStream(filepath.c_str());
|
||||||
if (!matIStream) {
|
if (!matIStream) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "WARN: Material file [ " << filepath << " ] not found." << std::endl;
|
ss << "Material file [ " << filepath << " ] not found." << std::endl;
|
||||||
if (err) {
|
if (warn) {
|
||||||
(*err) += ss.str();
|
(*warn) += ss.str();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string warning;
|
LoadMtl(matMap, materials, &matIStream, warn, err);
|
||||||
LoadMtl(matMap, materials, &matIStream, &warning);
|
|
||||||
|
|
||||||
if (!warning.empty()) {
|
|
||||||
if (err) {
|
|
||||||
(*err) += warning;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1724,32 +1728,26 @@ bool MaterialFileReader::operator()(const std::string &matId,
|
|||||||
bool MaterialStreamReader::operator()(const std::string &matId,
|
bool MaterialStreamReader::operator()(const std::string &matId,
|
||||||
std::vector<material_t> *materials,
|
std::vector<material_t> *materials,
|
||||||
std::map<std::string, int> *matMap,
|
std::map<std::string, int> *matMap,
|
||||||
std::string *err) {
|
std::string *warn, std::string *err) {
|
||||||
|
(void)err;
|
||||||
(void)matId;
|
(void)matId;
|
||||||
if (!m_inStream) {
|
if (!m_inStream) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "WARN: Material stream in error state. " << std::endl;
|
ss << "Material stream in error state. " << std::endl;
|
||||||
if (err) {
|
if (warn) {
|
||||||
(*err) += ss.str();
|
(*warn) += ss.str();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string warning;
|
LoadMtl(matMap, materials, &m_inStream, warn, err);
|
||||||
LoadMtl(matMap, materials, &m_inStream, &warning);
|
|
||||||
|
|
||||||
if (!warning.empty()) {
|
|
||||||
if (err) {
|
|
||||||
(*err) += warning;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
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 *warn,
|
||||||
const char *filename, const char *mtl_basedir,
|
std::string *err, const char *filename, const char *mtl_basedir,
|
||||||
bool trianglulate, bool default_vcols_fallback) {
|
bool trianglulate, bool default_vcols_fallback) {
|
||||||
attrib->vertices.clear();
|
attrib->vertices.clear();
|
||||||
attrib->normals.clear();
|
attrib->normals.clear();
|
||||||
@@ -1779,14 +1777,15 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
}
|
}
|
||||||
MaterialFileReader matFileReader(baseDir);
|
MaterialFileReader matFileReader(baseDir);
|
||||||
|
|
||||||
return LoadObj(attrib, shapes, materials, err, &ifs, &matFileReader,
|
return LoadObj(attrib, shapes, materials, warn, err, &ifs, &matFileReader,
|
||||||
trianglulate, default_vcols_fallback);
|
trianglulate, default_vcols_fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 *warn,
|
||||||
std::istream *inStream, MaterialReader *readMatFn /*= NULL*/,
|
std::string *err, std::istream *inStream,
|
||||||
bool triangulate, bool default_vcols_fallback) {
|
MaterialReader *readMatFn /*= NULL*/, bool triangulate,
|
||||||
|
bool default_vcols_fallback) {
|
||||||
std::stringstream errss;
|
std::stringstream errss;
|
||||||
|
|
||||||
std::vector<real_t> v;
|
std::vector<real_t> v;
|
||||||
@@ -1936,8 +1935,10 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
}
|
}
|
||||||
|
|
||||||
greatest_v_idx = greatest_v_idx > vi.v_idx ? greatest_v_idx : vi.v_idx;
|
greatest_v_idx = greatest_v_idx > vi.v_idx ? greatest_v_idx : vi.v_idx;
|
||||||
greatest_vn_idx = greatest_vn_idx > vi.vn_idx ? greatest_vn_idx : vi.vn_idx;
|
greatest_vn_idx =
|
||||||
greatest_vt_idx = greatest_vt_idx > vi.vt_idx ? greatest_vt_idx : vi.vt_idx;
|
greatest_vn_idx > vi.vn_idx ? greatest_vn_idx : vi.vn_idx;
|
||||||
|
greatest_vt_idx =
|
||||||
|
greatest_vt_idx > vi.vt_idx ? greatest_vt_idx : vi.vt_idx;
|
||||||
|
|
||||||
face.vertex_indices.push_back(vi);
|
face.vertex_indices.push_back(vi);
|
||||||
size_t n = strspn(token, " \t\r");
|
size_t n = strspn(token, " \t\r");
|
||||||
@@ -1986,19 +1987,24 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
SplitString(std::string(token), ' ', filenames);
|
SplitString(std::string(token), ' ', filenames);
|
||||||
|
|
||||||
if (filenames.empty()) {
|
if (filenames.empty()) {
|
||||||
if (err) {
|
if (warn) {
|
||||||
(*err) +=
|
(*warn) +=
|
||||||
"WARN: Looks like empty filename for mtllib. Use default "
|
"Looks like empty filename for mtllib. Use default "
|
||||||
"material. \n";
|
"material. \n";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (size_t s = 0; s < filenames.size(); s++) {
|
for (size_t s = 0; s < filenames.size(); s++) {
|
||||||
|
std::string warn_mtl;
|
||||||
std::string err_mtl;
|
std::string err_mtl;
|
||||||
bool ok = (*readMatFn)(filenames[s].c_str(), materials,
|
bool ok = (*readMatFn)(filenames[s].c_str(), materials,
|
||||||
&material_map, &err_mtl);
|
&material_map, &warn_mtl, &err_mtl);
|
||||||
|
if (warn && (!warn_mtl.empty())) {
|
||||||
|
(*warn) += warn_mtl;
|
||||||
|
}
|
||||||
|
|
||||||
if (err && (!err_mtl.empty())) {
|
if (err && (!err_mtl.empty())) {
|
||||||
(*err) += err_mtl; // This should be warn message.
|
(*err) += err_mtl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
@@ -2008,9 +2014,9 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
if (err) {
|
if (warn) {
|
||||||
(*err) +=
|
(*warn) +=
|
||||||
"WARN: Failed to load material file(s). Use default "
|
"Failed to load material file(s). Use default "
|
||||||
"material.\n";
|
"material.\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2048,14 +2054,13 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
|
|
||||||
if (names.size() < 2) {
|
if (names.size() < 2) {
|
||||||
// 'g' with empty names
|
// 'g' with empty names
|
||||||
if (err) {
|
if (warn) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "WARN: Empty group name. line: " << line_num << "\n";
|
ss << "Empty group name. line: " << line_num << "\n";
|
||||||
(*err) += ss.str();
|
(*warn) += ss.str();
|
||||||
name = "";
|
name = "";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << names[1];
|
ss << names[1];
|
||||||
|
|
||||||
@@ -2068,7 +2073,6 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
}
|
}
|
||||||
|
|
||||||
name = ss.str();
|
name = ss.str();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@@ -2190,28 +2194,25 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
vc.clear();
|
vc.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (greatest_v_idx >= static_cast<int>(v.size() / 3))
|
if (greatest_v_idx >= static_cast<int>(v.size() / 3)) {
|
||||||
{
|
if (warn) {
|
||||||
if (err) {
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "WARN: Vertex indices out of bounds.\n" << std::endl;
|
ss << "Vertex indices out of bounds.\n" << std::endl;
|
||||||
(*err) += ss.str();
|
(*warn) += ss.str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (greatest_vn_idx >= static_cast<int>(vn.size() / 3))
|
if (greatest_vn_idx >= static_cast<int>(vn.size() / 3)) {
|
||||||
{
|
if (warn) {
|
||||||
if (err) {
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "WARN: Vertex normal indices out of bounds.\n" << std::endl;
|
ss << "Vertex normal indices out of bounds.\n" << std::endl;
|
||||||
(*err) += ss.str();
|
(*warn) += ss.str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (greatest_vt_idx >= static_cast<int>(vt.size() / 2))
|
if (greatest_vt_idx >= static_cast<int>(vt.size() / 2)) {
|
||||||
{
|
if (warn) {
|
||||||
if (err) {
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "WARN: Vertex texcoord indices out of bounds.\n" << std::endl;
|
ss << "Vertex texcoord indices out of bounds.\n" << std::endl;
|
||||||
(*err) += ss.str();
|
(*warn) += ss.str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2241,6 +2242,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
|
bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
|
||||||
void *user_data /*= NULL*/,
|
void *user_data /*= NULL*/,
|
||||||
MaterialReader *readMatFn /*= NULL*/,
|
MaterialReader *readMatFn /*= NULL*/,
|
||||||
|
std::string *warn, /* = NULL*/
|
||||||
std::string *err /*= NULL*/) {
|
std::string *err /*= NULL*/) {
|
||||||
std::stringstream errss;
|
std::stringstream errss;
|
||||||
|
|
||||||
@@ -2377,19 +2379,25 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
|
|||||||
SplitString(std::string(token), ' ', filenames);
|
SplitString(std::string(token), ' ', filenames);
|
||||||
|
|
||||||
if (filenames.empty()) {
|
if (filenames.empty()) {
|
||||||
if (err) {
|
if (warn) {
|
||||||
(*err) +=
|
(*warn) +=
|
||||||
"WARN: Looks like empty filename for mtllib. Use default "
|
"Looks like empty filename for mtllib. Use default "
|
||||||
"material. \n";
|
"material. \n";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (size_t s = 0; s < filenames.size(); s++) {
|
for (size_t s = 0; s < filenames.size(); s++) {
|
||||||
|
std::string warn_mtl;
|
||||||
std::string err_mtl;
|
std::string err_mtl;
|
||||||
bool ok = (*readMatFn)(filenames[s].c_str(), &materials,
|
bool ok = (*readMatFn)(filenames[s].c_str(), &materials,
|
||||||
&material_map, &err_mtl);
|
&material_map, &warn_mtl, &err_mtl);
|
||||||
|
|
||||||
|
if (warn && (!warn_mtl.empty())) {
|
||||||
|
(*warn) += warn_mtl; // This should be warn message.
|
||||||
|
}
|
||||||
|
|
||||||
if (err && (!err_mtl.empty())) {
|
if (err && (!err_mtl.empty())) {
|
||||||
(*err) += err_mtl; // This should be warn message.
|
(*err) += err_mtl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
@@ -2399,9 +2407,9 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
if (err) {
|
if (warn) {
|
||||||
(*err) +=
|
(*warn) +=
|
||||||
"WARN: Failed to load material file(s). Use default "
|
"Failed to load material file(s). Use default "
|
||||||
"material.\n";
|
"material.\n";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user