From c29109d1a4ee237d60d4334acfbceb95b2e5cf3a Mon Sep 17 00:00:00 2001 From: Calvin Hsu Date: Mon, 30 Sep 2013 15:12:56 -0700 Subject: [PATCH 1/2] obj: Fix tabs causing vertices to be skipped If an obj vertex definition 'v' is followed by a tab instead of a space, the vertex definition is skipped. --- code/ObjFileParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index ab8fdd124..3d81ab925 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -112,7 +112,7 @@ void ObjFileParser::parseFile() case 'v': // Parse a vertex texture coordinate { ++m_DataIt; - if (*m_DataIt == ' ') + if (*m_DataIt == ' ' || *m_DataIt == '\t') { // Read in vertex definition getVector3(m_pModel->m_Vertices); From 32a10ec0a040aad78e3d9e5cbdac336a76af2903 Mon Sep 17 00:00:00 2001 From: Calvin Hsu Date: Mon, 30 Sep 2013 15:13:11 -0700 Subject: [PATCH 2/2] obj: Add support for relative vertex indexing obj files allow faces to specify indices relatively by using negative integers. See vertex refering in http://www.martinreddy.net/gfx/3d/OBJ.spec --- code/ObjFileParser.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index 3d81ab925..e701ddc62 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -290,6 +290,10 @@ void ObjFileParser::getFace(aiPrimitiveType type) std::vector *pNormalID = new std::vector; bool hasNormal = false; + const int vSize = m_pModel->m_Vertices.size(); + const int vtSize = m_pModel->m_TextureCoord.size(); + const int vnSize = m_pModel->m_Normals.size(); + const bool vt = (!m_pModel->m_TextureCoord.empty()); const bool vn = (!m_pModel->m_Normals.empty()); int iStep = 0, iPos = 0; @@ -323,7 +327,11 @@ void ObjFileParser::getFace(aiPrimitiveType type) { //OBJ USES 1 Base ARRAYS!!!! const int iVal = atoi( pPtr ); + + // increment iStep position based off of the sign and # of digits int tmp = iVal; + if (iVal < 0) + ++iStep; while ( ( tmp = tmp / 10 )!=0 ) ++iStep; @@ -348,6 +356,27 @@ void ObjFileParser::getFace(aiPrimitiveType type) reportErrorTokenInFace(); } } + else if ( iVal < 0 ) + { + // Store relatively index + if ( 0 == iPos ) + { + pIndices->push_back( vSize + iVal ); + } + else if ( 1 == iPos ) + { + pTexID->push_back( vtSize + iVal ); + } + else if ( 2 == iPos ) + { + pNormalID->push_back( vnSize + iVal ); + hasNormal = true; + } + else + { + reportErrorTokenInFace(); + } + } } pPtr += iStep; }