From 8be83c0e45b0e0ef5bcc1945b36556f2f5bb46cf Mon Sep 17 00:00:00 2001 From: cignoni Date: Wed, 23 Sep 2009 15:09:05 +0000 Subject: [PATCH] Added support of reading QOBJ variant of obj files (just quads) --- wrap/io_trimesh/import_obj.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/wrap/io_trimesh/import_obj.h b/wrap/io_trimesh/import_obj.h index f4494602..2878ca5e 100644 --- a/wrap/io_trimesh/import_obj.h +++ b/wrap/io_trimesh/import_obj.h @@ -378,8 +378,11 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi) numVNormals++; } - else if (header.compare("f")==0) // face + else if( (header.compare("f")==0) || (header.compare("q")==0) ) // face { + bool QuadFlag = false; // QOBJ format by Silva et al for simply storing quadrangular meshes. + if(header.compare("q")==0) { QuadFlag=true; assert(numTokens == 5); } + if (numTokens < 4) return E_LESS_THAN_3VERTINFACE; int vertexesPerFace = static_cast(tokens.size()-1); @@ -448,9 +451,11 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi) std::string vertex; std::string texcoord; std::string normal; - for(int i=0;i<3;++i) // remember index starts from 1 instead of 0 + for(int i=0;i<3;++i) + { // remember index starts from 1 instead of 0 SplitToken(tokens[i+1], ff.v[i], ff.n[i], ff.t[i], oi.mask); - + if(QuadFlag) { ff.v[i]+=1; } + } if ( oi.mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD ) { // verifying validity of texture coords indices @@ -512,11 +517,12 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi) while (iVertex < vertexesPerFace) // add other triangles { ObjIndexedFace ffNew=ff; - int v4_index; + int v4_index; int vt4_index; int vn4_index; SplitToken(tokens[++iVertex], v4_index, vn4_index, vt4_index, oi.mask); + if(QuadFlag) { v4_index+=1; } if(!GoodObjIndex(v4_index, numVertices)) return E_BAD_VERT_INDEX; @@ -867,7 +873,7 @@ static bool LoadMask(const char * filename, Info &oi) if(line[1]=='n') bHasNormals = true; } else - if(line[0]=='f') oi.numFaces++; + if((line[0]=='f') || (line[0]=='q')) oi.numFaces++; else if(line[0]=='u' && line[1]=='s') bHasPerFaceColor = true; // there is a usematerial so add per face color }