errors fix
This commit is contained in:
@@ -303,7 +303,8 @@ std::string matStream(
|
|||||||
virtual bool operator() (
|
virtual bool operator() (
|
||||||
const std::string& matId,
|
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::map<uint32_t, int>* matMap,
|
||||||
std::string* err)
|
std::string* err)
|
||||||
{
|
{
|
||||||
(void)matId;
|
(void)matId;
|
||||||
|
|||||||
@@ -1165,10 +1165,7 @@ static bool ParseTextureNameAndOption(std::string *texname,
|
|||||||
token += strspn(token, " \t"); // skip space
|
token += strspn(token, " \t"); // skip space
|
||||||
|
|
||||||
a_tok = token2tok(token);
|
a_tok = token2tok(token);
|
||||||
|
|
||||||
//tigra: minimize checks
|
|
||||||
if(a_tok>=TOK_blendu && a_tok<=TOK_mm)
|
|
||||||
{
|
|
||||||
//if ((0 == strncmp(token, "-blendu", 7)) && IS_SPACE((token[7])))
|
//if ((0 == strncmp(token, "-blendu", 7)) && IS_SPACE((token[7])))
|
||||||
if (a_tok == TOK_blendu)
|
if (a_tok == TOK_blendu)
|
||||||
{
|
{
|
||||||
@@ -1243,7 +1240,6 @@ static bool ParseTextureNameAndOption(std::string *texname,
|
|||||||
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 {
|
else {
|
||||||
// Assume texture filename
|
// Assume texture filename
|
||||||
#if 0
|
#if 0
|
||||||
@@ -1445,11 +1441,8 @@ std::map<uint32_t, int> *material_map,
|
|||||||
//group K
|
//group K
|
||||||
if (token[0] == 'K')
|
if (token[0] == 'K')
|
||||||
{
|
{
|
||||||
switch(token[1])
|
|
||||||
{
|
|
||||||
case 'a':
|
|
||||||
// ambient
|
// ambient
|
||||||
//if (token[1] == 'a')
|
if (token[1] == 'a')
|
||||||
{
|
{
|
||||||
token += 2;
|
token += 2;
|
||||||
real_t r, g, b;
|
real_t r, g, b;
|
||||||
@@ -1461,8 +1454,7 @@ std::map<uint32_t, int> *material_map,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// diffuse
|
// diffuse
|
||||||
case 'd':
|
if (token[1] == 'd')
|
||||||
//if (token[1] == 'd')
|
|
||||||
{
|
{
|
||||||
token += 2;
|
token += 2;
|
||||||
real_t r, g, b;
|
real_t r, g, b;
|
||||||
@@ -1474,8 +1466,7 @@ std::map<uint32_t, int> *material_map,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// specular
|
// specular
|
||||||
case 's':
|
if (token[1] == 's')
|
||||||
//if (token[1] == 's')
|
|
||||||
{
|
{
|
||||||
token += 2;
|
token += 2;
|
||||||
real_t r, g, b;
|
real_t r, g, b;
|
||||||
@@ -1487,8 +1478,7 @@ std::map<uint32_t, int> *material_map,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// transmittance
|
// transmittance
|
||||||
case 't':
|
if (token[1] == 't')
|
||||||
//if (token[1] == 't')
|
|
||||||
{
|
{
|
||||||
token += 2;
|
token += 2;
|
||||||
real_t r, g, b;
|
real_t r, g, b;
|
||||||
@@ -1500,8 +1490,7 @@ std::map<uint32_t, int> *material_map,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// emission
|
// emission
|
||||||
case 'e':
|
if (token[1] == 'e')
|
||||||
//if (token[1] == 'e')
|
|
||||||
{
|
{
|
||||||
token += 2;
|
token += 2;
|
||||||
real_t r, g, b;
|
real_t r, g, b;
|
||||||
@@ -1512,8 +1501,6 @@ std::map<uint32_t, int> *material_map,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// transmittance
|
// transmittance
|
||||||
if ( //(token[0] == 'K' && token[1] == 't') ||
|
if ( //(token[0] == 'K' && token[1] == 't') ||
|
||||||
@@ -1540,7 +1527,60 @@ std::map<uint32_t, int> *material_map,
|
|||||||
material.shininess = parseReal(&token);
|
material.shininess = parseReal(&token);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (token[0] == 'T' && token[1] == 'r') {
|
||||||
|
token += 2;
|
||||||
|
if (has_d) {
|
||||||
|
// `d` wins. Ignore `Tr` value.
|
||||||
|
ss << "WARN: Both `d` and `Tr` parameters defined for \""
|
||||||
|
<< material.name << "\". Use the value of `d` for dissolve."
|
||||||
|
<< std::endl;
|
||||||
|
} else {
|
||||||
|
// We invert value of Tr(assume Tr is in range [0, 1])
|
||||||
|
// NOTE: Interpretation of Tr is application(exporter) dependent. For
|
||||||
|
// some application(e.g. 3ds max obj exporter), Tr = d(Issue 43)
|
||||||
|
material.dissolve = 1.0f - parseReal(&token);
|
||||||
|
}
|
||||||
|
has_tr = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//tigra: refactoring for new speedup release
|
||||||
|
if (token[0] == 'P') {
|
||||||
|
|
||||||
|
// PBR: roughness
|
||||||
|
if(token[1] == 'r')
|
||||||
|
{
|
||||||
|
token += 2;
|
||||||
|
material.roughness = parseReal(&token);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
// PBR: metallic
|
||||||
|
if(token[1] == 'm')
|
||||||
|
{
|
||||||
|
token += 2;
|
||||||
|
material.metallic = parseReal(&token);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
// PBR: sheen
|
||||||
|
if(token[1] == 's')
|
||||||
|
{
|
||||||
|
token += 2;
|
||||||
|
material.sheen = parseReal(&token);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
// PBR: clearcoat thickness
|
||||||
|
if(token[1] == 'c')
|
||||||
|
{
|
||||||
|
token += 2;
|
||||||
|
material.clearcoat_thickness = parseReal(&token);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// dissolve
|
// dissolve
|
||||||
@@ -1555,43 +1595,6 @@ std::map<uint32_t, int> *material_map,
|
|||||||
}
|
}
|
||||||
has_d = true;
|
has_d = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
if (token[0] == 'T' && token[1] == 'r' && IS_SPACE(token[2])) {
|
|
||||||
token += 2;
|
|
||||||
if (has_d) {
|
|
||||||
// `d` wins. Ignore `Tr` value.
|
|
||||||
ss << "WARN: Both `d` and `Tr` parameters defined for \""
|
|
||||||
<< material.name << "\". Use the value of `d` for dissolve."
|
|
||||||
<< std::endl;
|
|
||||||
} else {
|
|
||||||
// We invert value of Tr(assume Tr is in range [0, 1])
|
|
||||||
// NOTE: Interpretation of Tr is application(exporter) dependent. For
|
|
||||||
// some application(e.g. 3ds max obj exporter), Tr = d(Issue 43)
|
|
||||||
material.dissolve = 1.0f - parseReal(&token);
|
|
||||||
}
|
|
||||||
has_tr = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//tigra: refactoring for new speedup release
|
|
||||||
if (token[0] == 'P' && IS_SPACE(token[2])) {
|
|
||||||
token += 2;
|
|
||||||
|
|
||||||
// PBR: roughness
|
|
||||||
if(token[1] == 'r')
|
|
||||||
material.roughness = parseReal(&token);
|
|
||||||
else
|
|
||||||
// PBR: metallic
|
|
||||||
if(token[1] == 'm')
|
|
||||||
material.metallic = parseReal(&token);
|
|
||||||
else
|
|
||||||
// PBR: sheen
|
|
||||||
if(token[1] == 's')
|
|
||||||
material.sheen = parseReal(&token);
|
|
||||||
else
|
|
||||||
// PBR: clearcoat thickness
|
|
||||||
if(token[1] == 'c')
|
|
||||||
material.clearcoat_thickness = parseReal(&token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2043,166 +2046,171 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
|
|
||||||
if (token[0] == '#') continue; // comment line
|
if (token[0] == '#') continue; // comment line
|
||||||
|
|
||||||
// vertex
|
if (IS_SPACE((token[1]))) {
|
||||||
if (token[0] == 'v' && IS_SPACE((token[1]))) {
|
// vertex
|
||||||
token += 2;
|
if (token[0] == 'v') {
|
||||||
real_t x, y, z;
|
token += 2;
|
||||||
real_t r, g, b;
|
real_t x, y, z;
|
||||||
parseVertexWithColor(&x, &y, &z, &r, &g, &b, &token);
|
real_t r, g, b;
|
||||||
v.push_back(x);
|
parseVertexWithColor(&x, &y, &z, &r, &g, &b, &token);
|
||||||
v.push_back(y);
|
v.push_back(x);
|
||||||
v.push_back(z);
|
v.push_back(y);
|
||||||
|
v.push_back(z);
|
||||||
|
|
||||||
vc.push_back(r);
|
vc.push_back(r);
|
||||||
vc.push_back(g);
|
vc.push_back(g);
|
||||||
vc.push_back(b);
|
vc.push_back(b);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// normal
|
// face
|
||||||
if (token[0] == 'v' && token[1] == 'n' && IS_SPACE((token[2]))) {
|
if (token[0] == 'f') {
|
||||||
token += 3;
|
token += 2;
|
||||||
real_t x, y, z;
|
token += strspn(token, " \t");
|
||||||
parseReal3(&x, &y, &z, &token);
|
|
||||||
vn.push_back(x);
|
|
||||||
vn.push_back(y);
|
|
||||||
vn.push_back(z);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// texcoord
|
std::vector<vertex_index> face;
|
||||||
if (token[0] == 'v' && token[1] == 't' && IS_SPACE((token[2]))) {
|
face.reserve(3);
|
||||||
token += 3;
|
|
||||||
real_t x, y;
|
|
||||||
parseReal2(&x, &y, &token);
|
|
||||||
vt.push_back(x);
|
|
||||||
vt.push_back(y);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// face
|
while (!IS_NEW_LINE(token[0])) {
|
||||||
if (token[0] == 'f' && IS_SPACE((token[1]))) {
|
vertex_index vi;
|
||||||
token += 2;
|
if (!parseTriple(&token, static_cast<int>(v.size() / 3),
|
||||||
token += strspn(token, " \t");
|
static_cast<int>(vn.size() / 3),
|
||||||
|
static_cast<int>(vt.size() / 2), &vi)) {
|
||||||
|
if (err) {
|
||||||
|
(*err) = "Failed parse `f' line(e.g. zero value for face index).\n";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<vertex_index> face;
|
face.push_back(vi);
|
||||||
face.reserve(3);
|
size_t n = strspn(token, " \t\r");
|
||||||
|
token += n;
|
||||||
|
}
|
||||||
|
|
||||||
while (!IS_NEW_LINE(token[0])) {
|
// replace with emplace_back + std::move on C++11
|
||||||
vertex_index vi;
|
faceGroup.push_back(std::vector<vertex_index>());
|
||||||
if (!parseTriple(&token, static_cast<int>(v.size() / 3),
|
faceGroup[faceGroup.size() - 1].swap(face);
|
||||||
static_cast<int>(vn.size() / 3),
|
|
||||||
static_cast<int>(vt.size() / 2), &vi)) {
|
|
||||||
if (err) {
|
|
||||||
(*err) = "Failed parse `f' line(e.g. zero value for face index).\n";
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
face.push_back(vi);
|
continue;
|
||||||
size_t n = strspn(token, " \t\r");
|
}
|
||||||
token += n;
|
|
||||||
}
|
|
||||||
|
|
||||||
// replace with emplace_back + std::move on C++11
|
// group name
|
||||||
faceGroup.push_back(std::vector<vertex_index>());
|
if (token[0] == 'g') {
|
||||||
faceGroup[faceGroup.size() - 1].swap(face);
|
// flush previous face group.
|
||||||
|
bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, name,
|
||||||
|
triangulate);
|
||||||
|
(void)ret; // return value not used.
|
||||||
|
|
||||||
continue;
|
if (shape.mesh.indices.size() > 0) {
|
||||||
}
|
shapes->push_back(shape);
|
||||||
|
}
|
||||||
|
|
||||||
// group name
|
shape = shape_t();
|
||||||
if (token[0] == 'g' && IS_SPACE((token[1]))) {
|
|
||||||
// flush previous face group.
|
|
||||||
bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, name,
|
|
||||||
triangulate);
|
|
||||||
(void)ret; // return value not used.
|
|
||||||
|
|
||||||
if (shape.mesh.indices.size() > 0) {
|
// material = -1;
|
||||||
shapes->push_back(shape);
|
faceGroup.clear();
|
||||||
}
|
|
||||||
|
|
||||||
shape = shape_t();
|
std::vector<std::string> names;
|
||||||
|
names.reserve(2);
|
||||||
|
|
||||||
// material = -1;
|
while (!IS_NEW_LINE(token[0])) {
|
||||||
faceGroup.clear();
|
std::string str = parseString(&token);
|
||||||
|
names.push_back(str);
|
||||||
|
token += strspn(token, " \t\r"); // skip tag
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> names;
|
assert(names.size() > 0);
|
||||||
names.reserve(2);
|
|
||||||
|
|
||||||
while (!IS_NEW_LINE(token[0])) {
|
// names[0] must be 'g', so skip the 0th element.
|
||||||
std::string str = parseString(&token);
|
if (names.size() > 1) {
|
||||||
names.push_back(str);
|
name = names[1];
|
||||||
token += strspn(token, " \t\r"); // skip tag
|
} else {
|
||||||
}
|
name = "";
|
||||||
|
}
|
||||||
|
|
||||||
assert(names.size() > 0);
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// names[0] must be 'g', so skip the 0th element.
|
// object name
|
||||||
if (names.size() > 1) {
|
if (token[0] == 'o') {
|
||||||
name = names[1];
|
// flush previous face group.
|
||||||
} else {
|
bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, name,
|
||||||
name = "";
|
triangulate);
|
||||||
}
|
if (ret) {
|
||||||
|
shapes->push_back(shape);
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
// material = -1;
|
||||||
}
|
faceGroup.clear();
|
||||||
|
shape = shape_t();
|
||||||
|
|
||||||
// object name
|
// @todo { multiple object name? }
|
||||||
if (token[0] == 'o' && IS_SPACE((token[1]))) {
|
token += 2;
|
||||||
// flush previous face group.
|
|
||||||
bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, name,
|
/*
|
||||||
triangulate);
|
std::stringstream ss;
|
||||||
if (ret) {
|
ss << token;
|
||||||
shapes->push_back(shape);
|
name = ss.str();
|
||||||
}
|
*/
|
||||||
|
|
||||||
|
name = std::string(token);
|
||||||
|
|
||||||
// material = -1;
|
continue;
|
||||||
faceGroup.clear();
|
}
|
||||||
shape = shape_t();
|
|
||||||
|
|
||||||
// @todo { multiple object name? }
|
if (token[0] == 't') {
|
||||||
token += 2;
|
tag_t tag;
|
||||||
|
|
||||||
/*
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << token;
|
|
||||||
name = ss.str();
|
|
||||||
*/
|
|
||||||
|
|
||||||
name = std::string(token);
|
|
||||||
|
|
||||||
continue;
|
token += 2;
|
||||||
}
|
|
||||||
|
|
||||||
if (token[0] == 't' && IS_SPACE(token[1])) {
|
tag.name = parseString(&token);
|
||||||
tag_t tag;
|
|
||||||
|
|
||||||
token += 2;
|
tag_sizes ts = parseTagTriple(&token);
|
||||||
|
|
||||||
tag.name = parseString(&token);
|
tag.intValues.resize(static_cast<size_t>(ts.num_ints));
|
||||||
|
|
||||||
tag_sizes ts = parseTagTriple(&token);
|
for (size_t i = 0; i < static_cast<size_t>(ts.num_ints); ++i) {
|
||||||
|
tag.intValues[i] = parseInt(&token);
|
||||||
|
}
|
||||||
|
|
||||||
tag.intValues.resize(static_cast<size_t>(ts.num_ints));
|
tag.floatValues.resize(static_cast<size_t>(ts.num_reals));
|
||||||
|
for (size_t i = 0; i < static_cast<size_t>(ts.num_reals); ++i) {
|
||||||
|
tag.floatValues[i] = parseReal(&token);
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < static_cast<size_t>(ts.num_ints); ++i) {
|
tag.stringValues.resize(static_cast<size_t>(ts.num_strings));
|
||||||
tag.intValues[i] = parseInt(&token);
|
for (size_t i = 0; i < static_cast<size_t>(ts.num_strings); ++i) {
|
||||||
}
|
tag.stringValues[i] = parseString(&token);
|
||||||
|
}
|
||||||
|
|
||||||
tag.floatValues.resize(static_cast<size_t>(ts.num_reals));
|
tags.push_back(tag);
|
||||||
for (size_t i = 0; i < static_cast<size_t>(ts.num_reals); ++i) {
|
}
|
||||||
tag.floatValues[i] = parseReal(&token);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
tag.stringValues.resize(static_cast<size_t>(ts.num_strings));
|
|
||||||
for (size_t i = 0; i < static_cast<size_t>(ts.num_strings); ++i) {
|
|
||||||
tag.stringValues[i] = parseString(&token);
|
|
||||||
}
|
|
||||||
|
|
||||||
tags.push_back(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (token[0] == 'v' && IS_SPACE((token[2]))) {
|
||||||
|
// normal
|
||||||
|
if (token[1] == 'n') {
|
||||||
|
token += 3;
|
||||||
|
real_t x, y, z;
|
||||||
|
parseReal3(&x, &y, &z, &token);
|
||||||
|
vn.push_back(x);
|
||||||
|
vn.push_back(y);
|
||||||
|
vn.push_back(z);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// texcoord
|
||||||
|
if (token[1] == 't') {
|
||||||
|
token += 3;
|
||||||
|
real_t x, y;
|
||||||
|
parseReal2(&x, &y, &token);
|
||||||
|
vt.push_back(x);
|
||||||
|
vt.push_back(y);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//tigra: refactoring for new speedup release
|
//tigra: refactoring for new speedup release
|
||||||
//tigra: compares one more start
|
//tigra: compares one more start
|
||||||
|
|||||||
Reference in New Issue
Block a user