Fixed OBJ loader

Former-commit-id: 492b5fa542b8744021ff11de4d0e4492a28203ac
This commit is contained in:
Lynix 2013-04-01 03:03:02 +02:00
parent 8c942ef19b
commit 650e317c04
1 changed files with 27 additions and 33 deletions

View File

@ -137,31 +137,13 @@ bool NzOBJParser::Parse()
int& p = face.vertices[i].position; int& p = face.vertices[i].position;
int& t = face.vertices[i].texCoord; int& t = face.vertices[i].texCoord;
if (std::sscanf(&m_currentLine[pos], "%d/%d/%d%n", &p, &t, &n, &offset) == 3) if (std::sscanf(&m_currentLine[pos], "%d/%d/%d%n", &p, &t, &n, &offset) != 3)
{ {
p--; if (std::sscanf(&m_currentLine[pos], "%d//%d%n", &p, &n, &offset) != 2)
t--;
n--;
}
else if (std::sscanf(&m_currentLine[pos], "%d//%d%n", &p, &n, &offset) == 2)
{ {
p--; if (std::sscanf(&m_currentLine[pos], "%d/%d%n", &p, &t, &offset) != 2)
n--;
t = -1;
}
else if (std::sscanf(&m_currentLine[pos], "%d/%d%n", &p, &t, &offset) == 2)
{ {
p--; if (std::sscanf(&m_currentLine[pos], "%d%n", &p, &offset) != 1)
n = -1;
t--;
}
else if (std::sscanf(&m_currentLine[pos], "%d%n", &p, &offset) == 1)
{
p--;
n = -1;
t = -1;
}
else
{ {
#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
UnrecognizedLine(); UnrecognizedLine();
@ -169,10 +151,22 @@ bool NzOBJParser::Parse()
error = true; error = true;
break; break;
} }
else
{
n = 0;
t = 0;
}
}
else
n = 0;
}
else
t = 0;
}
if (p < 0) if (p < 0)
{ {
p += m_positions.size() + 1; p += m_positions.size();
if (p < 0) if (p < 0)
{ {
Error("Vertex index out of range (" + NzString::Number(p) + " < 0"); Error("Vertex index out of range (" + NzString::Number(p) + " < 0");
@ -185,7 +179,7 @@ bool NzOBJParser::Parse()
if (n < 0) if (n < 0)
{ {
n += m_normals.size() + 1; n += m_normals.size();
if (n < 0) if (n < 0)
{ {
Error("Vertex index out of range (" + NzString::Number(n) + " < 0"); Error("Vertex index out of range (" + NzString::Number(n) + " < 0");
@ -198,7 +192,7 @@ bool NzOBJParser::Parse()
if (t < 0) if (t < 0)
{ {
t += m_texCoords.size() + 1; t += m_texCoords.size();
if (t < 0) if (t < 0)
{ {
Error("Vertex index out of range (" + NzString::Number(t) + " < 0"); Error("Vertex index out of range (" + NzString::Number(t) + " < 0");